Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/heathaze/src/lib/graphics/importer/static_model.cc @ 10772

Last change on this file since 10772 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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: 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 * @brief adds a new Face
96 * @param faceElemCount the number of Vertices to add to the Face.
97 * @param type The information Passed with each Vertex
98*/
99bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
100{
101  va_list itemlist;
102  va_start (itemlist, type);
103  bool retVal = this->data->addFace(faceElemCount, type, itemlist);
104  va_end(itemlist);
105  return retVal;
106}
107
108void StaticModel::updateBase()
109{
110  // write out the modelInfo data used for the collision detection!
111  this->pModelInfo.pVertices = &this->data->getVertices()[0];
112  this->pModelInfo.numVertices = this->data->getVertices().size();
113  this->pModelInfo.pNormals = &this->data->getNormals()[0];
114  this->pModelInfo.numNormals = this->data->getNormals().size();
115  this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0];
116  this->pModelInfo.numTexCoor = this->data->getTexCoords().size();
117
118  this->pModelInfo.pTriangles = this->data->getTrianglesExt();
119  this->pModelInfo.numTriangles = this->data->getTriangles().size();
120}
121
122
123/**
124 *  Includes a default model
125 *
126 * This will inject a Cube, because this is the most basic model.
127 */
128void StaticModel::cubeModel()
129{
130  this->addVertex (-0.5, -0.5, 0.5);
131  this->addVertex (0.5, -0.5, 0.5);
132  this->addVertex (-0.5, 0.5, 0.5);
133  this->addVertex (0.5, 0.5, 0.5);
134  this->addVertex (-0.5, 0.5, -0.5);
135  this->addVertex (0.5, 0.5, -0.5);
136  this->addVertex (-0.5, -0.5, -0.5);
137  this->addVertex (0.5, -0.5, -0.5);
138
139  this->addVertexTexture (0.0, 0.0);
140  this->addVertexTexture (1.0, 0.0);
141  this->addVertexTexture (0.0, 1.0);
142  this->addVertexTexture (1.0, 1.0);
143  this->addVertexTexture (0.0, 2.0);
144  this->addVertexTexture (1.0, 2.0);
145  this->addVertexTexture (0.0, 3.0);
146  this->addVertexTexture (1.0, 3.0);
147  this->addVertexTexture (0.0, 4.0);
148  this->addVertexTexture (1.0, 4.0);
149  this->addVertexTexture (2.0, 0.0);
150  this->addVertexTexture (2.0, 1.0);
151  this->addVertexTexture (-1.0, 0.0);
152  this->addVertexTexture (-1.0, 1.0);
153
154  this->addVertexNormal (0.0, 0.0, 1.0);
155  this->addVertexNormal (0.0, 0.0, 1.0);
156  this->addVertexNormal (0.0, 0.0, 1.0);
157  this->addVertexNormal (0.0, 0.0, 1.0);
158  this->addVertexNormal (0.0, 1.0, 0.0);
159  this->addVertexNormal (0.0, 1.0, 0.0);
160  this->addVertexNormal (0.0, 1.0, 0.0);
161  this->addVertexNormal (0.0, 1.0, 0.0);
162  this->addVertexNormal (0.0, 0.0, -1.0);
163  this->addVertexNormal (0.0, 0.0, -1.0);
164  this->addVertexNormal (0.0, 0.0, -1.0);
165  this->addVertexNormal (0.0, 0.0, -1.0);
166  this->addVertexNormal (0.0, -1.0, 0.0);
167  this->addVertexNormal (0.0, -1.0, 0.0);
168  this->addVertexNormal (0.0, -1.0, 0.0);
169  this->addVertexNormal (0.0, -1.0, 0.0);
170  this->addVertexNormal (1.0, 0.0, 0.0);
171  this->addVertexNormal (1.0, 0.0, 0.0);
172  this->addVertexNormal (1.0, 0.0, 0.0);
173  this->addVertexNormal (1.0, 0.0, 0.0);
174  this->addVertexNormal (-1.0, 0.0, 0.0);
175  this->addVertexNormal (-1.0, 0.0, 0.0);
176  this->addVertexNormal (-1.0, 0.0, 0.0);
177  this->addVertexNormal (-1.0, 0.0, 0.0);
178
179  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,1, 3,3,2, 2,2,3);
180  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,4, 3,3,5, 5,5,6, 4,4,7);
181  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,4,8, 5,5,9, 7,7,10, 6,6,11);
182  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,6,12, 7,7,13, 1,9,14, 0,8,15);
183  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,16, 7,10,17, 5,11,18, 3,3,19);
184  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,12,20, 0,0,21, 2,2,22, 4,13,23);
185}
Note: See TracBrowser for help on using the repository browser.