00001
00009 #ifndef _OBJECT_H_
00010 #define _OBJECT_H_
00011
00012 #include "material.h"
00013 #include "../extern/lib3ds/lib3ds.h"
00014
00016 enum Obj_types{PRIMITIVE,EXTERN,INSTANCE};
00018 enum Primitives{CUBE,PLANE,STRIP_PLANE,CONE,CYLINDER,DISK,SPHERE,TORUS,SPLINE,FONT,SCREEN_QUAD,MY_POINT};
00019
00021 enum VBOindices{P_VERTEX,P_NORMAL,P_TEXCOORD,P_INDEX};
00023 typedef float TVertex[3];
00025 typedef float TCoord[2];
00026
00028 struct VBO{
00030 GLuint buffer[4];
00032 GLuint vao;
00034 unsigned int indices;
00035 };
00036
00037
00043 class TObject
00044 {
00045 private:
00046 TVector pos,rot,scale;
00047 bool draw_object;
00048
00049
00050 bool shadow_cast;
00051 bool shadow_receive;
00052
00053
00054 TMaterial *mat;
00055
00056
00057 TMatrix transform;
00058 bool transformed;
00059
00060 int type;
00061 string name;
00062 VBO vbo;
00063 GLenum drawmode;
00064 bool element_indices;
00065
00066
00067 int instances;
00068
00069 public:
00071 GLuint cf_buffer;
00073 GLuint cr_buffer;
00075 GLuint render_cubemap;
00077 GLuint render_cubemap_depth;
00079 GLuint refl_size;
00080
00081
00082 TObject();
00083
00084 ~TObject();
00085
00086
00087 void Create(const char *name, int primitive, GLfloat size, GLfloat height, GLint sliceX, GLint sliceY);
00088
00089 VBO Create(const char *name, const char *file, bool load = true);
00090
00091 VBO Create(Lib3dsMesh *mesh);
00092
00093 void CreateInstance(const TObject &ref);
00096 void SetVBOdata(VBO data)
00097 { vbo = data; }
00099 void SetGInstances(int count)
00100 { if(count > 1) instances = count; }
00102 GLint GetVertexBuffer()
00103 { return vbo.buffer[0]; }
00104
00105
00106
00107 void Draw(TMatrix &viewMatrix, bool render_mat = true);
00108
00109 void DrawScreenQuad();
00111 void DrawObject(bool flag)
00112 { draw_object = flag; }
00113
00114
00116 void SetMaterial(TMaterial *m)
00117 { mat = m;}
00119 float GetReflect()
00120 { if(mat != NULL) return mat->GetReflect(); else return 0.0; }
00121
00123 bool HasMaterial()
00124 { return !(mat == NULL); }
00126 string GetMatName()
00127 { if(mat != NULL) return mat->GetName(); else return "<empty>"; }
00128
00129
00130 void Move(GLfloat wx, GLfloat wy, GLfloat wz);
00131 void MoveAbs(GLfloat wx, GLfloat wy, GLfloat wz);
00134 void MoveAbs(TVector w)
00135 { pos = w; }
00136
00137 void Rotate(GLfloat angle, GLint axis);
00138 void RotateAbs(GLfloat angle, GLint axis);
00139
00140 void Resize(GLfloat sx, GLfloat sy, GLfloat sz);
00141
00143 void CastShadow(bool flag = true)
00144 { shadow_cast = flag; }
00145
00147 string GetName()
00148 { return name; }
00150 TVector GetPosition()
00151 {return pos;}
00153 bool IsTransparent()
00154 { if(mat != NULL) return (mat->GetTrasparency() > 0.0); else return 0; }
00156 bool HasFramebuffer()
00157 { return (cf_buffer != 0 && cr_buffer != 0 && render_cubemap != 0); }
00158 };
00159 #endif