Sign in to follow this  
lucky6969b

How to convert a Camera if I only have an axis angle

Recommended Posts

Hi,
I found this article.
http://www.toymaker.info/Games/html/camera.html
Just wondering if I just have an axis angle (an axis with a rotation angle)
and that I don't have enough info to convert it into 3 (yaw, pitch, roll) different matrices,
how do I go about solving up, right and look in this case?
Thanks
Jack

Share this post


Link to post
Share on other sites
It reads 0.709184 0.631360 0.313756 1.222444 It's from IGame (3dxi) The example game exporter.

[b]Description:[/b] This class provides a representation for orientation in three space using an angle and axis. This class is similar to a quaternion, except that a normalized quaternion only represents -PI to +PI rotation. This class will have the number of revolutions stored. All methods of this class are implemented by the system.

The rotation convention in the 3ds Max API is the left-hand-rule. Note that this is different from the right-hand-rule used in the 3ds Max user interface. [b]Data Members:[/b] [b]Point3 axis;[/b]

The axis of rotation.

[b]float angle;[/b]

The angle of rotation about the axis in radians. This angle is left handed.

You see there are 3 matrices to calculate ( I need 3 floats namely roll, pitch and yaw) , but I just had one value in an axis angle
Any example code?
Any clue? Thanks Jack

Share this post


Link to post
Share on other sites
Ok, well There is an example exporter coming with 3dxi. it exports to xml format I'd like to extract the Camera info, so that the Camera in d3d is positioned and oriented correctly Now that the exporter only shows me a axis angle value, And i came across that article at the meanwhile. Wondering just how to connect both concepts together. Thanks Jack

Share this post


Link to post
Share on other sites
If you have an IGameNode representing the camera you can try pulling the transform info from it. Using IGameNode GetWorldTM() will return a GMatrix, you can then pull the cameras matrix rows or columns using GMatrix GetColumn() and GetRow().

Share this post


Link to post
Share on other sites
I am starting to catch this now. I think I need 3 bunches of axis vectors and 3 floats. But the exporter just gives one set which is really strange, I've looked at the output in depth and couldn't find the other ones. Thanks Jack

This is the ASCII dump of the Camera
[source]
*CAMERAOBJECT {
*NODE_NAME "Camera01"
*CAMERA_TYPE Target
*NODE_TM {
*NODE_NAME "Camera01"
*INHERIT_POS 0 0 0
*INHERIT_ROT 0 0 0
*INHERIT_SCL 1 1 1
*TM_ROW0 0.6726 0.7400 -0.0000
*TM_ROW1 -0.4469 0.4062 0.7971
*TM_ROW2 0.5898 -0.5361 0.6039
*TM_ROW3 546.8461 -133.5005 375.1562
*TM_POS 546.8461 -133.5005 375.1562
*TM_ROTAXIS -0.7092 -0.3138 -0.6314
*TM_ROTANGLE 1.2224
*TM_SCALE 1.0000 1.0000 1.0000
*TM_SCALEAXIS 0.0565 -0.0000 0.9984
*TM_SCALEAXISANG 0.3203
}
*NODE_TM {
*NODE_NAME "Camera01.Target"
*INHERIT_POS 0 0 0
*INHERIT_ROT 0 0 0
*INHERIT_SCL 0 0 0
*TM_ROW0 1.0000 0.0000 0.0000
*TM_ROW1 0.0000 1.0000 0.0000
*TM_ROW2 0.0000 0.0000 1.0000
*TM_ROW3 113.2334 260.6279 -68.8048
*TM_POS 113.2334 260.6279 -68.8048
*TM_ROTAXIS 0.0000 0.0000 0.0000
*TM_ROTANGLE 0.0000
*TM_SCALE 1.0000 1.0000 1.0000
*TM_SCALEAXIS 0.0000 0.0000 0.0000
*TM_SCALEAXISANG 0.0000
}
*CAMERA_SETTINGS {
*TIMEVALUE 0
*CAMERA_NEAR 0.0000
*CAMERA_FAR 1000.0000
*CAMERA_FOV 0.7854
*CAMERA_TDIST 735.1591
}
}
[/source]

Share this post


Link to post
Share on other sites
The info you need seems to be there

[code]
// transform matrix
*TM_ROW0 0.6726 0.7400 -0.0000
*TM_ROW1 -0.4469 0.4062 0.7971
*TM_ROW2 0.5898 -0.5361 0.6039
*TM_ROW3 546.8461 -133.5005 375.1562 // translation

*TM_POS 546.8461 -133.5005 375.1562 // translation pulled from matrix

*TM_ROTAXIS -0.7092 -0.3138 -0.6314 // resulting axis from convert matrix to axis/angle
*TM_ROTANGLE 1.2224 // angle part of axis/angle conversion (in radians it seems)

*TM_SCALE 1.0000 1.0000 1.0000 // no scale (probably because its a camera)
[/code]

