00001
00002 #define _3DS_FLG_TENSION 0x01
00003 #define _3DS_FLG_CONTINUITY 0x02
00004 #define _3DS_FLG_BIAS 0x04
00005 #define _3DS_FLG_EASE_TO 0x08
00006 #define _3DS_FLG_EASE_FROM 0x10
00007
00008 class GLTexture : public SystemCode {
00009 public:
00010
00011 int x, y;
00012 BOOL alpha;
00013 PTR img;
00014 uint32 refcnt;
00015 int mipmapcnt;
00016 PTR mipmaps[8];
00017
00018
00019 GLTexture();
00020 ~GLTexture();
00021 BOOL Load(char *, BOOL genmm = TRUE);
00022 BOOL Load(File *f, BOOL genmm = TRUE);
00023 void GenerateMipMaps();
00024 void FreeMipMaps();
00025 void AddAlpha(uint8 value=0);
00026 void SetAlpha(uint32 keyclr, uint8 value_true, uint8 value_false);
00027 void SetAlpha();
00028 void operator =(Bitmap &);
00029 };
00030
00031
00032
00033 struct GLPos {
00034 float x, y, z;
00035 };
00036
00037 struct GLRotate {
00038 float angle, x, y, z;
00039 };
00040
00041 struct GLScale {
00042 float x, y, z;
00043 };
00044
00045 struct GLVertex {
00046 float x,y,z;
00047 float tx,ty;
00048 };
00049
00050 struct GLPoly {
00051 Array<uint32> vl;
00052 uint32 tex;
00053 };
00054
00055 struct GLLightType {
00056 float ambient[4];
00057 float diffuse[4];
00058 float specular[4];
00059 float pos4;
00060 };
00061
00062 struct GLLight {
00063 GLObjectGroup *owner;
00064 float pos[4];
00065
00066 };
00067
00068 class GLObject : public SystemCode {
00069 friend class GLScene;
00070 private:
00071 Array<GLVertex> vl;
00072 Array<GLPoly> pl;
00073 uint32 texidx;
00074
00075 Array<GLPos> pos;
00076 Array<GLRotate> rot;
00077 Array<GLScale> scale;
00078 BOOL b_rotate, b_translate, b_scale;
00079 int i_light;
00080 public:
00081 GLObject();
00082 int32 FrameIndex;
00083 float angle, rx, ry, rz;
00084 float tx, ty, tz;
00085 float sx, sy, sz;
00086
00087 void SetRotate(float _angle, float x, float y, float z) {
00088 angle = _angle; rx = x; ry = y; rz = z;
00089 }
00090 void SetTranslate(float x, float y, float z) {
00091 tx = x; ty = y; tz = z;
00092 }
00093 void SetScale(float x, float y, float z) {
00094 sx = x; sy = y; sz = z;
00095 }
00096 BOOL SetFrame(uint32 idx);
00097 BOOL NextFrame();
00098 int32 FrameCount();
00099 void AddVertex(int cnt, float *xyz);
00100 void AddPoly(int cnt, uint16 *pts);
00101 };
00102
00103 class GLObjectGroup : public SystemCode {
00104 friend class GLScene;
00105 private:
00106 float m[16];
00107 public:
00108 GLObjectGroup();
00109 List<GLObject *> ol;
00110
00111 void Rotate(float angle, float x, float y, float z);
00112 void Translate(float x, float y, float z);
00113 void Scale(float x, float y, float z);
00114 BOOL NextFrame();
00115 BOOL SetFrame(int);
00116 };
00117
00118 class GLScene : public SystemCode {
00119 private:
00120 List<GLObjectGroup *> ogl;
00121 Array<GLLightType> ltl;
00122 Array<GLLight> ll;
00123 Array<GLTexture *> tl;
00124 int iwx, iwy;
00125 float fwx, fwy;
00126 float ratio;
00127 float m_camera[16];
00128 int AddLight(GLObject *, GLObjectGroup *);
00129 void DeleteLights(GLObjectGroup *og);
00130 public:
00131 GLScene();
00132 String TexturePath;
00133 void Init(int x, int y);
00134 void SetCamera(float angle, float rx, float ry, float rz, float tx, float ty, float tz);
00135 void CameraRotate(float angle, float rx, float ry, float rz);
00136 void CameraTranslate(float x, float y, float z);
00137
00138 void Render();
00139 void AddObject(GLObject *);
00140
00141 BOOL Load3DS(File *);
00142 BOOL Load3DS(char *);
00143 BOOL LoadAllTextures();
00144 BOOL LoadTexture(uint32 texidx);
00145 void FreeTexture(uint32 texidx);
00146 void FreeUnusedTextures();
00147 int ObjectCount() {
00148 return ogl.Count;
00149 }
00150 BOOL NextFrame(int objidx) {
00151 return ogl[objidx]->NextFrame();
00152 }
00153 BOOL SetFrame(int objidx, int frame) {
00154 return ogl[objidx]->SetFrame(frame);
00155 }
00156 void ObjectFree(GLObjectGroup *);
00157 void ObjectFree(int idx);
00158 void ObjectTranslate(int idx, float x, float y, float z) {ogl[idx]->Translate(x,y,z);}
00159 void ObjectRotate(int idx, float angle, float x, float y, float z) {
00160 ogl[idx]->Rotate(angle,x,y,z);
00161 }
00162 void ObjectScale(int idx, float x, float y, float z) {ogl[idx]->Scale(x,y,z);}
00163 void LightSetupAmbient(int idx, float r, float g, float b, float a);
00164 void LightSetupDiffuse(int idx, float r, float g, float b, float a);
00165 void LightSetupSpecular(int idx, float r, float g, float b, float a);
00166 void LightSetupPositionw(int idx, float w);
00167
00168 GLObjectGroup *AddLight(int idx, float x, float y, float z);
00169 };
00170
00171