Exemplo n.º 1
0
        public void Construct2()
        {
            Matrix34<double> m = new Matrix34<double>(
                1.0, 2.0, 3.0,
                4.0, 5.0, 6.0,
                7.0, 8.0, 9.0, 
                10.0, 11.0, 12.0);

            Assert.AreEqual(1.0, m.Column0Row0);
            Assert.AreEqual(2.0, m.Column1Row0);
            Assert.AreEqual(3.0, m.Column2Row0);
            Assert.AreEqual(4.0, m.Column0Row1);
            Assert.AreEqual(5.0, m.Column1Row1);
            Assert.AreEqual(6.0, m.Column2Row1);
            Assert.AreEqual(7.0, m.Column0Row2);
            Assert.AreEqual(8.0, m.Column1Row2);
            Assert.AreEqual(9.0, m.Column2Row2);
            Assert.AreEqual(10.0, m.Column0Row3);
            Assert.AreEqual(11.0, m.Column1Row3);
            Assert.AreEqual(12.0, m.Column2Row3);

            Assert.AreEqual(1.0, m.ReadOnlyColumnMajorValues[0]);
            Assert.AreEqual(4.0, m.ReadOnlyColumnMajorValues[1]);
            Assert.AreEqual(7.0, m.ReadOnlyColumnMajorValues[2]);
            Assert.AreEqual(10.0, m.ReadOnlyColumnMajorValues[3]);
            Assert.AreEqual(2.0, m.ReadOnlyColumnMajorValues[4]);
            Assert.AreEqual(5.0, m.ReadOnlyColumnMajorValues[5]);
            Assert.AreEqual(8.0, m.ReadOnlyColumnMajorValues[6]);
            Assert.AreEqual(11.0, m.ReadOnlyColumnMajorValues[7]);
            Assert.AreEqual(3.0, m.ReadOnlyColumnMajorValues[8]);
            Assert.AreEqual(6.0, m.ReadOnlyColumnMajorValues[9]);
            Assert.AreEqual(9.0, m.ReadOnlyColumnMajorValues[10]);
            Assert.AreEqual(12.0, m.ReadOnlyColumnMajorValues[11]);
        }
Exemplo n.º 2
0
        public void SetEffectMatrix(SCN0Node node, ModelPanelViewport v, float frame)
        {
            if (MapMode != MappingMethod.TexCoord)
            {
                switch (MapMode)
                {
                case MappingMethod.Projection:
                    _effectMatrix = Matrix34.ProjectionMapping(SCN0RefCamera, node, v, frame);
                    break;

                case MappingMethod.EnvSpec:
                    _effectMatrix = Matrix34.EnvSpecMap(SCN0RefCamera, SCN0RefLight, node, v, frame);
                    break;

                case MappingMethod.EnvLight:
                    _effectMatrix = Matrix34.EnvLightMap(SCN0RefLight, node, v, frame);
                    break;

                case MappingMethod.EnvCamera:
                    _effectMatrix = Matrix34.EnvCamMap(SCN0RefCamera, node, v, frame);
                    break;

                default:
                    _effectMatrix = Matrix.Identity;
                    break;
                }
            }
            else
            {
                _effectMatrix = Matrix.Identity;
            }
        }
Exemplo n.º 3
0
        public void TestIdentity()
        {
            Matrix34  nativeMatrix  = Matrix34.CreateIdentity();
            Matrix3x4 managedMatrix = Matrix3x4.Identity;

            // Compare native to managed identity
            Assert.That(nativeMatrix.m00, Is.EqualTo(managedMatrix[0, 0]));
            Assert.That(nativeMatrix.m01, Is.EqualTo(managedMatrix[0, 1]));
            Assert.That(nativeMatrix.m02, Is.EqualTo(managedMatrix[0, 2]));
            Assert.That(nativeMatrix.m03, Is.EqualTo(managedMatrix[0, 3]));
            Assert.That(nativeMatrix.m10, Is.EqualTo(managedMatrix[1, 0]));
            Assert.That(nativeMatrix.m11, Is.EqualTo(managedMatrix[1, 1]));
            Assert.That(nativeMatrix.m12, Is.EqualTo(managedMatrix[1, 2]));
            Assert.That(nativeMatrix.m13, Is.EqualTo(managedMatrix[1, 3]));
            Assert.That(nativeMatrix.m20, Is.EqualTo(managedMatrix[2, 0]));
            Assert.That(nativeMatrix.m21, Is.EqualTo(managedMatrix[2, 1]));
            Assert.That(nativeMatrix.m22, Is.EqualTo(managedMatrix[2, 2]));
            Assert.That(nativeMatrix.m23, Is.EqualTo(managedMatrix[2, 3]));

            // Compare managed matrix to real values.
            Assert.That(managedMatrix[0, 0], Is.EqualTo(1));
            Assert.That(managedMatrix[0, 1], Is.EqualTo(0));
            Assert.That(managedMatrix[0, 2], Is.EqualTo(0));
            Assert.That(managedMatrix[0, 3], Is.EqualTo(0));
            Assert.That(managedMatrix[1, 0], Is.EqualTo(0));
            Assert.That(managedMatrix[1, 1], Is.EqualTo(1));
            Assert.That(managedMatrix[1, 2], Is.EqualTo(0));
            Assert.That(managedMatrix[1, 3], Is.EqualTo(0));
            Assert.That(managedMatrix[2, 0], Is.EqualTo(0));
            Assert.That(managedMatrix[2, 1], Is.EqualTo(0));
            Assert.That(managedMatrix[2, 2], Is.EqualTo(1));
            Assert.That(managedMatrix[2, 3], Is.EqualTo(0));
        }
