# view matrix - look opposite direction

## 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 on other sites
[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 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 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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628308
• Total Posts
2981975

• 9
• 13
• 11
• 12
• 11