Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/world_entity.cc @ 5352

Last change on this file since 5352 was 5302, checked in by bensch, 19 years ago

orxonox/trunk: fixed bug in SkyShphere, doubly deleted Model

File size: 5.9 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer: Christian Meyer
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19#include "world_entity.h"
20#include "shell_command.h"
21
22#include "resource_manager.h"
23#include "load_param.h"
24#include "list.h"
25#include "vector.h"
26#include "obb_tree.h"
27
28using namespace std;
29
30SHELL_COMMAND(model, WorldEntity, loadModel)
31    ->describe("sets the Model of the WorldEntity")
32    ->defaultValues(1, "models/ships/reaplow.obj");
33
34
35/**
36 *  Loads the WordEntity-specific Part of any derived Class
37*/
38WorldEntity::WorldEntity(const TiXmlElement* root)
39{
40  this->setClassID(CL_WORLD_ENTITY, "WorldEntity");
41
42  this->model = NULL;
43  this->obbTree = NULL;
44
45  if (root)
46    this->loadParams(root);
47
48  this->setVisibiliy(true);
49}
50
51/**
52 *  standard destructor
53*/
54WorldEntity::~WorldEntity ()
55{
56  // if( collisioncluster != NULL) delete collisioncluster;
57  if (likely(this->model != NULL))
58    ResourceManager::getInstance()->unload(this->model);
59  if( this->obbTree != NULL)
60    delete this->obbTree;
61}
62
63void WorldEntity::loadParams(const TiXmlElement* root)
64{
65  static_cast<PNode*>(this)->loadParams(root);
66  // Model Loading
67  LoadParam<WorldEntity>(root, "model", this, &WorldEntity::loadModel)
68    .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") ;
69}
70
71/**
72 * loads a Model onto a WorldEntity
73 * @param fileName the name of the model to load
74 * @param scaling the Scaling of the model
75*/
76void WorldEntity::loadModelWithScale(const char* fileName, float scaling)
77{
78  if (this->model)
79    ResourceManager::getInstance()->unload(this->model, RP_LEVEL);
80  if (fileName != NULL)
81  {
82    PRINTF(4)("fetching %s\n", fileName);
83    if (scaling == 1.0)
84      this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN);
85    else
86      this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, &scaling);
87
88    this->buildObbTree(4);
89  }
90  else
91    this->model = NULL;
92}
93
94/**
95 * builds the obb-tree
96 * @param depth the depth to calculate
97 */
98bool WorldEntity::buildObbTree(unsigned int depth)
99{
100//   if (this->obbTree)
101//     delete this->obbTree;
102//
103//   if (this->model)
104//   {
105//     PRINTF(4)("creating obb tree\n");
106//     this->obbTree = new OBBTree(depth, (sVec3D*)this->model->getVertexArray(), this->model->getVertexCount());
107//     return true;
108//   }
109//   else
110//   {
111//     PRINTF(2)("could not create obb-tree, because no model was loaded yet\n");
112//     this->obbTree = NULL;
113//     return false;
114//  }
115}
116
117
118/**
119 * sets the character attributes of a worldentity
120 * @param character attributes
121 *
122 * these attributes don't have to be set, only use them, if you need them
123*/
124void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
125{}
126
127
128/**
129 * gets the Character attributes of this worldentity
130 * @returns character attributes
131*/
132CharacterAttributes* WorldEntity::getCharacterAttributes()
133{}
134
135
136/**
137 *  this function is called, when two entities collide
138 * @param entity: the world entity with whom it collides
139 *
140 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
141 */
142void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location)
143{
144//  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
145}
146
147/**
148 *  this function is called, when the ship is hit by a waepon
149 * @param weapon: the laser/rocket/shoot that hits.
150 * @param loc: place where it is hit
151 *
152 * calculate the damage depending
153*/
154void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {}
155
156
157/**
158 *  this is called immediately after the Entity has been constructed and initialized
159 *
160 * Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
161 * DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
162*/
163void WorldEntity::postSpawn ()
164{
165}
166
167
168/**
169 *  this method is called by the world if the WorldEntity leaves valid gamespace
170 *
171 * For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
172 * place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
173*/
174void WorldEntity::leftWorld ()
175{
176}
177
178
179/**
180 *  this method is called every frame
181 * @param time: the time in seconds that has passed since the last tick
182 *
183 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
184*/
185void WorldEntity::tick(float time)
186{
187}
188
189/**
190 *  the entity is drawn onto the screen with this function
191 *
192 * This is a central function of an entity: call it to let the entity painted to the screen.
193 * Just override this function with whatever you want to be drawn.
194*/
195void WorldEntity::draw()
196{
197  glMatrixMode(GL_MODELVIEW);
198  glPushMatrix();
199  float matrix[4][4];
200
201  /* translate */
202  glTranslatef (this->getAbsCoor ().x,
203                this->getAbsCoor ().y,
204                this->getAbsCoor ().z);
205  /* rotate */
206  this->getAbsDir ().matrix (matrix);
207  glMultMatrixf((float*)matrix);
208
209  if (this->model)
210    this->model->draw();
211  glPopMatrix();
212}
213
214
215void WorldEntity::drawBVTree(int depth, int drawMode)
216{
217  glMatrixMode(GL_MODELVIEW);
218  glPushMatrix();
219  /* translate */
220  glTranslatef (this->getAbsCoor ().x,
221                this->getAbsCoor ().y,
222                this->getAbsCoor ().z);
223  /* rotate */
224  Vector tmpRot = this->getAbsDir().getSpacialAxis();
225  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
226
227  if (this->obbTree)
228    this->obbTree->drawBV(depth, drawMode);
229  glPopMatrix();
230}
Note: See TracBrowser for help on using the repository browser.