Forked from mstevenson/ObliqueCameraProjection.cs
Last active
September 13, 2016 04:47
-
-
Save birdinforest/1dcbb839992a5259c464 to your computer and use it in GitHub Desktop.
Oblique Camera Projection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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