我希望能夠通過按下鍵盤上的某些按鍵來翻譯較小的多維數據集。在opengl中翻譯另一個形狀內的形狀
下面是我試圖完成這件事:
initialy X = 0,Y = 0,Z = 0,原點= 0,但全球範圍
void key_board(unsigned char key, int xx, int yy){//call back func for the glutKeyboardFunc
switch (key){
case 'x':
if(origin >= 0 && opposite >= 0){
opposite = 1 - size -origin;
x +=opposite;
break;
}
case 'y':
if(origin >= 0 && opposite >= 0){
opposite = 1 - size -origin;
y +=opposite;
break;
}
case 'z':
if(origin >= 0 && opposite >= 0){
opposite = 1 - size -origin;
z +=opposite;
break;
}
}
}
void solid_cube(double size){//this is the cube i would like to translate within the larger one,only perpendicular translation to the wall of bigger box are allowed
glPushMatrix();
glLineWidth(1.7f);
glShadeModel(GL_SMOOTH);
glColor3f(1.0f,0.0f,1.0f);
glTranslatef(x, y, z);
glutSolidCube(size);
}
void display(){//display call back func
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH);
gluPerspective(30.0, 4.0/3.0, 0.1f, 10.0);
glFrustum(3.0, 5.0, 3.0, 3.0, 5.0, 10.0);
gluLookAt(2.0,0,2.0,0.0,0.0,0.0,1.0,1.0,1.0);
glLineWidth(1.7f);
glColor3f(0.0f,0.0f,1.0f);
glutWireCube(1.0);
solid_cube(0.3);//smaller cube to be moved around
glutSwapBuffers();
}
「x」,「y」和「z」的值已初始化到什麼位置? – elimad 2014-09-30 15:40:01
所有'零'和全球 – Emma 2014-09-30 15:45:58
如果'大小'恰好是'1','相反= 1 - 大小-origin;'將評估爲'0',什麼也沒有發生 – user1781290 2014-09-30 15:48:20