# How to calculate stereoscopic view with custom projection matrix with only one camera

**URL:** <https://forums.unrealengine.com/t/how-to-calculate-stereoscopic-view-with-custom-projection-matrix-with-only-one-camera/417487>\
**Category:** Cinematics & Media\
**Tags:** projection-matrix, unreal-engine, CPP, question\
**Created:** [February 16, 2018, 12:21pm UTC](https://forums.unrealengine.com/t/how-to-calculate-stereoscopic-view-with-custom-projection-matrix-with-only-one-camera/417487 "2018-02-16T12:21:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![s0n4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@s0n4](https://forums.unrealengine.com/u/s0n4)\
**Post date:** [February 16, 2018, 12:21pm UTC](https://forums.unrealengine.com/t/how-to-calculate-stereoscopic-view-with-custom-projection-matrix-with-only-one-camera/417487/1 "2018-02-16T12:21:47Z")

</div>

Hi,  
I am trying to build a stereoscopic camera setup to use in a CAVE-Projection-System. But I noticed, that when calculating the Projection-Matrix per eye i can only set one camera position per frame.

In the Screenshot you can see that the frusta of the two cameras are calculated differently for the eyes but the centerpoints are at the same location so the frustum of one of the eyes is offset by the eye-distance.

So is it possible to offset the camera for the other eye or is there any other possible way to fix this problem?

![230875-neededtocurrent.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/1/581301fa768df57ac501adb51c02f45166457cfc.png)

```
FVector loc = cam->RelativeLocation;
FQuat rot = cam->RelativeRotation.Quaternion();
FVector newRotationOffset = rot.RotateVector(FVector(0, PassOffset, 0));
loc += newRotationOffset;
FTransform transform = FTransform();
transform.AddToTranslation(-newRotationOffset);

// ### Camera Rotation ###
FVector vectorRight = caveProjectionArea.bottomRight - caveProjectionArea.bottomLeft;
vectorRight.Normalize();
FVector vectorUp = (caveProjectionArea.topLeft - caveProjectionArea.bottomLeft);
vectorUp.Normalize();
FVector normal = -(FVector::CrossProduct(vectorRight, vectorUp));
normal.Normalize();
FVector nnormal = -normal;
cam->SetWorldRotation(nnormal.Rotation());

// ### Frustum calculation ###
FVector eyeToBottomLeft = caveProjectionArea.bottomLeft - loc;
FVector eyeToBottomRight = caveProjectionArea.bottomRight - loc;
FVector eyeToTopLeft = caveProjectionArea.topLeft - loc;

float distance = -(FVector::DotProduct(eyeToBottomLeft, normal));

float left = FVector::DotProduct(vectorRight, eyeToBottomLeft) * GNearClippingPlane / distance; //nearClip
float right = FVector::DotProduct(vectorRight, eyeToBottomRight) * GNearClippingPlane / distance;
float bottom = FVector::DotProduct(vectorUp, eyeToBottomLeft) * GNearClippingPlane / distance;
float top = FVector::DotProduct(vectorUp, eyeToTopLeft) * GNearClippingPlane / distance;
FMatrix newProjectionMatrix = AdjustedPerspectiveOffCenter(left, right, bottom, top, GNearClippingPlane, farClip);
FMatrix meantProjectionMatrix = PerspectiveOffCenter(left, right, bottom, top, GNearClippingPlane, farClip);

// ### FOV x ###
float fovX = FMath::RadiansToDegrees(2.0f * FMath::Atan((right - left) / (2 * GNearClippingPlane)));
float s = 1 / (FMath::Tan(fovX*0.5*(PI / 180.f)));

// ### use calculated data ###
cam->ClearAdditiveOffset();
cam->AddAdditiveOffset(transform, fovX);
// updating the projectionmatrix

```

The green frustum lines are for the right eye which is on the bottom of the camera view and the red lines for left view.

 ![230873-frustumfromtop.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/e/02e75c5cf619c5a9b913cd55c90e238608ad058c.jpeg)

 ![230874-viewsfromcamera.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/3/b/f3bdba14ed0e7ced3b74264a4e04f478916a7622.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_aea97b0b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_aea97b0b](https://forums.unrealengine.com/u/anonymous_user_aea97b0b)\
**Post date:** [May 10, 2018, 8:21am UTC](https://forums.unrealengine.com/t/how-to-calculate-stereoscopic-view-with-custom-projection-matrix-with-only-one-camera/417487/2 "2018-05-10T08:21:07Z")

</div>

I don’t really understand your question. But you can try -emulatestereo in  
Edit → Editor Preferences → Level Editor → Play → Play in Standalone Game,

and then set “Additional Launch Parameters” to -emulatestereo.

and then play your game in standalone mode.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9a1ef243](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9a1ef243](https://forums.unrealengine.com/u/anonymous_user_9a1ef243)\
**Post date:** [September 5, 2018, 2:53am UTC](https://forums.unrealengine.com/t/how-to-calculate-stereoscopic-view-with-custom-projection-matrix-with-only-one-camera/417487/3 "2018-09-05T02:53:33Z")

</div>

How to you update the projection matrix?
