Skip to content

Instantly share code, notes, and snippets.

@mstevenson
Created July 30, 2014 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mstevenson/f7217a5dddb02748d4d8 to your computer and use it in GitHub Desktop.
Save mstevenson/f7217a5dddb02748d4d8 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class ObliqueCameraProjection : MonoBehaviour
{
private Matrix4x4 originalProjection;
public Vector2 slideViewport;
public Vector2 slideFrustum;
public Vector2 slideFarClip; // compound slideViewport and slideFrustum
public Vector2 skew;
public Vector2 scale;
void Awake ()
{
originalProjection = camera.projectionMatrix;
}
void LateUpdate ()
{
CalculateProjection (originalProjection);
}
void OnPostRender ()
{
camera.projectionMatrix = originalProjection;
}
[ContextMenu ("Calculate Projection")]
public void CalculateProjectionInEditor ()
{
originalProjection = camera.projectionMatrix;
CalculateProjection (originalProjection);
}
void CalculateProjection (Matrix4x4 p)
{
// Matrix4x4 p = originalProjection;
p.m00 += scale.x;
p.m11 += scale.y;
p.m01 += skew.x;
p.m10 += skew.y;
p.m02 += slideViewport.x;
p.m12 += slideViewport.y;
p.m03 += slideFrustum.x;
p.m13 += slideFrustum.y;
p.m02 += slideFarClip.x;
p.m12 += slideFarClip.y;
p.m03 += slideFarClip.x / 2;
p.m13 += slideFarClip.y / 2;
camera.projectionMatrix = p;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment