Esempio n. 1
0
        public void ConstructorValuesAreAccessibleByIndexer()
        {
            Matrix4x3 matrix4x3;

            matrix4x3 = new Matrix4x3();

            for (int x = 0; x < matrix4x3.Columns; x++)
            {
                for (int y = 0; y < matrix4x3.Rows; y++)
                {
                    Assert.Equal(0, matrix4x3[x, y], Epsilon);
                }
            }

            double value = 33.33;
            matrix4x3 = new Matrix4x3(value);

            for (int x = 0; x < matrix4x3.Columns; x++)
            {
                for (int y = 0; y < matrix4x3.Rows; y++)
                {
                    Assert.Equal(value, matrix4x3[x, y], Epsilon);
                }
            }

            GenerateFilledMatrixWithValues(out matrix4x3);

            for (int y = 0; y < matrix4x3.Rows; y++)
            {
                for (int x = 0; x < matrix4x3.Columns; x++)
                {
                    Assert.Equal(y * matrix4x3.Columns + x, matrix4x3[x, y], Epsilon);
                }
            }
        }
Esempio n. 2
0
        public void ConstantValuesAreCorrect()
        {
            Matrix4x3 matrix4x3 = new Matrix4x3();

            Assert.Equal(4, matrix4x3.Columns);
            Assert.Equal(3, matrix4x3.Rows);
            Assert.Equal(Matrix4x3.ColumnCount, matrix4x3.Columns);
            Assert.Equal(Matrix4x3.RowCount, matrix4x3.Rows);
        }
Esempio n. 3
0
            public InstancedGeometry(CacheBase Cache, int Address)
            {
                EndianReader Reader = Cache.Reader;

                Reader.SeekTo(Address);

                Name      = Cache.Strings.GetItemByID(Reader.ReadInt32());
                NodeIndex = Reader.ReadInt32();

                TransformScale = Reader.ReadSingle();

                TransformMatrix = Matrix4x3.Read(Reader);
            }
Esempio n. 4
0
        public override void RestoreGraphicsState(object graphicsState)
        {
            var gs = graphicsState as GraphicState;

            if (null != gs)
            {
                _transformation = gs.Transformation;
                _transposedInverseTransformation = gs.TransposedInverseTransformation;
            }
            else
            {
                throw new ArgumentException(nameof(graphicsState) + " is not a valid graphic state!");
            }
        }
