/// <summary>Creates a static model out of the parameters.</summary>
 /// <param name="staticModelId">The id of this model for look up purposes.</param>
 /// <param name="meshes">A list of mesh ids, textures, and buffer references that make up this model.</param>
 internal StaticModel(string staticModelId, AvlTree<StaticMesh, string> meshes)
 {
     _id = staticModelId;
       _shaderOverride = null;
       _meshes = meshes;
       _position = new Vector(0, 0, 0);
       _scale = new Vector(1, 1, 1);
       _orientation = Quaternion.FactoryIdentity;
 }
 /// <summary>Creates a blank template for a static model (you will have to construct the model yourself).</summary>
 public StaticModel(string id)
 {
     _id = id;
       _shaderOverride = null;
       _meshes = new AvlTreeLinked<StaticMesh, string>(StaticMesh.CompareTo, StaticMesh.CompareTo);
       _position = new Vector(0, 0, 0);
       _scale = new Vector(1, 1, 1);
       _orientation = Quaternion.FactoryIdentity;
 }
 /// <summary>Creates a static model from the ids provided.</summary>
 /// <param name="staticModelId">The id to represent this model as.</param>
 /// <param name="textures">An array of the texture ids for each sub-mesh of this model.</param>
 /// <param name="meshes">An array of each mesh id for this model.</param>
 /// <param name="meshNames">An array of mesh names for this specific instanc3e of a static model.</param>
 internal StaticModel(string staticModelId, string[] meshNames, string[] meshes, string[] textures)
 {
     if (textures.Length != meshes.Length && textures.Length != meshNames.Length)
     throw new Exception("Attempting to create a static model with non-matching number of components.");
       _id = staticModelId;
       _meshes = new AvlTreeLinked<StaticMesh, string>(StaticMesh.CompareTo, StaticMesh.CompareTo);
       for (int i = 0; i < textures.Length; i++)
     _meshes.Add(new StaticMesh(meshNames[i], TextureManager.Get(textures[i]), StaticModelManager.GetMesh(meshes[i]).StaticMeshInstance));
       _shaderOverride = null;
       _position = new Vector(0, 0, 0);
       _scale = new Vector(1, 1, 1);
       _orientation = Quaternion.FactoryIdentity;
 }
Beispiel #4
0
        public Quaternion Slerp(Quaternion right, float blend)
        {
            if (blend < 0 || blend > 1.0f)
            throw new QuaternionException("Attempting sphereical interpolation with invalid blend (blend < 0.0f || blend > 1.0f).");

              if (LengthSquared == 0.0f)
              { if (right.LengthSquared == 0.0f)
              return IdentityFactory;
            else
              return new Quaternion(right.X, right.Y, right.Z, right.W); }
              else if (right.LengthSquared == 0.0f)
            return new Quaternion(_x, _y, _z, _w);

              float cosHalfAngle = _x * right.X + _y * right.Y + _z * right.Z + _w * right.W;

              if (cosHalfAngle >= 1.0f || cosHalfAngle <= -1.0f)
            return new Quaternion(_x, _y, _z, _w);
              else if (cosHalfAngle < 0.0f)
              {
            right = new Quaternion(-_x, -_y, -_z, -_w);
            cosHalfAngle = -cosHalfAngle;
              }

              float halfAngle = (float)Math.Acos(cosHalfAngle);
              float sinHalfAngle = Trigonometry.Sin(halfAngle);
              float blendA = Trigonometry.Sin(halfAngle * (1.0f - blend)) / sinHalfAngle;
              float blendB = Trigonometry.Sin(halfAngle * blend) / sinHalfAngle;

              Quaternion result = new Quaternion(
            blendA * _x + blendB * right.X,
            blendA * _y + blendB * right.Y,
            blendA * _z + blendB * right.Z,
            blendA * _w + blendB * right.W);

              if (result.LengthSquared > 0.0f)
            return result.Normalize();
              else
            return IdentityFactory;
        }
Beispiel #5
0
        public Quaternion Lerp(Quaternion right, float blend)
        {
            if (blend < 0 || blend > 1.0f)
            throw new QuaternionException("Attempting linear interpolation with invalid blend (blend < 0.0f || blend > 1.0f).");

              if (LengthSquared == 0.0f)
              { if (right.LengthSquared == 0.0f)
              return IdentityFactory;
            else
              return new Quaternion(right.X, right.Y, right.Z, right.W); }
              else if (right.LengthSquared == 0.0f)
            return new Quaternion(_x, _y, _z, _w);

              Quaternion result = new Quaternion(
            (1.0f - blend) * _x + blend * right.X,
            (1.0f - blend) * _y + blend * right.Y,
            (1.0f - blend) * _z + blend * right.Z,
            (1.0f - blend) * _w + blend * right.W);

              if (result.LengthSquared > 0.0f)
            return result.Normalize();
              else
            return IdentityFactory;
        }
