Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/height_map/src/lib/graphics/importer/vertex_array_model.cc @ 6249

Last change on this file since 6249 was 6249, checked in by bottac, 18 years ago

Uses VertexArrayModel now

File size: 4.5 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
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
17
18#include "vertex_array_model.h"
19
20#include "stdlibincl.h"
21#include <stdarg.h>
22
23using namespace std;
24
25/////////////
26/// MODEL ///
27/////////////
28/**
29 * @brief Creates a 3D-VertexArrayModel.
30 *
31 * assigns it a Name and a Type
32 */
33VertexArrayModel::VertexArrayModel()
34{
35  this->setClassID(CL_MODEL, "VertexArrayModel");
36
37  this->bFinalized = false;
38  this->newStripe();
39}
40
41
42/**
43 * @brief deletes an VertexArrayModel.
44 *
45 * Looks if any from model allocated space is still in use, and if so deleted it.
46 */
47VertexArrayModel::~VertexArrayModel()
48{
49  PRINTF(4)("Deleting VertexArrayModel ");
50  if (this->getName())
51  {
52    PRINT(4)("%s\n", this->getName());
53  }
54  else
55  {
56    PRINT(4)("\n");
57  }
58}
59
60
61/**
62 * @brief Draws the VertexArrayModels of all Groups.
63 *
64 * It does this by just calling the Lists that must have been created earlier.
65 */
66void VertexArrayModel::draw() const
67{
68  PRINTF(4)("drawing the 3D-VertexArrayModels\n");
69
70  glEnableClientState(GL_VERTEX_ARRAY |
71                      GL_TEXTURE_COORD_ARRAY |
72                      GL_NORMAL_ARRAY);
73  glEnableClientState(GL_INDEX_ARRAY);
74
75  glVertexPointer(3, GL_FLOAT, 0, this->vertices.getArray());
76  glNormalPointer(GL_FLOAT, 0, this->normals.getArray());
77  glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords.getArray()); 
78
79      glDrawElements(GL_TRIANGLE_STRIP, this->indices.getCount(), GL_UNSIGNED_BYTE, this->indices.getArray());
80/*  for (GLuint i = 1; i < this->stripes.size(); ++i)
81    {
82      glDrawRangeElements(GL_TRIANGLE_STRIP,
83                          this->stripes[i-1],
84                          this->stripes[i],
85                          this->indices.getCount(),
86                          GL_UNSIGNED_BYTE,
87                          this->indices.getArray());
88    }*/
89}
90
91
92//////////
93// MESH //
94//////////
95/**
96 * @brief generates a new Stripe in this Model
97 */
98void VertexArrayModel::newStripe()
99{
100  this->stripes.push_back(this->vertices.getCount()-1);
101}
102
103
104/**
105 * @brief parses a vertex-String
106 * @param x the X-coordinate of the Vertex to add.
107 * @param y the Y-coordinate of the Vertex to add.
108 * @param z the Z-coordinate of the Vertex to add.
109 */
110void VertexArrayModel::addVertex(float x, float y, float z)
111{
112  this->vertices.addEntry(x, y, z);
113  this->pModelInfo.numVertices++;
114}
115
116
117/**
118 * @brief adds a VertexNormal.
119 * @param x The x coordinate of the Normal.
120 * @param y The y coordinate of the Normal.
121 * @param z The z coordinate of the Normal.
122 *
123 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
124 */
125void VertexArrayModel::addNormal(float x, float y, float z)
126{
127  this->normals.addEntry(x, y, z);
128  this->pModelInfo.numNormals++;
129}
130
131
132/**
133 *  adds a Texture Coordinate
134 * @param u The u coordinate of the TextureCoordinate.
135 * @param v The y coordinate of the TextureCoordinate.
136 *
137 *  If a TextureCoordinate line is found this function will inject it into the TextureCoordinate-Array
138 */
139void VertexArrayModel::addTexCoor(float u, float v)
140{
141  this->texCoords.addEntry(u);
142  this->texCoords.addEntry(v);
143  this->pModelInfo.numTexCoor++;
144}
145
146
147/**
148 *  adds a new Face
149 * @param faceElemCount the number of Vertices to add to the Face.
150 * @param type The information Passed with each Vertex
151*/
152void VertexArrayModel::addIndice(GLubyte indice)
153{
154  this->indices.addEntry(indice);
155}
156
157
158/**
159 * @brief Finalizes an Object. This can be done outside of the Class.
160 */
161void VertexArrayModel::finalize()
162{
163  // finalize the Arrays
164  this->vertices.finalizeArray();
165  this->texCoords.finalizeArray();
166  this->normals.finalizeArray();
167  this->indices.finalizeArray();
168
169  this->newStripe();
170
171  /*
172    glEnableClientState(GL_VERTEX_ARRAY |
173    GL_TEXTURE_COORD_ARRAY |
174    GL_NORMAL_ARRAY);
175  */
176
177  this->bFinalized = true;
178}
179
180
181
182/////////////
183// TESTING //
184/////////////
185/**
186 * @brief Includes a default model
187 *
188 * This will inject a Cube, because this is the most basic model.
189 */
190void VertexArrayModel::planeModel()
191{
192  unsigned int i, j;
193  for (i = 0; i < 20; i++)
194    {
195      for (j = 0; j < 20; j++)
196        {
197          this->addVertex((float)i, .5, (float)(j));
198          this->addNormal(0, 1, 0);
199          this->addTexCoor((float)i/20.0, (float)j/20.0);
200
201        }
202    }
203  for (i = 0; i < 20; i++)
204    {
205      this->addIndice(i);
206      this->addIndice(i+20);
207    }
208}
Note: See TracBrowser for help on using the repository browser.