Mouse-Lighting
1.打開glut專案
找到idle函式與main中的lighting相關程式碼
2.light_position表示光的位址
glutMotionFunc(motion); 表示滑鼠的改變
將const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f }; 前面的const 刪去
即可改變light_position的變數
3.加上函式
void motion(int x, int y)
{
light_position[0]=(x-150*2)/150.0*2; //更變光源座標為滑鼠座標
light_position[1]=-(y-150)/150.0*2;
glLightfv(GL_LIGHT0,GL_POSITION,light_position); //重設光源
glutPostRedisplay(); //重畫
}
在main中加上glutMotionFunc(motion); //mouse motion函式
4.編譯執行
完成!
沒有留言:
張貼留言