Primitives (here cube) are centred in World Space. I want to rotate them by slider as in image below.
[ATTACH=CONFIG]898[/ATTACH]
So far I’m using this code:
This is rot object definition:
struct rotation
{
float x = 180;
float y = 180;
float z = 180;
}
This stuff is executed when user changes slider’s position
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;
}
}
This stuff is executed all time (on frames change):
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);
I know it isn’t good approach because sometimes ( when I mix x,y,z positions) rotations aren’t performed properly. For example when I rotate around x axis it looks like it was turned around y axis.
I’m looking for properly approach.