Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

G3DEngine.H

Go to the documentation of this file.
00001 
00009 #ifndef G3DENGINE_H
00010 #define G3DENGINE_H
00011 
00012 // inspace includes
00013 #include "ISVREngine.H"
00014 
00015 #define OUTSIDE_GLUE_CORE
00016 #include <mlib/points.H>
00017 
00018 #include <G3DAll.h>
00019 #include <Texture.H>
00020 
00021 namespace InSpace {
00022 
00024 #define RD G3DEngine::renderDevice()
00025 
00026 
00028 static inline Vector3  toVector3(cWvec v) { return Vector3(v[0],v[1],v[2]); }
00029 
00030 static inline Vector3  toVector3(cWpt p)  { return Vector3(p[0],p[1],p[2]); }
00031 
00032 static inline CoordinateFrame  toCoordinateFrame(cWtransf m) {
00033   Vector3 trans = toVector3(m.origin());
00034   Matrix3 m3(m(0,0), m(0,1), m(0,2),
00035          m(1,0), m(1,1), m(1,2),
00036          m(2,0), m(2,1), m(2,2));
00037   return CoordinateFrame(m3, trans);
00038 }
00039 
00040 static inline Matrix4  toMatrix4(cWtransf m) {
00041   Matrix4 m2;
00042   for (int i=0;i<4;i++)
00043     for (int j=0;j<4;j++)
00044       m2[i][j] = m(i,j);
00045   return m2;
00046 }
00047 
00048 static inline Wpt     toWpt(Vector3 p)  { return Wpt(p[0],p[1],p[2]); }
00049 
00050 static inline Wvec    toWvec(Vector3 v) { return Wvec(v[0],v[1],v[2]); }
00051 
00052 static inline Wtransf toWtransf(CoordinateFrame cf) {
00053   Matrix3 m3    = cf.rotation;
00054   Vector3 trans = cf.translation;
00055   return Wtransf(toWpt(trans), toWvec(m3.getColumn(0)),
00056          toWvec(m3.getColumn(1)), toWvec(m3.getColumn(2)));
00057 }
00058   
00059 static inline TextureRef toTextureRef(InSpace::Texture *t) {
00060   switch (t->type()) {
00061   case TEX_RGB:
00062     return G3D::Texture::fromGLTexture(**(t->name()), t->glName(),
00063                        TextureFormat::RGB8);
00064     break;
00065   case TEX_RGBA:
00066     return G3D::Texture::fromGLTexture(**(t->name()), t->glName(),
00067                        TextureFormat::RGBA8);
00068     break;
00069   }
00070 }
00071 
00072 // ====================================================================
00073 
00074 
00075 class G3DEngine : public ISVREngine
00076 {
00077 public:
00078 
00079   static ISVREngine* createInstance(int argc, char **argv) {
00080     if (_instance == NULL)
00081       _instance = new G3DEngine(argc,argv);
00082     return _instance;
00083   }
00084 
00085   void run(ISApp *app);
00086 
00087   int maxScreenWidth();
00088   int maxScreenHeight();
00089   
00090   void runloop();
00091 
00092   static RenderDevice* renderDevice() { return _renderDevice; }
00093 
00094   static VARArea* varDynamic() { return _varDynamic; }
00095   static VARArea* varStatic()  { return _varStatic; }
00096 
00097 
00098 protected:
00099   // call instance() rather than the constructor
00100   G3DEngine(int argc, char **argv);
00101   virtual ~G3DEngine();
00102 
00103   void setProjection(cWtransf &eye2room);
00104   void processSDLInput();
00105 
00106   void mousemotion(int x, int y);
00107   str_ptr getKeyName(SDLKey key);
00108   void sendKbdEvent(str_ptr keyname, bool down);
00109 
00110   int  _drawcount;
00111   XYpt _lastPos;
00112   
00113   int    _argc;
00114   char **_argv;
00115 
00116   Wtransf _room2tile;
00117   double  _halftilew;
00118   double  _halftileh;
00119 
00120   double _nearclip;
00121   double _farclip;
00122 
00123   // G3D
00124   static GWindow      *_gwindow;
00125   static RenderDevice *_renderDevice;
00126   static Log          *_debugLog;
00127   static VARArea      *_varDynamic;
00128   static VARArea      *_varStatic;
00129 
00130 };
00131 
00132 }
00133 #endif

Generated on Thu Jul 8 15:19:28 2004 for inspace by doxygen 1.3.4