Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/md2_loader: fixed linker problem, there is no a MathHelp class, which contains the redundant mathematical functions to solve the normalization problems

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