Esempio n. 5
0
        public void SimpleSubtractionGeneratesCorrectValues()
        {
            Matrix4x3 value1 = new Matrix4x3(100);
            Matrix4x3 value2 = new Matrix4x3(1);
            Matrix4x3 result = value1 - value2;

            for (int y = 0; y < Matrix4x3.RowCount; y++)
            {
                for (int x = 0; x < Matrix4x3.ColumnCount; x++)
                {
                    Assert.Equal(100 - 1, result[x, y], Epsilon);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the absolute enclosing rectangle, taking into account ScaleX, ScaleY, Rotation and Shear (SSRS).
        /// </summary>
        /// <returns>The enclosing rectangle in absolute values.</returns>
        public RectangleD3D GetAbsoluteEnclosingRectangle()
        {
            var m = Matrix4x3.NewScalingShearingRotationDegreesTranslation(
                ScaleX, ScaleY, ScaleZ,
                ShearX, ShearY, ShearZ,
                RotationX, RotationY, RotationZ,
                AbsolutePivotPositionX, AbsolutePivotPositionY, AbsolutePivotPositionZ);

            m.TranslatePrepend(AbsoluteVectorPivotToLeftUpper.X, AbsoluteVectorPivotToLeftUpper.Y, AbsoluteVectorPivotToLeftUpper.Z);

            var r = new RectangleD3D(PointD3D.Empty, AbsoluteSize);

            return(RectangleD3D.NewRectangleIncludingAllPoints(r.Vertices.Select(p => m.Transform(p))));
        }
Esempio n. 7
0
    private void TranslucentRender()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(AlphaBlend);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        device.SetVertexBuffer(VertexPositions, 0);
        device.SetVertexBuffer(VertexTextureCoords, 1);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTexture(Texture, 0);

        InstanceAlphas.Lock(Accessibility.DynamicWriteOnly);
        InstanceWVPs.Lock(Accessibility.DynamicWriteOnly);

        int k = 0;

        foreach (var instance in Instances)
        {
            Vector3 position = instance.Position;
            float   x        = instance.Time;
            float   scale    = clamp(-3 * sin(x) * log(x), 0, 1) * 15 + 10;
            float   alpha    = clamp(sin(square(1.2f - x)), 0, 1) * 0.5f;

            var world = new Matrix4x3().Identity();
            world.Translate(position * ViewingMatrix);
            world.Scale(scale);

            InstanceWVPs.Write(k, world * ProjectionMatrix);
            InstanceAlphas.Write(k, alpha);

            k++;
        }

        InstanceAlphas.Unlock();
        InstanceWVPs.Unlock();

        device.SetInstanceBuffer(InstanceAlphas, 2);
        device.SetInstanceBuffer(InstanceWVPs, 3);

        device.DrawInstanced(4, Instances.Count);
    }
Esempio n. 8
0
        public MultiRectangularObjectOutline(IEnumerable <RectangleD3D> rectangles, Matrix4x3 transformation)
        {
            if (null == rectangles)
            {
                throw new ArgumentNullException(nameof(rectangles));
            }

            _rectangles = rectangles.ToArray();

            if (_rectangles.Length == 0)
            {
                throw new ArgumentNullException(nameof(rectangles) + " yields no entries");
            }

            _transformation = transformation;
        }
            public InstancedGeometry(CacheBase Cache, int Address, int modifier)
            {
                EndianReader Reader = Cache.Reader;

                Reader.SeekTo(Address);

                TransformScale = Reader.ReadSingle();

                TransformMatrix = Matrix4x3.Read(Reader);

                SectionIndex = Reader.ReadInt16() + modifier;

                Reader.SeekTo(Address + 80);

                Name = Cache.Strings.GetItemByID(Reader.ReadInt16());
            }
Esempio n. 10
0
        public void ScalarMultiplicationIsCorrect()
        {
            GenerateFilledMatrixWithValues(out Matrix4x3 matrix4x3);

            for (double c = -10; c <= 10; c += 0.5)
            {
                Matrix4x3 result = matrix4x3 * c;

                for (int y = 0; y < matrix4x3.Rows; y++)
                {
                    for (int x = 0; x < matrix4x3.Columns; x++)
                    {
                        Assert.Equal(matrix4x3[x, y] * c, result[x, y], Epsilon);
                    }
                }
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Transforms the graphics context is such a way, that the object can be drawn in local coordinates.
 /// </summary>
 /// <param name="g">Graphics context (should be saved beforehand).</param>
 protected virtual void TransformGraphics(IGraphicsContext3D g)
 {
     if (RotationX != 0 || RotationY != 0 || RotationZ != 0 || ScaleX != 1 || ScaleY != 1 || ScaleZ != 1 || ShearX != 0 || ShearY != 0 || ShearZ != 0)
     {
         g.PrependTransform(Matrix4x3.NewScalingShearingRotationDegreesTranslation(
                                _location.ScaleX, _location.ScaleY, _location.ScaleY
                                ,
                                _location.ShearX, _location.ShearY, _location.ShearZ,
                                _location.RotationX, _location.RotationY, _location.RotationZ,
                                _location.AbsolutePivotPosition.X, _location.AbsolutePivotPositionY, _location.AbsolutePivotPositionZ));
     }
     else
     {
         var p = _location.AbsolutePivotPosition;
         g.TranslateTransform(p.X, p.Y, p.Z);
     }
 }
Esempio n. 12
0
    // 行列の連結
    public static Matrix4x3 operator *(Matrix4x3 a, Matrix4x3 b)
    {
        var r = new Matrix4x3();

        r.m11 = a.m11 * b.m11 + a.m12 * b.m21 + a.m13 * b.m31;
        r.m12 = a.m11 * b.m12 + a.m12 * b.m22 + a.m13 * b.m32;
        r.m13 = a.m11 * b.m13 + a.m12 * b.m23 + a.m13 * b.m33;

        r.m21 = a.m21 * b.m11 + a.m22 * b.m21 + a.m23 * b.m31;
        r.m22 = a.m21 * b.m12 + a.m22 * b.m22 + a.m23 * b.m32;
        r.m23 = a.m21 * b.m13 + a.m22 * b.m23 + a.m23 * b.m33;

        r.m31 = a.m31 * b.m11 + a.m32 * b.m21 + a.m33 * b.m31;
        r.m32 = a.m31 * b.m12 + a.m32 * b.m22 + a.m33 * b.m32;
        r.m33 = a.m31 * b.m13 + a.m32 * b.m23 + a.m33 * b.m33;

        return(r);
    }
    void TransparentRender()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        var viewing    = ViewingMatrix;
        var projection = ProjectionMatrix;

        int k = 0;

        foreach (var instance in Instances)
        {
            Vector3 position = instance.Position;
            float   x        = instance.Time;
            float   scale    = clamp(-3 * sin(x) * log(x), 0, 1) * 10 + 5;
            float   alpha    = clamp(sin(square(1.2f - x)), 0, 1) * 0.2f;

            var world = new Matrix4x3().Identity();
            world.Translate(position * ViewingMatrix);
            world.Scale(scale);

            InstanceWVPs[k]   = world * ProjectionMatrix;
            InstanceColors[k] = new Color(alpha, alpha, alpha, instance.Time);

            k++;
        }

        device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
        device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 1);
        VertexShader.SetConstantBuffer(InstanceWVPs, 0);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTextureArray(Textures, 0);
        PixelShader.SetConstantBuffer(InstanceColors, 0);

        device.DrawInstanced(4, InstanceCount);
    }
Esempio n. 14
0
            public override IGripManipulationHandle[] GetGrips(int gripLevel)
            {
                if (gripLevel <= 1)
                {
                    var ls  = (LineShape)_hitobject;
                    var pts = new PointD3D[] { PointD3D.Empty, (PointD3D)ls.Size };
                    for (int i = 0; i < pts.Length; i++)
                    {
                        var pt = ls._transformation.Transform(pts[i]);
                        pt     = Transformation.Transform(pt);
                        pts[i] = pt;
                    }

                    var grips = new IGripManipulationHandle[gripLevel == 0 ? 1 : 3];

                    // Translation grips
                    var bounds         = ls.Bounds;
                    var wn             = PolylineMath3D.GetWestNorthVectors(bounds.Size);
                    var transformation = Matrix4x3.NewFromBasisVectorsAndLocation(wn.Item1, wn.Item2, bounds.Size.Normalized, PointD3D.Empty);

                    transformation.AppendTransform(ls._transformation);
                    transformation.AppendTransform(Transformation);

                    double t1            = 0.55 * ls._linePen.Thickness1;
                    double t2            = 0.55 * ls._linePen.Thickness2;
                    var    rect          = new RectangleD3D(-t1, -t2, 0, 2 * t1, 2 * t2, bounds.Size.Length);
                    var    objectOutline = new RectangularObjectOutline(rect, transformation);
                    grips[0] = new MovementGripHandle(this, objectOutline, null);

                    // PathNode grips
                    if (gripLevel == 1)
                    {
                        grips[2] = grips[0]; // put the movement grip to the background, the two NodeGrips need more priority
                        var gripRadius = Math.Max(t1, t2);
                        grips[0] = new PathNodeGripHandle(this, new VectorD3D(0, 0, 0), pts[0], gripRadius);
                        grips[1] = new PathNodeGripHandle(this, new VectorD3D(1, 1, 1), pts[1], gripRadius);
                    }
                    return(grips);
                }
                else
                {
                    return(base.GetGrips(gripLevel));
                }
            }
Esempio n. 15
0
        /// <summary>
        /// Gets the object outline for arrangements.
        /// </summary>
        /// <param name="localToWorldTransformation">The local to world transformation.</param>
        /// <returns></returns>
        public override IObjectOutlineForArrangements GetObjectOutlineForArrangements(Matrix4x3 localToWorldTransformation)
        {
            var bounds = Bounds;

            double sx = Bounds.SizeX / 2;
            double sy = Bounds.SizeY / 2;
            double sz = Bounds.SizeZ / 2;

            var dx = Bounds.X + sx;
            var dy = Bounds.Y + sy;
            var dz = Bounds.Z + sz;

            var transformation = Matrix4x3.NewScalingShearingRotationDegreesTranslation(sx, sy, sz, 0, 0, 0, 0, 0, 0, dx, dy, dz); // represents a transformation from a unit sphere to the real sphere

            transformation.AppendTransform(_transformation);                                                                       // additional transformations of the ellipsoid
            transformation.AppendTransform(localToWorldTransformation);                                                            // local to global transformation

            return(new SphericalObjectOutline(transformation));
        }
Esempio n. 16
0
        public void MemberGetAndSetValuesCorrectly()
        {
            Matrix4x3 matrix4x3 = new Matrix4x3();

            matrix4x3.M11 = 0;
            matrix4x3.M21 = 1;
            matrix4x3.M31 = 2;
            matrix4x3.M41 = 3;
            matrix4x3.M12 = 4;
            matrix4x3.M22 = 5;
            matrix4x3.M32 = 6;
            matrix4x3.M42 = 7;
            matrix4x3.M13 = 8;
            matrix4x3.M23 = 9;
            matrix4x3.M33 = 10;
            matrix4x3.M43 = 11;

            Assert.Equal(0, matrix4x3.M11, Epsilon);
            Assert.Equal(1, matrix4x3.M21, Epsilon);
            Assert.Equal(2, matrix4x3.M31, Epsilon);
            Assert.Equal(3, matrix4x3.M41, Epsilon);
            Assert.Equal(4, matrix4x3.M12, Epsilon);
            Assert.Equal(5, matrix4x3.M22, Epsilon);
            Assert.Equal(6, matrix4x3.M32, Epsilon);
            Assert.Equal(7, matrix4x3.M42, Epsilon);
            Assert.Equal(8, matrix4x3.M13, Epsilon);
            Assert.Equal(9, matrix4x3.M23, Epsilon);
            Assert.Equal(10, matrix4x3.M33, Epsilon);
            Assert.Equal(11, matrix4x3.M43, Epsilon);

            Assert.Equal(matrix4x3[0, 0], matrix4x3.M11, Epsilon);
            Assert.Equal(matrix4x3[1, 0], matrix4x3.M21, Epsilon);
            Assert.Equal(matrix4x3[2, 0], matrix4x3.M31, Epsilon);
            Assert.Equal(matrix4x3[3, 0], matrix4x3.M41, Epsilon);
            Assert.Equal(matrix4x3[0, 1], matrix4x3.M12, Epsilon);
            Assert.Equal(matrix4x3[1, 1], matrix4x3.M22, Epsilon);
            Assert.Equal(matrix4x3[2, 1], matrix4x3.M32, Epsilon);
            Assert.Equal(matrix4x3[3, 1], matrix4x3.M42, Epsilon);
            Assert.Equal(matrix4x3[0, 2], matrix4x3.M13, Epsilon);
            Assert.Equal(matrix4x3[1, 2], matrix4x3.M23, Epsilon);
            Assert.Equal(matrix4x3[2, 2], matrix4x3.M33, Epsilon);
            Assert.Equal(matrix4x3[3, 2], matrix4x3.M43, Epsilon);
        }
Esempio n. 17
0
        /// <summary>
        /// Adds the triangle geometry for this cap.
        /// </summary>
        /// <param name="AddPositionAndNormal">The procedure to add a vertex position and normal.</param>
        /// <param name="AddIndices">The procedure to add vertex indices for one triangle.</param>
        /// <param name="vertexIndexOffset">The vertex index offset. Must be actualized during this call.</param>
        /// <param name="isStartCap">If set to <c>true</c>, a start cap is drawn; otherwise, an end cap is drawn.</param>
        /// <param name="basePoint">The location of the middle point of the line at the cap's location.</param>
        /// <param name="westVector">The west vector for orientation of the cross section.</param>
        /// <param name="northVector">The north vector for orientation of the cross section.</param>
        /// <param name="forwardVector">The forward vector for orientation of the cross section.</param>
        /// <param name="crossSection">The cross section of the line.</param>
        public static void AddGeometry(
            Action <PointD3D, VectorD3D> AddPositionAndNormal,
            Action <int, int, int, bool> AddIndices,
            ref int vertexIndexOffset,
            bool isStartCap,
            PointD3D basePoint,
            VectorD3D westVector,
            VectorD3D northVector,
            VectorD3D forwardVector,
            ICrossSectionOfLine crossSection
            )
        {
            if (isStartCap)
            {
                forwardVector = -forwardVector;
            }

            var matrix = Matrix4x3.NewFromBasisVectorsAndLocation(westVector, northVector, forwardVector, basePoint);

            int currIndex = vertexIndexOffset;
            int crossSectionPositionCount = crossSection.NumberOfVertices;

            // Add the midpoint
            // add the middle point of the end cap and the normal of the end cap
            AddPositionAndNormal(basePoint, forwardVector);
            ++currIndex;

            for (int i = 0; i < crossSectionPositionCount; ++i)
            {
                var sp = matrix.Transform(crossSection.Vertices(i));
                AddPositionAndNormal(sp, forwardVector);

                AddIndices(
                    currIndex - 1, // mid point of the end cap
                    currIndex + i,
                    currIndex + (1 + i) % crossSectionPositionCount,
                    isStartCap);
            }

            currIndex        += crossSectionPositionCount;
            vertexIndexOffset = currIndex;
        }
Esempio n. 18
0
        public void IndexerGetAndSetValuesCorrectly()
        {
            Matrix4x3 matrix4x3 = new Matrix4x3();

            for (int x = 0; x < matrix4x3.Columns; x++)
            {
                for (int y = 0; y < matrix4x3.Rows; y++)
                {
                    matrix4x3[x, y] = y * matrix4x3.Columns + x;
                }
            }

            for (int y = 0; y < matrix4x3.Rows; y++)
            {
                for (int x = 0; x < matrix4x3.Columns; x++)
                {
                    Assert.Equal(y * matrix4x3.Columns + x, matrix4x3[x, y], Epsilon);
                }
            }
        }
    public Vector3[] CalculateSegment(Vector3[] vectors)
    {
        const int iterations = 100;

        Vector3[] resultPoints = new Vector3[iterations];

        for (int i = 0; i < iterations; i++)
        {
            // računaj matrice
            float   t       = (float)i / iterations;
            Vector4 tVector = new Vector4(Mathf.Pow(t, 3), Mathf.Pow(t, 2), Mathf.Pow(t, 1), 1) / 6;
            Vector4 vector4 = MatrixHelper.MultiplyMatrices(tVector, matrix);

            Matrix4x3 pointsMatrix4x3 = new Matrix4x3(vectors);

            Vector3 point = MatrixHelper.MultiplyMatrices(vector4, pointsMatrix4x3);
            resultPoints[i] = point;
        }
        return(resultPoints);
    }
Esempio n. 20
0
        public void IndexerGetAndSetValuesCorrectly()
        {
            Matrix4x3 matrix4x3 = new Matrix4x3();

            for (int x = 0; x < matrix4x3.Columns; x++)
            {
                for (int y = 0; y < matrix4x3.Rows; y++)
                {
                    matrix4x3[x, y] = y * matrix4x3.Columns + x;
                }
            }

            for (int y = 0; y < matrix4x3.Rows; y++)
            {
                for (int x = 0; x < matrix4x3.Columns; x++)
                {
                    Assert.Equal(y * matrix4x3.Columns + x, matrix4x3[x, y], Epsilon);
                }
            }
        }
Esempio n. 21
0
    void TransparentRender()
    {
        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(AlphaBlend);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        device.SetVertexBuffer(VertexPositions, 0);
        device.SetVertexBuffer(VertexTextureCoords, 1);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTexture(Texture, 0);

        InstanceWVPs.Lock(Accessibility.DynamicWriteOnly);

        var eye = Entity.Find("camera").Get <TransformComponent>().Position;

        for (int i = 0; i < Instances.Length; i++)
        {
            var     instance = Instances[i];
            Vector3 position = instance.Position;
            float   scale    = instance.Scale;

            var world = new Matrix4x3().Identity();
            world.Translate(position * ViewingMatrix);
            world.Scale(scale);

            InstanceWVPs.Write(i, world * ProjectionMatrix);
        }

        InstanceWVPs.Unlock();

        device.SetInstanceBuffer(InstanceWVPs, 2);

        device.DrawInstanced(4, Instances.Length);
    }
Esempio n. 22
0
    private static Matrix3x3 aim(Matrix3x3 angle, Vector3 direction, float speed)
    {
        Vector3 forward = new Vector3();

        forward.X = angle.M31;
        forward.Y = angle.M32;
        forward.Z = angle.M33;

        float theta = Vector3.Angle(direction, forward);

        if (abs(theta) > speed)
        {
            Vector3 axis = Vector3.Outer(direction, forward);
            angle.Transform(new Matrix3x3(new Quaternion(axis.Normalize(), -speed)));
        }
        else
        {
            angle = new Matrix4x3().LookAt(Vector3.Zero, direction)._Matrix3x3;
        }
        return(angle);
    }
Esempio n. 23
0
        public void SetMatrix(string name, Matrix4x3 data)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("Shader: " + name);
            }

            if (_uniformLocations.ContainsKey(name))
            {
                float[] mat4x3 = new float[]
                {
                    data.M11, data.M12, data.M13,
                    data.M21, data.M22, data.M23,
                    data.M31, data.M32, data.M33,
                    data.M41, data.M42, data.M43
                };

                GL.UseProgram(Handle);
                GL.UniformMatrix4x3(_uniformLocations[name], 48, true, mat4x3);
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Creates a new camera which has the LookAtRH matrix as provided in the argument. Up and eye vector as well as eye position are calculated from the provided matrix, the target position is calculated from the eye vector and the provided <paramref name="newDistance"/> value.
        /// </summary>
        /// <param name="l">The LookAtRH matrix. This matrix must have a determinant of 1, and each of the vectors {M11, M21, M31}, {M12, M22, M32}, {M13, M23, M33} must have a length of 1.</param>
        /// <param name="newDistance">The distance between camera eye and target of the new camera.</param>
        /// <returns>A new camera which has the LookAtRH matrix as provided in the argument. Up and eye vector as well as eye position are calculated from the provided matrix, the target position is calculated from the eye vector and the provided <paramref name="newDistance"/> value.</returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public CameraBase WithLookAtRHMatrix(Matrix4x3 l, double newDistance)
        {
            double determinant = l.Determinant;

            if (!(determinant > 0.9 && determinant < 1.1))
            {
                throw new ArgumentOutOfRangeException(nameof(l) + " seems not to be a LookAtRH matrix because its determinant is not 1");
            }

            // get position
            var eyePos = new PointD3D(
                (l.M23 * l.M32 * l.M41 - l.M22 * l.M33 * l.M41 - l.M23 * l.M31 * l.M42 + l.M21 * l.M33 * l.M42 + l.M22 * l.M31 * l.M43 - l.M21 * l.M32 * l.M43) / determinant,
                (-(l.M13 * l.M32 * l.M41) + l.M12 * l.M33 * l.M41 + l.M13 * l.M31 * l.M42 - l.M11 * l.M33 * l.M42 - l.M12 * l.M31 * l.M43 + l.M11 * l.M32 * l.M43) / determinant,
                (l.M13 * l.M22 * l.M41 - l.M12 * l.M23 * l.M41 - l.M13 * l.M21 * l.M42 + l.M11 * l.M23 * l.M42 + l.M12 * l.M21 * l.M43 - l.M11 * l.M22 * l.M43) / determinant
                );

            var upVector  = new VectorD3D(l.M12, l.M22, l.M32);
            var eyeVector = new VectorD3D(l.M13, l.M23, l.M33);

            return(WithUpEyeTarget(upVector, eyePos, eyePos - eyeVector * newDistance));
        }
Esempio n. 25
0
        public override void Paint(IGraphicsContext3D g, IPaintContext context)
        {
            var buffers = g.GetPositionNormalIndexedTriangleBuffer(_material);

            if (null != buffers.PositionNormalIndexedTriangleBuffer)
            {
                var buffer = buffers.PositionNormalIndexedTriangleBuffer;

                var offs = buffer.VertexCount;

                var sphere = new SolidIcoSphere(3); // gives a sphere with radius = 1

                var bounds = Bounds;

                double sx = Bounds.SizeX / 2;
                double sy = Bounds.SizeY / 2;
                double sz = Bounds.SizeZ / 2;

                var dx = Bounds.X + sx;
                var dy = Bounds.Y + sy;
                var dz = Bounds.Z + sz;

                var transformation = Matrix4x3.NewScalingShearingRotationDegreesTranslation(sx, sy, sz, 0, 0, 0, 0, 0, 0, dx, dy, dz);
                transformation.AppendTransform(_transformation);

                var normalTransform = transformation.GetTransposedInverseMatrix3x3();

                foreach (var entry in sphere.VerticesAndNormalsForSphere)
                {
                    var pt = transformation.Transform(entry.Item1);
                    var nm = normalTransform.Transform(entry.Item2).Normalized;
                    buffer.AddTriangleVertex(pt.X, pt.Y, pt.Z, nm.X, nm.Y, nm.Z);
                }
                foreach (var idx in sphere.TriangleIndicesForSphere)
                {
                    buffer.AddTriangleIndices(idx.Item1 + offs, idx.Item2 + offs, idx.Item3 + offs);
                }
            }
        }
Esempio n. 26
0
    void TransparentRender()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        var position   = this.Owner.Get <TransformComponent>().Position;
        var viewing    = ViewingMatrix;
        var projection = ProjectionMatrix;

        for (int i = 0; i < InstanceCount; i++)
        {
            var instance = Instances[i];

            var world = new Matrix4x3().Identity();
            world.Translate((position + instance.Position) * viewing);
            world.Scale(instance.Scale);

            InstanceWVPs[i] = world * projection;
            var a = (1.0f - Time) * 0.1f;
            InstanceColors[i] = new Color(a, a, a, a);
        }

        device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
        device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 1);
        VertexShader.SetConstantBuffer(InstanceWVPs, 0);
        VertexShader.SetConstantBuffer(InstanceColors, 1);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTexture(Textures[(int)(Time * TextureCount)], 0);

        device.DrawInstanced(4, InstanceCount);
    }
