quaternion camera
-
- Posts: 52
- Joined: Wed Mar 03, 2010 7:11 pm
quaternion camera
does anyone have a tutorial or code snippets of how to rotate a camera with quaternions? I've plowed through the tutorials, and i thought I saw one in the past, but haven't been able to find one.
Kamikaze
this one might be worth looking into
not sure if its quaternion or not (havent looked myself)
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=26526
not sure if its quaternion or not (havent looked myself)
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=26526
-
- Posts: 52
- Joined: Wed Mar 03, 2010 7:11 pm
-
- Posts: 52
- Joined: Wed Mar 03, 2010 7:11 pm
well, what exactly do you mean by "rotate"? what is the effect you want to achieve? and why do you want to use quaternions for it?
Conversions are here:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=38283
Conversions are here:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=38283
-
- Posts: 52
- Joined: Wed Mar 03, 2010 7:11 pm
I want to rotate the camera in the X and Y axis's. (up, down, left, right).
the class i have right now which is suffering from gimbal lock, as i'm not using quaternions correctly is...
the class i have right now which is suffering from gimbal lock, as i'm not using quaternions correctly is...
Code: Select all
void CameraRotate(irr::scene::ISceneNode *node, irr::f32 cameraangle, irr::core::vector3df axis)
{
vector3df rotation;
quaternion first;
//create quaternion from angle and axis
first.fromAngleAxis(cameraangle, axis);
first.normalize();
//converting angle and axis to euler angle
first.toEuler(rotation);
//getting current rotation of your node
vector3df currentrot = node->getRotation();
matrix4 m1;
//setup your first matrix with your current rotation
m1.setRotationDegrees(currentrot);
matrix4 m2;
//setup your second matrix with your quaternion angle and axis
m2.setRotationDegrees(rotation);
//multiply together
m1 *= m2;
//set node to your resultant rotation
node->setRotation(m1.getRotationDegrees());
}
Kamikaze
you have to convert the result from toEuler to degrees.
first.toEuler(rotation);
rotation *= core::RADTODEG;
I guess your code using only quaternions would be something like:
Not tested. Also I don't know if the order of multiplication matters.
first.toEuler(rotation);
rotation *= core::RADTODEG;
I guess your code using only quaternions would be something like:
Code: Select all
void CameraRotate(irr::scene::ISceneNode *node, irr::f32 cameraangle, irr::core::vector3df axis)
{
quaternion first;
//create quaternion from angle and axis
first.fromAngleAxis(cameraangle, axis);
first.normalize();
core::quaternion qCurrentRot( node->getRotation() * core::DEGTORAD );
qCurrentRot = first * qCurrentRot;
core::vector3df newRotEuler;
qCurrentRot.toEuler(newRotEuler);
newRotEuler *= core::RADTODEG;
node->setRotation(newRotEuler);
}
-
- Posts: 52
- Joined: Wed Mar 03, 2010 7:11 pm
well it seems to move alot faster, but it still appears to suffer from gimbal lock, at some points ill be moving the Y axis up and down and will instead around the Z axis. =(
for cameraangle and axis im passing in this values (don't know if they make a difference)
cameraangle (-0.2f) or (0.2f) for direction
axis = (0.0f, 0.3f, 0.0f) for moving in Y direction
for cameraangle and axis im passing in this values (don't know if they make a difference)
cameraangle (-0.2f) or (0.2f) for direction
axis = (0.0f, 0.3f, 0.0f) for moving in Y direction
Kamikaze