Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/importer/static_model.cc @ 9830

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

orxonox/new_class_id: Static Model splitted up into Data and Logic part

File size: 4.7 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
46/**
47 * @brief deletes an Model.
48 *
49 * Looks if any from model allocated space is still in use, and if so deleted it.
50 */
51StaticModel::~StaticModel()
52{
53  PRINTF(4)("Deleting Model ");
54
55  // mark this stuff as beeing deleted
56  this->pModelInfo.pVertices = NULL;
57  this->pModelInfo.pNormals = NULL;
58  this->pModelInfo.pTexCoor = NULL;
59  this->pModelInfo.pTriangles = NULL;
60}
61
62/**
63 * @brief Finalizes an Object. This can be done outside of the Class.
64 */
65void StaticModel::finalize()
66{
67  data->finalize();
68
69  // write out the modelInfo data used for the collision detection!
70  this->pModelInfo.pVertices = &this->data->getVertices()[0];
71  this->pModelInfo.numVertices = this->data->getVertices().size();
72  this->pModelInfo.pNormals = &this->data->getNormals()[0];
73  this->pModelInfo.numNormals = this->data->getNormals().size();
74  this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0];
75  this->pModelInfo.numTexCoor = this->data->getTexCoords().size();
76
77  this->pModelInfo.pTriangles = this->data->getTrianglesExt();
78  this->pModelInfo.numTriangles = this->data->getTriangles().size();
79}
80
81/**
82 * @brief adds a new Face
83 * @param faceElemCount the number of Vertices to add to the Face.
84 * @param type The information Passed with each Vertex
85*/
86bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
87{
88  va_list itemlist;
89  va_start (itemlist, type);
90  bool retVal = this->data->addFace(faceElemCount, type, itemlist);
91  va_end(itemlist);
92  return retVal;
93}
94
95/**
96 *  Includes a default model
97 *
98 * This will inject a Cube, because this is the most basic model.
99 */
100void StaticModel::cubeModel()
101{
102  this->addVertex (-0.5, -0.5, 0.5);
103  this->addVertex (0.5, -0.5, 0.5);
104  this->addVertex (-0.5, 0.5, 0.5);
105  this->addVertex (0.5, 0.5, 0.5);
106  this->addVertex (-0.5, 0.5, -0.5);
107  this->addVertex (0.5, 0.5, -0.5);
108  this->addVertex (-0.5, -0.5, -0.5);
109  this->addVertex (0.5, -0.5, -0.5);
110
111  this->addVertexTexture (0.0, 0.0);
112  this->addVertexTexture (1.0, 0.0);
113  this->addVertexTexture (0.0, 1.0);
114  this->addVertexTexture (1.0, 1.0);
115  this->addVertexTexture (0.0, 2.0);
116  this->addVertexTexture (1.0, 2.0);
117  this->addVertexTexture (0.0, 3.0);
118  this->addVertexTexture (1.0, 3.0);
119  this->addVertexTexture (0.0, 4.0);
120  this->addVertexTexture (1.0, 4.0);
121  this->addVertexTexture (2.0, 0.0);
122  this->addVertexTexture (2.0, 1.0);
123  this->addVertexTexture (-1.0, 0.0);
124  this->addVertexTexture (-1.0, 1.0);
125
126  this->addVertexNormal (0.0, 0.0, 1.0);
127  this->addVertexNormal (0.0, 0.0, 1.0);
128  this->addVertexNormal (0.0, 0.0, 1.0);
129  this->addVertexNormal (0.0, 0.0, 1.0);
130  this->addVertexNormal (0.0, 1.0, 0.0);
131  this->addVertexNormal (0.0, 1.0, 0.0);
132  this->addVertexNormal (0.0, 1.0, 0.0);
133  this->addVertexNormal (0.0, 1.0, 0.0);
134  this->addVertexNormal (0.0, 0.0, -1.0);
135  this->addVertexNormal (0.0, 0.0, -1.0);
136  this->addVertexNormal (0.0, 0.0, -1.0);
137  this->addVertexNormal (0.0, 0.0, -1.0);
138  this->addVertexNormal (0.0, -1.0, 0.0);
139  this->addVertexNormal (0.0, -1.0, 0.0);
140  this->addVertexNormal (0.0, -1.0, 0.0);
141  this->addVertexNormal (0.0, -1.0, 0.0);
142  this->addVertexNormal (1.0, 0.0, 0.0);
143  this->addVertexNormal (1.0, 0.0, 0.0);
144  this->addVertexNormal (1.0, 0.0, 0.0);
145  this->addVertexNormal (1.0, 0.0, 0.0);
146  this->addVertexNormal (-1.0, 0.0, 0.0);
147  this->addVertexNormal (-1.0, 0.0, 0.0);
148  this->addVertexNormal (-1.0, 0.0, 0.0);
149  this->addVertexNormal (-1.0, 0.0, 0.0);
150
151  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,1, 3,3,2, 2,2,3);
152  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,4, 3,3,5, 5,5,6, 4,4,7);
153  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,4,8, 5,5,9, 7,7,10, 6,6,11);
154  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,6,12, 7,7,13, 1,9,14, 0,8,15);
155  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,16, 7,10,17, 5,11,18, 3,3,19);
156  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,12,20, 0,0,21, 2,2,22, 4,13,23);
157}
Note: See TracBrowser for help on using the repository browser.