Ok, Greg i understand what you want to say.
I was wondering how to show you my problem... and i did another example which should better describe this situation. I know the code is bad and ugly but is just example...
Just run code and wait 3 steps, the 4th step is the clue of my question.
Next you can press Z for change rotation axis and as you can see all working fine.
Code:
/******************************************************************************/
Actor ground,
box,
gun;
flt angle_full_x,
angle_full_y,
angle_full_z,
angle_base;
flt angle_counter = 0.0;
flt angle_max = 0.785;
flt pause_counter = 0.0;
bool paused = false;
VecI rot_axis = VecI(1, 0, 0);
/******************************************************************************/
void reset()
{
paused = true;
pause_counter = 0.0;
angle_counter = 0.0;
box.matrix(box.matrix().setPos(Vec(0.0, 0.0, 0.0)));
angle_base = (rot_axis * box.orn().angles()).sum();
}
/******************************************************************************/
void InitPre()
{
EE_INIT();
Ms.hide();
Ms.clip(null, 1);
}
bool Init()
{
Cam.dist=4;
// create physics
Physics.create(EE_PHYSX_DLL_PATH); // create physics by specifying the path to physx dll's
// create actors
ground.create(Box ( 15, 1, 15, Vec(0.0, -2, 0)), 0); // create ground actor from Box and density=0 (which means it's a static actor - will not move)
box.create(Box (0.5, Vec(0.0, 0.0, 0.0)));
gun.create(Tube(0.1, 3.0));
box.kinematic(true).collision(false);
gun.kinematic(true).collision(false);
// get angle startup value
angle_base = box.orn().angles().x;
return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
if(Kb.bp(KB_ESC))return false;
Cam.transformByMouse(0.1, 10, CAMH_ZOOM|CAMH_ROT);
{
Physics.startSimulation();
Physics.stopSimulation();
}
if(Kb.bp(KB_X)){ rot_axis = VecI(1, 0, 0); reset(); }
if(Kb.bp(KB_Y)){ rot_axis = VecI(0, 1, 0); reset(); }
if(Kb.bp(KB_Z)){ rot_axis = VecI(0, 0, 1); reset(); }
if(paused) // pause
{
pause_counter += Time.d();
if(pause_counter >= 1.0)
{
paused = false;
pause_counter = 0.0;
}
}else // rotation
{
angle_counter += Time.d();
box.orn(box.orn().setRotate(rot_axis, angle_base + angle_counter));
if(angle_counter >= angle_max)
{
box.orn(box.orn().setRotate(rot_axis, angle_base + angle_max));
angle_base = (rot_axis * box.orn().angles()).sum();
paused = true;
angle_counter = 0.0;
}
}
// gun matrix
gun.matrix(box.matrix() );
gun.pos (box.matrix().y * 2.0);
// get full angles
angle_full_x = AngleFull(box.orn().angles().x);
angle_full_y = AngleFull(box.orn().angles().y);
angle_full_z = AngleFull(box.orn().angles().z);
return true;
}
/******************************************************************************/
void Draw()
{
D.clear ();
Physics.draw();
{
SetMatrix();
box.matrix().pos.draw(WHITE, 0.02);
D.line(RED , box.pos(), box.pos() + box.matrix().x);
D.line(GREEN, box.pos(), box.pos() + box.matrix().y);
D.line(BLUE , box.pos(), box.pos() + box.matrix().z);
}
TextStyle ts;
ts.align = Vec2( 1, -1);
ts.size = Vec2(0.06, 0.06);
Flt y = D.h();
D.text(ts, -D.w() + 0.03, y, S + "Current box rot axis (X,Y,Z): " + rot_axis + " Press [X], [Y], [Z] - to select rotation axis."); y -= 0.06; y -= 0.06;
//D.text(ts, -D.w() + 0.03, y, S + "box.pos = " + box.pos() ); y -= 0.06;
//D.text(ts, -D.w() + 0.03, y, S + "box.matrix.angles = " + box.matrix().angles() ); y -= 0.06; y -= 0.06;
D.text(ts, -D.w() + 0.03, y, S + "RED - box.angle.x = " + angle_full_x + " rad | " + RadToDeg(angle_full_x) + " deg"); y -= 0.06;
D.text(ts, -D.w() + 0.03, y, S + "GREEN - box.angle.y = " + angle_full_y + " rad | " + RadToDeg(angle_full_y) + " deg"); y -= 0.06;
D.text(ts, -D.w() + 0.03, y, S + "BLUE - box.angle.z = " + angle_full_z + " rad | " + RadToDeg(angle_full_z) + " deg"); y -= 0.06;y -= 0.06;
D.text(ts, -D.w() + 0.03, y, S + "box angle_full_x = " + angle_full_x ); y -= 0.06;
D.text(ts, -D.w() + 0.03, y, S + "box angle_full_y = " + angle_full_y ); y -= 0.06;
D.text(ts, -D.w() + 0.03, y, S + "box angle_full_z = " + angle_full_z ); y -= 0.06;
}
/******************************************************************************/