2016年3月28日 星期一

week 06 Jim_c OpenGL

Mid-term pratice
glPushMatrix();//push =back up 
glRotatef(x,y,z);//移动
glScalef(x,y,z);//缩放
glBegin(GL_POLYGON);//开始画
  glNormal3f(nx,ny,nz);//法方向
  glTextCoord2f(tx,ty);//贴图坐标
  glColor3f(r,g,b);//色彩
  glVertex3f(x,y,z);//顶点
glEnd();
glPopMatrix();//pop =recover to default 矩阵还原

Class work -01
open (jsyeh/3dcg10)>download>data,window32,glut32> 
>extract window 32 file 
>extract data file into window 32
>place glut 32 into window 32


open light material.exe>to practice light in GL

material parameters-changing color

Class work-02
打光
use teacher source file

copy and paste the light program for pratice

>> glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);  //must include depth for doing 3d object
>>const GLfloat light_position[] = { 2.0f, 5.0f, -5.0f, 0.0f };//光打下的对焦

>>glEnable(GL_LIGHT0);      //开启一下功能
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

Class work 03

>>Changing light propeties
const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 0.5f };
const GLfloat light_diffuse[]  = { 1.0f, 0.0f, 0.0f, 2.0f };
const GLfloat light_specular[] = { 1.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, -5.0f, -5.0f, 0.0f };/

>>Mouse poiting light
void motion(int x,int y) //滑鼠按下后的函数
{
    light_position[0]=(x-150)/150.0;
    light_position[1]=-(y-150)/150.0;
    glLightfv(GL_LIGHT0,GL_POSITION,light_position);
    glutPostRedisplay();
    printf("%f %f\n",light_position[0],light_position[1]);


}

沒有留言:

張貼留言