Esempio n. 1
0
        /// <summary>
        /// Rotates the face by given angle and returns the interpolated brightness of this face.
        /// </summary>
        /// <param name="radX"></param>
        /// <param name="radY"></param>
        /// <param name="radZ"></param>
        /// <param name="BlockSideBrightnessByFacing">Array of brightness values between 0 and 1 per face. In index order (N, E, S, W, U, D)</param>
        /// <returns></returns>
        public float GetFaceBrightness(float radX, float radY, float radZ, float[] BlockSideBrightnessByFacing)
        {
            float[] matrix = Mat4f.Create();

            Mat4f.RotateX(matrix, matrix, radX);
            Mat4f.RotateY(matrix, matrix, radY);
            Mat4f.RotateZ(matrix, matrix, radZ);

            FastVec3f pos = Mat4f.MulWithVec3(matrix, Normalf.X, Normalf.Y, Normalf.Z);

            float brightness = 0;

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

                if (angle >= GameMath.PIHALF)
                {
                    continue;
                }

                brightness += (1 - angle / GameMath.PIHALF) * BlockSideBrightnessByFacing[f.Index];
            }

            return(brightness);
        }
Esempio n. 2
0
 /// <summary>
 /// Calculates the distance the two endpoints
 /// </summary>
 /// <param name="vec"></param>
 /// <returns></returns>
 public float Distance(FastVec3f vec)
 {
     return((float)Math.Sqrt(
                (X - vec.X) * (X - vec.X) +
                (Y - vec.Y) * (Y - vec.Y) +
                (Z - vec.Z) * (Z - vec.Z)
                ));
 }
Esempio n. 3
0
 public float Dot(FastVec3f a)
 {
     return(X * a.X + Y * a.Y + Z * a.Z);
 }
Esempio n. 4
0
 /// <summary>
 /// Sets the vector to the coordinates of given vector
 /// </summary>
 /// <param name="vec"></param>
 public void Set(FastVec3f vec)
 {
     this.X = (float)vec.X;
     this.Y = (float)vec.Y;
     this.Z = (float)vec.Z;
 }
Esempio n. 5
0
 /// <summary>
 /// Adds both vectors into a new vector. Both source vectors remain unchanged.
 /// </summary>
 /// <param name="vec"></param>
 /// <returns></returns>
 public FastVec3f AddCopy(FastVec3f vec)
 {
     return(new FastVec3f(X + vec.X, Y + vec.Y, Z + vec.Z));
 }