Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: stones visible as such, and not as cubes… i do not quite know whu this has changed in this release, but i think i am going to bed now…

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   \brief 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   \brief standard destructor
45*/
46WorldEntity::~WorldEntity ()
47{
48  // if( collisioncluster != NULL) delete collisioncluster;
49  if (this->model)
50    ResourceManager::getInstance()->unload(this->model);
51}
52
53void WorldEntity::loadParams(const TiXmlElement* root)
54{
55  static_cast<PNode*>(this)->loadParams(root);
56  // Model Loading
57  LoadParam<WorldEntity>(root, "model", this, &WorldEntity::loadModel)
58    .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") ;
59}
60
61/**
62   \brief loads a Model onto a WorldEntity
63   \param fileName the name of the model to load
64*/
65void WorldEntity::loadModel(const char* fileName)
66{
67  if (this->model)
68    ResourceManager::getInstance()->unload(this->model, RP_LEVEL);
69  if (fileName != NULL)
70  {
71    PRINTF(4)("loading %s\n", fileName);
72    this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN);
73  }
74  else
75    this->model = NULL;
76}
77
78/**
79   \brief sets the character attributes of a worldentity
80   \param character attributes
81
82   these attributes don't have to be set, only use them, if you need them
83*/
84void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
85{}
86
87
88/**
89   \brief gets the Character attributes of this worldentity
90   \returns character attributes
91*/
92CharacterAttributes* WorldEntity::getCharacterAttributes()
93{}
94
95
96/**
97   \brief set the WorldEntity's collision hull
98   \param newhull: a pointer to a completely assembled CollisionCluster
99
100   Any previously assigned collision hull will be deleted on reassignment
101*/
102/*
103void WorldEntity::setCollision (CollisionCluster* newhull)
104{
105  if( newhull == NULL) return;
106  if( collisioncluster != NULL) delete collisioncluster;
107  collisioncluster = newhull;
108}
109*/
110
111
112/**
113    \brief process draw function
114*/
115void WorldEntity::processDraw ()
116{
117
118}
119
120/**
121   \brief sets the drawable state of this entity.
122   \param bDraw TRUE if draweable, FALSE otherwise
123*/
124void WorldEntity::setDrawable (bool bDraw)
125{
126  this->bDraw = bDraw;
127}
128
129
130/**
131   \brief this function is called, when two entities collide
132   \param entity: the world entity with whom it collides
133
134   Implement behaviour like damage application or other miscellaneous collision stuff in this function
135*/
136void WorldEntity::collideWith(WorldEntity* entity)
137{
138  this->obbTree->collideWith(entity->obbTree, (PNode*)this, (PNode*)entity);
139}
140
141
142/**
143   \brief 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   \brief 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   \brief 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   \brief 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/**
186   \brief the entity is drawn onto the screen with this function
187
188   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.
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  float matrix[4][4];
215
216  /* translate */
217  glTranslatef (this->getAbsCoor ().x,
218                this->getAbsCoor ().y,
219                this->getAbsCoor ().z);
220  /* rotate */
221  this->getAbsDir ().matrix (matrix);
222  glMultMatrixf((float*)matrix);
223
224  if (this->obbTree)
225    this->obbTree->drawBV(depth, drawMode);
226  glPopMatrix();
227}
228
229/**
230   \brief this handles incoming command messages
231   \param cmd: a pointer to the incoming Command structure
232
233   Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
234   to send commands from one WorldEntity to another.
235*/
236void WorldEntity::command (Command* cmd)
237{
238}
Note: See TracBrowser for help on using the repository browser.