Skip to content

Commit

Permalink
improve support for ortho camera
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Jun 15, 2018
1 parent caa4d71 commit 7cbc036
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
7 changes: 6 additions & 1 deletion FContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ public fCamera OrthoUICamera
get { return camTracker.OrthoUICamera; }
}

public Cockpit ActiveCockpit {
public CameraTracking CameraManager {
get { return camTracker; }
}


public Cockpit ActiveCockpit {
get { return activeCockpit; }
}

Expand Down
5 changes: 5 additions & 0 deletions platform/fCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,16 @@ public Vector3f Right()
}


public bool IsOrthographic {
get { return camera.orthographic; }
}

//https://docs.unity3d.com/ScriptReference/Camera-orthographicSize.html
// Unity maintains fixed height of ortho camera, width changes
public float OrthoHeight
{
get { return camera.orthographicSize * 2; }
set { camera.orthographicSize = value / 2; }
}


Expand Down
34 changes: 22 additions & 12 deletions view/CameraManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,31 @@ public void SceneZoom(FScene scene, fCamera cam, float dz, bool bKeepTargetPos =
if (dz == 0.0f)
return;

float fScale = scene.GetSceneScale();
if (cam.IsOrthographic) {
float f = cam.OrthoHeight;
f = f - dz;
if (f < 0)
f = 0.01f;
cam.OrthoHeight = f;
scene.Context.CameraManager.UpdateMainCamOrthoSize();

} else {
float fScale = scene.GetSceneScale();

//Vector3f fw = cam.gameObject.transform.forward;
Vector3f fw = cam.GetTarget() - cam.GetPosition();
float fTargetDist = fw.Length;
fw.Normalize();
//Vector3f fw = cam.gameObject.transform.forward;
Vector3f fw = cam.GetTarget() - cam.GetPosition();
float fTargetDist = fw.Length;
fw.Normalize();

float fMinTargetDist = 0.1f*fScale;
if (dz > 0 && fTargetDist - dz < fMinTargetDist)
dz = fTargetDist - fMinTargetDist;
float fMinTargetDist = 0.1f * fScale;
if (dz > 0 && fTargetDist - dz < fMinTargetDist)
dz = fTargetDist - fMinTargetDist;

Vector3f delta = dz * fw;
scene.RootGameObject.Translate(-delta, false);
if ( bKeepTargetPos )
cam.SetTarget(cam.GetTarget() - delta);
Vector3f delta = dz * fw;
scene.RootGameObject.Translate(-delta, false);
if (bKeepTargetPos)
cam.SetTarget(cam.GetTarget() - delta);
}
}


Expand Down
19 changes: 18 additions & 1 deletion view/CameraTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,24 @@ public void Initialize (FContext controller) {
FPlatform.OrthoUICamera = uiCamera;
FPlatform.CursorCamera = cursorCamera;
}




/// <summary>
/// If we are using an orthographic camera, then to zoom we need to change
/// Camera.orthographicSize. However we need to transfer this change to the
/// rest of the cameras!
/// </summary>
public void UpdateMainCamOrthoSize()
{
if (widgetCamera != null)
widgetCamera.OrthoHeight = mainCamera.OrthoHeight;
if (hudCamera != null)
hudCamera.OrthoHeight = mainCamera.OrthoHeight;
if (cursorCamera != null)
cursorCamera.OrthoHeight = mainCamera.OrthoHeight;

}

}

Expand Down

0 comments on commit 7cbc036

Please sign in to comment.