Exemplo n.º 4
0
        public void TestAddTranslation()
        {
            //managed operation
            Vector3   point         = new Vector3(1f, -1f, 0.5f);
            Matrix3x4 matrix34      = new Matrix3x4(0f, 1f, 2f, 3f, 10f, 11f, 12f, 13f, 20f, 21f, 22f, 23f);
            Matrix3x4 managedMatrix = matrix34;

            Assert.IsTrue(!ReferenceEquals(matrix34, managedMatrix));
            managedMatrix.AddTranslation(point);

            //native operation
            Vec3     point2       = new Vec3(point.x, point.y, point.z);
            Matrix34 nativeMatrix = new Matrix34(0f, 1f, 2f, 3f, 10f, 11f, 12f, 13f, 20f, 21f, 22f, 23f);

            nativeMatrix.AddTranslation(point2);

            Assert.That(nativeMatrix.m00, Is.EqualTo(managedMatrix[0, 0]));
            Assert.That(nativeMatrix.m01, Is.EqualTo(managedMatrix[0, 1]));
            Assert.That(nativeMatrix.m02, Is.EqualTo(managedMatrix[0, 2]));
            Assert.That(nativeMatrix.m03, Is.EqualTo(managedMatrix[0, 3]));
            Assert.That(nativeMatrix.m10, Is.EqualTo(managedMatrix[1, 0]));
            Assert.That(nativeMatrix.m11, Is.EqualTo(managedMatrix[1, 1]));
            Assert.That(nativeMatrix.m12, Is.EqualTo(managedMatrix[1, 2]));
            Assert.That(nativeMatrix.m13, Is.EqualTo(managedMatrix[1, 3]));
            Assert.That(nativeMatrix.m20, Is.EqualTo(managedMatrix[2, 0]));
            Assert.That(nativeMatrix.m21, Is.EqualTo(managedMatrix[2, 1]));
            Assert.That(nativeMatrix.m22, Is.EqualTo(managedMatrix[2, 2]));
            Assert.That(nativeMatrix.m23, Is.EqualTo(managedMatrix[2, 3]));
        }
Exemplo n.º 5
0
        public void Matrix34()
        {
            string fs =
                @"#version 330

                  uniform mat3x4 exampleMat34;
                  out vec3 FragColor;

                  void main()
                  {
                      FragColor = vec3(exampleMat34[1].x, exampleMat34[2].z, 0.0);
                  }";

            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
                    using (ShaderProgram sp = Device.CreateShaderProgram(ShaderSources.PassThroughVertexShader(), fs))
                        using (VertexArray va = TestUtility.CreateVertexArray(window.Context, sp.VertexAttributes["position"].Location))
                        {
                            Matrix34 <float> m34 = new Matrix34 <float>(
                                0.0f, 1.0f, 0.0f,
                                0.0f, 0.0f, 0.0f,
                                0.0f, 0.0f, 1.0f,
                                0.0f, 0.0f, 0.0f);
                            Uniform <Matrix34 <float> > exampleMat34 = (Uniform <Matrix34 <float> >)sp.Uniforms["exampleMat34"];
                            Assert.AreEqual("exampleMat34", exampleMat34.Name);
                            Assert.AreEqual(UniformType.FloatMatrix34, exampleMat34.Datatype);
                            Assert.AreEqual(new Matrix34 <float>(), exampleMat34.Value);
                            exampleMat34.Value = m34;
                            Assert.AreEqual(m34, exampleMat34.Value);

                            window.Context.Framebuffer = framebuffer;
                            window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), new SceneState());
                            TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 255, 0);
                        }
        }
Exemplo n.º 6
0
        public static Enemy Create(int type, Vec3 pos)
        {
            var enemy = Entity.Instantiate <Enemy>(pos, Quat.Identity, 0.5f, EnemyTypes [type].Geometry);

            if (EnemyTypes[type].Material != null)
            {
                enemy.Material = Env.Engine.GetMaterialManager().LoadMaterial(EnemyTypes[type].Material);
            }

            // Rotate Z-Axis in degrees to have enemy facing forward.
            enemy.Rotation = Quat.CreateRotationZ(Utils.Deg2Rad(90f));

            var pfx = Env.ParticleManager.FindEffect("spaceship.Trails.blue_fire_trail");

            enemy.LoadParticleEmitter(1, pfx, 0.5f);

            // Get position of jet on enemy (Note: Non-Existing position means x, y and z are all 0).
            Vec3 jetPosition = enemy.GetHelperPos(0, "particle_01");

            // NOTE ON MATRIX34
            // ----------------
            // First Vec3 parameter indicates scale
            // Second Quat parameter indicate rotation
            // Third Vec3 parameter indicates position

            // Scale, Rotate and Position particle effect to ensure it's shown at the back of the ship.
            enemy.SetTM(1, Matrix34.Create(Vec3.One, Quat.CreateRotationX(Utils.Deg2Rad(270f)), jetPosition));

            // Put into game loop.
            GamePool.AddObjectToPool(enemy);
            return(enemy);
        }
Exemplo n.º 7
0
        public void Construct1()
        {
            Matrix34<double> m = new Matrix34<double>(1.0);

            for (int i = 0; i < m.NumberOfComponents; ++i)
            {
                Assert.AreEqual(1.0, m.ReadOnlyColumnMajorValues[0], 1e-14);
            }
        }
Exemplo n.º 8
0
 internal UniformFloatMatrix34GL3x(string name, int location, ICleanableObserver observer)
     : base(name, UniformType.FloatMatrix34)
 {
     _location = location;
     _value    = new Matrix34 <float>();
     _dirty    = true;
     _observer = observer;
     _observer.NotifyDirty(this);
 }
Exemplo n.º 9
0
//        GameObject core;

        public override void OnInitialize()
        {
            base.OnInitialize();

            Health = new Health();
            NativeEntity.LoadGeometry(0, AssetLibrary.Meshes.BasePlate);
            NativeEntity.SetMaterial(AssetLibrary.Materials.BasePlate);

            NativeEntity.LoadGeometry(1, AssetLibrary.Meshes.Diamond);
            NativeEntity.SetSlotMaterial(1, AssetLibrary.Materials.BaseCore);
            NativeEntity.SetSlotLocalTM(1, Matrix34.Create(Vec3.One, Quat.Identity, new Vec3(0, 0, 2f)));
        }
