Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 matrix
ProjectionOfB = ProjectionOfA;

/// get X, Y and Z direction of view matrix A
XDirectionOfA = (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 B
XDirectionOfB = XDirectionOfA;
YDirectionOfB = YDirectionOfA;
ZDirectionOfB = -ZDirectionOfA;

/// calculate inverse of view matrix A
InvViewOfA = MatrixInverse(ViewOfA);
/// retrieve camera position from A
PositionOfA = (InvViewOfA.M41, InvViewOfA.M42, InvViewOfA.M43);

/// calculate camera position for B
PositionOfB = PositionOfA + ZDirectionOfA * FarPlaneOfA;

/// construct view matrix of B

ViewOfB.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 this post

Link to post
Share on other sites

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

Best regards,

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!