Ogre Version: 1.10
Operating System: Win10
Render System: D3d11
Hey guys. Been forever since I posted here but I have a question for the math and 3d whizzes out there. I know the easy way to handle an FPS camera is separate yaw and pitch nodes but it really got me wondering - Is it actually possible to make an FPS style camera with only a single scenenode that the camera is attached to? Strictly speaking, using only vectors and quaternions to handle the rotations, is there any way possible to do it? Not talking Euler rotations here. Would love to see examples if this can actually be achieved or the actual reason why if it is simply not possible. Thanks!
EDIT: Forgot to mention a FPS style camera that doesn't induce roll
FPS style camera with a single scenenode?
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
FPS style camera with a single scenenode?
Last edited by drwbns on Tue Jan 11, 2022 4:28 am, edited 1 time in total.
- sercero
- Bronze Sponsor
- Posts: 449
- Joined: Sun Jan 18, 2015 4:20 pm
- Location: Buenos Aires, Argentina
- x 156
Re: FPS style camera with a single scenenode?
I think that it is not possible as you probably are being told by your intuition.
If you start using quaternions and vectors in addition to the node the most likely outcome is that you will end up creating an additional (virtual) node the same way as the standard solution.
I discovered this the hard way trying to do a 3rd person camera with only two nodes and being always a degree of freedom short. (tried spherical and cylindrical coordinates, in the end it didn't matter).
All my problems were solved when I ended up adding the third node.
Hopefully someone can give a more proper or formal answer.
If you start using quaternions and vectors in addition to the node the most likely outcome is that you will end up creating an additional (virtual) node the same way as the standard solution.
I discovered this the hard way trying to do a 3rd person camera with only two nodes and being always a degree of freedom short. (tried spherical and cylindrical coordinates, in the end it didn't matter).
All my problems were solved when I ended up adding the third node.
Hopefully someone can give a more proper or formal answer.
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Re: FPS style camera with a single scenenode?
I realized there is totally a way to do it and answered my own question. Something like this works:
I believe that's what the SetFixedYawAxis() function can handle as well but will have to try that. But still curious if this can be done in a single call to rotate() without inducing roll.
EDIT: For reference, this did not work as expected:
I am assuming I have the wrong idea about what setFixedYawAxis() is capable of.
EDIT2: I found that rotating the single camera node loses proper track of the angle of rotation around the X-axis which is needed to make sure the player can't pitch up and down in 360 degrees of freedom. The pitch angle is falsely reported when turning left or right when using a single scenenode for FPS style camera instead of the proper 2 scenenodes.
Example:
Code: Select all
getCameraNode()->rotate(qPitch);
getCameraNode()->rotate(qYaw,Ogre::Node::TS_WORLD);
EDIT: For reference, this did not work as expected:
Code: Select all
getCameraNode()->setFixedYawAxis(false);
getCameraNode()->rotate(qPitch);
getCameraNode()->setFixedYawAxis(true, Ogre::Vector3::UNIT_Y);
getCameraNode()->rotate(qYaw);
EDIT2: I found that rotating the single camera node loses proper track of the angle of rotation around the X-axis which is needed to make sure the player can't pitch up and down in 360 degrees of freedom. The pitch angle is falsely reported when turning left or right when using a single scenenode for FPS style camera instead of the proper 2 scenenodes.
Example:
Code: Select all
float pitchAngle = (2 * Ogre::Degree(Ogre::Math::ACos(getCameraNode()->getOrientation().w)).valueDegrees());
// Just to determine the sign of the angle we pick up above, the
// value itself does not interest us.
float pitchAngleSign = getCameraNode()->getOrientation().x;
// Limit the pitch between -90 degress and +90 degrees, Quake3-style.
if (pitchAngle > 90.0f)
{
if (pitchAngleSign > 0)
// Set orientation to 90 degrees on X-axis.
getCameraNode()->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),
Ogre::Math::Sqrt(0.5f), 0, 0));
else if (pitchAngleSign < 0)
// Sets orientation to -90 degrees on X-axis.
getCameraNode()->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),
-Ogre::Math::Sqrt(0.5f), 0, 0));
}
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Re: FPS style camera with a single scenenode?
Thanks Paroj! I'll have to check out the source for that. Are there any tutorials that explain how the cameraMan class works?
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact: