I made a very simple camera controller class which uses a sphere object. LinearVelocity and AngularMomentum are applied to the sphere based on user input. It's a free floating camera, no gravity.
When I look around fast (using AngularMomentum) the sphere "rolls". How can I make the sphere maintain "up" and "down" and stop rolling?
Pretty sure I'm missing the basics again...
Thank you.
Stop Sphere object from rolling
Re: Stop Sphere object from rolling
The easiest way to handle a sphere-based camera is to totally disable angular motion by setting the entity.LocalInertiaTensorInverse = new Matrix3x3(), i.e. all zeroes. The camera's rotation would then be directly tied to user input rather than involving the orientation of the sphere.
If you want to maintain physical yaw as a behavior but want a fixed up direction, you could set only the first and third rows of the entity.LocalInertiaTensorInverse to zeroes.
Allowing pitch and yaw but disallowing all roll (even roll that happens to occur through combinations of pitching and yawing) is a little trickier, but doable- you would just have to measure and control the orientation more tightly according to whatever behavior you desired.
For a typical camera, though, usually disabling all physical rotation is the easiest and most effective.
If you want to maintain physical yaw as a behavior but want a fixed up direction, you could set only the first and third rows of the entity.LocalInertiaTensorInverse to zeroes.
Allowing pitch and yaw but disallowing all roll (even roll that happens to occur through combinations of pitching and yawing) is a little trickier, but doable- you would just have to measure and control the orientation more tightly according to whatever behavior you desired.
For a typical camera, though, usually disabling all physical rotation is the easiest and most effective.
Re: Stop Sphere object from rolling
ok... I will turn off physical rotation then.
Next question is how can I rotate the sphere?
Normally I would use Matrix.CreateRotationY or something like that, but how to do that with Matrix3X3 (which doesn't have a similar method as I understand)?
If it has anything to do with Quaternions please don't assume that I understand them (I don't...)
Next question is how can I rotate the sphere?
Normally I would use Matrix.CreateRotationY or something like that, but how to do that with Matrix3X3 (which doesn't have a similar method as I understand)?
If it has anything to do with Quaternions please don't assume that I understand them (I don't...)
-
- Posts: 91
- Joined: Tue May 14, 2013 12:17 pm
Re: Stop Sphere object from rolling
You can use conversions between Matrix4x4 and Matrix3x3, like this :
Where matrixOut will be the conversion of your matrix ( 3x3 ) to a matrix 4x4.
You also do the invert matrix4x4 to matrix3x3 like :
Code: Select all
Matrix3x3.ToMatrix4X4(ref matrixFrom, out matrixOut);
You also do the invert matrix4x4 to matrix3x3 like :
Code: Select all
Matrix3x3.CreateFromMatrix(ref matrixFrom, out matrixOut);
Re: Stop Sphere object from rolling
The easiest option is to simply not rotate the sphere. Just allow the camera to control its own orientation independently of whatever the sphere's fixed rotation is.
If you did, however, want to rotate the sphere, then you could either use Matrix3x3.CreateFromAxisAngle to simulate the CreateRotationY etc. functions, or you could create a Matrix directly and convert it to a Matrix3x3 using the Matrix3x3.CreateFromMatrix function. (Edit: as kavatortank mentioned)
You could also use quaternions. Don't be too scared of them
For your purposes, you can treat them as rotations, just like you do with rotation matrices; you don't need to be perfectly familiar with their inner workings. Just be careful about the multiply order. The XNA Quaternion * operator is the Quaternion.Multiply method, which is the opposite order from Matrix.Multiply. Quaternion.Concatenate has the same order as Matrix.Multiply.
If you did, however, want to rotate the sphere, then you could either use Matrix3x3.CreateFromAxisAngle to simulate the CreateRotationY etc. functions, or you could create a Matrix directly and convert it to a Matrix3x3 using the Matrix3x3.CreateFromMatrix function. (Edit: as kavatortank mentioned)
You could also use quaternions. Don't be too scared of them

Re: Stop Sphere object from rolling
Thanks guys. I'll try it out.