Exemplo n.º 1
0
        /** Calc
         */
        public void Calc(UnityEngine.Camera a_look_camera, UnityEngine.Transform a_look_transform)
        {
            //worldToCameraMatrix
            this.raw_camera.worldToCameraMatrix = a_look_camera.worldToCameraMatrix * this.matrix;

            //projectionMatrix
            {
                UnityEngine.Matrix4x4 t_mirror_camera_matrix = this.raw_camera.worldToCameraMatrix;
                UnityEngine.Vector4   t_mirror_clip_plane;
                {
                    UnityEngine.Vector3 t_pos             = -this.plane_normal * this.plane_distance;
                    UnityEngine.Vector3 t_mirror_position = t_mirror_camera_matrix.MultiplyPoint(t_pos);
                    UnityEngine.Vector3 t_mirror_normal   = t_mirror_camera_matrix.MultiplyVector(this.plane_normal).normalized;
                    t_mirror_clip_plane = new UnityEngine.Vector4(t_mirror_normal.x, t_mirror_normal.y, t_mirror_normal.z, -UnityEngine.Vector3.Dot(t_mirror_position, t_mirror_normal));
                }
                this.raw_camera.projectionMatrix = a_look_camera.CalculateObliqueMatrix(t_mirror_clip_plane);
            }

            //position
            {
                this.raw_camera.transform.position = this.matrix.MultiplyPoint(a_look_transform.position);
            }

            //rotation
            {
                UnityEngine.Vector3 t_up      = this.matrix_rotate.MultiplyPoint(a_look_transform.up).normalized;
                UnityEngine.Vector3 t_forward = this.matrix_rotate.MultiplyPoint(a_look_transform.forward).normalized;
                UnityEngine.Vector3 t_right   = UnityEngine.Vector3.Cross(t_up, t_forward);

                UnityEngine.Matrix4x4 t_matrix = new UnityEngine.Matrix4x4(
                    new UnityEngine.Vector4(t_right.x, t_right.y, t_right.z, 0.0f),
                    new UnityEngine.Vector4(t_up.x, t_up.y, t_up.z, 0.0f),
                    new UnityEngine.Vector4(t_forward.x, t_forward.y, t_forward.z, 0.0f),
                    new UnityEngine.Vector4(0.0f, 0.0f, 0.0f, 1.0f)
                    );

                this.raw_camera.transform.rotation = t_matrix.rotation;
            }
        }
Exemplo n.º 2
0
        public void Values()
        {
            var values = new float[16];

            // T
            {
                var um = UnityEngine.Matrix4x4.Translate(new UnityEngine.Vector3(1, 2, 3));
                using (var pin = Pin.Create(new[] { um }))
                {
                    Marshal.Copy(pin.Ptr, values, 0, 16);
                }
                Assert.AreEqual(1, um.m03);
                Assert.AreEqual(2, um.m13);
                Assert.AreEqual(3, um.m23);
                Assert.AreEqual(new UnityEngine.Vector4(1, 2, 3, 1), um.GetColumn(3));
                Assert.AreEqual(new float[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1 }, values);

                var v = new UnityEngine.Vector4();
                var m = new UnityEngine.Matrix4x4();
                m.MultiplyVector(v);

                // new UnityEngine.Matrix4x4.mul new UnityEngine.Vector3().mul
            }

            {
                var nm = System.Numerics.Matrix4x4.CreateTranslation(1, 2, 3);
                using (var pin = Pin.Create(new[] { nm }))
                {
                    Marshal.Copy(pin.Ptr, values, 0, 16);
                }
                Assert.AreEqual(1, nm.M41);
                Assert.AreEqual(2, nm.M42);
                Assert.AreEqual(3, nm.M43);
                Assert.AreEqual(new System.Numerics.Vector3(1, 2, 3), nm.Translation);
                Assert.AreEqual(new float[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1 }, values);
            }
        }