Jump to content
  • Advertisement
Sign in to follow this  
david w

view matrix - look opposite direction

This topic is 2588 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 have my view matrix and everything works fine, however I am trying to make it look behind. I hope I'm explaining this properly, but say you are driving your virtual car around and press the "A" button to look at the traffic behind/following you. That what I am trying to do, just a rear-view mirror look. Any ideas how I can take my current view matrix and change it so I can point it to the rear of the direction its currently facing?

Thank you.

Share this post


Link to post
Share on other sites
Advertisement

I have my view matrix and everything works fine, however I am trying to make it look behind. I hope I'm explaining this properly, but say you are driving your virtual car around and press the "A" button to look at the traffic behind/following you. That what I am trying to do, just a rear-view mirror look. Any ideas how I can take my current view matrix and change it so I can point it to the rear of the direction its currently facing?

Thank you.



I'm definately no expert on the matter but how about you do the following? ( given that ViewMatrix, EyeVector and UpVector are already defined globally )



UserPressedA()
{
D3DXMATRIX RotationMatrix;
D3DXVECTOR4 LookAtVector_buffer;
D3DXVECTOR3 LookAtVector;

// Just to clarify we're dealing with a vector and not a point
LookAtVector_buffer.w = 0.0f;

// Create a 180 degree rotation matrix
D3DXMatrixRotationY(&RotationMatrix, D3DX_PI); // PI radians equals 180 degrees

// Apply the rotation matrix to the buffer vector4
D3DXVec4Transform(&LookAtVector_buffer, &LookAtVector_buffer, &RotationMatrix);

// Convert to a vector3 that works with D3DXMatrixLookAtLH method
LookAtVector = D3DXVECTOR3(LookAtVector_buffer.x, LookAtVector_buffer.y, LookATVector_buffer.z);


// Update the viewmatrix based on the new LookAtVector
D3DXMatrixLookAtLH(&ViewMatrix, &EyeVector, &LookAtVector, &UpVector);
}



You'd call this function once when the user presses A, and then call it again once the user releases A. I'm not sure this'll do it but that's what i would've tried :)

Share this post


Link to post
Share on other sites
Are you wanting to look behind from your "Exact" position?

if so you can just minus the lookat position -(lookAt) flips the positions behind the cameras current pos, build a view mat from that and your current pos and up vector and your sorted :)
no need to build a rotation matrix and transform a position etc if thats the case :)

Share this post


Link to post
Share on other sites
Ok I will give it a shot. I haven't looked at my issue in a few days as I've had other stuff going on, but now I'm back on the wagon. Thanks everyone

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!