Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/static_model.cc @ 9869

Last change on this file since 9869 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
RevLine 
[4577]1/*
[2823]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: ...
[4793]14
15   2005-07-06: (Patrick) added new function buildTriangleList()
[2823]16*/
17
[3590]18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
19
[6021]20#include "static_model.h"
[3427]21
[8362]22#include "debug.h"
[3418]23#include <stdarg.h>
[3398]24
[2776]25
[4022]26
[9406]27
[4022]28/////////////
29/// MODEL ///
30/////////////
[9869]31ObjectListDefinition(StaticModel);
32
[2842]33/**
[6031]34 * @brief Creates a 3D-Model.
35 *
36 * assigns it a Name and a Type
37 */
[7221]38StaticModel::StaticModel(const std::string& modelName)
[9869]39    : data(new StaticModelData(modelName))
[3398]40{
[9869]41  this->registerObject(this, StaticModel::_objectList);
[4577]42  PRINTF(4)("new 3D-Model is being created\n");
[3398]43  this->setName(modelName);
[9869]44}
[3909]45
[9869]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}
[6031]53
[4577]54
[3398]55/**
[6031]56 * @brief deletes an Model.
57 *
58 * Looks if any from model allocated space is still in use, and if so deleted it.
59 */
[6021]60StaticModel::~StaticModel()
[2847]61{
[3548]62  PRINTF(4)("Deleting Model ");
[3396]63
[7732]64  // mark this stuff as beeing deleted
65  this->pModelInfo.pVertices = NULL;
66  this->pModelInfo.pNormals = NULL;
67  this->pModelInfo.pTexCoor = NULL;
[9869]68  this->pModelInfo.pTriangles = NULL;
[2847]69}
70
[9869]71StaticModel& StaticModel::operator=(const StaticModel& model)
[3398]72{
[9869]73  this->data = model.data;
74  this->updateBase();
75  return *this;
76};
[3916]77
[3398]78
[5790]79/**
[9869]80 * @brief Finalizes an Object. This can be done outside of the Class.
[5790]81 */
[9869]82void StaticModel::finalize()
[5790]83{
[9869]84  data->finalize();
85  this->updateBase();
[5790]86}
87
[9869]88void StaticModel::acquireData(const StaticModelData::Pointer& data)
[2748]89{
[9869]90  this->data = data;
91  this->updateBase();
[2748]92}
[2754]93
[2842]94/**
[6031]95 * @brief adds a new Face
[4836]96 * @param faceElemCount the number of Vertices to add to the Face.
97 * @param type The information Passed with each Vertex
[3400]98*/
[6021]99bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
[3400]100{
[3418]101  va_list itemlist;
102  va_start (itemlist, type);
[9869]103  bool retVal = this->data->addFace(faceElemCount, type, itemlist);
[3418]104  va_end(itemlist);
[9869]105  return retVal;
[3400]106}
107
[9869]108void StaticModel::updateBase()
[3063]109{
[9869]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();
[4577]117
[9869]118  this->pModelInfo.pTriangles = this->data->getTrianglesExt();
119  this->pModelInfo.numTriangles = this->data->getTriangles().size();
[3801]120}
121
[4577]122
[3066]123/**
[9869]124 *  Includes a default model
[6031]125 *
[9869]126 * This will inject a Cube, because this is the most basic model.
[6031]127 */
[6021]128void StaticModel::cubeModel()
[2821]129{
[3656]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);
[2967]138
[3656]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);
[3081]153
[3656]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);
[2821]178
[4112]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);
[2821]185}
Note: See TracBrowser for help on using the repository browser.