Permalink
Browse files

Created numerical vector class so we can easily handle 2d as well as …

…3d vectors
  • Loading branch information...
1 parent 95d0b19 commit 4d583a95e8d2357d0e3e1f59e58d3976c521d94c @petewarden petewarden committed Jan 5, 2010
@@ -13,37 +13,11 @@
#endif // __APPLE__
#include "livefeed.h"
+#include "vect.h"
#define WINDOW_WIDTH (1024)
#define WINDOW_HEIGHT (768)
-struct Vect
-{
- double x;
- double y;
- double z;
-
- Vect() : x(0.0), y(0.0), z(0.0) { }
- Vect(double _x, double _y, double _z) : x(_x), y(_y), z(_z) { }
- Vect(const Vect& other) : x(other.x), y(other.y), z(other.z) { }
-
- const Vect& operator*=(double factor) { x*=factor; y*=factor; z*=factor; return *this; }
- const Vect& operator+=(const Vect& other) { x+=other.x; y+=other.y; z+=other.z; return *this; }
- const Vect& operator-=(const Vect& other) { x-=other.x; y-=other.y; z-=other.z; return *this; }
-
- Vect operator*(double factor) { return Vect(x*factor, y*factor, z*factor); }
- Vect operator+(const Vect& other) { return Vect(x+other.x, y+other.y, z+other.z); }
- Vect operator-(const Vect& other) { return Vect(x-other.x, y-other.y, z-other.z); }
-
- Vect Cross(const Vect& other) { return Vect((y*other.z)-(z*other.y),
- (z*other.x)-(x*other.z), (x*other.y)-(y*other.x)); }
-
- double dot(const Vect& other) { return (x*other.x)+(y*other.y)+(z*other.z); }
-};
-
-inline Vect operator*(double factor, const Vect& other) {
- return Vect(factor*other.x, factor*other.y, factor*other.z); }
-
double getSeconds()
{
struct timeval timeValue;
@@ -55,15 +29,15 @@ double getSeconds()
class BasicTexQuad
{
public:
- BasicTexQuad (Vect _pos, Vect _over, Vect _norm, double _width, double _height);
+ BasicTexQuad (Vect3d _pos, Vect3d _over, Vect3d _norm, double _width, double _height);
void SetupTexture ();
void DrawSelf ();
public:
- Vect pos;
- Vect over;
- Vect norm;
+ Vect3d pos;
+ Vect3d over;
+ Vect3d norm;
double width;
double height;
@@ -97,7 +71,7 @@ do { \
exit(0); \
} while (false)
-BasicTexQuad::BasicTexQuad (Vect _pos, Vect _over, Vect _norm,
+BasicTexQuad::BasicTexQuad (Vect3d _pos, Vect3d _over, Vect3d _norm,
double _width, double _height)
{ pos = _pos;
over = _over;
@@ -151,10 +125,10 @@ void BasicTexQuad::DrawSelf ()
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, g_mungData->textureID);
glEnable(GL_TEXTURE_RECTANGLE_EXT);
- Vect up = over.Cross (norm);
- Vect north = height * up;
- Vect east = width * over;
- Vect v = pos - 0.5 * (east + north);
+ Vect3d up = over.Cross (norm);
+ Vect3d north = height * up;
+ Vect3d east = width * over;
+ Vect3d v = pos - 0.5 * (east + north);
float left = 0.0;
float right = FEED_WIDTH;;
float bottom = FEED_HEIGHT;
@@ -173,9 +147,9 @@ void BasicTexQuad::DrawSelf ()
}
BasicTexQuad g_texQuad(
- Vect((WINDOW_WIDTH/2), (WINDOW_HEIGHT/2),0),
- Vect(0,1,0),
- Vect(0,0,1),
+ Vect3d((WINDOW_WIDTH/2), (WINDOW_HEIGHT/2),0),
+ Vect3d(0,1,0),
+ Vect3d(0,0,1),
FEED_WIDTH,
FEED_HEIGHT);
bool g_isTextureSetup = false;
@@ -206,7 +180,7 @@ display(void)
glClear(GL_COLOR_BUFFER_BIT);
const double angle = 0;
- g_texQuad.over = Vect(cos(angle), sin(angle), 0);
+ g_texQuad.over = Vect3d(cos(angle), sin(angle), 0);
g_texQuad.DrawSelf();
@@ -271,7 +271,7 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
- <integer>2</integer>
+ <integer>5</integer>
<integer>1</integer>
<integer>0</integer>
</array>
@@ -296,7 +296,7 @@
<real>186</real>
</array>
<key>RubberWindowFrame</key>
- <string>350 312 1395 866 0 0 1920 1178 </string>
+ <string>228 276 1395 866 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>PBXSmartGroupTreeModule</string>
@@ -314,24 +314,25 @@
<key>PBXProjectModuleGUID</key>
<string>1CE0B20306471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
- <string>isightviewer.cpp</string>
+ <string>vect.h</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CE0B20406471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
- <string>isightviewer.cpp</string>
+ <string>vect.h</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
- <string>5928F97110F3CB26004C76C6</string>
+ <string>5928F98810F3D3F0004C76C6</string>
<key>history</key>
<array>
<string>5928F95110F3CA20004C76C6</string>
<string>5928F96110F3CABF004C76C6</string>
- <string>5928F96210F3CABF004C76C6</string>
+ <string>5928F98610F3D3F0004C76C6</string>
+ <string>5928F98710F3D3F0004C76C6</string>
</array>
</dict>
<key>SplitCount</key>
@@ -345,7 +346,7 @@
<key>Frame</key>
<string>{{0, 0}, {1187, 639}}</string>
<key>RubberWindowFrame</key>
- <string>350 312 1395 866 0 0 1920 1178 </string>
+ <string>228 276 1395 866 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
@@ -365,7 +366,7 @@
<key>Frame</key>
<string>{{0, 644}, {1187, 181}}</string>
<key>RubberWindowFrame</key>
- <string>350 312 1395 866 0 0 1920 1178 </string>
+ <string>228 276 1395 866 0 0 1920 1178 </string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
@@ -529,7 +530,7 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
- <string>5928F97210F3CB26004C76C6</string>
+ <string>5928F98910F3D3F0004C76C6</string>
<string>5928F93010F3C649004C76C6</string>
<string>5928F93110F3C649004C76C6</string>
<string>1CD10A99069EF8BA00B06720</string>
@@ -538,7 +539,7 @@
<string>/Users/petewarden/Projects/moveable/isightviewer/isightviewer.xcodeproj</string>
</array>
<key>WindowString</key>
- <string>350 312 1395 866 0 0 1920 1178 </string>
+ <string>228 276 1395 866 0 0 1920 1178 </string>
<key>WindowToolsV3</key>
<array>
<dict>
Oops, something went wrong.

0 comments on commit 4d583a9

Please sign in to comment.