Esempio n. 27
0
    // ワールド空間からオブジェクト空間へ座標変換を実行する
    public void FromWorldToObjectMatrix(Matrix4x3 m)
    {
        var sp = -m.m23;

        // ジンバルロックチェック
        if (Mathf.Abs(sp) > 0.999f)
        {
            // 真上か真下を向いている
            pitch = MathUtil.kPiOver2 * sp;

            // ヘディングを計算し、バンクを0に設定する
            heading = Mathf.Atan2(-m.m31, m.m11);
            bank    = 0f;
        }
        else
        {
            // ジンバルロックなし
            pitch   = Mathf.Asin(sp);
            heading = Mathf.Atan2(m.m13, m.m33);
            bank    = Mathf.Atan2(m.m21, m.m22);
        }
    }
Esempio n. 28
0
        public void ConstructorValuesAreAccessibleByIndexer()
        {
            Matrix4x3 matrix4x3;

            matrix4x3 = new Matrix4x3();

            for (int x = 0; x < matrix4x3.Columns; x++)
            {
                for (int y = 0; y < matrix4x3.Rows; y++)
                {
                    Assert.Equal(0, matrix4x3[x, y], Epsilon);
                }
            }

            double value = 33.33;

            matrix4x3 = new Matrix4x3(value);

            for (int x = 0; x < matrix4x3.Columns; x++)
            {
                for (int y = 0; y < matrix4x3.Rows; y++)
                {
                    Assert.Equal(value, matrix4x3[x, y], Epsilon);
                }
            }

            GenerateFilledMatrixWithValues(out matrix4x3);

            for (int y = 0; y < matrix4x3.Rows; y++)
            {
                for (int x = 0; x < matrix4x3.Columns; x++)
                {
                    Assert.Equal(y * matrix4x3.Columns + x, matrix4x3[x, y], Epsilon);
                }
            }
        }
