Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Changed up to revision 0.3.1_alpha
ChangeLog

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