AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzMath.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if (!defined__CZ_MATH_H__)
00015 #define __CZ_MATH_H__
00016 
00017 #include "CzVec2.h"
00018 #include "CzVec3.h"
00019 
00020 #if (!defined PI)
00021     #define PI 3.1415926535f
00022 #endif
00023 
00024 #if (!defined NULL)
00025     #define NULL    0
00026 #endif
00027 
00028 class CzMath
00029 {
00030 private:
00031 public:
00032 
00033 private:
00034 public:
00035     // Angle operations
00036     static float    AngleDiff(float a1, float a2);
00037 
00038     // Misc
00039     static float    abs(float n);
00040     static int      abs(int n);
00041 
00042     // Trig
00043     static float    sqrt(float n);
00044     static float    sin(float n);
00045     static float    cos(float n);
00046     static float    tan(float n);
00047     static float    acos(float n);
00048     static float    atan(float n);
00049     static float    atan2(float n1, float n2);
00050     static float    RadToDeg(float n);
00051     static float    DegToRad(float n);
00052 
00053     // Quaternions
00054     static void     QuatSLERP(float *pQ1, float *pQ2, float *pQOut, float t);
00055 
00056     // Random numbers
00057     static void     SeedRand(unsigned int seed);
00058     static int      Rand();
00059     static float    Rand(float range);
00060 
00061     // Point Routines
00062     static int      PointClosestToPerimeter(CzVec3& point, CzVec3* v, int nNumLines, CzVec3& out);
00063     static float    PointDistanceToPlane(CzVec3& point, CzVec3& pop, CzVec3& normal);
00064     static void     PointProjectOntoPlane(CzVec3& point, CzVec3& pop, CzVec3& normal, CzVec3& out);
00065     static bool     PointInsidePolygon(CzVec3& point, CzVec3* poly, int nNumPoints);
00066     static float    PointIntersectWedge(CzVec3& wedge_base_pos, CzVec3& wedge_size, int type, CzVec3& pos);
00067 
00068     // Ray / Line Routines
00069     static float    LineIntersectPlane(CzVec3& line_start, CzVec3& line_end, CzVec3& pop, CzVec3& normal, CzVec3& out);
00070     static float    RayIntersectSphere(CzVec3& ray_pos, CzVec3& ray_dir, CzVec3& sphere_pos, float radius, CzVec3& out);
00071     static float    LineIntersectCappedCylinder(CzVec3& line_start, CzVec3& line_end, CzVec3& cyl_start, CzVec3& cyl_end, float radius, CzVec3& out);
00072 
00073     // Sphere Routines
00074     static float    SphereIntersectPlane(CzVec3& sphere_pos, CzVec3& sphere_vel, CzVec3& pop, CzVec3& normal, CzVec3& out, float radius);
00075     static bool     SphereIntersectCuboidTest(CzVec3& sphere_pos, float sphere_size, CzVec3& box_pos, CzVec3& box_size);
00076 
00077     // Cuboid Routines
00078     static int      CuboidIntersectTest(CzVec3& box1_pos, CzVec3& box1_size, CzVec3& box2_pos, CzVec3& box2_size);
00079 
00080     // Miscellaneous
00081     static CzVec3   CalcSlideVelocity(CzVec3& original_pos, CzVec3& original_vel, CzVec3& pop, CzVec3& normal, CzVec3& cp);
00082 
00083     // 2D routines
00084     static int      PointInsidePolygon2D(CzVec3& point, CzVec3* poly, int nNumPoints);
00085 };
00086 
00087 #endif  // __CZ_MATH_H__