Exemplo n.º 1
0
        public static BlockFacing FromNormal(Vec3f vec)
        {
            float       smallestAngle = GameMath.PI;
            BlockFacing facing        = null;

            for (int i = 0; i < ALLFACES.Length; i++)
            {
                BlockFacing f     = ALLFACES[i];
                float       angle = (float)Math.Acos(f.Normalf.Dot(vec));

                if (angle < smallestAngle)
                {
                    smallestAngle = angle;
                    facing        = f;
                }
            }

            return(facing);
        }
Exemplo n.º 2
0
        static ShapeUtil()
        {
            cubicShellNormalizedVectors = new Vec3f[16][];
            int[] ab = new int[2];

            for (int r = 1; r < 16; r++)
            {
                cubicShellNormalizedVectors[r] = new Vec3f[(2 * r + 1) * (2 * r + 1) * 6];
                int j = 0;

                foreach (BlockFacing facing in BlockFacing.ALLFACES)
                {
                    for (ab[0] = -r; ab[0] <= r; ab[0]++)
                    {
                        for (ab[1] = -r; ab[1] <= r; ab[1]++)
                        {
                            Vec3f pos = new Vec3f(facing.Normali.X * r, facing.Normali.Y * r, facing.Normali.Z * r);
                            int   l   = 0;
                            if (pos.X == 0)
                            {
                                pos.X = ab[l++];
                            }
                            if (pos.Y == 0)
                            {
                                pos.Y = ab[l++];
                            }
                            if (l < 2 && pos.Z == 0)
                            {
                                pos.Z = ab[l++];
                            }

                            cubicShellNormalizedVectors[r][j++] = pos.Normalize();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Sets the vector to the coordinates of given vector
 /// </summary>
 /// <param name="vec"></param>
 public void Set(Vec3f vec)
 {
     this.X = (float)vec.X;
     this.Y = (float)vec.Y;
     this.Z = (float)vec.Z;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Adds both vectors into a new vector. Both source vectors remain unchanged.
 /// </summary>
 /// <param name="vec"></param>
 /// <returns></returns>
 public Vec3f AddCopy(Vec3f vec)
 {
     return(new Vec3f(X + vec.X, Y + vec.Y, Z + vec.Z));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates the cross product from a and b and sets own values accordingly
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 public void Cross(Vec3f a, Vec4f b)
 {
     X = a.Y * b.Z - a.Z * b.Y;
     Y = a.Z * b.X - a.X * b.Z;
     Z = a.X * b.Y - a.Y * b.X;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Returns the dot product with given vector
 /// </summary>
 /// <param name="a"></param>
 /// <returns></returns>
 public float Dot(Vec3f a)
 {
     return(X * a.X + Y * a.Y + Z * a.Z);
 }
Exemplo n.º 7
0
 public Vec3d AddCopy(Vec3f a)
 {
     return(new Vec3d(X + a.X, Y + a.Y, Z + a.Z));
 }
Exemplo n.º 8
0
        private BlockFacing(string code, byte flag, int index, int oppositeIndex, int horizontalAngleIndex, Vec3i facingVector, Vec3f planeCenter, EnumAxis axis, Cuboidf plane)
        {
            this.index                = index;
            this.meshDataIndex        = (byte)(index + 1);
            this.horizontalAngleIndex = horizontalAngleIndex;
            this.flag          = flag;
            this.code          = code;
            this.oppositeIndex = oppositeIndex;
            this.normali       = facingVector;
            this.normalf       = new Vec3f(facingVector.X, facingVector.Y, facingVector.Z);
            this.normald       = new Vec3d((double)facingVector.X, (double)facingVector.Y, (double)facingVector.Z);
            this.plane         = plane;

            normalPacked = NormalUtil.PackNormal(normalf.X, normalf.Y, normalf.Z);
            normalb      = (byte)(
                (axis == EnumAxis.Z ? 1 : 0) << 0
                    | (facingVector.Z < 0 ? 1 : 0) << 1

                    | (axis == EnumAxis.Y ? 1 : 0) << 2
                    | (facingVector.Y < 0 ? 1 : 0) << 3

                    | (axis == EnumAxis.X ? 1 : 0) << 4
                    | (facingVector.X < 0 ? 1 : 0) << 5
                );

            normalPackedFlags = VertexFlags.PackNormal(normalf);

            this.planeCenter = planeCenter;
            this.axis        = axis;
        }