Alpha Engine: AEMath.h Source File

AlphaEngine

AEMath.h
Go to the documentation of this file.
1 /******************************************************************************/
15 /******************************************************************************/
16 
17 #ifndef AE_MATH_H
18 #define AE_MATH_H
19 
20 // ---------------------------------------------------------------------------
21 
22 #include "AEVec2.h" //Vector 2D
23 #include "AEMtx33.h" //Matrix 3x3
24 #include "AELineSegment2.h" //LineSegment 2D
25 
26 #include <float.h>
27 
28 #include "math.h"
29 
30 // ---------------------------------------------------------------------------
31 #ifdef __cplusplus
32 
33 extern "C"
34 {
35 #endif
36 
37 //AE_API void MathInit();
38 
39 // ---------------------------------------------------------------------------
40 
41 /******************************************************************************/
53 /******************************************************************************/
55 
56 /******************************************************************************/
68 /******************************************************************************/
70 
71 /******************************************************************************/
83 /******************************************************************************/
84 AE_API f32 AESin (f32 x);
85 
86 /******************************************************************************/
98 /******************************************************************************/
99 AE_API f32 AECos (f32 x);
100 
101 /******************************************************************************/
113 /******************************************************************************/
114 AE_API f32 AETan (f32 x);
115 
116 /******************************************************************************/
128 /******************************************************************************/
129 AE_API f32 AEASin (f32 x);
130 
131 /******************************************************************************/
143 /******************************************************************************/
144 AE_API f32 AEACos (f32 x);
145 
146 /******************************************************************************/
158 /******************************************************************************/
159 AE_API f32 AEATan (f32 x);
160 
161 // ---------------------------------------------------------------------------
162 
164  #define AESinDeg(x) AESin(AEDegToRad(x))
166  #define AECosDeg(x) AECos(AEDegToRad(x))
167  #define AETanDeg(x) AETan(AEDegToRad(x))
168  #define AEASinDeg(x) AERadToDeg(AEASin(x))
169  #define AEACosDeg(x) AERadToDeg(AEACos(x))
170  #define AEATanDeg(x) AERadToDeg(AEATan(x))
171 
172 
173 // ---------------------------------------------------------------------------
174 
175 /******************************************************************************/
197 /******************************************************************************/
199 
200 /******************************************************************************/
221 /******************************************************************************/
223 
224 /******************************************************************************/
238 /******************************************************************************/
240 
241 /******************************************************************************/
263 /******************************************************************************/
264 AE_API f32 AEClamp (f32 X, f32 Min, f32 Max);
265 
266 /******************************************************************************/
290 /******************************************************************************/
291 AE_API f32 AEWrap (f32 x, f32 x0, f32 x1);
292 
293 /******************************************************************************/
311 /******************************************************************************/
312 AE_API f32 AEMin (f32 x, f32 y);
313 
314 
315 /******************************************************************************/
333 /******************************************************************************/
334 AE_API f32 AEMax (f32 x, f32 y);
335 
336 /******************************************************************************/
359 /******************************************************************************/
360 AE_API s32 AEInRange (f32 x, f32 x0, f32 x1);
361 
362 // ---------------------------------------------------------------------------
363 
364 /******************************************************************************/
394 /******************************************************************************/
395 AE_API f32 AECalcDistPointToCircle (AEVec2* pPos, AEVec2* pCtr, f32 radius);
396 
397 /******************************************************************************/
438 /******************************************************************************/
439 AE_API f32 AECalcDistPointToRect (AEVec2* pPos, AEVec2* pRect, f32 sizeX, f32 sizeY);
440 
441 /******************************************************************************/
469 /******************************************************************************/
470 AE_API f32 AECalcDistPointToLineSeg (AEVec2* pPos, AEVec2* pLine0, AEVec2* pLine1);
471 
472 /******************************************************************************/
504 /******************************************************************************/
505 AE_API f32 AECalcDistPointToConvexPoly (AEVec2* pPos, AEVec2* pVtx, u32 vtxNum);
506 
507 /******************************************************************************/
540 /******************************************************************************/
541 AE_API f32 AECalcDistCircleToCircle (AEVec2* pCtr0, f32 radius0, AEVec2* pCtr1, f32 radius1);
542 
543 /******************************************************************************/
587 /******************************************************************************/
588 AE_API f32 AECalcDistCircleToRect (AEVec2* pCtr, f32 radius, AEVec2* pRect, f32 sizeX, f32 sizeY);
589 
590 /******************************************************************************/
641 /******************************************************************************/
642 AE_API f32 AECalcDistRectToRect (AEVec2* pRect0, f32 sizeX0, f32 sizeY0, AEVec2* pRect1, f32 sizeX1, f32 sizeY1, AEVec2* pNormal);
643 
644 /* Functions not defined
645 AE_API f32 AECalcDistCircleToLineSeg (AEVec2* pPos, AEVec2* pLine0, AEVec2* pLine1);
646 AE_API f32 AECalcDistCircleToConvexPoly (AEVec2* pPos, AEVec2* pVtx, u32 vtxNum);
647 */
648 
649 // ---------------------------------------------------------------------------
650 
651 /******************************************************************************/
678 /******************************************************************************/
679 AE_API s32 AETestPointToCircle (AEVec2* pPos, AEVec2* pCtr, f32 radius);
680 
681 /******************************************************************************/
716 /******************************************************************************/
717 AE_API s32 AETestPointToRect (AEVec2* pPos, AEVec2* pRect, f32 sizeX, f32 sizeY);
718 
719 /******************************************************************************/
750 /******************************************************************************/
751 AE_API s32 AETestCircleToCircle (AEVec2* pCtr0, f32 radius0, AEVec2* pCtr1, f32 radius1);
752 
753 /******************************************************************************/
794 /******************************************************************************/
795 AE_API s32 AETestCircleToRect (AEVec2* pCtr, f32 radius, AEVec2* pRect, f32 sizeX, f32 sizeY);
796 
797 /******************************************************************************/
841 /******************************************************************************/
842 AE_API s32 AETestRectToRect (AEVec2* pRect0, f32 sizeX0, f32 sizeY0, AEVec2* pRect1, f32 sizeX1, f32 sizeY1);
843 
844 // ---------------------------------------------------------------------------
845 
846 /******************************************************************************/
870 /******************************************************************************/
872 
873 /******************************************************************************/
906 /******************************************************************************/
908 
909 /******************************************************************************/
948 /******************************************************************************/
949 AE_API f32 AEAnimatedCircleToStaticLineSegment(AEVec2 *pStart, AEVec2 *pEnd, f32 radius, AELineSegment2 *pLine, AEVec2 *pInter);
950 
951 /******************************************************************************/
989 /******************************************************************************/
991 
992 /******************************************************************************/
1037 /******************************************************************************/
1038 AE_API f32 AEReflectAnimatedCircleOnStaticLineSegment(AEVec2 *pStart, AEVec2 *pEnd, f32 radius, AELineSegment2 *pLine, AEVec2 *pInter, AEVec2 *pReflect);
1039 
1040 /******************************************************************************/
1078 /******************************************************************************/
1079 AE_API f32 AEAnimatedPointToStaticCircle(AEVec2 *pStart, AEVec2 *pEnd, AEVec2 *pCtr, f32 radius, AEVec2 *pInter);
1080 
1081 /******************************************************************************/
1124 /******************************************************************************/
1125 AE_API f32 AEReflectAnimatedPointOnStaticCircle(AEVec2 *pStart, AEVec2 *pEnd, AEVec2 *pCtr, f32 radius, AEVec2 *pInter, AEVec2 *pReflect);
1126 
1127 /******************************************************************************/
1169 /******************************************************************************/
1170 AE_API f32 AEAnimatedCircleToStaticCircle(AEVec2 *pCtr0s, AEVec2 *pCtr0e, f32 radius0, AEVec2 *pCtr1, f32 radius1, AEVec2 *pInter);
1171 
1172 /******************************************************************************/
1220 /******************************************************************************/
1221 AE_API f32 AEReflectAnimatedCircleOnStaticCircle(AEVec2 *pCtr0s, AEVec2 *pCtr0e, f32 radius0, AEVec2 *pCtr1, f32 radius1, AEVec2 *pInter, AEVec2 *pReflect);
1222 
1223 
1224 
1225 /*
1226 // sweep a circle with radius 'radius' from ctr0 -> ctr1 againts a point
1227 // * return -ve if circle does not touch the point at any time
1228 AE_API f32 AESweepCircleToPoint (AEVec2* pCtr0, AEVec2* pCtr1, f32 radius, AEVec2* pP);
1229 
1230 // sweep a circle with radius 'radius' from ctr0 -> ctr1 againts a line segment
1231 // * return -ve if circle does not intersect the line segment at any time
1232 AE_API f32 AESweepCircleToLineSeg (AEVec2* pCtr0, AEVec2* pCtr1, f32 radius, AEVec2* pP0, AEVec2* pP1, AEVec2* pN);
1233 
1234 
1235 //TO TEST
1236 //Sweeps a moving point against a static line
1237 AE_API f32 AESweepPointToLine (AEVec2 *pPos, AEVec2 *pVel, AEVec2 *pPnt, AEVec2 *pDirection);
1238 
1239 //TO TEST
1240 //Sweeps a moving circle against a static line
1241 AE_API f32 AESweepCircleToLine (AEVec2 *pCtr, f32 radius, AEVec2 *pVel, AEVec2 *pPnt, AEVec2 *pDirection);
1242 
1243 //TO TEST
1244 //Reflects a moving point on a static line. Returns 0 if there is no
1245 //collision between the point and the line.
1246 AE_API s32 AEReflectPointOnLine (AEVec2 *pPos, AEVec2 *pVel, AEVec2 *pPnt, AEVec2 *pDirection, AEVec2 *pNewPosition, AEVec2 *pNewVelocity);
1247 
1248 
1249 //TO TEST
1250 //Reflects a moving circle on a static line. Returns 0 if there is no
1251 //collision between the circle and the line.
1252 AE_API s32 AEReflectCircleOnLine (AEVec2 *pCtr, f32 radius, AEVec2 *pVel, AEVec2 *pPnt, AEVec2 *pDirection, AEVec2 *pNewPosition, AEVec2 *newVelocity);
1253 */
1254 // ---------------------------------------------------------------------------
1255 
1256 #ifdef __cplusplus
1257 }
1258 #endif
1259 
1260 // ---------------------------------------------------------------------------
1261 
1262 #endif // AE_MATH_H
f32 AEAnimatedPointToStaticLineSegment(AEVec2 *pStart, AEVec2 *pEnd, AELineSegment2 *pLine, AEVec2 *pInter)
Calculate the collision between a moving point with a line.
f32 AECalcDistCircleToCircle(AEVec2 *pCtr0, f32 radius0, AEVec2 *pCtr1, f32 radius1)
Calculate the shortest distance between the edges of two circles.
s32 AETestCircleToCircle(AEVec2 *pCtr0, f32 radius0, AEVec2 *pCtr1, f32 radius1)
Test for collision between two circles.
float f32
Definition: AETypes.h:31
u32 AELogBase2(u32 x)
Calculate the log2 of x.
f32 AECalcDistRectToRect(AEVec2 *pRect0, f32 sizeX0, f32 sizeY0, AEVec2 *pRect1, f32 sizeX1, f32 sizeY1, AEVec2 *pNormal)
Calculate the shortest distance between the edges of two rectangles.
f32 AEACos(f32 x)
Calculate the ArcCosine value of an angle.
Header file for the 3x3 matrix library.
f32 AESin(f32 x)
Calculate the Sine value of an angle.
unsigned int u32
Definition: AETypes.h:28
Header file for the 2D line segment library.
f32 AEReflectAnimatedCircleOnStaticCircle(AEVec2 *pCtr0s, AEVec2 *pCtr0e, f32 radius0, AEVec2 *pCtr1, f32 radius1, AEVec2 *pInter, AEVec2 *pReflect)
Calculate the collision between a moving circle with a static circle and the reflected path of moving...
f32 AEMax(f32 x, f32 y)
Find which of the 2 value is higher.
f32 AECalcDistPointToRect(AEVec2 *pPos, AEVec2 *pRect, f32 sizeX, f32 sizeY)
Calculate the shortest distance from a point to the edge of a rectangle.
Definition: AEVec2.h:26
f32 AEAnimatedPointToStaticCircle(AEVec2 *pStart, AEVec2 *pEnd, AEVec2 *pCtr, f32 radius, AEVec2 *pInter)
Calculate the collision between a moving point with a circle.
f32 AECos(f32 x)
Calculate the Cosine value of an angle.
f32 AEStaticPointToStaticLineSegment(AEVec2 *pPos, AELineSegment2 *pLine)
Calculate the shortest distance from a point to a line.
s32 AETestPointToCircle(AEVec2 *pPos, AEVec2 *pCtr, f32 radius)
Test if a point is inside a circle.
s32 AETestRectToRect(AEVec2 *pRect0, f32 sizeX0, f32 sizeY0, AEVec2 *pRect1, f32 sizeX1, f32 sizeY1)
Test for collision between two rectangles.
s32 AETestCircleToRect(AEVec2 *pCtr, f32 radius, AEVec2 *pRect, f32 sizeX, f32 sizeY)
Test for collision between a circle and a rectangle.
f32 AECalcDistPointToCircle(AEVec2 *pPos, AEVec2 *pCtr, f32 radius)
Calculate the shortest distance from a point to the edge of a circle.
s32 AEInRange(f32 x, f32 x0, f32 x1)
Find if x is in the range (x0 to x1), inclusive.
f32 AEMin(f32 x, f32 y)
Find which of the 2 value is lower.
f32 AEReflectAnimatedPointOnStaticCircle(AEVec2 *pStart, AEVec2 *pEnd, AEVec2 *pCtr, f32 radius, AEVec2 *pInter, AEVec2 *pReflect)
Calculate the collision between a moving point with a circle and the reflected path of the point...
f32 AEATan(f32 x)
Calculate the ArcTangent value of an angle.
f32 AEASin(f32 x)
Calculate the ArcSine value of an angle.
Header file for the 2D vector library.
f32 AEAnimatedCircleToStaticLineSegment(AEVec2 *pStart, AEVec2 *pEnd, f32 radius, AELineSegment2 *pLine, AEVec2 *pInter)
Calculate the collision between a moving circle with a line.
f32 AETan(f32 x)
Calculate the Tangent value of an angle.
f32 AECalcDistPointToLineSeg(AEVec2 *pPos, AEVec2 *pLine0, AEVec2 *pLine1)
Calculate the shortest distance from a point to a line segment.
signed int s32
Definition: AETypes.h:27
f32 AEAnimatedCircleToStaticCircle(AEVec2 *pCtr0s, AEVec2 *pCtr0e, f32 radius0, AEVec2 *pCtr1, f32 radius1, AEVec2 *pInter)
Calculate the collision between a moving circle with a static circle.
s32 AETestPointToRect(AEVec2 *pPos, AEVec2 *pRect, f32 sizeX, f32 sizeY)
Test if a point is inside a rectangle.
f32 AEClamp(f32 X, f32 Min, f32 Max)
Clamp x to between x0 and x1.
f32 AEWrap(f32 x, f32 x0, f32 x1)
Wraparound for x with respect to range (x0 to x1).
f32 AECalcDistPointToConvexPoly(AEVec2 *pPos, AEVec2 *pVtx, u32 vtxNum)
Calculate the shortest distance from a point to the edge of a convex polygon.
#define AE_API
Definition: AEExport.h:53
f32 AEReflectAnimatedCircleOnStaticLineSegment(AEVec2 *pStart, AEVec2 *pEnd, f32 radius, AELineSegment2 *pLine, AEVec2 *pInter, AEVec2 *pReflect)
Calculate the collision between a moving circle with a line and the reflected path of the circle...
u32 AENextPowOf2(u32 x)
Calculate the next power of 2 that is greater than x.
f32 AERadToDeg(f32 x)
Convert an angle from Radians to Degree.
f32 AEDegToRad(f32 x)
Convert an angle from Degree to Radians.
u32 AEIsPowOf2(u32 x)
Check if x is a power of 2.
f32 AEReflectAnimatedPointOnStaticLineSegment(AEVec2 *pStart, AEVec2 *pEnd, AELineSegment2 *pLine, AEVec2 *pInter, AEVec2 *pReflect)
Calculate the collision between a moving point with a line and the reflected path of the point...
f32 AECalcDistCircleToRect(AEVec2 *pCtr, f32 radius, AEVec2 *pRect, f32 sizeX, f32 sizeY)
Calculate the shortest distance between the edges of a circle and a rectangle.
Generated on Sat Jan 4 2014 02:06:22 for Alpha Engine by   doxygen 1.8.5