예제 #1
0
    public void ApplyTransformation(IGB283.Matrix4x4 m)
    {
        for (int i = 0; i < Vertices.Length; i++)
        {
            var vert = Vertices[i];
            Vertices[i] = m.MultiplyVector3(vert);
        }

        CalculateCenter();
    }
    public void Matrix4x4TestSimplePasses()
    {
        Matrix4x4 identity = Matrix4x4.identity;
        Matrix4x4 a        = new Matrix4x4(new Vector4(10, 948, 23, 5), new Vector4(1, 948, 23, 5), new Vector4(10, 948, 23, 5), new Vector4(1, 948, 23, 5));
        Matrix4x4 b        = new Matrix4x4(new Vector4(10, 1, 948, 5), new Vector4(1, 948, 23, 5), new Vector4(10, 948, 23, 5), new Vector4(1, 948, 23, 5));
        Matrix4x4 r        = new Matrix4x4(new Vector4(1283, 925258, 31928, 4930), new Vector4(1193, 925249, 23396, 4885), new Vector4(1283, 925258, 31928, 4930), new Vector4(1193, 925249, 23396, 4885));
        Matrix4x4 c        = new Matrix4x4(new Vector4(1, 0, 0, 1), new Vector4(0, 1, 0, 5), new Vector4(0, 0, 1, 5), new Vector4(0, 0, 0, 1));
        Vector3   vec      = new Vector3(1, 1, 1);
        Vector3   rvec     = new Vector3(2, 6, 6);

        Debug.Log(identity * identity);
        Debug.Assert((identity * identity) == identity);
        Debug.Log(a * b);
        Debug.Assert((a * b) == r);
        Debug.Log(c.MultiplyVector3(vec));
        Debug.Assert(c.MultiplyVector3(vec) == rvec);
    }
    private void RotateAndTranslate(Shape shape, float point1, float point2)
    {
        Vector3 moveDir;

        if (!shape.MoveTowardsFirst)
        {
            if (shape.Center.x >= point2)
            {
                shape.MoveTowardsFirst = true;
            }
            moveDir = Vector3.right;
        }
        else
        {
            if (shape.Center.x <= point1)
            {
                shape.MoveTowardsFirst = false;
            }
            moveDir = Vector3.left;
        }

        if (!ThreeDimensional)
        {
            var       center   = new Vector2(shape.Center.x, shape.Center.y);
            Matrix3x3 T        = IGB283Transform.Translate(-center);
            Matrix3x3 R        = IGB283Transform.Rotate(shape.RotationSpeed.z * Time.deltaTime);
            Matrix3x3 TReverse = IGB283Transform.Translate(center + Time.deltaTime * shape.Speed * new Vector2(moveDir.x, moveDir.y));
            shape.ApplyTransformation(TReverse * R * T);
        }
        else
        {
            IGB283.Matrix4x4 T        = IGB283Transform.Translate(-shape.Center);
            IGB283.Matrix4x4 R        = IGB283Transform.Rotate(shape.RotationSpeed * Time.deltaTime);
            IGB283.Matrix4x4 TReverse = IGB283Transform.Translate(shape.Center + Time.deltaTime * shape.Speed * moveDir);
            shape.ApplyTransformation(TReverse * R * T);
        }
    }