我用glTranslate将我的对象翻译到另一个位置。但问题是法线保持原状。如何将它们与对象顶点一起翻译。 我读到了使用逆模型视图矩阵的转置。但这不起作用。它延伸了我的整个模型。我已经将这段代码留在了需要//翻译法线
的评论中//Rotate model because Z axes is up
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(4, 4, 0.7);
glRotatef(90, 1.0, 0, 0);
//translate normals
//glGetDoublev(GL_MODELVIEW_MATRIX, matrix);
//printMatrix(matrix);
//inverse(matrix, inverseM);
//transpose(inverseM);
//printMatrix(inverseM);
//glMultMatrixd(inverseM);
glBegin(GL_TRIANGLES);
for (int i = 0; i<triangles.size(); ++i)
{
Vec3Df edge01 = vertices[triangles[i].v[1]].p - vertices[triangles[i].v[0]].p;
Vec3Df edge02 = vertices[triangles[i].v[2]].p - vertices[triangles[i].v[0]].p;
Vec3Df n = Vec3Df::crossProduct(edge01, edge02);
n.normalize();
glNormal3f(n[0], n[1], n[2]);
for (int v = 0; v < 3; v++) {
//color
if (triangles[i].v[v] < meshColor.size()) {
glColor3f(meshColor[triangles[i].v[v]].p[0], meshColor[triangles[i].v[v]].p[1], meshColor[triangles[i].v[v]].p[2]);
glVertex3f(vertices[triangles[i].v[v]].p[0], vertices[triangles[i].v[v]].p[1], vertices[triangles[i].v[v]].p[2]);
}
}
}
glEnd();
glPopMatrix();