Skip to content

Instantly share code, notes, and snippets.

@akirayou
Created November 20, 2017 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akirayou/2721e4d781664f32fbbde8f4188d9835 to your computer and use it in GitHub Desktop.
Save akirayou/2721e4d781664f32fbbde8f4188d9835 to your computer and use it in GitHub Desktop.
あっちの窓の行列forUnity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WindowCamCont : MonoBehaviour {
public Vector3 eyePos = new Vector3(0, 0, 0);
public Camera targetCamera;
public float displayWidth = 0.29f;
public float displayHeight = 0.16f;
public float nearPlane = 0;
public float farPlane = 10;
private Vector3 oldPos = Vector3.zero;
private Matrix4x4 a = Matrix4x4.zero;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float x = eyePos[0] ;
float y = eyePos[1] ;
float z = eyePos[2] ;
float n = nearPlane- z;
float f = farPlane - z;
float w = displayWidth; w /= 2;
float h = displayHeight; h /= 2;
a[0, 0] = -z / w;
a[0, 2] = x / w;
a[1, 1] = -z / h;
a[1, 2] = y / h;
a[2, 2] = -1 * (z - f) / (n - f);
a[2, 3] = -n * (z - f) / (n - f);
a[3, 2] = -1;
a[3, 3] = -z;
targetCamera.projectionMatrix = a;
Vector3 pos= new Vector3(-x, -y, z);
targetCamera.transform.Translate(pos-oldPos);
oldPos = pos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment