Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: remove unused stuff

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