Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

objframe.hpp

00001 //==========================================================================
00002 // objframe.hpp : moving object coordinate frame
00003 //   All objects within this framework are assumed to be positioned within
00004 //   the world-space with the given object coordinate frame (axes, origin,
00005 //   uniform scale). The Obj points to an object in object-space. The frame
00006 //   creates an instance of the object pointed to.
00007 //==========================================================================
00008 
00009 #ifndef _OBJECT_FRAME_
00010 #define _OBJECT_FRAME_
00011 
00012 #include <GL/glut.h>
00013 #include <object.hpp>
00014 
00015 class ObjectFrame
00016 {
00017   private:
00018 
00019     GLuint DisplayListID;
00020 
00021     // Hierarchy
00022     ObjectFrame *parent;      // pointer to parent frame
00023     ObjectFrame *child;       // pointer to head of a list of children
00024     ObjectFrame *leftSibling; // left in a doubly linked sibling list
00025     ObjectFrame *rightSibling;// right in a doubly linked sibling list
00026 
00027     int numChildren;
00028     float mass;
00029     float units;      // units of object in fraction of meters
00030     bool moving;      // set when there is an applied force 
00031     Vec3f velocity;
00032     Vec3f totalForce; // total force currently applied to object
00033     void RecursiveDisplay(unsigned int Attribs=OBJ_ALL, int UseDisplayLists=0);
00034   public:
00035 
00036     Vec3f X,Y,Z,O;  // OBJECT COORDINATE SYSTEM FRAME (AXES,ORIGIN)
00037     float Scale;    // UNIFORM OBJECT SCALING
00038 
00039     Object *Obj;    // PTR TO OBJECT (TO BE ABLE TO EASILY INSTANCE OBJECTS)
00040 
00041     ObjectFrame(Object *ObjPtr);
00042 
00043     void GetOBBverts(Vec3f *V);
00044     void GetBoundingSphere(Vec3f *Cntr, float *Rad);
00045 
00046     void DrawOBB(float r=0, float g=0, float b=1);
00047     void DrawBoundingSphere(float r, float g, float b);
00048     void DrawAxes(float LineWidth=1, float scale=1);
00049 
00050     int RayIsect(Vec3f &Start, Vec3f &Dir, float &InT, float &OutT);
00051 
00052     void TranslateObj(Vec3f T);
00053     void ScaleObj(float scale);
00054     void RotateObj(float Ang, Vec3f Axis);
00055     void RotateObjAboutMinMaxCntr(float Ang, Vec3f Axis);
00056 
00057     void ScaleObj(float scale, Vec3f Pt);
00058     void RotateObj(float Ang, Vec3f Axis, Vec3f Pt);
00059     
00060     Vec3f objMinMaxCntr();
00061     Vec3f worldMinMaxCntr();
00062 
00063     void LoadIdentity();
00064     void Xform(float M[16]);
00065 
00066     float* GetObj2WorldXform(float *M);
00067     float* GetWorld2ObjXform(float *M);
00068 
00069     float* GetRotationMatrix(float *M, float DegAng, Vec3f Axis);
00070 
00071     void UpdateMinMax() { Obj->UpdateMinMax(); }
00072     void GetWorldMinMax(Vec3f &Min, Vec3f &Max);
00073 
00074     void Display(unsigned int Attribs=OBJ_ALL, int UseDisplayLists=0);
00075     void FastDisplay(int UseDisplayLists=0) { Display(OBJ_NONE,UseDisplayLists); }
00076 
00077     void WriteToFile(FILE *fp);
00078     int ReadFromFile(FILE *fp);
00079 
00080     void GetTris(float* &Tris, int &NumTris);
00081     int GetNumTris();
00082 
00083     // Hierarchical stuff
00084     void AttachChild(ObjectFrame *newChild);
00085     void DetachChild(ObjectFrame *detached);
00086 
00087     // heirarchy navigation
00088     ObjectFrame* GetParent() { return parent; }
00089     ObjectFrame* GetRoot();
00090     int GetNumChildren() { return numChildren; }
00091     ObjectFrame* GetChild() { return child; }
00092     ObjectFrame* GetLeftSibling() { return leftSibling; }
00093     ObjectFrame* GetRightSibling() { return rightSibling; }
00094 
00095     float *GetObj2ParentXform(float *M); // in the case of no parent, same as Obj2World
00096     float *GetParent2ObjXform(float *M); // in the case of no parent, same as World2Obj
00097 
00098     ObjectFrame* SelectHier(Vec3f &Start, Vec3f &Dir, float &InT, float &OutT);
00099 
00100     // physics stuff
00101     void ResetForce() { totalForce = Vec3f(0, 0, 0); moving = false; }
00102     void ResetVelocity() { velocity = Vec3f(0, 0, 0); }
00103     void SetMass(float newMass) { mass = newMass; }
00104     void SetUnits(float newUnits) { units = newUnits; }
00105     float GetUnits() { return units; }
00106     float GetMass() { return mass; }
00107     void UpdatePosition(float deltaTime);
00108     void ApplyForce(Vec3f force) { totalForce += force*units; moving = true; }
00109     bool IsMoving() { return moving; } 
00110 };
00111 
00112 #endif

Generated at Fri Oct 12 15:12:21 2001 for GLVU by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001