Beispiel #6
0
 public Quaternion Add(Quaternion right)
 {
     return new Quaternion(
     _x + right.X,
     _y + right.Y,
     _z + right.Z,
     _w + right.W);
 }
Beispiel #7
0
 public static Vector RotateBy(Vector vector, Quaternion rotation)
 {
     Quaternion answer = (rotation * vector) * Quaternion.Conjugate(rotation);
       return new Vector(answer.X, answer.Y, answer.Z);
 }
Beispiel #8
0
 public Quaternion Slerp(Quaternion right, float blend)
 {
     return Quaternion.Slerp(this, right, blend);
 }
Beispiel #9
0
 public Quaternion Add(Quaternion right)
 {
     return Quaternion.Add(this, right);
 }
Beispiel #10
0
 public static float Length(Quaternion quaternion)
 {
     return
     Calc.SquareRoot(
       quaternion.X * quaternion.X +
       quaternion.Y * quaternion.Y +
       quaternion.Z * quaternion.Z +
       quaternion.W * quaternion.W);
 }
Beispiel #11
0
 public static Quaternion Invert(Quaternion quaternion)
 {
     float lengthSquared = Quaternion.LengthSquared(quaternion);
       if (lengthSquared == 0.0)
     return new Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
       return new Quaternion(
     -quaternion.X / lengthSquared,
     -quaternion.Y / lengthSquared,
     -quaternion.Z / lengthSquared,
     quaternion.W / lengthSquared);
 }
Beispiel #12
0
 public static bool Equals(Quaternion left, Quaternion right)
 {
     if (object.ReferenceEquals(left, right))
     return true;
       else if (left == null || right == null)
     return false;
       else return
     left.X == right.X &&
     left.Y == right.Y &&
     left.Z == right.Z &&
     left.W == right.W;
 }
Beispiel #13
0
 public static Quaternion Conjugate(Quaternion quaternion)
 {
     return new Quaternion(
     -quaternion.X,
     -quaternion.Y,
     -quaternion.Z,
     quaternion.W);
 }
Beispiel #14
0
 public static Quaternion Add(Quaternion left, Quaternion right)
 {
     return new Quaternion(
     left.X + right.X,
     left.Y + right.Y,
     left.Z + right.Z,
     left.W + right.W);
 }
Beispiel #15
0
 public Vector RotateBy(Quaternion rotation)
 {
     Quaternion answer = rotation.Multiply(this).Multiply(rotation.Conjugate());
       return new Vector(answer.X, answer.Y, answer.Z);
 }
Beispiel #16
0
 public static Quaternion Subtract(Quaternion left, Quaternion right)
 {
     return new Quaternion(
     left.X - right.X,
     left.Y - right.Y,
     left.Z - right.Z,
     left.W - right.W);
 }
Beispiel #17
0
 public static Matrix3x3 ToMatrix(Quaternion q)
 {
     return new Matrix3x3(
     q.W * q.W + q.X * q.X - q.Y * q.Y - q.Z * q.Z,
     2 * q.X * q.Y - 2 * q.W * q.Z,
     2 *q.X * q.Z + 2 * q.W * q.Y,
     2 * q.X * q.Y + 2 * q.W * q.Z,
     q.W * q.W - q.X * q.X + q.Y * q.Y - q.Z * q.Z,
     2 * q.Y * q.Z + 2 * q.W * q.X,
     2 * q.X * q.Z - 2 * q.W * q.Y,
     2 * q.Y * q.Z - 2 * q.W * q.X,
     q.W * q.W - q.X * q.X - q.Y * q.Y + q.Z * q.Z);
 }
Beispiel #18
0
 public static float LengthSquared(Quaternion quaternion)
 {
     return
     quaternion.X * quaternion.X +
     quaternion.Y * quaternion.Y +
     quaternion.Z * quaternion.Z +
     quaternion.W * quaternion.W;
 }
Beispiel #19
0
 public Quaternion Multiply(Quaternion right)
 {
     return Quaternion.Multiply(this, right);
 }
Beispiel #20
0
 public static Quaternion Lerp(Quaternion left, Quaternion right, float blend)
 {
     if (blend < 0 || blend > 1.0f)
     throw new QuaternionException("invalid blending value during lerp !(blend < 0.0f || blend > 1.0f).");
       if (Quaternion.LengthSquared(left) == 0.0f)
       {
     if (Quaternion.LengthSquared(right) == 0.0f)
       return FactoryIdentity;
     else
       return new Quaternion(right.X, right.Y, right.Z, right.W); }
       else if (Quaternion.LengthSquared(right) == 0.0f)
     return new Quaternion(left.X, left.Y, left.Z, left.W);
       Quaternion result = new Quaternion(
     (1.0f - blend) * left.X + blend * right.X,
     (1.0f - blend) * left.Y + blend * right.Y,
     (1.0f - blend) * left.Z + blend * right.Z,
     (1.0f - blend) * left.W + blend * right.W);
       if (Quaternion.LengthSquared(result) > 0.0f)
     return Quaternion.Normalize(result);
       else
     return FactoryIdentity;
 }
