00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_GEOMETRY_STRUCTURES_H__
00009 #define __SP_GEOMETRY_STRUCTURES_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spMath.hpp"
00014 #include "Base/spMaterialColor.hpp"
00015
00016
00017 namespace sp
00018 {
00019 namespace scene
00020 {
00021
00022
00023
00024
00025
00026
00027 class SceneNode;
00028 class Mesh;
00029 class Terrain;
00030 class Collision;
00031
00032
00033
00034
00035
00036
00037 static const f32 DEF_PERSPECTIVE_FOV = 74.0f;
00038 static const s32 DEF_MESH_SEGMENTS = 10;
00039 static const s32 DEF_MESH_TESSELLATION = 8;
00040 static const s32 DEF_GEOMIP_LEVELS = 5;
00041 static const s32 DEF_SCENE_FLAGS = ~0;
00042
00043
00044
00045
00046
00047
00049 enum ENodeOrderTypes
00050 {
00051 ORDER_FOREGROUND = -1,
00052 ORDER_NORMAL = 0,
00053 ORDER_BACKGROUND = 1,
00054 };
00055
00057 enum ELightModels
00058 {
00059 LIGHT_DIRECTIONAL = 0,
00060 LIGHT_POINT,
00061 LIGHT_SPOT,
00062 };
00063
00065 enum EBasicMeshes
00066 {
00067
00068 MESH_CUBE,
00069 MESH_CONE,
00070 MESH_CYLINDER,
00071 MESH_SPHERE,
00072 MESH_ICOSPHERE,
00073 MESH_TORUS,
00074 MESH_TORUSKNOT,
00075 MESH_SPIRAL,
00076 MESH_PIPE,
00077 MESH_PLANE,
00078 MESH_DISK,
00079 MESH_CUBOCTAHEDRON,
00080 MESH_TETRAHEDRON,
00081 MESH_OCTAHEDRON,
00082 MESH_DODECAHEDRON,
00083 MESH_ICOSAHEDRON,
00084 MESH_TEAPOT,
00085
00086
00087 MESH_WIRE_CUBE,
00088 };
00089
00091 enum EMeshFileFormats
00092 {
00093 MESHFORMAT_UNKNOWN,
00094
00095
00096 MESHFORMAT_SPM,
00097 MESHFORMAT_3DS,
00098 MESHFORMAT_MS3D,
00099 MESHFORMAT_X,
00100 MESHFORMAT_B3D,
00101 MESHFORMAT_MD2,
00102 MESHFORMAT_MD3,
00103 MESHFORMAT_OBJ,
00104
00105
00106 MESHFORMAT_OGRE,
00107 MESHFORMAT_LWO,
00108 };
00109
00111 enum ESceneFileFormats
00112 {
00113 SCENEFORMAT_UNKNOWN,
00114
00115
00116 SCENEFORMAT_SPSB,
00117 SCENEFORMAT_BSP1,
00118 SCENEFORMAT_BSP3,
00119 };
00120
00122 enum ESuperShapeModels
00123 {
00124 SUPERSHAPE_SMALL_CRYSTAL1 = 0,
00125 SUPERSHAPE_SMALL_CRYSTAL2,
00126
00127 SUPERSHAPE_SMALL_STAR1,
00128 SUPERSHAPE_SMALL_STAR2,
00129 SUPERSHAPE_SMALL_STAR3,
00130 SUPERSHAPE_SMALL_STAR4,
00131
00132 SUPERSHAPE_BIG_STAR1,
00133
00134 SUPERSHAPE_URCHIN1,
00135
00136 SUPERSHAPE_CUSHION1,
00137
00138 SUPERSHAPE_RANDOM
00139 };
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00151 class SPrimitiveVertex2D
00152 {
00153
00154 public:
00155
00156 SPrimitiveVertex2D() : d3dColor(0xFFFFFFFF), oglColor(255)
00157 {
00158 }
00159 SPrimitiveVertex2D(f32 X, f32 Y, f32 U, f32 V, const video::color &Clr = 255, const f32 RHW = 1.0f)
00160 #ifndef __DRAW2DXYZ__
00161 : d3dPosition(X, Y, 0.0f, RHW), d3dColor(Clr.getSingle()), TexCoord(U, V),
00162 #else
00163 : d3dPosition(X, Y, 0.0f), d3dColor(Clr.getSingle()), TexCoord(U, V),
00164 #endif
00165 oglPosition(X / RHW, Y / RHW, 0.0f, 1.0f / RHW), oglColor(Clr)
00166 {
00167 }
00168 ~SPrimitiveVertex2D()
00169 {
00170 }
00171
00172
00173
00174 inline void setPosition(const dim::vector4df &VertexPosition)
00175 {
00176 d3dPosition = VertexPosition;
00177 #ifndef __DRAW2DXYZ__
00178 oglPosition.W = 1.0f / VertexPosition.W;
00179 #endif
00180 oglPosition.X = VertexPosition.X * oglPosition.W;
00181 oglPosition.Y = VertexPosition.Y * oglPosition.W;
00182 oglPosition.Z = VertexPosition.Z * oglPosition.W;
00183 }
00184 inline void setPosition(const dim::point2di &VertexPosition)
00185 {
00186 #ifndef __DRAW2DXYZ__
00187 setPosition(dim::vector4df(
00188 static_cast<f32>(VertexPosition.X), static_cast<f32>(VertexPosition.Y), 0.0f
00189 ));
00190 #else
00191 setPosition(dim::vector3df(
00192 static_cast<f32>(VertexPosition.X), static_cast<f32>(VertexPosition.Y), 0.0f
00193 ));
00194 #endif
00195 }
00196 inline dim::vector4df getPosition() const
00197 {
00198 return d3dPosition;
00199 }
00200
00201 inline void setColor(const video::color &VertexColor)
00202 {
00203 oglColor = VertexColor;
00204 d3dColor = VertexColor.getSingle();
00205 }
00206 inline video::color getColor() const
00207 {
00208 return oglColor;
00209 }
00210
00211 inline void setTexCoord(const dim::point2df &VertexTexCoord)
00212 {
00213 TexCoord = VertexTexCoord;
00214 }
00215 inline dim::point2df getTexCoord() const
00216 {
00217 return TexCoord;
00218 }
00219
00220 private:
00221
00222
00223
00225 #ifndef __DRAW2DXYZ__
00226 dim::vector4df d3dPosition;
00227 #else
00228 dim::vector3df d3dPosition;
00229 #endif
00230
00232 u32 d3dColor;
00233
00235 dim::point2df TexCoord;
00236
00238 dim::vector4df oglPosition;
00239
00241 video::color oglColor;
00242
00243 };
00244
00245
00246
00247
00249 class SMeshVertex3D
00250 {
00251
00252 public:
00253
00254 SMeshVertex3D()
00255 : Normal(0.f, 0.f, 1.f), Fog(0.f)
00256 {
00257 setColor(0xFFFFFFFF);
00258 }
00259 SMeshVertex3D(f32 X, f32 Y, f32 Z, const video::color &Clr)
00260 : Position(X, Y, Z), Normal(0.f, 0.f, 1.f), Fog(0.f)
00261 {
00262 setColor(Clr);
00263 }
00264 SMeshVertex3D(f32 X, f32 Y, f32 Z, u32 Clr, f32 U = 0.0f, f32 V = 0.0f)
00265 : Position(X, Y, Z), Normal(0.f, 0.f, 1.f), Fog(0.f)
00266 {
00267 setColor(Clr);
00268 for (s32 i = 0; i < MAX_COUNT_OF_TEXTURES; ++i)
00269 TexCoord[i] = dim::vector3df(U, V, 0.f);
00270 }
00271
00272
00273
00274 inline void setPosition(const dim::vector3df &VertexPosition)
00275 {
00276 Position = VertexPosition;
00277 }
00278 inline dim::vector3df getPosition() const
00279 {
00280 return Position;
00281 }
00282 inline dim::vector3df& getPosition()
00283 {
00284 return Position;
00285 }
00286
00287 inline void setNormal(const dim::vector3df &VertexNormal)
00288 {
00289 Normal = VertexNormal;
00290 }
00291 inline dim::vector3df getNormal() const
00292 {
00293 return Normal;
00294 }
00295 inline dim::vector3df& getNormal()
00296 {
00297 return Normal;
00298 }
00299
00300 inline void setTexCoord(u8 Layer, const dim::vector3df &VertexTexCoord)
00301 {
00302 TexCoord[Layer] = VertexTexCoord;
00303 }
00304 inline dim::vector3df getTexCoord(u8 Layer) const
00305 {
00306 return TexCoord[Layer];
00307 }
00308 inline dim::vector3df& getTexCoord(u8 Layer)
00309 {
00310 return TexCoord[Layer];
00311 }
00312
00313 inline void setColor(const video::color &VertexColor)
00314 {
00315 oglColor = VertexColor;
00316 d3d9Color = VertexColor.getSingle();
00317 }
00318 inline void setColor(const dim::vector4df &VertexColor)
00319 {
00320 oglColor = video::color(
00321 (u8)(VertexColor.X * 255), (u8)(VertexColor.Y * 255), (u8)(VertexColor.Z * 255), (u8)(VertexColor.W * 255)
00322 );
00323 d3d9Color = oglColor.getSingle();
00324 }
00325 inline void setColor(const u32 VertexColor)
00326 {
00327 const video::color Clr(
00328 video::getRed(VertexColor), video::getGreen(VertexColor), video::getBlue(VertexColor), video::getAlpha(VertexColor)
00329 );
00330
00331 oglColor = Clr;
00332 d3d9Color = VertexColor;
00333 }
00334 inline video::color getColor() const
00335 {
00336 return oglColor;
00337 }
00338 inline video::color& getColor()
00339 {
00340 return oglColor;
00341 }
00342
00343 inline void setFog(f32 VertexFog)
00344 {
00345 Fog = VertexFog;
00346 }
00347 inline f32 getFog() const
00348 {
00349 return Fog;
00350 }
00351 inline f32& getFog()
00352 {
00353 return Fog;
00354 }
00355
00356 inline void setTangent(const dim::vector3df &VertexTangent)
00357 {
00358 Tangent = VertexTangent;
00359 }
00360 inline dim::vector3df getTangent() const
00361 {
00362 return Tangent;
00363 }
00364 inline dim::vector3df& getTangent()
00365 {
00366 return Tangent;
00367 }
00368
00369 inline void setBinormal(const dim::vector3df &VertexBinormal)
00370 {
00371 Binormal = VertexBinormal;
00372 }
00373 inline dim::vector3df getBinormal() const
00374 {
00375 return Binormal;
00376 }
00377 inline dim::vector3df& getBinormal()
00378 {
00379 return Binormal;
00380 }
00381
00382 private:
00383
00384
00385
00387 dim::vector3df Position;
00388
00390 dim::vector3df Normal;
00391
00393 u32 d3d9Color;
00394
00396 dim::vector3df TexCoord[MAX_COUNT_OF_TEXTURES];
00397
00399 video::color oglColor;
00400
00402 f32 Fog;
00403
00405 dim::vector3df Tangent;
00406
00408 dim::vector3df Binormal;
00409
00410 };
00411
00412
00413
00414
00416 struct SMeshTriangle3D
00417 {
00418 SMeshTriangle3D()
00419 : a(0), b(0), c(0)
00420 {
00421 }
00422 SMeshTriangle3D(u32 IndexA, u32 IndexB, u32 IndexC, u32 ExCounter = 0)
00423 : a(IndexA + ExCounter), b(IndexB + ExCounter), c(IndexC + ExCounter)
00424 {
00425 }
00426 ~SMeshTriangle3D()
00427 {
00428 }
00429
00430
00431 void flip()
00432 {
00433 math::Swap(a, c);
00434 }
00435
00436 u32& operator [] (const s32 i)
00437 {
00438 return *(&a + i);
00439 }
00440 const u32 operator [] (const s32 i) const
00441 {
00442 return i < 3 ? *(&a + i) : 0;
00443 }
00444
00446 u32 a, b, c;
00447 };
00448
00449
00450 }
00451
00452 }
00453
00454
00455 #endif
00456
00457
00458
00459