Archived

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

Setting up a view matrix...

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

Recommended Posts

Hey. I'm trying my hand at 3d, but I'm stuck already. I've already drawn a triangle on the screen (wow, fear me!), and now I've decided to add a viewpoint function so that the player can move the viewpoint around. Okay, here is my viewpoint function called once per frame:
  //------------------------------------------------------------------- // ViewMatrix //------------------------------------------------------------------- void ViewMatrix(VIEW *pView) { // setup view matrices D3DXMATRIX matWorld; D3DXMatrixRotationY(&matWorld, timeGetTime()/150.0f); // object -> world space D3DXMATRIX matView; D3DXVECTOR3 vView(pView->x, pView->y, pView->z); D3DXVECTOR3 vAngle(pView->x_ang, pView->y_ang, pView->z_ang); D3DXVECTOR3 vOrientation(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &vView, &vAngle, &vOrientation); // projection D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f); pID3DDevice->SetTransform(D3DTS_WORLD, &matWorld); pID3DDevice->SetTransform(D3DTS_VIEW, &matView); pID3DDevice->SetTransform(D3DTS_PROJECTION, &matProj); } 
However, something is way wrong with this. I'm probably just not doing this right, but basically, the values aren't doing what I'd expect them to do. Also, x/z movement wise, if I move the cameras past the triangle, the z axis like flips so that as I move forward, I see the triangle again, scrolling back out in to space in front of the viewer, when in actuality it should be behind me! Any suggestions? Thanks, -Jesse Edited by - webmunkey on November 15, 2001 6:40:15 PM

Share on other sites
G''day!

Your use of D3DXMatrixLookAtLH seems a little off to me based on the variable names you''re using. The third parameter in particular (which you pass an angle) is the look at point. Based on the results you''re describing, you probably have it set to (0,0,0) so when you move forward, as soon as you go past (0,0,0) you flip around and face the origin.

Set the look at point to be something far in the distance and it should stop misbehaving. Then if you want the camera to turn you have to rotate that point (the look at point).

Stay Casual,

Ken
Drunken Hyena

Share on other sites
Ah, I see. Okay, stuff just doesn''t do what I thought it did, I guess. Time to break out the sdk and look at what each of those numbers really mean, thanks for the clarification. Great site by the way,
Cheers,
-Jesse

Share on other sites
Hmm, D3DXMatrixLookAtLH() obviously isn''t the function I want, but I''m not sure what function I do want. I basically have a viewpoint with xpos, ypos, and zpos data as well view angle, view pitch and view roll data and I want to intergrate them into a matrix calculation function called once per frame. Basically, I want the viewpoint to be able to be defined on-the-fly by the userinput. Does anyone know how to setup the ViewMatrix() function so that it actually works like how I described it above? Thanks,
-Jesse

Share on other sites
Sorry guys, scratch that last question. I figured it out . I just had to use quaternions and stuff. It''s nice to see that my brain actually works every once and a while...
Thanks,
-Jesse

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5
frob
12

• 17
• 9
• 31
• 16
• 9
• Forum Statistics

• Total Topics
632614
• Total Posts
3007440

×