Beispiel #21
0
 public Quaternion Subtract(Quaternion right)
 {
     return Quaternion.Subtract(this, right);
 }
Beispiel #22
0
 public static Quaternion Multiply(Quaternion left, Quaternion right)
 {
     return new Quaternion(
     left.X * right.W + left.W * right.X + left.Y * right.Z - left.Z * right.Y,
     left.Y * right.W + left.W * right.Y + left.Z * right.X - left.X * right.Z,
     left.Z * right.W + left.W * right.Z + left.X * right.Y - left.Y * right.X,
     left.W * right.W - left.X * right.X - left.Y * right.Y - left.Z * right.Z);
 }
Beispiel #23
0
 public Vector RotateBy(Quaternion rotation)
 {
     return Vector.RotateBy(this, rotation);
 }
Beispiel #24
0
 public static Quaternion Multiply(Quaternion left, float right)
 {
     return new Quaternion(
     left.X * right,
     left.Y * right,
     left.Z * right,
     left.W * right);
 }
Beispiel #25
0
 public bool Equals(Quaternion right)
 {
     return
     _x == right.X &&
     _y == right.Y &&
     _z == right.Z &&
     W == right.W;
 }
Beispiel #26
0
 public static Quaternion Multiply(Quaternion left, Vector vector)
 {
     return new Quaternion(
     left.W * vector.X + left.Y * vector.Z - left.Z * vector.Y,
     left.W * vector.Y + left.Z * vector.X - left.X * vector.Z,
     left.W * vector.Z + left.X * vector.Y - left.Y * vector.X,
     -left.X * vector.X - left.Y * vector.Y - left.Z * vector.Z);
 }
Beispiel #27
0
 public Quaternion Multiply(Quaternion right)
 {
     return new Quaternion(
     _x * right.W + _w * right.X + _y * right.Z - _z * right.Y,
     _y * right.W + _w * right.Y + _z * right.X - _x * right.Z,
     _z * right.W + _w * right.Z + _x * right.Y - _y * right.X,
     _w * right.W - _x * right.X - _y * right.Y - _z * right.Z);
 }
Beispiel #28
0
 public static Quaternion Normalize(Quaternion quaternion)
 {
     float length = Quaternion.Length(quaternion);
       return new Quaternion(
     quaternion.X / length,
     quaternion.Y / length,
     quaternion.Z / length,
     quaternion.W / length);
 }
Beispiel #29
0
 public Quaternion Subtract(Quaternion right)
 {
     return new Quaternion(
     _x - right.X,
     _y - right.Y,
     _z - right.Z,
     _w - right.W);
 }
Beispiel #30
0
 public static Quaternion Slerp(Quaternion left, Quaternion right, float blend)
 {
     if (blend < 0 || blend > 1.0f)
     throw new QuaternionException("invalid blending value during slerp !(blend < 0.0f || blend > 1.0f).");
       if (Quaternion.LengthSquared(left) == 0.0f)
       {
     if (Quaternion.LengthSquared(right) == 0.0f)
       return FactoryIdentity;
     else
       return new Quaternion(right.X, right.Y, right.Z, right.W); }
       else if (Quaternion.LengthSquared(right) == 0.0f)
     return new Quaternion(left.X, left.Y, left.Z, left.W);
       float cosHalfAngle = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
       if (cosHalfAngle >= 1.0f || cosHalfAngle <= -1.0f)
     return new Quaternion(left.X, left.Y, left.Z, left.W);
       else if (cosHalfAngle < 0.0f)
       {
     right = new Quaternion(-left.X, -left.Y, -left.Z, -left.W);
     cosHalfAngle = -cosHalfAngle;
       }
       float halfAngle = (float)Math.Acos(cosHalfAngle);
       float sinHalfAngle = Calc.Sin(halfAngle);
       float blendA = Calc.Sin(halfAngle * (1.0f - blend)) / sinHalfAngle;
       float blendB = Calc.Sin(halfAngle * blend) / sinHalfAngle;
       Quaternion result = new Quaternion(
     blendA * left.X + blendB * right.X,
     blendA * left.Y + blendB * right.Y,
     blendA * left.Z + blendB * right.Z,
     blendA * left.W + blendB * right.W);
       if (Quaternion.LengthSquared(result) > 0.0f)
     return Quaternion.Normalize(result);
       else
     return FactoryIdentity;
 }