Sign in to follow this  
david w

view matrix - look opposite direction

Recommended Posts

david w    191
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
papulko    1418
[quote name='david w' timestamp='1305792114' post='4812916']
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.
[/quote]


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 )

[code]

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);
}

[/code]

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
DanielDoyle    102
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
david w    191
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this