### Subversion checkout URL

You can clone with
or
.

Make double the default precision throughout

1 parent 5f50af5 commit e1e4c38b6ee59e628103c7e5be4c30ffdcbfe8e5 Luke Benstead committed
34 kazmath/mat3.c
60 kazmath/mat4.c
2  kazmath/plane.c
 @@ -163,7 +163,7 @@ const POINT_CLASSIFICATION kmPlaneClassifyPoint(const kmPlane* pIn, const kmVec3 { // This function will determine if a point is on, in front of, or behind // the plane. First we store the dot product of the plane and the point. - float distance = pIn->a * pP->x + pIn->b * pP->y + pIn->c * pP->z + pIn->d; + kmScalar distance = pIn->a * pP->x + pIn->b * pP->y + pIn->c * pP->z + pIn->d; // Simply put if the dot product is greater than 0 then it is infront of it. // If it is less than 0 then it is behind it. And if it is 0 then it is on it.
30 kazmath/quaternion.c
 @@ -204,11 +204,11 @@ taken from the Matrix and Quaternion FAQ } */ - float x, y, z, w; - float *pMatrix = NULL; - float m4x4[16] = {0}; - float scale = 0.0f; - float diagonal = 0.0f; + kmScalar x, y, z, w; + kmScalar *pMatrix = NULL; + kmScalar m4x4[16] = {0}; + kmScalar scale = 0.0f; + kmScalar diagonal = 0.0f; if(!pIn) { return NULL; @@ -239,7 +239,7 @@ taken from the Matrix and Quaternion FAQ if(diagonal > kmEpsilon) { // Calculate the scale of the diagonal - scale = (float)sqrt(diagonal ) * 2; + scale = (kmScalar)sqrt(diagonal ) * 2; // Calculate the x, y, x and w of the quaternion through the respective equation x = ( pMatrix[9] - pMatrix[6] ) / scale; @@ -253,7 +253,7 @@ taken from the Matrix and Quaternion FAQ if ( pMatrix[0] > pMatrix[5] && pMatrix[0] > pMatrix[10] ) { // Find the scale according to the first element, and double that value - scale = (float)sqrt( 1.0f + pMatrix[0] - pMatrix[5] - pMatrix[10] ) * 2.0f; + scale = (kmScalar)sqrt( 1.0f + pMatrix[0] - pMatrix[5] - pMatrix[10] ) * 2.0f; // Calculate the x, y, x and w of the quaternion through the respective equation x = 0.25f * scale; @@ -265,7 +265,7 @@ taken from the Matrix and Quaternion FAQ else if (pMatrix[5] > pMatrix[10]) { // Find the scale according to the second element, and double that value - scale = (float)sqrt( 1.0f + pMatrix[5] - pMatrix[0] - pMatrix[10] ) * 2.0f; + scale = (kmScalar)sqrt( 1.0f + pMatrix[5] - pMatrix[0] - pMatrix[10] ) * 2.0f; // Calculate the x, y, x and w of the quaternion through the respective equation x = (pMatrix[4] + pMatrix[1] ) / scale; @@ -277,7 +277,7 @@ taken from the Matrix and Quaternion FAQ else { // Find the scale according to the third element, and double that value - scale = (float)sqrt( 1.0f + pMatrix[10] - pMatrix[0] - pMatrix[5] ) * 2.0f; + scale = (kmScalar)sqrt( 1.0f + pMatrix[10] - pMatrix[0] - pMatrix[5] ) * 2.0f; // Calculate the x, y, x and w of the quaternion through the respective equation x = (pMatrix[2] + pMatrix[8] ) / scale; @@ -385,12 +385,12 @@ kmQuaternion* kmQuaternionSlerp(kmQuaternion* pOut, kmScalar t) { - /*float CosTheta = Q0.DotProd(Q1); - float Theta = acosf(CosTheta); - float SinTheta = sqrtf(1.0f-CosTheta*CosTheta); + /*kmScalar CosTheta = Q0.DotProd(Q1); + kmScalar Theta = acosf(CosTheta); + kmScalar SinTheta = sqrtf(1.0f-CosTheta*CosTheta); - float Sin_T_Theta = sinf(T*Theta)/SinTheta; - float Sin_OneMinusT_Theta = sinf((1.0f-T)*Theta)/SinTheta; + kmScalar Sin_T_Theta = sinf(T*Theta)/SinTheta; + kmScalar Sin_OneMinusT_Theta = sinf((1.0f-T)*Theta)/SinTheta; Quaternion Result = Q0*Sin_OneMinusT_Theta; Result += (Q1*Sin_T_Theta); @@ -470,7 +470,7 @@ kmQuaternion* kmQuaternionScale(kmQuaternion* pOut, kmQuaternion* kmQuaternionAssign(kmQuaternion* pOut, const kmQuaternion* pIn) { - memcpy(pOut, pIn, sizeof(float) * 4); + memcpy(pOut, pIn, sizeof(kmScalar) * 4); return pOut; }
28 kazmath/ray2.c
 @@ -11,27 +11,27 @@ void kmRay2Fill(kmRay2* ray, kmScalar px, kmScalar py, kmScalar vx, kmScalar vy) kmBool kmRay2IntersectLineSegment(const kmRay2* ray, const kmVec2* p1, const kmVec2* p2, kmVec2* intersection) { - float x1 = ray->start.x; - float y1 = ray->start.y; - float x2 = ray->start.x + ray->dir.x; - float y2 = ray->start.y + ray->dir.y; - float x3 = p1->x; - float y3 = p1->y; - float x4 = p2->x; - float y4 = p2->y; + kmScalar x1 = ray->start.x; + kmScalar y1 = ray->start.y; + kmScalar x2 = ray->start.x + ray->dir.x; + kmScalar y2 = ray->start.y + ray->dir.y; + kmScalar x3 = p1->x; + kmScalar y3 = p1->y; + kmScalar x4 = p2->x; + kmScalar y4 = p2->y; - float denom = (y4 -y3) * (x2 - x1) - (x4 - x3) * (y2 - y1); + kmScalar denom = (y4 -y3) * (x2 - x1) - (x4 - x3) * (y2 - y1); //If denom is zero, the lines are parallel if(denom > -kmEpsilon && denom < kmEpsilon) { return KM_FALSE; } - float ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom; - float ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom; + kmScalar ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom; + kmScalar ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom; - float x = x1 + ua * (x2 - x1); - float y = y1 + ua * (y2 - y1); + kmScalar x = x1 + ua * (x2 - x1); + kmScalar y = y1 + ua * (y2 - y1); if(x < min(p1->x, p2->x) - kmEpsilon || x > max(p1->x, p2->x) + kmEpsilon || @@ -131,7 +131,7 @@ void calculate_line_normal(kmVec2 p1, kmVec2 p2, kmVec2 other_point, kmVec2* nor n.x = edge.y; n.y = -edge.x; - float d = kmVec2Dot(&n, &other_edge); + kmScalar d = kmVec2Dot(&n, &other_edge); if(d > 0.0f) { n.x = -n.x; n.y = -n.y;
4 kazmath/utility.h
 @@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #ifndef kmScalar -#define kmScalar float +#define kmScalar double #endif #ifndef kmBool @@ -51,7 +51,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define kmPI 3.141592f #define kmPIOver180 0.017453f // PI / 180 #define kmPIUnder180 57.295779f // 180 / PI -#define kmEpsilon 0.00001 +#define kmEpsilon 0.0001
4 kazmath/vec2.c
 @@ -161,6 +161,10 @@ kmVec2* kmVec2RotateBy(kmVec2* pOut, kmVec2* pIn, * Returns the angle in degrees between the two vectors */ kmScalar kmVec2DegreesBetween(const kmVec2* v1, const kmVec2* v2) { + if(kmVec2AreEqual(v1, v2)) { + return 0.0; + } + return kmRadiansToDegrees(acos(kmVec2Dot(v1, v2))); }
6 kazmath/vec2.h
 @@ -26,11 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef VEC2_H_INCLUDED #define VEC2_H_INCLUDED -struct kmMat3; +#include "utility.h" -#ifndef kmScalar -#define kmScalar float -#endif +struct kmMat3; #pragma pack(push) /* push current alignment to stack */ #pragma pack(1) /* set alignment to 1 byte boundary */
5 kazmath/vec3.h
 @@ -27,10 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define VEC3_H_INCLUDED #include - -#ifndef kmScalar -#define kmScalar float -#endif +#include "utility.h" struct kmMat4;
2  kazmath/vec4.c
 @@ -147,7 +147,7 @@ int kmVec4AreEqual(const kmVec4* p1, const kmVec4* p2) { kmVec4* kmVec4Assign(kmVec4* pOut, const kmVec4* pIn) { assert(pOut != pIn); - memcpy(pOut, pIn, sizeof(float) * 4); + memcpy(pOut, pIn, sizeof(kmScalar) * 4); return pOut; }