|
From: Mike D. <o3d...@us...> - 2004-07-23 05:45:14
|
Update of /cvsroot/grappelmann/spaceplane In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9950 Added Files: coord3d.h opengl_includes.h Log Message: - split out these files to make the include tree more sensible --- NEW FILE: coord3d.h --- /* $Id: coord3d.h,v 1.1 2004/07/23 05:45:06 o3dozone Exp $ */ #ifndef COORD3D_H #define COORD3D_H #include <iostream> using namespace std; typedef long double pos_t; struct Coord3D { Coord3D() : m_x(0), m_y(0), m_z(0) {}; Coord3D(pos_t x, pos_t y, pos_t z) : m_x(x), m_y(y), m_z(z) {}; Coord3D(const Coord3D& rhs) : m_x(rhs.m_x), m_y(rhs.m_y), m_z(rhs.m_z) {}; bool isZero() { if(m_x == 0 && m_y == 0 && m_z == 0) { return true; } else { return false; } }; bool operator==(const Coord3D& rhs) { if((m_x == rhs.m_x) && (m_y == rhs.m_y) && (m_z == rhs.m_z)) { return true; } else { return false; } }; bool operator==(const Coord3D& rhs) const { return((Coord3D)(*this) == rhs); }; Coord3D& operator=(const Coord3D& rhs) { m_x = rhs.m_x; m_y = rhs.m_y; m_z = rhs.m_z; return(*this); }; Coord3D operator*(long double rhs) const { return((Coord3D)(*this) * rhs); }; Coord3D operator*(long double rhs) { Coord3D result(0, 0, 0); result.m_x = m_x * rhs; result.m_y = m_y * rhs; result.m_z = m_z * rhs; return result; }; Coord3D operator+(const Coord3D& rhs) const { return((Coord3D)(*this) + rhs); }; Coord3D operator+(const Coord3D& rhs) { Coord3D result(0, 0, 0); result.m_x = m_x + rhs.m_x; result.m_y = m_y + rhs.m_y; result.m_z = m_z + rhs.m_z; return result; }; Coord3D operator-(const Coord3D& rhs) const { return((Coord3D)(*this) + rhs); }; Coord3D operator-(const Coord3D& rhs) { Coord3D result(0, 0, 0); result.m_x = m_x - rhs.m_x; result.m_y = m_y - rhs.m_y; result.m_z = m_z - rhs.m_z; return result; }; Coord3D crossProduct(const Coord3D& rhs) { Coord3D result(0, 0, 0); //(aybz - azby)i+ (azbx - axbz)j+ (axby - aybx)k; result.m_x = m_y * rhs.m_z - m_z * rhs.m_y; result.m_y = m_z * rhs.m_x - m_x * rhs.m_z; result.m_z = m_x * rhs.m_y - m_y * rhs.m_x; return result; }; Coord3D distance(const Coord3D& rhs) { Coord3D result(0, 0, 0); result.m_x = m_x - rhs.m_x; result.m_y = m_y - rhs.m_y; result.m_z = m_z - rhs.m_z; return result; }; void normalise() { pos_t vectorLength = length(); if(vectorLength != 0) { m_x /= vectorLength; m_y /= vectorLength; m_z /= vectorLength; } else { m_x = 0; m_y = 0; m_z = 0; } }; bool isParallel(const Coord3D& rhs, bool& sameDirection) { pos_t x = m_x / rhs.m_x; pos_t y = m_y / rhs.m_y; pos_t z = m_z / rhs.m_z; //cout << "<::isParallel>\tx [" << x << "] y [" << y << "] z [" << z << "]" << endl; /* if((m_x == rhs.m_x) && (m_x == 0)) { cout << "x is zero" << endl; } else if((m_y == rhs.m_y) && (m_y == 0)) { cout << "y is zero" << endl; } else if((m_z == rhs.m_z) && (m_z == 0)) { cout << "z is zero" << endl; } */ sameDirection = true; if((!((m_x == rhs.m_x) && (m_x == 0))) && (!((m_y == rhs.m_y) && (m_y == 0))) && (x != y)) { cout << "1" << endl; return false; } else if((!((m_x == rhs.m_x) && (m_x == 0))) && (!((m_z == rhs.m_z) && (m_z == 0))) && (x != z)) { cout << "2" << endl; return false; } else if((!((m_z == rhs.m_z) && (m_z == 0))) && (!((m_y == rhs.m_y) && (m_y == 0))) && (z != y)) { cout << "3" << endl; return false; } else { //cout << "parallel" << endl; if((x < 0) || (y < 0) || (z < 0)) { //cout << "\topposite direction" << endl; sameDirection = false; } return true; } }; pos_t length() const { return (pos_t)sqrt(m_x * m_x + m_y * m_y + m_z * m_z); } pos_t length() { return (pos_t)sqrt(m_x * m_x + m_y * m_y + m_z * m_z); } pos_t m_x; pos_t m_y; pos_t m_z; }; Coord3D operator*(long double lhs, const Coord3D& rhs); #endif --- NEW FILE: opengl_includes.h --- /* $Id: opengl_includes.h,v 1.1 2004/07/23 05:45:06 o3dozone Exp $ */ #include <SDL.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> /* $Log: opengl_includes.h,v $ Revision 1.1 2004/07/23 05:45:06 o3dozone - split out these files to make the include tree more sensible */ |