Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/mount_points/src/lib/graphics/importer/static_model.cc @ 10089

Last change on this file since 10089 was 10089, checked in by patrick, 17 years ago

working on mountpoint extraction

File size: 5.8 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: Benjamin Grauer
13   co-programmer: ...
14
15   2005-07-06: (Patrick) added new function buildTriangleList()
16*/
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
19
20#include "static_model.h"
21
22#include "debug.h"
23#include <stdarg.h>
24
25
26
27
28/////////////
29/// MODEL ///
30/////////////
31ObjectListDefinition(StaticModel);
32
33/**
34 * @brief Creates a 3D-Model.
35 *
36 * assigns it a Name and a Type
37 */
38StaticModel::StaticModel(const std::string& modelName)
39    : data(new StaticModelData(modelName))
40{
41  this->registerObject(this, StaticModel::_objectList);
42  PRINTF(4)("new 3D-Model is being created\n");
43  this->setName(modelName);
44}
45
46StaticModel::StaticModel(const StaticModel& staticModel)
47  : data(staticModel.data)
48{
49  this->registerObject(this, StaticModel::_objectList);
50  this->setName(staticModel.getName());
51  this->updateBase();
52}
53
54
55/**
56 * @brief deletes an Model.
57 *
58 * Looks if any from model allocated space is still in use, and if so deleted it.
59 */
60StaticModel::~StaticModel()
61{
62  PRINTF(4)("Deleting Model ");
63
64  // mark this stuff as beeing deleted
65  this->pModelInfo.pVertices = NULL;
66  this->pModelInfo.pNormals = NULL;
67  this->pModelInfo.pTexCoor = NULL;
68  this->pModelInfo.pTriangles = NULL;
69}
70
71StaticModel& StaticModel::operator=(const StaticModel& model)
72{
73  this->data = model.data;
74  this->updateBase();
75  return *this;
76};
77
78
79/**
80 * @brief Finalizes an Object. This can be done outside of the Class.
81 */
82void StaticModel::finalize()
83{
84  data->finalize();
85  this->updateBase();
86}
87
88void StaticModel::acquireData(const StaticModelData::Pointer& data)
89{
90  this->data = data;
91  this->updateBase();
92}
93
94
95
96/**
97 * extract the mount points from this file: looking at each group and checking if the group realy is a mountpoint marker
98 * if so get place and orientation
99 */
100void StaticModel::extractMountPoints()
101{
102
103  // go through all groups and check if they are mounts
104  const ModelGroup* groupPtr = this->data->getModelGroup();
105  for( ; groupPtr != NULL; groupPtr = groupPtr->next)
106  {
107    // get the name of this group and check if it's a mout point identifier
108    std::string groupName = groupPtr->name;
109    if( groupName.find("MP.", 0) != std::string::npos)
110    {}
111  }
112}
113
114
115
116/**
117 * @brief adds a new Face
118 * @param faceElemCount the number of Vertices to add to the Face.
119 * @param type The information Passed with each Vertex
120*/
121bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
122{
123  va_list itemlist;
124  va_start (itemlist, type);
125  bool retVal = this->data->addFace(faceElemCount, type, itemlist);
126  va_end(itemlist);
127  return retVal;
128}
129
130void StaticModel::updateBase()
131{
132  // write out the modelInfo data used for the collision detection!
133  this->pModelInfo.pVertices = &this->data->getVertices()[0];
134  this->pModelInfo.numVertices = this->data->getVertices().size();
135  this->pModelInfo.pNormals = &this->data->getNormals()[0];
136  this->pModelInfo.numNormals = this->data->getNormals().size();
137  this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0];
138  this->pModelInfo.numTexCoor = this->data->getTexCoords().size();
139
140  this->pModelInfo.pTriangles = this->data->getTrianglesExt();
141  this->pModelInfo.numTriangles = this->data->getTriangles().size();
142}
143
144
145/**
146 *  Includes a default model
147 *
148 * This will inject a Cube, because this is the most basic model.
149 */
150void StaticModel::cubeModel()
151{
152  this->addVertex (-0.5, -0.5, 0.5);
153  this->addVertex (0.5, -0.5, 0.5);
154  this->addVertex (-0.5, 0.5, 0.5);
155  this->addVertex (0.5, 0.5, 0.5);
156  this->addVertex (-0.5, 0.5, -0.5);
157  this->addVertex (0.5, 0.5, -0.5);
158  this->addVertex (-0.5, -0.5, -0.5);
159  this->addVertex (0.5, -0.5, -0.5);
160
161  this->addVertexTexture (0.0, 0.0);
162  this->addVertexTexture (1.0, 0.0);
163  this->addVertexTexture (0.0, 1.0);
164  this->addVertexTexture (1.0, 1.0);
165  this->addVertexTexture (0.0, 2.0);
166  this->addVertexTexture (1.0, 2.0);
167  this->addVertexTexture (0.0, 3.0);
168  this->addVertexTexture (1.0, 3.0);
169  this->addVertexTexture (0.0, 4.0);
170  this->addVertexTexture (1.0, 4.0);
171  this->addVertexTexture (2.0, 0.0);
172  this->addVertexTexture (2.0, 1.0);
173  this->addVertexTexture (-1.0, 0.0);
174  this->addVertexTexture (-1.0, 1.0);
175
176  this->addVertexNormal (0.0, 0.0, 1.0);
177  this->addVertexNormal (0.0, 0.0, 1.0);
178  this->addVertexNormal (0.0, 0.0, 1.0);
179  this->addVertexNormal (0.0, 0.0, 1.0);
180  this->addVertexNormal (0.0, 1.0, 0.0);
181  this->addVertexNormal (0.0, 1.0, 0.0);
182  this->addVertexNormal (0.0, 1.0, 0.0);
183  this->addVertexNormal (0.0, 1.0, 0.0);
184  this->addVertexNormal (0.0, 0.0, -1.0);
185  this->addVertexNormal (0.0, 0.0, -1.0);
186  this->addVertexNormal (0.0, 0.0, -1.0);
187  this->addVertexNormal (0.0, 0.0, -1.0);
188  this->addVertexNormal (0.0, -1.0, 0.0);
189  this->addVertexNormal (0.0, -1.0, 0.0);
190  this->addVertexNormal (0.0, -1.0, 0.0);
191  this->addVertexNormal (0.0, -1.0, 0.0);
192  this->addVertexNormal (1.0, 0.0, 0.0);
193  this->addVertexNormal (1.0, 0.0, 0.0);
194  this->addVertexNormal (1.0, 0.0, 0.0);
195  this->addVertexNormal (1.0, 0.0, 0.0);
196  this->addVertexNormal (-1.0, 0.0, 0.0);
197  this->addVertexNormal (-1.0, 0.0, 0.0);
198  this->addVertexNormal (-1.0, 0.0, 0.0);
199  this->addVertexNormal (-1.0, 0.0, 0.0);
200
201  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,1, 3,3,2, 2,2,3);
202  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,4, 3,3,5, 5,5,6, 4,4,7);
203  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,4,8, 5,5,9, 7,7,10, 6,6,11);
204  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,6,12, 7,7,13, 1,9,14, 0,8,15);
205  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,16, 7,10,17, 5,11,18, 3,3,19);
206  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,12,20, 0,0,21, 2,2,22, 4,13,23);
207}
Note: See TracBrowser for help on using the repository browser.