you could take this info and convert it to angles if you want, look up matrix to yaw pitch roll.

Share this post


Link to post
Share on other sites
I still don't get it. Why are there only one axis of rotation and one angle can make up 3 different matrices? there should be 3 vectors(ROTAXIS) and 3 floats(ROTANGLE)
Could you provide some code snippet if you don't mind?

Another Link which may be relevant
[url="http://www.toymaker.info/Games/XNA/html/xna_camera.html"]http://www.toymaker....xna_camera.html[/url]

At least it says " I am assuming here that you are holding your three rotations in a Vector3 called rotations"
I think he is saying I need 3 separate floats(ROTANGLE)

Thanks
Jack

Share this post


Link to post
Share on other sites
If you had pitch yaw and roll angles, converted them to matrices and multiplied them together you would have a single matrix, that single matrix can be stored in axis/angle form. This matrix and its equivalent axis/angle form is whats being provided by the node transform output. The axis/angle is just another form of that matrix, it does not represent the pitch yaw or roll axis, so nothing is missing. If you want pitch yaw and roll angles representing that matrix, look for how to convert from a matrix to pitch yaw and roll, there are a few ways to do it. What do you intend to do with the angles? Are you reloading a Max scene or are you trying to create your own camera?

Share this post


Link to post
Share on other sites
[code]
<Node Name="Camera01" NodeID="1953" NodeType="Camera">
<NodeTM>
<Translation>546.846069 375.156189 -133.500519</Translation>
<Rotation>0.709184 0.631360 0.313756 1.222444</Rotation>
<Scale>1.000000 1.000000 1.000000 0.250154 -0.838539 0.484021</Scale>
</NodeTM>
<CameraData Type="Targeted">
<Properties>
<Prop name="fov" value="0.785398"/>
<Prop name="farclip" value="1000.000000"/>
<Prop name="nearclip" value="1.000000"/>
</Properties>
<Target Name="Camera01Target" NodeID="1954" ParentNodeID="8869">
<NodeTM>
<Translation>113.233398 -68.804779 260.627930</Translation>
<Rotation>0.000000 0.000000 0.000000 0.000000</Rotation>
<Scale>1.000000 1.000000 1.000000 0.000000 0.000000 0.000000</Scale>
</NodeTM>
</Target>
</CameraData>
[/code]

This is the data dumped from the direct3d oriented exporter, seems to be the opposite of the ASCII exporter. Should I use this or the previous one?

And finally comes down to some coding
[code]
D3DXVECTOR3 up(0.0, 1.0, 0.0);
D3DXVECTOR3 look(0.0f, 0.0f, 1.0f);
D3DXVECTOR3 right(1.0f, 0.0f, 0.0f);


D3DXVECTOR3 axis(0.709184, 0.631360, 0.313756);
float angle = 1.222444;



D3DXMATRIX rotation;
D3DXMatrixRotationAxis(&rotation, &axis, angle);
D3DXVec3TransformCoord(&look, &look, &rotation);
D3DXVec3TransformCoord(&up, &up, &rotation);
D3DXVec3TransformCoord(&right, &right, &rotation);

D3DXMATRIX viewMatrix;
D3DXMatrixIdentity(&viewMatrix);

viewMatrix._11 = right.x; viewMatrix._12 = up.x; viewMatrix._13 = look.x;
viewMatrix._21 = right.y; viewMatrix._22 = up.y; viewMatrix._23 = look.y;
viewMatrix._31 = right.z; viewMatrix._32 = up.z; viewMatrix._33 = look.z;

viewMatrix._41 = - D3DXVec3Dot( &m_vPos, &right );
viewMatrix._42 = - D3DXVec3Dot( &m_vPos, &up );
viewMatrix._43 = - D3DXVec3Dot( &m_vPos, &look );


g_pDevice->SetTransform(D3DTS_VIEW, &viewMatrix);


[/code]

[code]
m_Cam.SetPos(D3DXVECTOR3(546.0f, 375.0f, -133.0f));
m_Cam.SetLookAt(D3DXVECTOR3(113.233398 ,-68.804779, 260.627930));
[/code]

Look down from the top to the bottom, back to front and right to left, should be correct.
Here is the object location:
v.x = 113.0f;
v.y = -68.0f;
v.z = 260.0f;
Same as the target position. but i didn't make use of it, where should I have?

But I cannot see anything in the view. Should be something wrong with the direction...(some plagarisms)
Don't know where the target lookat vector comes to play....
Don't know which.
Thanks
Jack

Share this post


Link to post
Share on other sites
When the above code snippet is compared to this
[code]
D3DXVECTOR3 up (0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&mat, &m_vPos, &m_vLookAt, &up);
g_pDevice->SetTransform(D3DTS_VIEW, &mat);
[/code]


this view is skew, while the first one never has something to be seen. A blank screen. Any further help? Thanks Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this