Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: minor cleanup

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