Skip to content

Commit

Permalink
Created numerical vector class so we can easily handle 2d as well as …
Browse files Browse the repository at this point in the history
…3d vectors
  • Loading branch information
petewarden committed Jan 5, 2010
1 parent 95d0b19 commit 4d583a9
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 67 deletions.
54 changes: 14 additions & 40 deletions isightviewer/isightviewer.cpp
Expand Up @@ -13,37 +13,11 @@
#endif // __APPLE__ #endif // __APPLE__


#include "livefeed.h" #include "livefeed.h"
#include "vect.h"


#define WINDOW_WIDTH (1024) #define WINDOW_WIDTH (1024)
#define WINDOW_HEIGHT (768) #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() double getSeconds()
{ {
struct timeval timeValue; struct timeval timeValue;
Expand All @@ -55,15 +29,15 @@ double getSeconds()
class BasicTexQuad class BasicTexQuad
{ {
public: 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 SetupTexture ();
void DrawSelf (); void DrawSelf ();


public: public:
Vect pos; Vect3d pos;
Vect over; Vect3d over;
Vect norm; Vect3d norm;
double width; double width;
double height; double height;


Expand Down Expand Up @@ -97,7 +71,7 @@ do { \
exit(0); \ exit(0); \
} while (false) } while (false)


BasicTexQuad::BasicTexQuad (Vect _pos, Vect _over, Vect _norm, BasicTexQuad::BasicTexQuad (Vect3d _pos, Vect3d _over, Vect3d _norm,
double _width, double _height) double _width, double _height)
{ pos = _pos; { pos = _pos;
over = _over; over = _over;
Expand Down Expand Up @@ -151,10 +125,10 @@ void BasicTexQuad::DrawSelf ()
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, g_mungData->textureID); glBindTexture(GL_TEXTURE_RECTANGLE_EXT, g_mungData->textureID);
glEnable(GL_TEXTURE_RECTANGLE_EXT); glEnable(GL_TEXTURE_RECTANGLE_EXT);


Vect up = over.Cross (norm); Vect3d up = over.Cross (norm);
Vect north = height * up; Vect3d north = height * up;
Vect east = width * over; Vect3d east = width * over;
Vect v = pos - 0.5 * (east + north); Vect3d v = pos - 0.5 * (east + north);
float left = 0.0; float left = 0.0;
float right = FEED_WIDTH;; float right = FEED_WIDTH;;
float bottom = FEED_HEIGHT; float bottom = FEED_HEIGHT;
Expand All @@ -173,9 +147,9 @@ void BasicTexQuad::DrawSelf ()
} }


BasicTexQuad g_texQuad( BasicTexQuad g_texQuad(
Vect((WINDOW_WIDTH/2), (WINDOW_HEIGHT/2),0), Vect3d((WINDOW_WIDTH/2), (WINDOW_HEIGHT/2),0),
Vect(0,1,0), Vect3d(0,1,0),
Vect(0,0,1), Vect3d(0,0,1),
FEED_WIDTH, FEED_WIDTH,
FEED_HEIGHT); FEED_HEIGHT);
bool g_isTextureSetup = false; bool g_isTextureSetup = false;
Expand Down Expand Up @@ -206,7 +180,7 @@ display(void)
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);


const double angle = 0; 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(); g_texQuad.DrawSelf();


Expand Down
21 changes: 11 additions & 10 deletions isightviewer/isightviewer.xcodeproj/petewarden.mode1v3
Expand Up @@ -271,7 +271,7 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key> <key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array> <array>
<array> <array>
<integer>2</integer> <integer>5</integer>
<integer>1</integer> <integer>1</integer>
<integer>0</integer> <integer>0</integer>
</array> </array>
Expand All @@ -296,7 +296,7 @@
<real>186</real> <real>186</real>
</array> </array>
<key>RubberWindowFrame</key> <key>RubberWindowFrame</key>
<string>350 312 1395 866 0 0 1920 1178 </string> <string>228 276 1395 866 0 0 1920 1178 </string>
</dict> </dict>
<key>Module</key> <key>Module</key>
<string>PBXSmartGroupTreeModule</string> <string>PBXSmartGroupTreeModule</string>
Expand All @@ -314,24 +314,25 @@
<key>PBXProjectModuleGUID</key> <key>PBXProjectModuleGUID</key>
<string>1CE0B20306471E060097A5F4</string> <string>1CE0B20306471E060097A5F4</string>
<key>PBXProjectModuleLabel</key> <key>PBXProjectModuleLabel</key>
<string>isightviewer.cpp</string> <string>vect.h</string>
<key>PBXSplitModuleInNavigatorKey</key> <key>PBXSplitModuleInNavigatorKey</key>
<dict> <dict>
<key>Split0</key> <key>Split0</key>
<dict> <dict>
<key>PBXProjectModuleGUID</key> <key>PBXProjectModuleGUID</key>
<string>1CE0B20406471E060097A5F4</string> <string>1CE0B20406471E060097A5F4</string>
<key>PBXProjectModuleLabel</key> <key>PBXProjectModuleLabel</key>
<string>isightviewer.cpp</string> <string>vect.h</string>
<key>_historyCapacity</key> <key>_historyCapacity</key>
<integer>0</integer> <integer>0</integer>
<key>bookmark</key> <key>bookmark</key>
<string>5928F97110F3CB26004C76C6</string> <string>5928F98810F3D3F0004C76C6</string>
<key>history</key> <key>history</key>
<array> <array>
<string>5928F95110F3CA20004C76C6</string> <string>5928F95110F3CA20004C76C6</string>
<string>5928F96110F3CABF004C76C6</string> <string>5928F96110F3CABF004C76C6</string>
<string>5928F96210F3CABF004C76C6</string> <string>5928F98610F3D3F0004C76C6</string>
<string>5928F98710F3D3F0004C76C6</string>
</array> </array>
</dict> </dict>
<key>SplitCount</key> <key>SplitCount</key>
Expand All @@ -345,7 +346,7 @@
<key>Frame</key> <key>Frame</key>
<string>{{0, 0}, {1187, 639}}</string> <string>{{0, 0}, {1187, 639}}</string>
<key>RubberWindowFrame</key> <key>RubberWindowFrame</key>
<string>350 312 1395 866 0 0 1920 1178 </string> <string>228 276 1395 866 0 0 1920 1178 </string>
</dict> </dict>
<key>Module</key> <key>Module</key>
<string>PBXNavigatorGroup</string> <string>PBXNavigatorGroup</string>
Expand All @@ -365,7 +366,7 @@
<key>Frame</key> <key>Frame</key>
<string>{{0, 644}, {1187, 181}}</string> <string>{{0, 644}, {1187, 181}}</string>
<key>RubberWindowFrame</key> <key>RubberWindowFrame</key>
<string>350 312 1395 866 0 0 1920 1178 </string> <string>228 276 1395 866 0 0 1920 1178 </string>
</dict> </dict>
<key>Module</key> <key>Module</key>
<string>XCDetailModule</string> <string>XCDetailModule</string>
Expand Down Expand Up @@ -529,7 +530,7 @@
<integer>5</integer> <integer>5</integer>
<key>WindowOrderList</key> <key>WindowOrderList</key>
<array> <array>
<string>5928F97210F3CB26004C76C6</string> <string>5928F98910F3D3F0004C76C6</string>
<string>5928F93010F3C649004C76C6</string> <string>5928F93010F3C649004C76C6</string>
<string>5928F93110F3C649004C76C6</string> <string>5928F93110F3C649004C76C6</string>
<string>1CD10A99069EF8BA00B06720</string> <string>1CD10A99069EF8BA00B06720</string>
Expand All @@ -538,7 +539,7 @@
<string>/Users/petewarden/Projects/moveable/isightviewer/isightviewer.xcodeproj</string> <string>/Users/petewarden/Projects/moveable/isightviewer/isightviewer.xcodeproj</string>
</array> </array>
<key>WindowString</key> <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> <key>WindowToolsV3</key>
<array> <array>
<dict> <dict>
Expand Down

0 comments on commit 4d583a9

Please sign in to comment.