Skip to content

Instantly share code, notes, and snippets.

@tsterker
Last active December 24, 2015 23:39
Show Gist options
  • Save tsterker/6882467 to your computer and use it in GitHub Desktop.
Save tsterker/6882467 to your computer and use it in GitHub Desktop.
void drawFaceNormals()
{
glColor3f(0,0,1); // The colour we will be drawing is white (red = 1, green = 1, blue = 1).
vector<vec3> verts = trig.Vertices();
vector<vec3> fnorms = trig.FaceNormals();
vec3 fnorm, pos, from, to;
glBegin(GL_LINES);
for(int i = 0; i < fnorms.size(); i++){
fnorm = 10.0f*fnorms[i];
vec3 pos1 = verts[i*3];
vec3 pos2 = verts[i*3+1];
vec3 pos3 = verts[i*3+2];
float mul = 1/2.0f;
vec3 center = mul*pos1 + mul*(pos2-pos1) + mul*(pos3 - mul*(pos2-pos1));
from = vec3(mvp * vec4(center, 1.0f));
to = vec3(mvp * vec4(center+fnorm, 1.0f));
glVertex3f(from.x, from.y, from.z);
glVertex3f(to.x, to.y, to.z);
}
glEnd();
}
void drawVertexNormals()
{
vector<vec3> verts = trig.Vertices();
vector<vec3> vnorms = trig.VertexNormals();
vec3 vnorm, pos, from, to;
glColor3f(0,1,0); // The colour we will be drawing is white (red = 1, green = 1, blue = 1).
glBegin(GL_LINES);
for(int i = 0; i < vnorms.size(); i++){
vnorm = 10.0f*vnorms[i];
vec3 pos = verts[i];
from = vec3(mvp * vec4(pos, 1.0f));
to = vec3(mvp* vec4(pos+vnorm, 1.0f));
glVertex3f(from.x, from.y, from.z);
glVertex3f(to.x, to.y, to.z);
}
glEnd();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment