public static bool Intersects(Ray ray, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3, out float distance, out float barycentricU, out float barycentricV) { unsafe { fixed(float *pinnedDist = &distance) { fixed(float *pinnedU = &barycentricU) { fixed(float *pinnedV = &barycentricV) { if (IDllImportApi.D3DXIntersectTri(&vertex1, &vertex2, &vertex3, &ray.Position, &ray.Direction, pinnedU, pinnedV, pinnedDist) != 0) { return(true); } else { return(false); } } } } } }
public static void RotationMatrix(ref Matrix matrix, out Quaternion result) { //float scale = matrix.M11 + matrix.M22 + matrix.M33; //if( scale > 0.0f ) //{ // float sqrt = (float)( Math.Sqrt( (double)(scale + 1.0f) ) ); // result.W = sqrt * 0.5f; // sqrt = 0.5f / sqrt; // result.X = (matrix.M23 - matrix.M32) * sqrt; // result.Y = (matrix.M31 - matrix.M13) * sqrt; // result.Z = (matrix.M12 - matrix.M21) * sqrt; // return; //} //if( (matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33) ) //{ // float sqrt = (float)( Math.Sqrt( (double)(1.0f + matrix.M11 - matrix.M22 - matrix.M33) ) ); // float half = 0.5f / sqrt; // result.X = 0.5f * sqrt; // result.Y = (matrix.M12 + matrix.M21) * half; // result.Z = (matrix.M13 + matrix.M31) * half; // result.W = (matrix.M23 - matrix.M32) * half; // return; //} //if( matrix.M22 > matrix.M33 ) //{ // float sqrt = (float)( Math.Sqrt( (double)(1.0f + matrix.M22 - matrix.M11 - matrix.M33) ) ); // float half = 0.5f / sqrt; // result.X = (matrix.M21 + matrix.M12) * half; // result.Y = 0.5f * sqrt; // result.Z = (matrix.M32 + matrix.M23) * half; // result.W = (matrix.M31 - matrix.M13) * half; // return; //} //float sqrt = (float)( Math.Sqrt( (double)(1.0f + matrix.M33 - matrix.M11 - matrix.M22) ) ); //float half = 0.5f / sqrt; //result.X = (matrix.M31 + matrix.M13) * half; //result.Y = (matrix.M32 + matrix.M23) * half; //result.Z = 0.5f * sqrt; //result.W = (matrix.M12 - matrix.M21) * half; unsafe { fixed(Quaternion *pin_result = &result) { fixed(Matrix *pin_matrix = &matrix) { IDllImportApi.D3DXQuaternionRotationMatrix(pin_result, pin_matrix); } } } }
public static Quaternion Exponential(Quaternion quat) { Quaternion result = new Quaternion(); unsafe { IDllImportApi.D3DXQuaternionExp((Quaternion *)&result, (Quaternion *)&quat); } return(result); }
public static Plane operator *(Plane plane, float scale) { Plane result; unsafe { IDllImportApi.D3DXPlaneScale((Plane *)(&result), (Plane *)(&plane), scale); } return(result); }
public static Quaternion Logarithm(Quaternion quat) { Quaternion result; unsafe { IDllImportApi.D3DXQuaternionLn((Quaternion *)&result, (Quaternion *)&quat); } return(result); }
public static Plane Multiply(Plane plane, float scale) { Plane result = new Plane(); unsafe { IDllImportApi.D3DXPlaneScale((Plane *)&result, (Plane *)&plane, scale); } return(result); }
public static Quaternion Barycentric(Quaternion q1, Quaternion q2, Quaternion q3, float f, float g) { Quaternion result = new Quaternion(); unsafe { IDllImportApi.D3DXQuaternionBaryCentric((Quaternion *)&result, (Quaternion *)&q1, (Quaternion *)&q2, (Quaternion *)&q3, f, g); } return(result); }
public static Quaternion Squad(Quaternion q1, Quaternion a, Quaternion b, Quaternion c, float t) { Quaternion result; unsafe { IDllImportApi.D3DXQuaternionSquad((Quaternion *)&result, (Quaternion *)&q1, (Quaternion *)&a, (Quaternion *)&b, (Quaternion *)&c, t); } return(result); }
public static void Exponential(ref Quaternion quat, out Quaternion result) { unsafe { fixed(Quaternion *pinQuat = &quat) { fixed(Quaternion *pinResult = &result) { IDllImportApi.D3DXQuaternionExp(pinResult, pinQuat); } } } }
public float GetAngleWithAxis(Vector3 axis) { unsafe { fixed(Quaternion *pinThis = &this) { float angle; IDllImportApi.D3DXQuaternionToAxisAngle(pinThis, (Vector3 *)&axis, &angle); return(angle); } } }
public static void Logarithm(ref Quaternion quat, out Quaternion result) { unsafe { fixed(Quaternion *pinQuat = &quat) { fixed(Quaternion *pinResult = &result) { IDllImportApi.D3DXQuaternionLn((Quaternion *)pinResult, (Quaternion *)pinQuat); } } } }
public static void Multiply(ref Plane plane, float scale, out Plane result) { unsafe { fixed(Plane *pResult = &result) { fixed(Plane *pPlane = &plane) { IDllImportApi.D3DXPlaneScale(pResult, pPlane, scale); } } } }
public static BoundingSphere FromPoints(Vector3[] points) { BoundingSphere sphere = new BoundingSphere(); unsafe { fixed(Vector3 *pinnedPoints = &points[0]) { int hr = IDllImportApi.D3DXComputeBoundingSphere(pinnedPoints, (UInt32)points.Length, sizeof(float) * 3, &sphere.Center, &sphere.Radius); if (hr != 0) { return(new BoundingSphere()); } } } return(sphere); }
public static void Barycentric(ref Quaternion q1, ref Quaternion q2, ref Quaternion q3, float f, float g, out Quaternion result) { unsafe { fixed(Quaternion *pinResult = &result) { fixed(Quaternion *pin1 = &q1) { fixed(Quaternion *pin2 = &q2) { fixed(Quaternion *pin3 = &q3) { IDllImportApi.D3DXQuaternionBaryCentric(pinResult, pin1, pin2, pin3, f, g); } } } } } }
public static Quaternion[] SquadSetup(Quaternion source1, Quaternion source2, Quaternion source3, Quaternion source4) { Quaternion result1 = new Quaternion(); Quaternion result2 = new Quaternion(); Quaternion result3 = new Quaternion(); Quaternion[] results = new Quaternion[3]; unsafe { IDllImportApi.D3DXQuaternionSquadSetup((Quaternion *)&result1, (Quaternion *)&result2, (Quaternion *)&result3, (Quaternion *)&source1, (Quaternion *)&source2, (Quaternion *)&source3, (Quaternion *)&source4); } results[0] = result1; results[1] = result2; results[2] = result3; return(results); }
public static void Squad(ref Quaternion q1, ref Quaternion a, ref Quaternion b, ref Quaternion c, float t, out Quaternion result) { unsafe { fixed(Quaternion *pin1 = &q1) { fixed(Quaternion *pinA = &a) { fixed(Quaternion *pinB = &b) { fixed(Quaternion *pinC = &c) { fixed(Quaternion *pinResult = &result) { IDllImportApi.D3DXQuaternionSquad(pinResult, pin1, pinA, pinB, pinC, t); } } } } } } }
public static bool Intersects(ref Plane plane, ref Vector3 start, ref Vector3 end, out Vector3 intersectPoint) { unsafe { fixed(Plane *pPlane = &plane) { fixed(Vector3 *pStart = &start) { fixed(Vector3 *pEnd = &end) { fixed(Vector3 *pIntersectPoint = &intersectPoint) { if (0 == (int)IDllImportApi.D3DXPlaneIntersectLine(pIntersectPoint, pPlane, pStart, pEnd)) { return(false); } return(true); } } } } } }
public unsafe static void Transform(Vector3 *vectorsIn, int inputStride, Matrix *transformation, Vector4 *vectorsOut, int outputStride, int count) { IDllImportApi.D3DXVec3TransformArray((vectorsOut), (UInt32)outputStride, (vectorsIn), (UInt32)inputStride, (transformation), (UInt32)count); }
public unsafe static void TransformCoordinate(Vector3 *coordsIn, int inputStride, Matrix *transformation, Vector3 *coordsOut, int outputStride, int count) { IDllImportApi.D3DXVec3TransformCoordArray(coordsOut, (UInt32)outputStride, coordsIn, (UInt32)inputStride, transformation, (UInt32)count); }
public static Quaternion RotationMatrix(Matrix matrix) { Quaternion result; //float scale = matrix.M11 + matrix.M22 + matrix.M33; //if( scale > 0.0f ) //{ // float sqrt = (float)( Math.Sqrt( (double)(scale + 1.0f) ) ); // result.W = sqrt * 0.5f; // sqrt = 0.5f / sqrt; // result.X = (matrix.M23 - matrix.M32) * sqrt; // result.Y = (matrix.M31 - matrix.M13) * sqrt; // result.Z = (matrix.M12 - matrix.M21) * sqrt; // return result; //} //if( (matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33) ) //{ // float sqrt = (float)( Math.Sqrt( (double)(1.0f + matrix.M11 - matrix.M22 - matrix.M33) ) ); // float half = 0.5f / sqrt; // result.X = 0.5f * sqrt; // result.Y = (matrix.M12 + matrix.M21) * half; // result.Z = (matrix.M13 + matrix.M31) * half; // result.W = (matrix.M23 - matrix.M32) * half; // return result; //} //if( matrix.M22 > matrix.M33 ) //{ // float sqrt = (float)( Math.Sqrt( (double)(1.0f + matrix.M22 - matrix.M11 - matrix.M33) ) ); // float half = 0.5f / sqrt; // result.X = (matrix.M21 + matrix.M12) * half; // result.Y = 0.5f * sqrt; // result.Z = (matrix.M32 + matrix.M23) * half; // result.W = (matrix.M31 - matrix.M13) * half; // return result; //} //float sqrt = (float)( Math.Sqrt( (double)(1.0f + matrix.M33 - matrix.M11 - matrix.M22) ) ); //float half = 0.5f / sqrt; //result.X = (matrix.M31 + matrix.M13) * half; //result.Y = (matrix.M32 + matrix.M23) * half; //result.Z = 0.5f * sqrt; //result.W = (matrix.M12 - matrix.M21) * half; //Quaternion result2; unsafe { IDllImportApi.D3DXQuaternionRotationMatrix((Quaternion *)&result, (Matrix *)&matrix); } return(result); }
public unsafe static void TransformNormal(Vector3 *normalsIn, int inputStride, Matrix *transformation, Vector3 *normalsOut, int outputStride, int count) { IDllImportApi.D3DXVec3TransformNormalArray(normalsOut, (UInt32)outputStride, normalsIn, (UInt32)inputStride, transformation, (UInt32)count); }