// Use this for initialization void Start() { Registrar reg = this.GetComponent <Registrar> (); tiling = reg.tiling; ballRend = ball.gameObject.GetComponent <Renderer> (); IP = this.GetComponent <InitialPoses> (); //Vector3 ballInitPos = IP.ballInitialPosition; //Vector4 ballInititalPosition = new Vector4(ballInitPos.x, ballInitPos.y, ballInitPos.z, 1f); //initial_diff = ballInititalPosition - wrap(ballInititalPosition); }
void Awake() { // STEP 1: SHADER INITIALIZATION // Every instance of VRMOP needs projection and eye shift matrices. // Retrieve the current projection Matrix4x4 currentP = GL.GetGPUProjectionMatrix(Camera.main.projectionMatrix, true); // Create a standard view matrix Matrix4x4 defaultV = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, -1)); var VP0 = currentP * defaultV; // 6cm Interpupillary Distance assumed Matrix4x4 eye0shift = Matrix4x4.TRS(new Vector3(0.5f * IPD, 0, 0), Quaternion.identity, new Vector3(1, 1, 1)); Matrix4x4 eye1shift = Matrix4x4.TRS(new Vector3(-0.5f * IPD, 0, 0), Quaternion.identity, new Vector3(1, 1, 1)); foreach (GameObject target in GameObject.FindGameObjectsWithTag(targetTag)) { Renderer rend = target.GetComponent <Renderer> (); // First we duplicate so changed properties will not be saved. rend.sharedMaterial = new Material(rend.sharedMaterial); if (cameraMode == CameraMode.MOP) { // TODO: Move these into MOPUtil? // Now we initialize their locks and PV matrices rend.sharedMaterial.SetMatrix("_VP0", VP0); rend.sharedMaterial.SetInt("_locked", 1); rend.sharedMaterial.SetMatrix("_eye0shift", eye0shift); rend.sharedMaterial.SetMatrix("_eye1shift", eye1shift); } // Disable culling Mesh mesh = target.GetComponent <MeshFilter>().mesh; if (mesh != null) { mesh.bounds = new Bounds(new Vector3(0, 0, 0), new Vector3(float.MaxValue, float.MaxValue, float.MaxValue)); } else { Debug.Log("Failed to update bounds on \"" + target.name + "\", no MeshFilter component found."); } } Matrix4x4 origin = Matrix4x4.identity; InitialPoses IP = this.GetComponent <InitialPoses> (); if (IP != null) { Vector3 ibp = IP.globalRelativeShift + IP.ballInitialPosition; origin.SetColumn(3, new Vector4(ibp.x, ibp.y, ibp.z, 1.0f)); } if (ForceTilingType) { GlobalPreferences.tilingType = ForcedTilingValue; } // Create the tiling (so it can be accessed in other classes Start()) var tt = GlobalPreferences.tilingType; if (tt == TilingType.Torus) { tiling = new TorusTiling(origin, N, cubesize); } else if (tt == TilingType.Boro) { tiling = new BoroTiling(origin, N, cubesize); } else if (tt == TilingType.MirrorCube) { tiling = new MirrorCubeTiling(origin, N, cubesize); } }