Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00049
00050
00051 #ifndef __MO_GFX_H__
00052 #define __MO_GFX_H__
00053
00054
00055 #include "mo_def.h"
00056 #include <math.h>
00057 #include <sys/time.h>
00058 #include <OpenGLES/ES1/gl.h>
00059
00060
00061
00067
00068 class Vector3D
00069 {
00070 public:
00071 Vector3D( ) : x(0), y(0), z(0) { }
00072 Vector3D( GLfloat _x, GLfloat _y, GLfloat _z ) { set( _x, _y, _z ); }
00073 Vector3D( const Vector3D & other ) { *this = other; }
00074 ~Vector3D() { }
00075
00076 public:
00077 void set( GLfloat _x, GLfloat _y, GLfloat _z ) { x = _x; y = _y; z = _z; }
00078 void setAll( GLfloat val ) { x = y = z = val; }
00079
00080 public:
00081 GLfloat & operator []( int index )
00082 { if( index == 0 ) return x; if( index == 1 ) return y;
00083 if( index == 2 ) return z; return nowhere; }
00084 const GLfloat & operator []( int index ) const
00085 { if( index == 0 ) return x; if( index == 1 ) return y;
00086 if( index == 2 ) return z; return zero; }
00087 const Vector3D & operator =( const Vector3D & rhs )
00088 { x = rhs.x; y = rhs.y; z = rhs.z; return *this; }
00089
00090 Vector3D operator +( const Vector3D & rhs ) const
00091 { Vector3D result = *this; result += rhs; return result; }
00092 Vector3D operator -( const Vector3D & rhs ) const
00093 { Vector3D result = *this; result -= rhs; return result; }
00094 Vector3D operator *( GLfloat scalar ) const
00095 { Vector3D result = *this; result *= scalar; return result; }
00096
00097 inline void operator +=( const Vector3D & rhs )
00098 { x += rhs.x; y += rhs.y; z += rhs.z; }
00099 inline void operator -=( const Vector3D & rhs )
00100 { x -= rhs.x; y -= rhs.y; z -= rhs.z; }
00101 inline void operator *=( GLfloat scalar )
00102 { x *= scalar; y *= scalar; z *= scalar; }
00103
00105 inline GLfloat operator *( const Vector3D & rhs ) const
00106 { GLfloat result = x*rhs.x + y*rhs.y + z*rhs.z; return result; }
00108 inline GLfloat magnitude() const
00109 { return ::sqrt( x*x + y*y + z*z ); }
00111 inline void normalize()
00112 { GLfloat mag = magnitude(); if( mag == 0 ) return; *this *= 1/mag; }
00114 inline GLfloat angleXY() const
00115 { return ::atan2( y, x ); }
00116 inline GLfloat angleYZ() const
00117 { return ::atan2( z, y ); }
00118 inline GLfloat angleXZ() const
00119 { return ::atan2( z, x ); }
00120
00121 public:
00122 inline void interp()
00123 { value = (goal-value)*slew + value; }
00124 inline void update( GLfloat _goal )
00125 { goal = _goal; }
00126 inline void update( GLfloat _goal, GLfloat _slew )
00127 { goal = _goal; slew = _slew; }
00128
00129 public:
00131 union { GLfloat x; GLfloat value; };
00132 union { GLfloat y; GLfloat goal; };
00133 union { GLfloat z; GLfloat slew; };
00134
00135 public:
00136 static GLfloat nowhere;
00137 static GLfloat zero;
00138 };
00139
00140
00141
00146
00147 class MoGfx
00148 {
00149 public:
00151 static void perspective( double fovy, double aspectRatio, double zNear, double zFar );
00152
00154
00155 static void ortho( GLint width = 320, GLint height = 480, GLint landscape = 0 );
00156
00158 static void lookAt( double eye_x, double eye_y, double eye_z,
00159 double at_x, double at_y, double at_z,
00160 double up_x, double up_y, double up_z );
00161
00163 static bool loadTexture( NSString * name, NSString * ext );
00164
00166 static bool loadTexture( UIImage * image );
00167
00169 static bool isPointInTriangle2D( const Vector3D & pt, const Vector3D & a,
00170 const Vector3D & b, const Vector3D & c );
00171
00173 static double getCurrentTime( bool fresh );
00174
00176 static void resetCurrentTime();
00177
00179 static GLfloat delta();
00180
00182 static void setDeltaFactor( GLfloat factor );
00183
00184 public:
00185 static struct timeval ourPrevTime;
00186 static struct timeval ourCurrTime;
00187 static GLfloat ourDeltaFactor;
00188 };
00189
00190
00191 #endif