Esempio n. 29
0
        public void AccessorThrowsWhenOutOfBounds()
        {
            Matrix4x3 matrix4x3 = new Matrix4x3();

            try
            {
                matrix4x3[-1, 0] = 0;
                Assert.Fail("Matrix4x3[-1, 0] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix4x3[0, -1] = 0;
                Assert.Fail("Matrix4x3[0, -1] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix4x3[4, 0] = 0;
                Assert.Fail("Matrix4x3[4, 0] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix4x3[0, 3] = 0;
                Assert.Fail("Matrix4x3[0, 3] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }
        }
Esempio n. 30
0
    private void Render()
    {
        var world = new Matrix4x3().Identity();

        world.Translate(Transform.Position * ViewingMatrix);
        world.Scale(0.5f * sin(this.Owner.Get <LimitedLifeTimeComponent>().CountTime) * PI);

        VertexShader.SetConstantBuffer(world * ProjectionMatrix, 0);
        PixelShader.SetTexture(GraphicsModel.Texture, 0);
        PixelShader.SetConstantBuffer(new Color(1, 1, 1, 1 - this.Owner.Get <LimitedLifeTimeComponent>().CountTime), 0);

        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(GraphicsModel.Topology);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);
        device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
        device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 1);
        device.Draw(4);
    }
Esempio n. 31
0
        public void MemberGetAndSetValuesCorrectly()
        {
            Matrix4x3 matrix4x3 = new Matrix4x3();

            matrix4x3.M11 = 0;
            matrix4x3.M21 = 1;
            matrix4x3.M31 = 2;
            matrix4x3.M41 = 3;
            matrix4x3.M12 = 4;
            matrix4x3.M22 = 5;
            matrix4x3.M32 = 6;
            matrix4x3.M42 = 7;
            matrix4x3.M13 = 8;
            matrix4x3.M23 = 9;
            matrix4x3.M33 = 10;
            matrix4x3.M43 = 11;

            Assert.Equal(0, matrix4x3.M11, Epsilon);
            Assert.Equal(1, matrix4x3.M21, Epsilon);
            Assert.Equal(2, matrix4x3.M31, Epsilon);
            Assert.Equal(3, matrix4x3.M41, Epsilon);
            Assert.Equal(4, matrix4x3.M12, Epsilon);
            Assert.Equal(5, matrix4x3.M22, Epsilon);
            Assert.Equal(6, matrix4x3.M32, Epsilon);
            Assert.Equal(7, matrix4x3.M42, Epsilon);
            Assert.Equal(8, matrix4x3.M13, Epsilon);
            Assert.Equal(9, matrix4x3.M23, Epsilon);
            Assert.Equal(10, matrix4x3.M33, Epsilon);
            Assert.Equal(11, matrix4x3.M43, Epsilon);

            Assert.Equal(matrix4x3[0, 0], matrix4x3.M11, Epsilon);
            Assert.Equal(matrix4x3[1, 0], matrix4x3.M21, Epsilon);
            Assert.Equal(matrix4x3[2, 0], matrix4x3.M31, Epsilon);
            Assert.Equal(matrix4x3[3, 0], matrix4x3.M41, Epsilon);
            Assert.Equal(matrix4x3[0, 1], matrix4x3.M12, Epsilon);
            Assert.Equal(matrix4x3[1, 1], matrix4x3.M22, Epsilon);
            Assert.Equal(matrix4x3[2, 1], matrix4x3.M32, Epsilon);
            Assert.Equal(matrix4x3[3, 1], matrix4x3.M42, Epsilon);
            Assert.Equal(matrix4x3[0, 2], matrix4x3.M13, Epsilon);
            Assert.Equal(matrix4x3[1, 2], matrix4x3.M23, Epsilon);
            Assert.Equal(matrix4x3[2, 2], matrix4x3.M33, Epsilon);
            Assert.Equal(matrix4x3[3, 2], matrix4x3.M43, Epsilon);
        }
Esempio n. 32
0
        /// <summary>
        /// Sets the value of the uniform.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="transpose">Indicates whether to transpose the matrix value before transmitting it to the shader.</param>
        public unsafe void Set(ref Matrix4x3 value, bool transpose)
        {
            this.VerifyAccess();

            fixed (Matrix4x3* pValue = &value)
            {
                GL.ProgramUniformMatrix4x3(this.Program, this.Location, 1, transpose, (float*)pValue);
            }
        }
Esempio n. 33
0
 /// <summary>
 /// Sets the value of the uniform.
 /// </summary>
 /// <remarks>The value will not be transposed.</remarks>
 /// <param name="value">The value.</param>
 public void Set(ref Matrix4x3 value)
 {
     this.Set(ref value, false);
 }
Esempio n. 34
0
        public void MuliplyByMatrix4x2ProducesMatrix4x3()
        {
            Matrix2x3 matrix1 = new Matrix2x3(3);
            Matrix4x2 matrix2 = new Matrix4x2(2);
            Matrix4x3 result = matrix1 * matrix2;
            Matrix4x3 expected = new Matrix4x3(12, 12, 12, 12, 
                                               12, 12, 12, 12, 
                                               12, 12, 12, 12);

            Assert.Equal(expected, result);
        }
Esempio n. 35
0
        public void SimpleSubtractionGeneratesCorrectValues()
        {
            Matrix4x3 value1 = new Matrix4x3(100);
            Matrix4x3 value2 = new Matrix4x3(1);
            Matrix4x3 result = value1 - value2;

            for (int y = 0; y < Matrix4x3.RowCount; y++)
            {
                for (int x = 0; x < Matrix4x3.ColumnCount; x++)
                {
                    Assert.Equal(100 - 1, result[x, y], Epsilon);
                }
            }
        }
Esempio n. 36
0
        public void MuliplyByMatrix4x4ProducesMatrix4x3()
        {
            Matrix4x3 matrix1 = new Matrix4x3(3);
            Matrix4x4 matrix2 = new Matrix4x4(2);
            Matrix4x3 result = matrix1 * matrix2;
            Matrix4x3 expected = new Matrix4x3(24, 24, 24, 24, 
                                               24, 24, 24, 24, 
                                               24, 24, 24, 24);

            Assert.Equal(expected, result);
        }
Esempio n. 37
0
			internal SphericalObjectOutline(Matrix4x3 transformation)
			{
				_transformation = transformation;
			}
Esempio n. 38
0
        public void SimpleAdditionGeneratesCorrectValues()
        {
            Matrix4x3 value1 = new Matrix4x3(1);
            Matrix4x3 value2 = new Matrix4x3(99);
            Matrix4x3 result = value1 + value2;

            for (int y = 0; y < Matrix4x3.RowCount; y++)
            {
                for (int x = 0; x < Matrix4x3.ColumnCount; x++)
                {
                    Assert.AreEqual(1 + 99, result[x, y], Epsilon);
                }
            }
        }
Esempio n. 39
0
        public void MuliplyByMatrix4x3ProducesMatrix4x4()
        {
            Matrix3x4 matrix1 = new Matrix3x4(3);
            Matrix4x3 matrix2 = new Matrix4x3(2);
            Matrix4x4 result = matrix1 * matrix2;
            Matrix4x4 expected = new Matrix4x4(18, 18, 18, 18, 
                                               18, 18, 18, 18, 
                                               18, 18, 18, 18, 
                                               18, 18, 18, 18);

            Assert.Equal(expected, result);
        }
Esempio n. 40
0
 public void Set(ref Matrix4x3 value)
 {
     this.Uniform.Set(ref value);
 }
Esempio n. 41
0
        public void EqualityOperatorWorksCorrectly()
        {
            Matrix4x3 value1 = new Matrix4x3(100);
            Matrix4x3 value2 = new Matrix4x3(50) * 2;

            Assert.Equal(value1, value2);
            Assert.True(value1 == value2, "Equality operator failed.");
        }
Esempio n. 42
0
		/// <summary>
		/// Gets the object outline for arrangements.
		/// </summary>
		/// <param name="localToWorldTransformation">The local to world transformation.</param>
		/// <returns></returns>
		public override IObjectOutlineForArrangements GetObjectOutlineForArrangements(Matrix4x3 localToWorldTransformation)
		{
			var bounds = this.Bounds;

			double sx = this.Bounds.SizeX / 2;
			double sy = this.Bounds.SizeY / 2;
			double sz = this.Bounds.SizeZ / 2;

			var dx = this.Bounds.X + sx;
			var dy = this.Bounds.Y + sy;
			var dz = this.Bounds.Z + sz;

			var transformation = Matrix4x3.NewScalingShearingRotationDegreesTranslation(sx, sy, sz, 0, 0, 0, 0, 0, 0, dx, dy, dz); // represents a transformation from a unit sphere to the real sphere

			transformation.AppendTransform(_transformation); // additional transformations of the ellipsoid
			transformation.AppendTransform(localToWorldTransformation); // local to global transformation

			return new SphericalObjectOutline(transformation);
		}
Esempio n. 43
0
 private void GenerateFilledMatrixWithValues(out Matrix4x3 matrix)
 {
     matrix = new Matrix4x3( 0,  1,  2,  3, 
                             4,  5,  6,  7, 
                             8,  9, 10, 11);
 }
Esempio n. 44
0
        public void MuliplyByMatrix4x3ProducesMatrix4x2()
        {
            Matrix3x2 matrix1 = new Matrix3x2(3);
            Matrix4x3 matrix2 = new Matrix4x3(2);
            Matrix4x2 result = matrix1 * matrix2;
            Matrix4x2 expected = new Matrix4x2(18, 18, 18, 18,
                                               18, 18, 18, 18);

            Assert.AreEqual(expected, result);
        }
Esempio n. 45
0
 public static void transform(Matrix4x3 m)
 {
     _world.Transform(new Matrix4x4(m));
 }
Esempio n. 46
0
 public Bone(int APIversion, EventHandler handler, string name, Matrix4x3 inverseBindPose) : base(APIversion, handler)
 {
     this.name = name; this.inverseBindPose = new Matrix4x3(requestedApiVersion, handler, inverseBindPose);
 }
Esempio n. 47
0
 public static void loadMatrix(Matrix4x3 m)
 {
     _world = new Matrix4x4(m);
 }
Esempio n. 48
0
 public static void UniformMatrix4x3(int location, bool transpose, ref Matrix4x3 matrix)
 {
     unsafe
     {
         fixed (float* matrix_ptr = &matrix.Row0.X)
         {
             GL.UniformMatrix4x3(location, 1, transpose, matrix_ptr);
         }
     }
 }
Esempio n. 49
0
        public void AccessorThrowsWhenOutOfBounds()
        {
            Matrix4x3 matrix4x3 = new Matrix4x3();

            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x3[-1, 0] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x3[0, -1] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x3[4, 0] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x3[0, 3] = 0; });
        }
Esempio n. 50
0
 private void GenerateFilledMatrixWithValues(out Matrix4x3 matrix)
 {
     matrix = new Matrix4x3(0, 1, 2, 3,
                            4, 5, 6, 7,
                            8, 9, 10, 11);
 }
Esempio n. 51
0
        public void MuliplyByMatrix4x1ProducesMatrix4x3()
        {
            Matrix1x3 matrix1 = new Matrix1x3(3);
            Matrix4x1 matrix2 = new Matrix4x1(2);
            Matrix4x3 result = matrix1 * matrix2;
            Matrix4x3 expected = new Matrix4x3(6, 6, 6, 6, 
                                               6, 6, 6, 6, 
                                               6, 6, 6, 6);

            Assert.Equal(expected, result);
        }
Esempio n. 52
0
        public void HashCodeGenerationWorksCorrectly()
        {
            HashSet<int> hashCodes = new HashSet<int>();
            Matrix4x3 value = new Matrix4x3(1);

            for (int i = 2; i <= 100; i++)
            {
                Assert.True(hashCodes.Add(value.GetHashCode()), "Unique hash code generation failure.");

                value *= i;
            }
        }
Esempio n. 53
0
 public void Set(ref Matrix4x3 value, bool transpose)
 {
     this.Uniform.Set(ref value, transpose);
 }