예제 #1
0
        private static bool CheckRadiusCollision(Vertex Position, Vertex Scale, Vertex ColliderPosition, Vertex ColliderScale)
        {
            VertexBuilder Center         = new VertexBuilder(Position.X + Scale.X / 2, Position.Y + Scale.Y / 2, 0);
            VertexBuilder ColliderCenter = new VertexBuilder(ColliderPosition.X + ColliderScale.X / 2, ColliderPosition.Y + ColliderScale.Y / 2, 0);
            double        Distance       = Math.Abs((Center - ColliderCenter).Length());
            double        HalfSize       = 0;

            if (Scale.X > Scale.Y)
            {
                HalfSize = Scale.X / 2;
            }
            else
            {
                HalfSize = Scale.Y / 2;
            }
            double ColliderHalfSize = 0;

            if (ColliderScale.X > ColliderScale.Y)
            {
                ColliderHalfSize = ColliderScale.X / 2;
            }
            else
            {
                ColliderHalfSize = ColliderScale.Y / 2;
            }
            return(Distance < HalfSize + ColliderHalfSize);
        }
예제 #2
0
 public VertexBuilder Scale(VertexBuilder A)
 {
     this.X *= A.X;
     this.Y *= A.Y;
     this.Z *= A.Z;
     return(this);
 }
예제 #3
0
 public VertexBuilder Translate(VertexBuilder A)
 {
     this.X += A.X;
     this.Y += A.Y;
     this.Z += A.Z;
     return(this);
 }
예제 #4
0
        public static VertexBuilder LaGrangeProduct(Vertex V1, Vertex V2, Vertex V3)
        {
            VertexBuilder V1B = new VertexBuilder(V1);
            VertexBuilder V2B = new VertexBuilder(V2);
            VertexBuilder V3B = new VertexBuilder(V3);

            //V2 X (V1*V3) - V3 X (V1*V2)
            return(CrossProduct(V2, (V1B * V3B).ToVertex()) - CrossProduct(V3, (V1B * V2B).ToVertex()));
        }
예제 #5
0
        public VertexBuilder Normalize()
        {
            float         Divider = 1.0f / this.Length();
            VertexBuilder VB      = new VertexBuilder(this);

            VB.X *= Divider;
            VB.Y *= Divider;
            VB.Z *= Divider;
            return(VB);
        }
예제 #6
0
        public static VertexBuilder Average(Vertex[] Vertices)
        {
            VertexBuilder Average = new VertexBuilder(0, 0, 0);

            for (int i = 0; i < Vertices.Length; i++)
            {
                Average.X += Vertices[i].X;
                Average.Y += Vertices[i].Y;
                Average.Z += Vertices[i].Z;
            }
            return(Average *= 1.0f / Vertices.Length);
        }
예제 #7
0
        public static VertexBuilder CalculateNormal(Vertex[] Vertices)
        {
            if (Vertices.Length == 2)
            {
                return(Normalize(CrossProduct(Vertices[0], Vertices[1]).ToVertex()));
            }
            //return LaGrangeProduct(Vertices[0], Vertices[1], Vertices[2]);
            VertexBuilder V0 = new VertexBuilder(Vertices[0]);
            VertexBuilder V1 = new VertexBuilder(Vertices[1]);
            VertexBuilder V2 = new VertexBuilder(Vertices[2]);
            VertexBuilder Z0 = new VertexBuilder(0, 0, 0);
            VertexBuilder Z1 = new VertexBuilder(0, 0, 0);

            V0 *= -1;
            Z0  = V1 + V0;
            Z1  = V2 + V0;
            return(CrossProduct(Z0.ToVertex(), Z1.ToVertex()));
        }
예제 #8
0
        public void LookAt(float EyeX, float EyeY, float EyeZ, float TargetX, float TargetY, float TargetZ, float UpX, float UpY, float UpZ)
        {
            float[]       Matrix  = new float[16];
            VertexBuilder Forward = new VertexBuilder(TargetX - EyeX, TargetY - EyeY, TargetZ - EyeZ);
            VertexBuilder Up      = new VertexBuilder(UpX, UpY, UpZ);
            VertexBuilder Side    = new VertexBuilder(0, 0);

            Forward = Forward.Normalize();
            Side    = VertexBuilder.Cross(Forward, Up);
            Side    = Side.Normalize();
            Up      = VertexBuilder.Cross(Side, Forward);
            MTIdentity(ref Matrix);
            Matrix[0 * 4 + 0] = Side.X;
            Matrix[1 * 4 + 0] = Side.Y;
            Matrix[2 * 4 + 0] = Side.Z;
            Matrix[0 * 4 + 1] = Up.X;
            Matrix[1 * 4 + 1] = Up.Y;
            Matrix[2 * 4 + 1] = Up.Z;
            Matrix[0 * 4 + 2] = -Forward.X;
            Matrix[1 * 4 + 2] = -Forward.Y;
            Matrix[2 * 4 + 2] = -Forward.Z;
            MultMatrix(Matrix);
            Translate(-EyeX, -EyeY, -EyeZ);
        }
예제 #9
0
 public VertexBuilder(VertexBuilder V)
 {
     X = V.X;
     Y = V.Y;
     Z = V.Z;
 }
예제 #10
0
 public static VertexBuilder Cross(VertexBuilder Left, VertexBuilder Right)
 {
     return(new VertexBuilder(Left.Y * Right.Z - Left.Z * Right.Y,
                              Left.Z * Right.X - Left.X * Right.Z,
                              Left.X * Right.Y - Left.Y * Right.X));
 }