0
基元以世界空间为中心。我想通过滑块来旋转它们,如下图所示。基本元素通过滑块围绕世界空间中的x,y,z轴旋转
到目前为止,我正在使用此代码:
这是腐对象定义:
struct rotation
{
float x = 180;
float y = 180;
float z = 180;
}
当用户改变滑块的位置执行这东西
void MyFrame::OnSliderChanged(wxScrollEvent &event)
{
//cur_sel is currently selected primitive and scene
switch(event.GetId())
{
case ID_SLIDER0: //slider X
GLCanvas->rot[GLCanvas->cur_sel].x = event.GetPosition();
break;
case ID_SLIDER1: //slider Y
GLCanvas->rot[GLCanvas->cur_sel].y = event.GetPosition();
break;
case ID_SLIDER2: //slider Z
GLCanvas->rot[GLCanvas->cur_sel].z = event.GetPosition();
break;
}
}
这个东西是所有的时间执行(在帧改变) :
glRotatef(rot[cur_sel].x,rot[cur_sel].x, 0.0f, 0.0f);
glRotatef(rot[cur_sel].y,0.0f, rot[cur_sel].y, 0.0f);
glRotatef(rot[cur_sel].z,0.0f, 0.0f, rot[cur_sel].z);
我知道这是不好的方法,因为有时(当我混合x,y,z位置)旋转不正确执行。例如,当我围绕x轴旋转时,它看起来像绕y轴转动。
我正在寻找适当的方法。