Exemplo n.º 10
0
        public void TestNativeManagedEqualityMatrix3by4()
        {
            Matrix3x4 managedmatrix = new Matrix3x4(0f, 3f, 6f, 9f, 1f, 4f, 7f, 10f, 2f, 5f, 8f, 11f);
            Matrix34  nativematrix  = new Matrix34(0f, 3f, 6f, 9f, 1f, 4f, 7f, 10f, 2f, 5f, 8f, 11f);

            //managed quaternion
            Quaternion managedQuat = new Quaternion(managedmatrix);
            //native quaternion
            Quat nativeQuat = Quat.CreateQuatFromMatrix(nativematrix);

            Assert.IsTrue(managedQuat == nativeQuat);
        }
Exemplo n.º 11
0
        private void AddToGamePoolWithDoor(Vec3 position = null)
        {
            GamePool.AddObjectToPool(this);

            if (position == null)             // Get position via Engine EntitySystem.
            {
                position = this.Position;
            }

            // Create a door case as connector between tunnels.
            _tunnelDoor       = Door.Create(new Vec3(position.x, position.y, position.z), 0);
            _tunnelDoor.Speed = LevelGeometry.GlobalGeomSpeed;

            // Create random door types
            int rand = Rand.NextInt(3);

            if (rand != 0)
            {
                _tunnelDoor       = Door.Create(new Vec3(position.x, position.y, position.z), rand);
                _tunnelDoor.Speed = LevelGeometry.GlobalGeomSpeed;
            }

            ColorF lightColor = new ColorF(_randomizer.Next(0, 255), _randomizer.Next(0, 255), _randomizer.Next(0, 255));

            // Till 'MaxValue' as the for-loop is quit when once the first empty position is discovered.
            for (int i = 1; i < int.MaxValue; i++)
            {
                Vec3 helperPos = GetHelperPos(0, "Light_0" + i.ToString());

                if (helperPos.x != 0 || helperPos.y != 0 || helperPos.z != 0)
                {
                    CDLight light = new CDLight()
                    {
                        m_fRadius = 25f,
                        m_fAttenuationBulbSize = 0.1f,
                        m_BaseColor            = lightColor,
                        m_BaseSpecMult         = 1f
                    };

                    LoadLight(i, light);
                    SetTM(i, Matrix34.Create(Vec3.One, Quat.Identity, helperPos));
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 12
0
        public void TestTransformDirection()
        {
            //managed
            Vector3   vector3      = new Vector3(0.2f, 0.2f, 0.2f);
            Matrix3x4 matrix3x4    = Matrix3x4.Identity;
            Vector3   transVector3 = matrix3x4.TransformDirection(vector3);

            //native
            Vec3     vec3      = new Vec3(vector3.x, vector3.y, vector3.z);
            Matrix34 matrix34  = Matrix34.CreateIdentity();
            Vec3     transVec3 = matrix34.TransformVector(vec3);

            Assert.IsTrue(transVector3.x == transVec3.x, "x is different");
            Assert.IsTrue(transVector3.y == transVec3.y, "y is different");
            Assert.IsTrue(transVector3.z == transVec3.z, "z is different");
            Assert.IsTrue(transVector3 == transVec3, "vector is different");
        }
Exemplo n.º 13
0
        public void ConversionFromManagedToNative()
        {
            Matrix3x4 managedMatrix = new Matrix3x4(0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23);
            Matrix34  nativeMatrix  = managedMatrix;

            Assert.That(nativeMatrix.m00, Is.EqualTo(managedMatrix[0, 0]));
            Assert.That(nativeMatrix.m01, Is.EqualTo(managedMatrix[0, 1]));
            Assert.That(nativeMatrix.m02, Is.EqualTo(managedMatrix[0, 2]));
            Assert.That(nativeMatrix.m03, Is.EqualTo(managedMatrix[0, 3]));
            Assert.That(nativeMatrix.m10, Is.EqualTo(managedMatrix[1, 0]));
            Assert.That(nativeMatrix.m11, Is.EqualTo(managedMatrix[1, 1]));
            Assert.That(nativeMatrix.m12, Is.EqualTo(managedMatrix[1, 2]));
            Assert.That(nativeMatrix.m13, Is.EqualTo(managedMatrix[1, 3]));
            Assert.That(nativeMatrix.m20, Is.EqualTo(managedMatrix[2, 0]));
            Assert.That(nativeMatrix.m21, Is.EqualTo(managedMatrix[2, 1]));
            Assert.That(nativeMatrix.m22, Is.EqualTo(managedMatrix[2, 2]));
            Assert.That(nativeMatrix.m23, Is.EqualTo(managedMatrix[2, 3]));
        }
Exemplo n.º 14
0
        public void TestMatrix3x4Construction()
        {
            Matrix34  nativeMatrix  = new Matrix34(1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15);
            Matrix4x4 managedMatrix = new Matrix4x4(nativeMatrix);

            Assert.That(nativeMatrix.m00, Is.EqualTo(managedMatrix[0, 0]));
            Assert.That(nativeMatrix.m01, Is.EqualTo(managedMatrix[0, 1]));
            Assert.That(nativeMatrix.m02, Is.EqualTo(managedMatrix[0, 2]));
            Assert.That(nativeMatrix.m03, Is.EqualTo(managedMatrix[0, 3]));
            Assert.That(nativeMatrix.m10, Is.EqualTo(managedMatrix[1, 0]));
            Assert.That(nativeMatrix.m11, Is.EqualTo(managedMatrix[1, 1]));
            Assert.That(nativeMatrix.m12, Is.EqualTo(managedMatrix[1, 2]));
            Assert.That(nativeMatrix.m13, Is.EqualTo(managedMatrix[1, 3]));
            Assert.That(nativeMatrix.m20, Is.EqualTo(managedMatrix[2, 0]));
            Assert.That(nativeMatrix.m21, Is.EqualTo(managedMatrix[2, 1]));
            Assert.That(nativeMatrix.m22, Is.EqualTo(managedMatrix[2, 2]));
            Assert.That(nativeMatrix.m23, Is.EqualTo(managedMatrix[2, 3]));
        }
Exemplo n.º 15
0
        public void TestAddTranslation()
        {
            //managed operation
            Vector3   point     = new Vector3(1f, -1f, 0.5f);
            Matrix3x4 matrix34  = new Matrix3x4(0f, 1f, 2f, 3f, 10f, 11f, 12f, 13f, 20f, 21f, 22f, 23f);
            Matrix3x4 newMatrix = matrix34;

            Assert.IsTrue(!ReferenceEquals(matrix34, newMatrix));
            newMatrix.AddTranslation(point);

            //native operation
            Vec3     point2       = new Vec3(point.x, point.y, point.z);
            Matrix34 nativeMatrix = new Matrix34(0f, 1f, 2f, 3f, 10f, 11f, 12f, 13f, 20f, 21f, 22f, 23f);

            nativeMatrix.AddTranslation(point2);

            Assert.IsTrue(newMatrix == nativeMatrix);
        }
Exemplo n.º 16
0
        public void ConversionFromManagedToNative()
        {
            Matrix3x4 managedmatrix = new Matrix3x4(0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23);
            Matrix34  nativeMatrix  = managedmatrix;

            Assert.That(true, Is.EqualTo(managedmatrix == nativeMatrix));
            Assert.That(nativeMatrix.m00, Is.EqualTo(managedmatrix.m00));
            Assert.That(nativeMatrix.m01, Is.EqualTo(managedmatrix.m01));
            Assert.That(nativeMatrix.m02, Is.EqualTo(managedmatrix.m02));
            Assert.That(nativeMatrix.m03, Is.EqualTo(managedmatrix.m03));
            Assert.That(nativeMatrix.m10, Is.EqualTo(managedmatrix.m10));
            Assert.That(nativeMatrix.m11, Is.EqualTo(managedmatrix.m11));
            Assert.That(nativeMatrix.m12, Is.EqualTo(managedmatrix.m12));
            Assert.That(nativeMatrix.m13, Is.EqualTo(managedmatrix.m13));
            Assert.That(nativeMatrix.m20, Is.EqualTo(managedmatrix.m20));
            Assert.That(nativeMatrix.m21, Is.EqualTo(managedmatrix.m21));
            Assert.That(nativeMatrix.m22, Is.EqualTo(managedmatrix.m22));
            Assert.That(nativeMatrix.m23, Is.EqualTo(managedmatrix.m23));
            Assert.IsTrue(managedmatrix == nativeMatrix);
        }
Exemplo n.º 17
0
        public void TestIdentity()
        {
            Assert.That(true, Is.EqualTo(Matrix3x4.Identity == Matrix34.CreateIdentity()));

            Matrix3x4 managedmatrix = Matrix3x4.Identity;

            Assert.That(true, Is.EqualTo(managedmatrix == Matrix3x4.Identity));
            Assert.That(managedmatrix.m00, Is.EqualTo(1));
            Assert.That(managedmatrix.m01, Is.EqualTo(0));
            Assert.That(managedmatrix.m02, Is.EqualTo(0));
            Assert.That(managedmatrix.m03, Is.EqualTo(0));
            Assert.That(managedmatrix.m10, Is.EqualTo(0));
            Assert.That(managedmatrix.m11, Is.EqualTo(1));
            Assert.That(managedmatrix.m12, Is.EqualTo(0));
            Assert.That(managedmatrix.m13, Is.EqualTo(0));
            Assert.That(managedmatrix.m20, Is.EqualTo(0));
            Assert.That(managedmatrix.m21, Is.EqualTo(0));
            Assert.That(managedmatrix.m22, Is.EqualTo(1));
            Assert.That(managedmatrix.m23, Is.EqualTo(0));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Spawn this instance.
        /// </summary>
        public static Player Create(Vec3 pos)
        {
            var player         = Entity.Instantiate <Player>(pos, Quat.Identity, 10, PlayerSkin.Geometry);
            var particleEffect = Env.ParticleManager.FindEffect("spaceship.Trails.fire_trail");

            player.LoadParticleEmitter(1, particleEffect, 0.03f);

            // Get position where to spawn the particle effect.
            Vec3 jetPosition = player.GetHelperPos(0, "particle_01");

            // Rotate particle effect to ensure it's shown at the back of the ship.
            player.SetTM(1, Matrix34.Create(Vec3.One, Quat.CreateRotationX(Utils.Deg2Rad(270f)), jetPosition));

            // Rotate Z-Axis of player ship in degrees.
            player.Rotation = new Quat(Matrix34.CreateRotationZ(Utils.Deg2Rad(180.0f)));

            Hud.CurrentHud.SetEnergy(player.MaxLife);
            GamePool.AddObjectToPool(player);
            return(player);
        }
Exemplo n.º 19
0
        public void TestMatrix3x4Construction()
        {
            //native parts
            Vec3     scale     = new Vec3(0.45f, 0.55f, 0.65f);
            Quat     rotation  = new Quat(0.2f, 0.1f, 0.1f, 0.1f);
            Vec3     position  = new Vec3(0.1f, 0.2f, 0.3f);
            Matrix34 nativeM34 = new Matrix34(scale, rotation, position);

            //managed parts
            Vector3    scale2        = new Vector3(0.45f, 0.55f, 0.65f);
            Quaternion rotation2     = new Quaternion(0.2f, 0.1f, 0.1f, 0.1f);
            Vector3    position2     = new Vector3(0.1f, 0.2f, 0.3f);
            Matrix3x4  managedMatrix = new Matrix3x4(scale2, rotation2, position2);

            Assert.IsTrue(scale == scale2, "Scale are not equal");
            //TODO test fails
            //Assert.IsTrue(rotation == rotation2, "Rotation are not equal");
            Assert.IsTrue(position == position2, "Position are not equal");

            //TODO test fails
            //Assert.IsTrue(nativeM34 == (Matrix34)managedMatrix, "Native and managed matrix34 are not equal");
        }
Exemplo n.º 20
0
        public void TestTransformPoint()
        {
            //managed
            Vector3   point3      = new Vector3(0.2f, 0.2f, 0.2f);
            Matrix3x4 matrix3x4   = Matrix3x4.Identity;
            Vector3   transPoint3 = matrix3x4.TransformPoint(point3);

            //native
            Vec3     pt3      = new Vec3(point3.x, point3.y, point3.z);
            Matrix34 matrix34 = Matrix34.CreateIdentity();
            Vec3     transPt3 = matrix34.TransformPoint(pt3);

            Assert.IsTrue(point3.x == pt3.x, "x is different");
            Assert.IsTrue(point3.y == pt3.y, "y is different");
            Assert.IsTrue(point3.z == pt3.z, "z is different");
            Assert.IsTrue(point3 == pt3, "point is different");

            Assert.IsTrue(transPoint3.x == transPt3.x, "x is different");
            Assert.IsTrue(transPoint3.y == transPt3.y, "y is different");
            Assert.IsTrue(transPoint3.z == transPt3.z, "z is different");
            Assert.IsTrue(transPoint3 == transPt3, "point is different");
        }
Exemplo n.º 21
0
        public void DoubleToFloat()
        {
            Matrix34<double> m = new Matrix34<double>(
                1.0, 2.0, 3.0,
                4.0, 5.0, 6.0,
                7.0, 8.0, 9.0,
                10.0, 11.0, 12.0);

            Matrix34<float> mf = Matrix34<double>.DoubleToFloat(m);

            Assert.AreEqual(1.0f, mf.Column0Row0, 1e-7);
            Assert.AreEqual(2.0f, mf.Column1Row0, 1e-7);
            Assert.AreEqual(3.0f, mf.Column2Row0, 1e-7);
            Assert.AreEqual(4.0f, mf.Column0Row1, 1e-7);
            Assert.AreEqual(5.0f, mf.Column1Row1, 1e-7);
            Assert.AreEqual(6.0f, mf.Column2Row1, 1e-7);
            Assert.AreEqual(7.0f, mf.Column0Row2, 1e-7);
            Assert.AreEqual(8.0f, mf.Column1Row2, 1e-7);
            Assert.AreEqual(9.0f, mf.Column2Row2, 1e-7);
            Assert.AreEqual(10.0f, mf.Column0Row3, 1e-7);
            Assert.AreEqual(11.0f, mf.Column1Row3, 1e-7);
            Assert.AreEqual(12.0f, mf.Column2Row3, 1e-7);
        }
Exemplo n.º 22
0
        public override string ToString()
        {
            if (HasSignal)
            {
                string ret = string.Format("{0} Handle:{1} Frame:{7} x:{3} y:{4} z:{5} Error:{6} Status:{8} {9}",
                                           TimeStamp.ToLongTimeString(),
                                           SensorIdx,
                                           HasSignal,
                                           Matrix14.ToString("F1").PadLeft(6, ' '),
                                           Matrix24.ToString("F1").PadLeft(6, ' '),
                                           Matrix34.ToString("F1").PadLeft(6, ' '),
                                           Error.ToString("F1").PadLeft(4, ' '),
                                           FrameNumber,
                                           PortStatus,
                                           Is6D ? "6D" : "5D");
                if (PartiallyOutOfVolume)
                {
                    ret += " PartiallyOutOfVolume";
                }

                return(ret);
            }
            else
            {
                string ret = string.Format("{0} Handle:{1} Status:{2}", TimeStamp.ToLongTimeString(), SensorIdx, PortStatus);
                if (SensorCoilIsBroken)
                {
                    ret += " Sensor is broken!";
                }
                if (OutOfVolume)
                {
                    ret += " OutOfVolume!";
                }

                return(ret);
            }
        }
Exemplo n.º 23
0
 extern internal static void SetWorldTM(IntPtr ptr, Matrix34 tm);
Exemplo n.º 24
0
 extern public static void SetLocalTM(IntPtr ptr, Matrix34 tm);
Exemplo n.º 25
0
        public void TestMethods()
        {
            //we need 3 orthonormal vectors for equivalence test to pass
            Vector3 right = new Vec3(1f, 0f, -1f);

            right = right.Normalized;

            Vector3 forward = new Vec3(1f, 1.4142136f, 1f);

            forward = forward.Normalized;

            Vector3 up = new Vec3(1f, -1.4142136f, 1f);

            up = up.Normalized;

            //native
            Matrix34 nativematrix = new Matrix34(0f, 3f, 6f, 9f, 1f, 4f, 7f, 10f, 2f, 5f, 8f, 11f);
            Quat     nativeQuat   = Quat.CreateQuatFromMatrix(nativematrix);

            //managed
            Matrix3x4  managedmatrix = new Matrix3x4(0f, 3f, 6f, 9f, 1f, 4f, 7f, 10f, 2f, 5f, 8f, 11f);
            Quaternion managedQuat   = Quat.CreateQuatFromMatrix(managedmatrix);

            float radians = 1.57f;

            //1 normalize
            {
                Quaternion test1a = managedQuat;
                test1a.Normalize();

                Quat test1b = nativeQuat;
                test1b.Normalize();

                Assert.IsTrue(Quat.IsEquivalent(test1a, test1b), "Normalize Equivalence test failed");
            }
            //2 Dot

            //3 Difference

            //4 CreateFromVectors
            {
                Matrix3x3 matrix33 = Matrix33.CreateFromVectors(right, forward, up);
                Quat      quat2a   = Quat.CreateQuatFromMatrix(matrix33);

                Vector3    right2   = new Vector3(right.x, right.y, right.z);
                Vector3    forward2 = new Vector3(forward.x, forward.y, forward.z);
                Vector3    up2      = new Vector3(up.x, up.y, up.z);
                Quaternion quat2b   = Quaternion.CreateFromVectors(right2, forward2, up2);
                Assert.IsTrue(quat2a == quat2b, "CreateFromVectors equality failed");
                Assert.IsTrue(Quat.IsEquivalent(quat2a, quat2b), "CreateFromVectors equivalence failed");
            }

            //5 SetLookOrientation
            //5a
            {
                //compare to SetRotationVDir, up vector = (0,0,1)

                //get 2 orthogonal vectors
                Vector3 up5      = new Vector3(0f, 0f, 1f);
                Vector3 forward5 = new Vector3(1f, 1.4142136f, 0f);
                forward5 = forward5.Normalized;
                Vector3 right5 = forward5.Cross(up5);

                Quat nativeQuaternion2 = Quat.CreateIdentity();
                nativeQuaternion2.SetRotationVDir(forward5);

                Matrix33 nativeMatrix      = Matrix33.CreateMatrix33(right5, forward5, up5);
                Quat     nativeQuaternion3 = Quat.CreateQuatFromMatrix(nativeMatrix);

                Assert.IsTrue(Quat.IsEquivalent(nativeQuaternion2, nativeQuaternion3), "Native Quaternion constructor failed comparison with SetRotationVDir. Expected :" + ((Quaternion)nativeQuaternion2).ToString() + ", Actual :" + ((Quaternion)nativeQuaternion3).ToString());
            }

            //5b
            {
                // test new C# SetLookOrientation, DEV-3691
                // rotate forward around x-y plane, z=0
                // i) 20 values for x-y plane
                // ii) 20 values for y-z plane

                Vec3[] testVectors = new Vec3[40];
                for (uint i = 0; i < 20; ++i)
                {
                    radians        = ((float)System.Math.PI) / 20.0f * i;
                    testVectors[i] = new Vec3((float)System.Math.Cos(radians), (float)System.Math.Sin(radians), 0f);
                }
                for (uint i = 20; i < 40; ++i)
                {
                    radians        = ((float)System.Math.PI) / 20.0f * i;
                    testVectors[i] = new Vec3(0f, (float)System.Math.Cos(radians), (float)System.Math.Sin(radians));
                }

                const float test_margin_error = 0.05f;
                for (uint i = 0; i < testVectors.Length; ++i)
                {
                    Vec3 forward5c = testVectors[i];
                    forward5c = forward5c.normalized();
                    Quat nativeQuat5c = Quat.CreateIdentity();
                    nativeQuat5c.SetRotationVDir(forward5c);
                    float dtPrdt1 = MathHelpers.Clamp(forward5c.Dot(nativeQuat5c.GetColumn1()), -1f, 1f);

                    Quaternion managedQuat5c = Quaternion.Identity;
                    Vector3    upManaged     = Vector3.Up;
                    managedQuat5c.SetLookOrientation(forward5c, upManaged);
                    float dtPrdt2 = MathHelpers.Clamp(forward5c.Dot(managedQuat5c.Forward), -1f, 1f);

                    float diffFromNative  = (float)(System.Math.Acos(dtPrdt1) * (180f / System.Math.PI));
                    float diffFromManaged = (float)(System.Math.Acos(dtPrdt2) * (180f / System.Math.PI));
                    float absoluteDiff    = System.Math.Abs(diffFromManaged - diffFromNative);
                    Assert.IsTrue(absoluteDiff <= test_margin_error, "SetLookOrientation failed at loop index " + i + ".Absolute Difference:" + absoluteDiff + " Expected (Native) :" + diffFromNative + ", Actual (Managed) :" + diffFromManaged + ", Forward : " + NativeExtensions.PrintString(forward5c) + ", Up :" + upManaged.ToString());
                }
                {
                    //boundary case where axis are flipped when comparing native to managed
                    Quaternion quatManaged    = Quaternion.Identity;
                    Vector3    upManaged      = Vector3.Up;
                    Vector3    forwardManaged = new Vector3(-8.126793f, 3.401123f, -1.644333f);
                    forwardManaged = forwardManaged.Normalized;
                    quatManaged.SetLookOrientation(forwardManaged, upManaged);

                    Quat quatNative    = Quat.CreateIdentity();
                    Vec3 forwardNative = new Vec3(-8.126793f, 3.401123f, -1.644333f);
                    forwardNative = forwardNative.normalized();
                    quatNative.SetRotationVDir(forwardNative);
                    bool isEqui1 = Quat.IsEquivalent(quatManaged, quatNative, 0.00999999776f);
                    Assert.IsTrue(isEqui1, String.Format("Native Quaternion {0} and Managed Quaternion {1} are not equivalent", ((Quaternion)quatNative).ToString(), quatManaged));
                }
            }

            //6 SetFromTORotation(Vector3 , Vector3)
            {
                Vec3 fromVec = new Vec3(0.5f, 0.5f, 0.5f);
                Vec3 toVec   = new Vec3(0.5f, -0.5f, -0.5f);
                Quat quat6a  = Quat.CreateIdentity();
                quat6a.SetRotationV0V1(fromVec, toVec);

                Vector3    fromVec2 = new Vector3(fromVec.x, fromVec.y, fromVec.z);
                Vector3    toVec2   = new Vector3(toVec.x, toVec.y, toVec.z);
                Quaternion quat6b   = Quaternion.Identity;
                quat6b.SetFromToRotation(fromVec2, toVec2);
                Assert.IsTrue(Quat.IsEquivalent(quat6a, quat6b), "SetFromToRotation failed");
            }
            //7 CreateRotationX(float)
            {
                Quat       quat7a = Quat.CreateRotationX(radians);
                Quaternion quat7b = Quaternion.CreateRotationX(radians);
                Assert.IsTrue(Quat.IsEquivalent(quat7a, quat7b), "CreateRotationX failed");
            }


            //8 CreateRotationY(float)
            {
                Quat       quat8a = Quat.CreateRotationY(radians + 0.1f);
                Quaternion quat8b = Quaternion.CreateRotationY(radians + 0.1f);
                Assert.IsTrue(Quat.IsEquivalent(quat8a, quat8b), "CreateRotationY failed");
            }


            //9 CreateRotationZ(float)
            {
                Quat       quat9a = Quat.CreateRotationZ(radians + 0.1f);
                Quaternion quat9b = Quaternion.CreateRotationZ(radians + 0.1f);
                Assert.IsTrue(Quat.IsEquivalent(quat9a, quat9b), "CreateRotationZ failed");
            }


            //10 CreateRotationXYZ(Angles3)
            {
                Angles3 angles  = new Vec3(radians, radians, radians);
                Quat    quat10a = Quat.CreateRotationXYZ(angles);

                Quaternion quat10b = Quaternion.CreateRotationXYZ(angles);
                Assert.IsTrue(Quat.IsEquivalent(quat10a, quat10b), "CreateRotationXYZ equivalence failed");
            }


            //11 Slerp(Quaternion, Quaternion, float)
            {
                float timeRatio = 0.5f;
                Quat  quat11a   = Quat.CreateRotationX(radians);
                Quat  quat11b   = Quat.CreateRotationY(radians);
                Quat  quat11c   = Quat.CreateIdentity();
                quat11c.SetSlerp(quat11a, quat11b, timeRatio);

                Quaternion quat11d = Quaternion.CreateRotationX(radians);
                Quaternion quat11e = Quaternion.CreateRotationY(radians);
                Quaternion quat11f = Quaternion.Slerp(quat11d, quat11e, timeRatio);
                Assert.IsTrue(Quat.IsEquivalent(quat11c, quat11f), "Slerp equivalence failed");
            }


            //12 Lerp(Quaternion, Quaternion, float)
            {
                float timeRatio = 0.5f;
                Quat  quat12a   = Quat.CreateRotationX(radians);
                Quat  quat12b   = Quat.CreateRotationY(radians);
                Quat  quat12c   = Quat.CreateIdentity();
                quat12c.SetNlerp(quat12a, quat12b, timeRatio);

                Quaternion quat12d = Quaternion.CreateRotationX(radians);
                Quaternion quat12e = Quaternion.CreateRotationY(radians);
                Quaternion quat12f = Quaternion.Lerp(quat12d, quat12e, timeRatio);
                Assert.IsTrue(Quat.IsEquivalent(quat12c, quat12f), "Lerp equivalence failed");
            }

            //13 Properties
            {
                Matrix3x3 matrix33 = Matrix33.CreateFromVectors(right, forward, up);
                Quat      quat13a  = Quat.CreateQuatFromMatrix(matrix33);

                Vector3    right2   = new Vector3(right.x, right.y, right.z);
                Vector3    forward2 = new Vector3(forward.x, forward.y, forward.z);
                Vector3    up2      = new Vector3(up.x, up.y, up.z);
                Quaternion quat13b  = Quaternion.CreateFromVectors(right2, forward2, up2);
                Assert.IsTrue(quat13a == quat13b, "Quaternions equality test failed");
                Assert.IsTrue(Quat.IsEquivalent(quat13a, quat13b), "Quaternions equivalence test failed");

                Assert.IsTrue(Vec3.IsEquivalent(right2, quat13b.Right), "Right equivalence test failed");
                Assert.IsTrue(Vec3.IsEquivalent(forward2, quat13b.Forward), "Forward equivalence test failed");
                Assert.IsTrue(Vec3.IsEquivalent(up2, quat13b.Up), "Up equivalence test failed");

                //inversion
                Quat       invertNative  = quat13a.GetInverted();
                Quaternion invertManaged = quat13b.Inverted;
                Assert.IsTrue(Quat.IsEquivalent(invertNative, invertManaged), "Inversion equivalence test failed");

                //normalization
                Quat       normalNative  = quat13a.GetNormalized();
                Quaternion normalManaged = quat13b.Normalized;
                Assert.IsTrue(Quat.IsEquivalent(normalNative, normalManaged), "Normalization test failed");

                //length
                float lengthNative  = quat13a.GetLength();
                float lengthManaged = quat13b.Length;
                Assert.IsTrue(System.Math.Abs(lengthNative - lengthManaged) <= Single.Epsilon, "Length test failed");

                //IsIdentity
                Quaternion managedIdentity = Quaternion.Identity;
                Assert.IsTrue(managedIdentity.IsIdentity, "Managed Identity test failed");

                Quat nativeIdentity = new Quat();
                nativeIdentity.SetIdentity();
                Assert.IsTrue(nativeIdentity.IsIdentity(), "Native Identity test failed");
                Assert.IsTrue(managedIdentity == nativeIdentity, "Identity comparison failed");

                // yaw pitch roll
            }
        }
Exemplo n.º 26
0
 internal static extern void SetCameraMatrix(IntPtr cameraPtr, Matrix34 matrix);
Exemplo n.º 27
0
 /// <summary>
 /// Creates new instance of <see cref="Quaternion"/> struct.
 /// </summary>
 /// <param name="matrix">
 /// 3x4 matrix that contains representation of rotation.
 /// </param>
 public Quaternion(Matrix34 matrix)
     : this(new Matrix33(matrix))
 {
 }
Exemplo n.º 28
0
 extern public static void SetWorldTM(IntPtr ptr, Matrix34 tm);
Exemplo n.º 29
0
 internal static extern void SetWorldTM(IntPtr ptr, Matrix34 tm);
Exemplo n.º 30
0
        public void Equals()
        {
            Matrix34<double> a = new Matrix34<double>(
                1.0, 2.0, 3.0,
                4.0, 5.0, 6.0,
                7.0, 8.0, 9.0,
                10.0, 11.0, 12.0);
            Matrix34<double> b = new Matrix34<double>(0.0);
            Matrix34<double> c = new Matrix34<double>(
                1.0, 2.0, 3.0,
                4.0, 5.0, 6.0,
                7.0, 8.0, 9.0,
                10.0, 11.0, 12.0);

            Assert.IsTrue(a.Equals(c));
            Assert.IsTrue(c.Equals(a));
            Assert.IsTrue(a == c);
            Assert.IsTrue(c == a);
            Assert.IsFalse(c != a);
            Assert.IsFalse(c != a);
            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
            Assert.IsFalse(a == b);
            Assert.IsFalse(b == a);
            Assert.IsTrue(a != b);
            Assert.IsTrue(b != a);

            object objA = a;
            object objB = b;
            object objC = c;

            Assert.IsTrue(a.Equals(objA));
            Assert.IsTrue(a.Equals(objC));
            Assert.IsFalse(a.Equals(objB));

            Assert.IsTrue(objA.Equals(objC));
            Assert.IsFalse(objA.Equals(objB));

            Assert.IsFalse(a.Equals(null));
            Assert.IsFalse(a.Equals(5));
        }
Exemplo n.º 31
0
 /// <summary>
 /// Creates new instance of type <see cref="QuaternionTranslation"/>.
 /// </summary>
 /// <param name="m">
 /// <see cref="Matrix34"/> that represents both translation and orientation.
 /// </param>
 public QuaternionTranslation(Matrix34 m)
 {
     this.Q = new Quaternion(m);
     this.T = m.Translation;
 }
Exemplo n.º 32
0
 extern internal static void SetCameraMatrix(IntPtr cameraPtr, Matrix34 matrix);
Exemplo n.º 33
0
 public override bool OnInitialize()
 {
     _isRotationMatrix = _memberType == hkClassMember.Type.TYPE_ROTATION;
     _value            = *(bMatrix43 *)Data;
     return(false);
 }
Exemplo n.º 34
0
        public void Matrix34()
        {
            string fs =
                @"#version 330

                  uniform mat3x4 exampleMat34;
                  out vec3 FragColor;

                  void main()
                  {
                      FragColor = vec3(exampleMat34[1].x, exampleMat34[2].z, 0.0);
                  }";

            using (GraphicsWindow window = Device.CreateWindow(1, 1))
            using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
            using (ShaderProgram sp = Device.CreateShaderProgram(ShaderSources.PassThroughVertexShader(), fs))
            using (VertexArray va = TestUtility.CreateVertexArray(window.Context, sp.VertexAttributes["position"].Location))
            {
                Matrix34<float> m34 = new Matrix34<float>(
                        0.0f, 1.0f, 0.0f,
                        0.0f, 0.0f, 0.0f,
                        0.0f, 0.0f, 1.0f,
                        0.0f, 0.0f, 0.0f);
                Uniform<Matrix34<float>> exampleMat34 = (Uniform<Matrix34<float>>)sp.Uniforms["exampleMat34"];
                Assert.AreEqual("exampleMat34", exampleMat34.Name);
                Assert.AreEqual(UniformType.FloatMatrix34, exampleMat34.Datatype);
                Assert.AreEqual(new Matrix34<float>(), exampleMat34.Value);
                exampleMat34.Value = m34;
                Assert.AreEqual(m34, exampleMat34.Value);

                window.Context.Framebuffer = framebuffer;
                window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), sp, va), new SceneState());
                TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 255, 0);
            }
        }
