Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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#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->bDraw = 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*/
67void WorldEntity::loadModel(const char* fileName)
68{
69  if (this->model)
70    ResourceManager::getInstance()->unload(this->model, RP_LEVEL);
71  if (fileName != NULL)
72  {
73    PRINTF(4)("loading %s\n", fileName);
74    this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN);
75  }
76  else
77    this->model = NULL;
78}
79
80/**
81 *  sets the character attributes of a worldentity
82 * @param character attributes
83
84   these attributes don't have to be set, only use them, if you need them
85*/
86void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
87{}
88
89
90/**
91 *  gets the Character attributes of this worldentity
92 * @returns character attributes
93*/
94CharacterAttributes* WorldEntity::getCharacterAttributes()
95{}
96
97
98/**
99 *  set the WorldEntity's collision hull
100 * @param newhull: a pointer to a completely assembled CollisionCluster
101
102   Any previously assigned collision hull will be deleted on reassignment
103*/
104/*
105void WorldEntity::setCollision (CollisionCluster* newhull)
106{
107  if( newhull == NULL) return;
108  if( collisioncluster != NULL) delete collisioncluster;
109  collisioncluster = newhull;
110}
111*/
112
113
114/**
115  *  process draw function
116*/
117void WorldEntity::processDraw ()
118{
119
120}
121
122/**
123 *  sets the drawable state of this entity.
124 * @param bDraw TRUE if draweable, FALSE otherwise
125*/
126void WorldEntity::setDrawable (bool bDraw)
127{
128  this->bDraw = bDraw;
129}
130
131
132/**
133 *  this function is called, when two entities collide
134 * @param entity: the world entity with whom it collides
135
136   Implement behaviour like damage application or other miscellaneous collision stuff in this function
137*/
138void WorldEntity::collideWith(WorldEntity* entity)
139{
140  this->obbTree->collideWith(entity->obbTree, (PNode*)this, (PNode*)entity);
141}
142
143
144/**
145 *  this function is called, when the ship is hit by a waepon
146 * @param weapon: the laser/rocket/shoot that hits.
147 * @param loc: place where it is hit
148
149   calculate the damage depending
150*/
151void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {}
152
153
154/**
155 *  this is called immediately after the Entity has been constructed and initialized
156
157   Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
158   DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
159*/
160void WorldEntity::postSpawn ()
161{
162}
163
164
165/**
166 *  this method is called by the world if the WorldEntity leaves valid gamespace
167
168   For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
169   place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
170*/
171void WorldEntity::leftWorld ()
172{
173}
174
175
176/**
177 *  this method is called every frame
178 * @param time: the time in seconds that has passed since the last tick
179
180   Handle all stuff that should update with time inside this method (movement, animation, etc.)
181*/
182void WorldEntity::tick(float time)
183{
184}
185
186
187/**
188 *  the entity is drawn onto the screen with this function
189
190   This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn.
191*/
192void WorldEntity::draw()
193{
194  glMatrixMode(GL_MODELVIEW);
195  glPushMatrix();
196  float matrix[4][4];
197
198  /* translate */
199  glTranslatef (this->getAbsCoor ().x,
200                this->getAbsCoor ().y,
201                this->getAbsCoor ().z);
202  /* rotate */
203  this->getAbsDir ().matrix (matrix);
204  glMultMatrixf((float*)matrix);
205
206  if (this->model)
207    this->model->draw();
208  glPopMatrix();
209}
210
211
212void WorldEntity::drawBVTree(int depth, int drawMode)
213{
214  glMatrixMode(GL_MODELVIEW);
215  glPushMatrix();
216  float matrix[4][4];
217
218  /* translate */
219  glTranslatef (this->getAbsCoor ().x,
220                this->getAbsCoor ().y,
221                this->getAbsCoor ().z);
222  /* rotate */
223  this->getAbsDir ().matrix (matrix);
224  glMultMatrixf((float*)matrix);
225
226  if (this->obbTree)
227    this->obbTree->drawBV(depth, drawMode);
228  glPopMatrix();
229}
230
231/**
232 *  this handles incoming command messages
233 * @param cmd: a pointer to the incoming Command structure
234
235   Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
236   to send commands from one WorldEntity to another.
237*/
238void WorldEntity::command (Command* cmd)
239{
240}
Note: See TracBrowser for help on using the repository browser.