-
Notifications
You must be signed in to change notification settings - Fork 11
/
ObliqueProjection.cs
34 lines (30 loc) · 961 Bytes
/
ObliqueProjection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using UnityEngine;
using System.Collections;
[ExecuteInEditMode, RequireComponent(typeof(Camera))]
public class ObliqueProjection : MonoBehaviour
{
public float angle = 45.0f;
public float zScale = 0.5f;
public float zOffset = 0.0f;
public void Apply ()
{
camera.orthographic = true;
var orthoHeight = camera.orthographicSize;
var orthoWidth = camera.aspect * orthoHeight;
var m = Matrix4x4.Ortho (-orthoWidth, orthoWidth, -orthoHeight, orthoHeight, camera.nearClipPlane, camera.farClipPlane);
var s = zScale / orthoHeight;
m [0, 2] = +s * Mathf.Sin (Mathf.Deg2Rad * -angle);
m [1, 2] = -s * Mathf.Cos (Mathf.Deg2Rad * -angle);
m [0, 3] = -zOffset * m [0, 2];
m [1, 3] = -zOffset * m [1, 2];
camera.projectionMatrix = m;
}
void OnEnable ()
{
Apply ();
}
void OnDisable ()
{
camera.ResetProjectionMatrix ();
}
}