Hi guys, I''ve got a rotation problem I''ve can''t seem to get right... Basically I have a planet, I''m controlling what portion you look at with the number pad.
8 up around X axis;
2 down around X axis;
4 left around Y axis;
6 right around Y axis;
7 rotates around Z axis;
9 rotates around Z axis;
I need left to ALWAYS move left ect... at any orientation.
The problem is, it only rotates in the correct directions all the time for the first matrix I multiply by. In this case, around the X axis:
D3DXMatrixRotationX (&matViewTemp, angYZ);
D3DXMatrixRotationY (&matViewTemp, angXZ);
D3DXMatrixRotationZ (&matViewTemp, angXY);
Is there any way to make this work with out manually checking each angle for each axis? So far I''ve come up with alot of funny paths, but no correct ones. Any help would be really great!
BTW: im aware that being above 90 degrees in the Y direction flips the directions of the x keys... that''s not the problem. later!
I think you need to use axis angle rotations. The first one can rotate around the spheres whatever axis, but after that the cameras axes are no longer aligned with the spheres axes. So for the second rotation to move you towards the pole you have to rotate around the right axis for the camera. That would give you the ability to control longitude and latitude. I have no idea what the purpose of the third rotation is. That would seem to have little practical value and mainly serve to disorient the user.
Ok I think this is what you mean?... probably not. what I''ve got here just seems to change the total axis of the whole sphere.
ang = CamXYAng*(3.14f/180); D3DXMatrixRotationAxis(&matViewTemp, &D3DXVECTOR3 (0, 0, 1), ang) D3DXMatrixMultiply(&matView,&matViewTemp,&matView);
ang = CamXZAng*(3.14f/180); D3DXMatrixRotationAxis(&matViewTemp, &D3DXVECTOR3 (0, 1, 0), ang) D3DXMatrixMultiply(&matView,&matViewTemp,&matView);
ang = CamYZAng*(3.14f/180); D3DXMatrixRotationAxis(&matViewTemp, &D3DXVECTOR3 (1, 0, 0), ang) D3DXMatrixMultiply(&matView,&matViewTemp,&matView);
Incase the wording of my question was strange I''ve got a better one. If i draw a dot each time i rotate the sphere on the sphere, it would make a line of my path. Right now, that line is curving all over. What I need it to do is, after rotating 360 degrees in any one direction, connect back to the starting point. So it would look like a ring around the sphere. If that helps any...
if I have a big enough sphere, the 3rd axis is pretty useful on a terrain.
This isn''t a strong area for me. You need to rotate an axis around an axis. Rather than x, y and z axes picture it as forward, right and up. Rotating up means rotating the forward and up axes around the right axes. Rotating right means rotating the forward and right axes around the up axes. The third one, whatever you would call it, is rotating the up and right axes around the forward axis. That would be assuming that you are basically doing a fly by. None of it affects the cameras position. Seperately you have a velocity in the direction of the forward axis. The axis are the orientation of the camera in world space since in camera space they don''t move. Within camera space the x-axis is always (1,0,0). Within world space the x-axis of the camera is not always (1,0,0).
The rotations are around the current orientation of the axis. If your camera is assumed to start with its axis pointing in the same direction as the worlds axis then the first rotation can use (1,0,0) to rotate around the x-axis. The second one can''t use (0,1,0) though because that is no longer the direction the cameras y axis is pointing due to the first rotation. Rather that vector has to be ran through the first matrix to find what direction it now points. You then perform your second rotation around that axis. The same is true of the third. I don''t know what MatView starts out as, but assuming that it starts as the identity matrix then you can use it for transforming the (0,0,1) vector to get your third rotation.
Under that context I can see the purpose of the third rotation. I had assumed your camera stays pointed at the center of the sphere. Under that scenerio you have to both rotate the position of the camera and its orientation. I believe to do that all you have to do is transform the original position using the orientation matrix. I''m not strong at this stuff though and mainly responded figuring a little help is better than none if no one else did.