Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: VERY simplistic Banking of the Player

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