# Projection and camera matrix math question

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

## Recommended Posts

I have a simple problem but unfortunately im not that skilled with math so i was hoping someone can help me out a bit. Basically i have a camera A and camera B, and how do i calculate camera B so that it's near plane equals in size but opposite in direction to camera A FAR plane So i want to my camera A view/projection matrix to give me camera B which starts on the far plane of camera a and is looking in the opposite direction.

##### Share on other sites
I'm not sure I got you right, but you may try something like this:

A - source matrix
B - destination matrix

[source lang=cpp]/// copy projection matrixProjectionOfB = ProjectionOfA;/// get X, Y and Z direction of view matrix AXDirectionOfA = (ViewOfA.M11, ViewOfA.M21, ViewOfA.M31);YDirectionOfA = (ViewOfA.M12, ViewOfA.M22, ViewOfA.M32);ZDirectionOfA = (ViewOfA.M13, ViewOfA.M23, ViewOfA.M33);/// calculate directions of view matrix BXDirectionOfB =  XDirectionOfA;YDirectionOfB =  YDirectionOfA;ZDirectionOfB = -ZDirectionOfA;/// calculate inverse of view matrix AInvViewOfA = MatrixInverse(ViewOfA);/// retrieve camera position from APositionOfA = (InvViewOfA.M41, InvViewOfA.M42, InvViewOfA.M43);/// calculate camera position for BPositionOfB = PositionOfA + ZDirectionOfA * FarPlaneOfA;/// construct view matrix of BViewOfB.M11 = XDirectionOfB.X;ViewOfB.M21 = XDirectionOfB.Y;ViewOfB.M31 = XDirectionOfB.Z;ViewOfB.M41 = -DotProduct(XDirectionOfB, PositionOfB);ViewOfB.M12 = YDirectionOfB.X;ViewOfB.M22 = YDirectionOfB.Y;ViewOfB.M32 = YDirectionOfB.Z;ViewOfB.M42 = -DotProduct(YDirectionOfB, PositionOfB);ViewOfB.M13 = ZDirectionOfB.X;ViewOfB.M23 = ZDirectionOfB.Y;ViewOfB.M33 = ZDirectionOfB.Z;ViewOfB.M43 = -DotProduct(ZDirectionOfB, PositionOfB);ViewOfB.M14 = 0;ViewOfB.M24 = 0;ViewOfB.M34 = 0;ViewOfB.M44 = 1;

Hope this helps.

##### Share on other sites
where

FarPlaneOfA = -ProjectionOfA.M43 / (ProjectionOfA.M33-1);

Best regards,
Paool

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 15
• 18
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633360
• Total Posts
3011520
• ### Who's Online (See full list)

There are no registered users currently online

×