Archived

This topic is now archived and is closed to further replies.

Setting the view matrix up

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently using DX7. I have DX8 on another computer but I cannot bother downloading DX when 9 is just around the corner. The question isn''t very specific though: How can I manipulate the view matrix? I can translate it easy enough: D3DMATRIX matView; matView._11 = matView._22 = matView._33 = matView._44 = 1.0f; matView._12 = matView._13 = matView._14 = matView._41 = 0.0f; matView._21 = matView._23 = matView._24 = matView._42 = 0.0f; matView._31 = matView._32 = matView._34 = matView._43 = 0.0f; matView._43 = camera.zpos; matView._42 = -0.5f; matView._41 = camera.xpos; pd3dDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView ); But I have no clue how to set the rotation. I was thinking of building a rotation matrix then changing _43, _42 and _41 but I have no clue how to set up a rotation matrix... Incase anyone hasn''t noticed I am new to DX. Thanks...

Share this post


Link to post
Share on other sites
You set the camera's orientation by using three vectors representing the camera's current three axes: right, up, and look-at (or u, v, and n respectively). These three vectors collectively describe the camera's orientation in space.

Make sure that these vectors are always perpendicular to each other and normalized every round, and set them into the view matrix like this:


    
m_ViewMatrix._11 = m_Right.x;
m_ViewMatrix._12 = m_Up.x;
m_ViewMatrix._13 = m_LookAt.x;

m_ViewMatrix._21 = m_Right.y;
m_ViewMatrix._22 = m_Up.y;
m_ViewMatrix._23 = m_LookAt.y;

m_ViewMatrix._31 = m_Right.z;
m_ViewMatrix._32 = m_Up.z;
m_ViewMatrix._33 = m_LookAt.z;


To rotate your camera, of course, you have to rotate each of the three vectors appropriately. One way to do this is to create a rotation matrix with one of the D3DXMatrixRotation...() functions and then transform the uvn vectors by this matrix.

I believe Graphics Gems 1 has an article about view cameras, as do articles on this site and perhaps on Gamasutra.com.

(edit: grammar)
--Hoozit.

[edited by - HoozitWhatzit on July 25, 2002 5:25:10 PM]

Share this post


Link to post
Share on other sites
This works:
matView._11 = (FLOAT)cos(0.7);
matView._33 = (FLOAT)cos(0.7);
matView._13 = (FLOAT)sin(0.7);
matView._31 =-(FLOAT)sin(0.7);

Now my problem is actually setting the position relative to 0,0,0 world. If I do this:
matView._43 = camera.zpos;
matView._42 = -0.5f;
the camera is moved away from 0,0,0 at its current direction. I want to simply set its position then rotate it from there.

Share this post


Link to post
Share on other sites
Always remember that if you want the camera's rotations to occur around the camera's center point always, then your view matrix must perform all rotations before doing any translations.

I know this sounds crazy--after all, you're thinking, "I want to move my camera to (10,20,30) and then I want to rotate it," right? But in the world of matrices, you have split up your rotations and translations, and perform them in the proper order.

Solution: make a matrix, mRot, which is used to compute a desired rotational change. Keep it separate from your camera's view matrix--let's call the view matrix mView.

Each round, you first concatenate your rotational change to the mView matrix by multiplying it (be careful to note the order of multiplication):


// mView = mRot * mView
D3DXMatrixMultiply(&mView, &mRot, &mView);


Then, add your positional change into the soup by changing mView's translation cells by hand:


mView._41 += xChange;
mView._42 += yChange;
mView._43 += zChange;


And this process would occur every round. So, to summarize, for each round, make a rotation matrix for the camera's rotational change, multiply it into the view matrix on the left side, and then add your camera's translation changes to the view matrix directly.

Sorry if I'm not understanding your problem or if I'm saying stuff you already know. Hope this helps.

--Hoozit.

[edited by - HoozitWhatzit on July 26, 2002 4:27:59 PM]

Share this post


Link to post
Share on other sites