《垂直於平面的法向量(perpendicular.ppt》由会员分享,可在线阅读,更多相关《垂直於平面的法向量(perpendicular.ppt(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、NormalsSpecifying the normalvoid glNormal3d(GLdouble nx,GLdouble ny,GLdouble nz);When using lighting effects,normals must be defined for each polygon or for each vertex.OpenGL does not calculate a normal by itself.垂直於平面的法向量(perpendicular to a plane)單位法向量(normalized normal vector)Normal VectorWhat is
2、 cross product(外積)Normalized Normal VectorV=(Vx,Vy,Vz),Length of V=|V|=(Vx2+Vy2+Vz2)1/2Normalized Normal Vector V=(Vx,Vy,Vz)/|V|=(Vx/|V|,Vy/|V|,Vz/|V|)Shading ModelsChoose the shading modelvoid glShadeModel(GLenum mode);mode may beGL_FLATGL_SMOOTH(the same as the Gouraud shading model)OpenGL does no
3、t support the Phong shading model.Material PropertiesAn object has a certain reflective propertiesWhen using lighting,each model part has its own material properties,which also define its color.glMaterialfv(GLenum face,GLenum pname,const GLfloat*params)Face must be one of GL_FRONT,GL_BACK,or GL_FRON
4、T_AND_BACK.pname can be GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_SHININESS etc.params change accordingly.ColorsIn case you want to specify colors per face or per vertex,you mustEnable color tracking.glEnable(GL_COLOR_MATRERIAL);Set material properties to follow glColor values.glColorMaterial(GLenum face
5、,GLenum mode);Specify the color before defining its corresponding vertex.glColor3d(GLdouble red,GLdouble green,GLdouble blue);glColor3ub(GLubyte red,GLubyte green,GLubyte blue);Adding Light to a SceneEnabling lightingglEnable(GL_LIGHT);OpenGL supports up to GL_MAX_LIGHTS lights simultaneouslyQuery with glGetIntegerv(GL_MAX_LIGHTS)Set the light propertiesvoid glLightfv(GLenum light,GLenum pname,const GLfloat*params);pname can be GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_POSITION etc.params change accordingly.Enable the specific lightglEnable(GL_LIGHTi);i is between 0 and GL_MAX_LIGHTS-1