
[Solved] Rotation axis
Posted Wednesday, 24 June, 2009 - 12:06 by Soundbomber inHow do I find a Vector that represents an axis corresponding to a 2D x and y axis in 3D space.
To explain, I have a 3D model which I am viewing through a camera position which is variable (variable eye position).
So I could be looking at my 3D object from above and to the right, or below and to the left, and anywhere inbetween.
I want to rotate my object about what would be the screen x or y axis in 2D.
Any suggestions?


Comments
Re: Rotation axis
Are you saying you want to confine a 3d object to a single 2d plane?
If you restrict the object to a 2d plane such that a it's z-position never changes, and have it only ever facing in a direction on that plane, the only rotation-axis you'll need is Vector3.UnitZ.
If you need something more general (e,g. if for some reason you had two or more non-parallel 2d planes) then you can still use these basic coordinates to specify the x,y position of units, in these planes, but just carry out a transform on the modelview matrix to set it up prior to drawing each plane.
You should carry out the camera transforms first. All other object transforms will be independent the camera position.
It's all about simplifying the maths as much as possible - it not only makes things easier to understand, it will also optimise your code.
Re: Rotation axis
Quick basic example:
Re: Rotation axis
I dont want to confine my 3D object to a single plane but I want to confine the rotation of the object (viewed from any position) to the screen x and y planes.
If you look at the attached sketch, I want to be able to rotate my 3d object about the screen x and y planes (
GL.Rotate(angle,NewVector)). A little bit like the effect you get with a quaternion camera only clamped to x and y I think.Re: Rotation axis
So you'd to find two rotational axes - one corresponding to to the camera-orientation's X-direction, and the other to the camera-orientation's y-direction?
If you have a Matrix4 called Transforms which defines the camera's position and orientation, try rotating around new Vector3(Transforms.Row0), new Vector3(Transforms.Row1) and new Vector3(Transforms.Row2).
These are world position vectors the define the x, y and z axes of the camera.
edit: Why do I keep confusing classes and instances in my forum posts? Never mind. Corrected above.
Re: Rotation axis
Thanks. Yes thats exactly it. I will give it a try.
Re: Rotation axis
Tried it and it just seems to be rotating about world coordinates.
I retrieved my cameras transform matrix using
should this work?
Re: Rotation axis
Tried it and it just seems to be rotating about world coordinates.
I retrieved my cameras transform matrix using
should this work?
Depends:
-Is there an overload for GL.GetFloat that takes a Matrix4 by reference?
-You should probably call it immediately after setting up your camera position matrix, but before you make any other transforms.
-If in doubt, output the Matrix4.ToString() as debug text to your screen to see if the matrix you're using does seem to correspond to what you'd expect.
I don't think it's too efficient, but all my 3d objects (and the camera) have a Transforms Matri4 object which I carry out all the required operations on outside of OpenGL, then I call GL.MultMatrix(ref Transforms) (in C#) before rendering. This method does, at least, make it easy to find the world coordinates and relative axes of an object.
Just thought of something: GL.Rotate(...) rotates the specified matrix around the point(0,0,0) so if you translate the matrix to Position(0,0,0), rotate, and translate back to the desired position, does it work then? Very inefficient, I realise, but if it works it takes you a step closer to where you want to be.
Re: Rotation axis
Yes GL.GetFloat does have a Matrix4 overload by reference.
My scene is centred around 0,0,0. Indeed this is where I want to rotate around.
Just tried placing my Matrix calc directly after the camera transform and it works a treat.
Thank you very much.
Re: Rotation axis
Yes GL.GetFloat does have a Matrix4 overload by reference.
I've learnt from you, too :-)
This'll make my OpenGL programs much more efficient...
Re: Rotation axis
Hi All,
I have a problem with the quad rotation using mouse.
During rotation it hides the quad...
Can you help me to solve this..
I used this code for quad drawing
GL.Color3(System.Drawing.Color.Gold);
GL.Begin(BeginMode.Quads);
GL.Vertex3(-1.0, -1.0, -3.0);
GL.Vertex3(1.0, -1.0, -3.0);
GL.Vertex3(1.0, 1.0, -3.0);
GL.Vertex3(-1.0, 1.0, -3.0);
GL.End();
Thanks,
Bindumol