Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/md2_loader: altered some vector functions and wiped out most of the compiler errors. still remaining one link error.

File size: 5.0 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
121// vector between two points
122CVector3 VectorDiff(CVector3 vPoint1, CVector3 vPoint2)
123{
124        CVector3 vVector;                                                       
125
126        vVector.x = vPoint1.x - vPoint2.x;                     
127        vVector.y = vPoint1.y - vPoint2.y;                     
128        vVector.z = vPoint1.z - vPoint2.z;                     
129
130        return vVector;                                                         
131}
132
133// adding vectors, returning result
134CVector3 AddVector(CVector3 vVector1, CVector3 vVector2)
135{
136        CVector3 vResult;                                                       
137       
138        vResult.x = vVector2.x + vVector1.x;           
139        vResult.y = vVector2.y + vVector1.y;           
140        vResult.z = vVector2.z + vVector1.z;           
141
142        return vResult;
143}
144
145// This divides a vector by a single number (scalar) and returns the result
146CVector3 DivideVectorByScaler(CVector3 vVector1, float Scaler)
147{
148        CVector3 vResult;                                                       
149       
150        vResult.x = vVector1.x / Scaler;                       
151        vResult.y = vVector1.y / Scaler;               
152        vResult.z = vVector1.z / Scaler;
153
154        return vResult; 
155}
156
157// cross product between 2 vectors
158CVector3 CrossProduct(CVector3 vVector1, CVector3 vVector2)
159{
160        CVector3 vCross;       
161        vCross.x = ((vVector1.y * vVector2.z) - (vVector1.z * vVector2.y));
162        vCross.y = ((vVector1.z * vVector2.x) - (vVector1.x * vVector2.z));
163        vCross.z = ((vVector1.x * vVector2.y) - (vVector1.y * vVector2.x));
164        return vCross; 
165}
166
167// calculate the normal of a vector
168CVector3 NormalizeVector(CVector3 vNormal)
169{
170        double Magnitude;
171        Magnitude = Mag(vNormal);       
172        vNormal.x /= (float)Magnitude; 
173        vNormal.y /= (float)Magnitude; 
174        vNormal.z /= (float)Magnitude; 
175
176        return vNormal; 
177}
178
179
180#endif /* _ABSTRACT_MODEL_H */
Note: See TracBrowser for help on using the repository browser.