Transformation
轉動理解:右手安陪定律
數字越大>>>逆時針
數字越小>>>順時針

方向
-----------------------------------------------------------------

旋轉正題
float myAngle=0;
void motion(int x, int y)
{
myAngle =x;
glutPostRedisplay();
}
static void display(void)
{
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = myAngle;
glutMotionFunc(motion);
變化1(結合)
滑鼠左右圖會跟著轉

#include <GL/glut.h>
float myAngle=0;
void motion(int x, int y)
{
myAngle =x;
glutPostRedisplay(); 上一個程式
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(myAngle,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix(); 上周程式
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week04");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
變化2(加入)
滑鼠按著才能轉
#include <GL/glut.h>
float myAngle=0, oldX=0;
void motion(int x, int y)
{
myAngle +=(x-oldX);
oldX =x;
glutPostRedisplay();
}
void mouse(int button,int state,int x, int y)
{
oldX=x; 把按下去的位置記起來
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(myAngle,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week04");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
每次會換基準點,再重新的點出發

沒有留言:
張貼留言