summaryrefslogtreecommitdiffstats
path: root/matchblox/engine/typedefs.h
diff options
context:
space:
mode:
Diffstat (limited to 'matchblox/engine/typedefs.h')
-rw-r--r--matchblox/engine/typedefs.h99
1 files changed, 55 insertions, 44 deletions
diff --git a/matchblox/engine/typedefs.h b/matchblox/engine/typedefs.h
index a7b0b49..867b85a 100644
--- a/matchblox/engine/typedefs.h
+++ b/matchblox/engine/typedefs.h
@@ -2,46 +2,60 @@
#define TYPEDEFS_H
-//#include <wiimote.h>
-#include <wiiuse.h>
+#include <iostream>
+#include <iomanip>
+#include <sstream>
#include <vector>
#include <limits>
+#include <GL/glut.h>
+
+using namespace std;
#undef max
-typedef struct vec3d
+typedef struct v3 //3d vector struct with overloaded operators
{
- double x, y, z;
-
- //constructors
- vec3d()
- { x=0.0, y=0.0, z=0.0; }
- vec3d(double fx, double fy, double fz)
- { x=fx, y=fy, z=fz; }
- vec3d(const vec3d &clone)
- { x=clone.x; y=clone.y; z=clone.z; }
-
- inline vec3d& operator=(const vec3d &rhs)
- { x=rhs.x; y=rhs.y; z=rhs.z; return *this; }
- inline vec3d& operator+=(const vec3d &rhs)
- { x+=rhs.x; y+=rhs.y; z+=rhs.z; return *this; }
- inline vec3d& operator-=(const vec3d &rhs)
- { x-=rhs.x; y-=rhs.y; z-=rhs.z; return *this; }
- inline vec3d& operator*=(const vec3d &rhs)
- { x*=rhs.x; y*=rhs.y; z*=rhs.z; return *this; }
- inline vec3d& operator*=(const double &scal)
- { x*=scal; y*=scal; z*=scal; return *this; }
-
- inline const vec3d& operator+(const vec3d &rhs) const
- { return vec3d(*this) += rhs; }
- inline const vec3d& operator-(const vec3d &rhs) const
- { return vec3d(*this) -= rhs; }
- inline const vec3d& operator*(const vec3d &rhs) const
- { return vec3d(*this) *= rhs; }
- inline const vec3d& operator*(const double &scal) const
- { return vec3d(*this) *= scal; }
+ double x,y,z;
+
+ inline v3() {x=y=z= 0.0;}
+ inline v3(double vx, double vy, double vz) { x=vx; y=vy; z=vz; }
+ inline v3(const v3 &v) {x=v.x; y=v.y; z=v.z;}
+
+ v3& operator=(const v3 &rhs) {x=rhs.x; y=rhs.y; z=rhs.z; return *this;}
+
+ inline v3& operator+=(const v3 &rhs) {x+=rhs.x; y+=rhs.y; z+=rhs.z; return *this;}
+ inline v3& operator-=(const v3 &rhs) {x-=rhs.x; y-=rhs.y; z-=rhs.z; return *this;}
+ inline v3& operator*=(const v3 &rhs) {x*=rhs.x; y*=rhs.y; z*=rhs.z; return *this;}
+ inline v3& operator/=(const v3 &rhs) {x/=rhs.x; y/=rhs.y; z/=rhs.z; return *this;}
+
+ //scalar mult/div
+ inline v3& operator*=(const double s) {x*=s; y*=s; z*=s; return *this;}
+ inline v3& operator/=(const double s) {x/=s; y/=s; z/=s; return *this;}
+
+ inline const v3 operator+(const v3 &rhs) const {v3 v(*this); return v+=rhs;}
+ inline const v3 operator-(const v3 &rhs) const {v3 v(*this); return v-=rhs;}
+ inline const v3 operator*(const v3 &rhs) const {v3 v(*this); return v*=rhs;}
+ inline const v3 operator/(const v3 &rhs) const {v3 v(*this); return v/=rhs;}
+
+ inline const v3 operator*(const double s) const {v3 v(*this); return v*=s;}
+ inline const v3 operator/(const double s) const {v3 v(*this); return v/=s;}
+
+ inline bool operator>(const v3 &rhs) const { return x>rhs.x && y>rhs.y && z>rhs.z; }
+ inline bool operator<(const v3 &rhs) const { return x<rhs.x && y<rhs.y && z<rhs.z; }
} Vect3D_t;
+//scalar vector multiplication s * v
+inline const v3 operator*(const double s, const v3 &rhs) {return rhs*s;}
+
+//output stream operator for Vect3D_t (handy for printing)
+inline std::ostream& operator<<(std::ostream& os, const Vect3D_t& v )
+{
+ stringstream ss;
+ ss << fixed << setprecision(2) << "(" << v.x << ", " << v.y << ", " << v.z << ")";
+
+ return os << ss.str();
+}
+
typedef struct bb
{
Vect3D_t m_Min, //minimal corner vertex (-x, -y, -z)
@@ -62,7 +76,7 @@ typedef struct bb
//translating a bounding box
inline bb& operator+=(const Vect3D_t &v)
{ m_Min += v; m_Max += v; return *this; }
- inline const bb& operator+(const Vect3D_t &v) const
+ inline const bb operator+(const Vect3D_t &v) const
{ return (bb(*this) += v); }
//update the bounding box min/max coords with vertex v
@@ -80,9 +94,7 @@ typedef struct bb
inline bool Contains(const Vect3D_t &v) const
{
//check if the point is contained in the box
- return m_Min.x < v.x && v.x < m_Max.x &&
- m_Min.y < v.y && v.y < m_Max.y &&
- m_Min.z < v.z && v.z < m_Max.z;
+ return m_Min < v && v < m_Max;
}
inline bool Contains(const bb& b) const
@@ -92,13 +104,8 @@ typedef struct bb
inline bool Overlap(const bb& rhs) const
{
- //check if the boxes overlap in all three axis
- return ( ( m_Min.x < rhs.m_Min.x && rhs.m_Min.x < rhs.m_Max.x) ||
- ( m_Min.x < rhs.m_Max.x && rhs.m_Max.x < rhs.m_Max.x) ) &&
- ( ( m_Min.y < rhs.m_Min.y && rhs.m_Min.y < rhs.m_Max.y) ||
- ( m_Min.y < rhs.m_Max.y && rhs.m_Max.y < rhs.m_Max.y) ) &&
- ( ( m_Min.z < rhs.m_Min.z && rhs.m_Min.z < rhs.m_Max.z) ||
- ( m_Min.z < rhs.m_Max.z && rhs.m_Max.z < rhs.m_Max.z) );
+
+ return m_Min < rhs.m_Max && m_Max > rhs.m_Min;
}
} BoundingBox_t;
@@ -176,13 +183,17 @@ typedef enum EyeOrigin {
MONO_CENTER = 2
} EyeOrigin_t;
+
+//forward class declaration
+class AbstractWiimote;
+
typedef struct GameState
{
FrustumParms_t m_FrustumParms;
bool m_bHeadTrackingEnabled;
bool m_bStereoEnabled;
//wiimote *m_pTrackingWiimote;
- wiimote **m_ppWiimotes;
+ AbstractWiimote *m_pWiimote[2];
GLuint m_GreyScaleShaderProgram; //handle to the grayscale shader program
GLint m_GSConvScaleLoc; //handle to the g_ConversionScale variable in the shader
GLfloat m_GSConvScale[3]; //grayscale conversion scale (default 0.299, 0.587, 0.114)