00001
00002
00003
00004
00005
00006
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
00022 ObjectFrame *parent;
00023 ObjectFrame *child;
00024 ObjectFrame *leftSibling;
00025 ObjectFrame *rightSibling;
00026
00027 int numChildren;
00028 float mass;
00029 float units;
00030 bool moving;
00031 Vec3f velocity;
00032 Vec3f totalForce;
00033 void RecursiveDisplay(unsigned int Attribs=OBJ_ALL, int UseDisplayLists=0);
00034 public:
00035
00036 Vec3f X,Y,Z,O;
00037 float Scale;
00038
00039 Object *Obj;
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
00084 void AttachChild(ObjectFrame *newChild);
00085 void DetachChild(ObjectFrame *detached);
00086
00087
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);
00096 float *GetParent2ObjXform(float *M);
00097
00098 ObjectFrame* SelectHier(Vec3f &Start, Vec3f &Dir, float &InT, float &OutT);
00099
00100
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