Skip to content

Instantly share code, notes, and snippets.

@akirayou
Created Nov 20, 2017
Embed
What would you like to do?
あっちの窓の行列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