Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/lib/graphics/importer/abstract_model.h @ 4159

Last change on this file since 4159 was 4159, checked in by patrick, 19 years ago

orxonox/branches/md2_loader: cleaned out the unuseable texture loader and fixed also some minor issues

File size: 5.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer:
14*/
15
16/*!
17    \file abstract_model.h
18    \brief Definition of an abstract model. containing all needed for other model
19*/
20
21#ifndef _ABSTRACT_MODEL_H
22#define _ABSTRACT_MODEL_H
23
24#include "stdincl.h"
25#include "base_object.h"
26#include <vector>
27#include <math.h>
28#include <SDL_image.h>
29
30using namespace std;
31
32//template<class T> class tList;
33;
34
35//! This is our 3D point class.  CONFLICTING with Vector.cc
36class CVector3
37{
38public:
39        float x, y, z;
40};
41
42//! This is our 2D point class.  CONFLICTING with Vector.cc
43class CVector2
44{
45public:
46        float x, y;
47};
48
49// CONFLICTING with model.h
50struct tFace
51{
52        int vertIndex[3];                       // indicies for the verts that make up this triangle
53        int coordIndex[3];                      // indicies for the tex coords to texture this face
54};
55
56// CONFLICTING with material.cc, there are some small differences, i will use this struct and switch over later
57struct tMaterialInfo
58{
59        char  strName[255];                     // The texture name
60        char  strFile[255];                     // The texture file name (If this is set it's a texture map)
61        byte  color[3]; // The color of the object (R, G, B)
62        int   texureId;                         // the texture ID
63        float uTile;                            // u tiling of texture 
64        float vTile;                            // v tiling of texture 
65        float uOffset;                      // u offset of texture
66        float vOffset;                          // v offset of texture
67} ;
68
69//! properties of a 3D object
70struct t3DObject
71{
72        int  numOfVerts;                        // The number of verts in the model
73        int  numOfFaces;                        // The number of faces in the model
74        int  numTexVertex;                      // The number of texture coordinates
75        int  materialID;                        // The texture ID to use, which is the index into our texture array
76        bool bHasTexture;                       // This is TRUE if there is a texture map for this object
77        char strName[255];                      // The name of the object
78        CVector3  *pVerts;                      // The object's vertices
79        CVector3  *pNormals;                    // The object's normals
80        CVector2  *pTexVerts;                   // The texture's UV coordinates
81        tFace *pFaces;                          // The faces information of the object
82};
83
84// CONFLICTING with animation.cc
85struct tAnimationInfo
86{
87        char strName[255];                      // This stores the name of the animation (Jump, Pain, etc..)
88        int startFrame;                         // This stores the first frame number for this animation
89        int endFrame;                           // This stores the last frame number for this animation
90};
91
92// CONFLICTING with animation.cc and vector.cc
93struct t3DModel
94{
95        int numOfObjects;                                       // The number of objects in the model
96        int numOfMaterials;                                     // The number of materials for the model
97        int numOfAnimations;                            // The number of animations in this model (NEW)
98        int currentAnim;                                        // The current index into pAnimations list (NEW)
99        int currentFrame;                                       // The current frame of the current animation (NEW)
100        vector<tAnimationInfo> animationList; // The list of animations (NEW)
101        vector<tMaterialInfo> materialList;     // The list of material information (Textures and colors)
102        vector<t3DObject> objectList;                   // The object list for our model
103};
104
105
106
107//! This class defines the basic components of a model
108class AbstractModel : public BaseObject {
109
110 public:
111  AbstractModel() {}
112  virtual ~AbstractModel() {}
113};
114
115
116/* TESTING TESTING TESTING */
117/* some mathematical functions that are already implemented by vector.cc class */
118
119// magnitude of a normal
120#define Mag(Normal) (sqrt(Normal.x*Normal.x + Normal.y*Normal.y + Normal.z*Normal.z))
121
122class MathHelp {
123
124 public:
125  // vector between two points
126  static CVector3 VectorDiff(CVector3 vPoint1, CVector3 vPoint2)
127    {
128      CVector3 vVector;                                                 
129
130      vVector.x = vPoint1.x - vPoint2.x;                       
131      vVector.y = vPoint1.y - vPoint2.y;                       
132      vVector.z = vPoint1.z - vPoint2.z;                       
133
134      return vVector;                                                           
135    }
136
137  // adding vectors, returning result
138  static CVector3 AddVector(CVector3 vVector1, CVector3 vVector2)
139    {
140      CVector3 vResult;                                                 
141       
142      vResult.x = vVector2.x + vVector1.x;             
143      vResult.y = vVector2.y + vVector1.y;             
144      vResult.z = vVector2.z + vVector1.z;             
145
146      return vResult;
147    }
148
149  // This divides a vector by a single number (scalar) and returns the result
150  static CVector3 DivideVectorByScaler(CVector3 vVector1, float Scaler)
151    {
152      CVector3 vResult;                                                 
153       
154      vResult.x = vVector1.x / Scaler;                 
155      vResult.y = vVector1.y / Scaler;         
156      vResult.z = vVector1.z / Scaler;
157
158      return vResult;   
159    }
160
161  // cross product between 2 vectors
162  static CVector3 CrossProduct(CVector3 vVector1, CVector3 vVector2)
163    {
164      CVector3 vCross; 
165      vCross.x = ((vVector1.y * vVector2.z) - (vVector1.z * vVector2.y));
166      vCross.y = ((vVector1.z * vVector2.x) - (vVector1.x * vVector2.z));
167      vCross.z = ((vVector1.x * vVector2.y) - (vVector1.y * vVector2.x));
168      return vCross;   
169    }
170
171  // calculate the normal of a vector
172  static CVector3 NormalizeVector(CVector3 vNormal)
173    {
174      double Magnitude;
175      Magnitude = Mag(vNormal); 
176      vNormal.x /= (float)Magnitude;   
177      vNormal.y /= (float)Magnitude;   
178      vNormal.z /= (float)Magnitude;   
179
180      return vNormal;   
181    }
182};
183
184
185#endif /* _ABSTRACT_MODEL_H */
Note: See TracBrowser for help on using the repository browser.