ibr_ozdemir thank you for trying to help.
Yes my camera is like other objects, it has X,Y,Z and Pitch,Yaw,Roll properties.
So let's say now I want to set my camera. What will I do? afcourse I will use
D3DXMatrixLookAtLH() couse all tutorials shows it;
D3DXMatrixLookAtLH ( &view, &D3DXVECTOR3(X, Y, Z), // the camera position <= wow it's cool I can just simply pass object's position properties &lookat, // the look-at position <= this is my nightmare &D3DXVECTOR3(0.0f, 1.0f, 0.0f) // the up direction );
All parameters of this function are good just how they are except "look-at".
Ye it's good if you want have static camera or you want make camera to fallow
for example a ball, afcourse camera will not change it's position but it will change it's angles.
Exactly "look-at"parameter and is my PROBLEM. What I wish to do is get some kind of direction vector calculated from given angles (Pitch,Yaw,Row).
Let's say I wish to make camera be rotated 45 degrees around Y axis,
then my direction(look-at) vector should become (0.707, 0, 0.707) let's take another example "Rotate camera 30 degrees around Y axis" than look-at vector should be (0.866, 0, 0.5).
Current camera render function code looks like that
D3DXMatrixRotationX(&mat_pitch,D3DXToRadian(Pitch)); D3DXMatrixRotationY(&mat_yaw,D3DXToRadian(Yaw)); D3DXMatrixRotationZ(&mat_roll,D3DXToRadian(Roll)); mat_rotation = mat_yaw * mat_pitch * mat_roll; lookat.x = mat_rotation._31; lookat.y = mat_rotation._32; lookat.z = mat_rotation._33; D3DXVec3Add(&lookat,&D3DXVECTOR3(X, Y, Z),&lookat); D3DXMatrixLookAtLH ( &mat_view, &D3DXVECTOR3(X, Y, Z), // the camera position &lookat, // the look-at position &D3DXVECTOR3(0.0f, 1.0f, 0.0f) // the up direction ); d3dDevice->SetTransform(D3DTS_VIEW, &mat_view);// set the view transform D3DXMatrixPerspectiveFovLH ( &mat_projection, D3DXToRadian(60), // the horizontal field of view Aspect, // aspect ratio 1.0f, // the near view-plane Range ); d3dDevice->SetTransform(D3DTS_PROJECTION, &mat_projection); // set the projection transform
this code version is allmost good becouse:
1. It doesn't interpretate camera position inversly
2. It looks like it rotates to correct direction along X and Y axis, BUT it has no effect on Z axis.
What am I doing wrong?
What is the right order to multiply transformation matrices. Is this one correct?
"scale * rotationY * rotationX * rotationZ * position"
Now here's how I understand PointOfView, ZNear, ZFar:
PointOfView - This is point(vector) where camera looks for example 0,0,0 it will looks at word orign
ZNear - it's the distance from camera position at which camera actulay starts to see something. I set it to 1.0f
ZFar - it's distance from camera position where camera stops to see. I set it to big number 1024.0f. So ZFar - ZNear = camera view range
[Edited by - redas on March 23, 2007 9:08:24 AM]