Exemplo n.º 35
0
 extern internal static void SetLocalTM(IntPtr ptr, Matrix34 tm);
Exemplo n.º 36
0
 /// <summary>
 /// </summary>
 /// <param name="vx"> </param>
 /// <param name="vy"> </param>
 /// <param name="vz"> </param>
 /// <param name="pos"></param>
 public void SetFromVectors(Vector3 vx, Vector3 vy, Vector3 vz, Vector3 pos)
 {
     var m34 = new Matrix34
     {
         M00 = vx.X,
         M01 = vy.X,
         M02 = vz.X,
         M03 = pos.X,
         M10 = vx.Y,
         M11 = vy.Y,
         M12 = vz.Y,
         M13 = pos.Y,
         M20 = vx.Z,
         M21 = vy.Z,
         M22 = vz.Z,
         M23 = pos.Z
     };
     this = new QuaternionTranslation(m34);
 }
Exemplo n.º 37
0
 internal static extern void SetLocalTM(IntPtr ptr, Matrix34 tm);
 public static extern void SetWorldTM(IntPtr ptr, Matrix34 tm);
Exemplo n.º 39
0
 public void CalcTransforms()
 {
     CalcFlags();
     _transform = (Matrix)Matrix34.TextureMatrix(this);
 }
 public static extern void SetLocalTM(IntPtr ptr, Matrix34 tm);
Exemplo n.º 41
0
 /// <summary>
 /// Sets position, rotation and scale of an entity slot, ba a matrix.
 /// </summary>
 /// <param name="slot">Slot.</param>
 /// <param name="mx">Mx.</param>
 public void SetTM(int slot, Matrix34 mx)
 {
     BaseEntity.SetSlotLocalTM(slot, mx);
 }
Exemplo n.º 42
0
        public void TestGetHashCode()
        {
            Matrix34<double> a = new Matrix34<double>(
                1.0, 2.0, 3.0,
                4.0, 5.0, 6.0,
                7.0, 8.0, 9.0,
                10.0, 11.0, 12.0);
            Matrix34<double> b = new Matrix34<double>(0.0);
            Matrix34<double> c = new Matrix34<double>(
                1.0, 2.0, 3.0,
                4.0, 5.0, 6.0,
                7.0, 8.0, 9.0,
                10.0, 11.0, 12.0);

            Assert.AreEqual(a.GetHashCode(), c.GetHashCode());
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }