Example #1
0
        internal static MyVec AddVector3(MyVec v1, MyVec v2)
        {
            MyVec result;

            result.x = v1.x + v2.x;
            result.y = v1.y + v2.y;
            result.z = v1.z + v2.z;

            return(result);
        }
Example #2
0
        internal static MyVec ScaleVector3(MyVec v, float scalar)
        {
            MyVec result;

            result.x = v.x * scalar;
            result.y = v.y * scalar;
            result.z = v.z * scalar;

            return(result);
        }
Example #3
0
        internal static MyVec Vector3CrossProduct(MyVec v1, MyVec v2)
        {
            MyVec result;

            result.x = (v1.y * v2.z) - (v1.z * v2.y);
            result.y = (v1.z * v2.x) - (v1.x * v2.z);
            result.z = (v1.x * v2.y) - (v1.y * v2.x);

            return(result);
        }
Example #4
0
        internal static MyQuat Rotate(MyQuat currentRotation, MyVec axis, float angle)
        {
            //takes currentRotation, and calculates a new quaternion rotated by an angle "angle" along the normalized axis "axis"

            MyQuat result, quat2;
            MyVec  qV2;

            //Create a second quaternion from the axis and angle:
            float theta = ((float)Math.PI / 180) * angle; //convert euler angle to radians (theta)!!

            quat2.w = (float)Math.Cos(theta / 2);
            qV2     = ScaleVector3(axis, (float)Math.Sin(theta / 2));
            quat2.x = qV2.x;
            quat2.y = qV2.y;
            quat2.z = qV2.z;

            //Multiply both quaternions to implement the rotation:
            result = Multiply(currentRotation, quat2);

            return(result);
        }
Example #5
0
        internal static float Vector3DotProduct(MyVec v1, MyVec v2)
        {
            float result = (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);

            return(result);
        }