【发布时间】:2015-02-08 16:15:42
【问题描述】:
基元以世界空间为中心。我想通过滑块旋转它们,如下图所示。
到目前为止,我正在使用此代码:
这是腐烂的对象定义:
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 轴旋转。
我正在寻找合适的方法。
【问题讨论】:
标签: c++ opengl rotation slider