Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: fixed the Bug, that crashed the second level

File size: 6.3 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 "model.h"
22#include "list.h"
23#include "vector.h"
24
25//#include "stdincl.h"
26//#include "collision.h"
27
28using namespace std;
29
30/**
31   \brief standard constructor
32   
33   Every derived contructor HAS to call the previous one supplying the isFree parameter. This is necessary to distunguish
34   between free and bound entities. The difference between them is simply the fact that the movement of a free entity is
35   not bound to the track of a world. Use this to implement projectile or effect classes that do not have to travel along the track.
36   To specify an entity to be free or bound set the default parameter in the declaration of the constructor.
37   Theoretically you should never have to call the constructor of an Entity directly, for it is called by the spawn() function of the World
38   class. So if you want to create a new entity at any time, call World::spawn(). It will handle everything that is necessary.
39*/
40WorldEntity::WorldEntity ()
41{
42  this->setClassName ("WorldEntity");
43  this->bDraw = true;
44  this->model = NULL;
45  //  collisioncluster = NULL;
46}
47
48WorldEntity::WorldEntity(TiXmlElement* root)
49{
50  // Name Setup
51  char* temp;
52  const char* string;
53  string = grabParameter( root, "name");
54  if( string == NULL)
55    {
56      PRINTF(0)("WorldEntity is missing a proper 'name'\n");
57      string = "Unknown";
58      temp = new char[strlen(string + 2)];
59      strcpy( temp, string);
60      this->setName( temp);
61    }
62  else
63    {
64      temp = new char[strlen(string + 2)];
65      strcpy( temp, string);
66      this->setName( temp);
67    }
68  // Model Loading     
69  this->model = NULL;
70  string = grabParameter( root, "model");
71  if( string != NULL)
72    this->model = (Model*)ResourceManager::getInstance()->load(string, OBJ, RP_CAMPAIGN);
73  else
74    {
75      PRINTF(0)("WorldEntity is missing a proper 'model'\n");
76      this->model = NULL;
77    }
78  if( this->model == NULL)
79    {
80      PRINTF(0)("WorldEntity model '%s' could not be loaded\n", string);
81    }
82
83  this->bDraw = true;
84}
85
86/**
87   \brief standard destructor
88*/
89WorldEntity::~WorldEntity ()
90{
91  // if( collisioncluster != NULL) delete collisioncluster;
92  if (this->model)
93    ResourceManager::getInstance()->unload(this->model);
94}
95
96/**
97   \brief sets the character attributes of a worldentity
98   \param character attributes
99
100   these attributes don't have to be set, only use them, if you need them
101*/
102void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
103{}
104
105
106/**
107   \brief gets the Character attributes of this worldentity
108   \returns character attributes
109*/
110CharacterAttributes* WorldEntity::getCharacterAttributes()
111{}
112
113
114/**
115   \brief set the WorldEntity's collision hull
116   \param newhull: a pointer to a completely assembled CollisionCluster
117   
118   Any previously assigned collision hull will be deleted on reassignment
119*/
120/*
121void WorldEntity::setCollision (CollisionCluster* newhull)
122{
123  if( newhull == NULL) return;
124  if( collisioncluster != NULL) delete collisioncluster;
125  collisioncluster = newhull;
126}
127*/
128
129
130/**
131    \brief process draw function
132*/
133void WorldEntity::processDraw ()
134{
135
136}
137
138/**
139   \brief sets the drawable state of this entity.
140   \param bDraw TRUE if draweable, FALSE otherwise
141*/
142void WorldEntity::setDrawable (bool bDraw)
143{
144  this->bDraw = bDraw;
145}
146
147
148/**
149   \brief this function is called, when two entities collide
150   \param other: the world entity with whom it collides
151   \param ownhitflags: flags to the CollisionCluster subsections that registered an impact
152   \param otherhitflags: flags to the CollisionCluster subsections of the other entity that registered an impact
153
154   Implement behaviour like damage application or other miscellaneous collision stuff in this function
155*/
156void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {}
157
158
159/**
160   \brief this function is called, when the ship is hit by a waepon
161   \param weapon: the laser/rocket/shoot that hits.
162   \param loc: place where it is hit
163
164   calculate the damage depending
165*/
166void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {}
167
168
169/**
170   \brief this is called immediately after the Entity has been constructed and initialized
171   
172   Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
173   DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
174*/
175void WorldEntity::postSpawn ()
176{
177}
178
179
180/**
181   \brief this method is called by the world if the WorldEntity leaves valid gamespace
182   
183   For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
184   place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
185*/
186void WorldEntity::leftWorld ()
187{
188}
189
190
191/**
192   \brief this method is called every frame
193   \param time: the time in seconds that has passed since the last tick
194   
195   Handle all stuff that should update with time inside this method (movement, animation, etc.)
196*/
197void WorldEntity::tick(float time) 
198{
199}
200
201
202/**
203   \brief the entity is drawn onto the screen with this function
204   
205   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.
206*/
207void WorldEntity::draw() 
208{
209  glMatrixMode(GL_MODELVIEW);
210  glPushMatrix();
211  float matrix[4][4];
212 
213  /* translate */
214  glTranslatef (this->getAbsCoor ().x, 
215                this->getAbsCoor ().y, 
216                this->getAbsCoor ().z);
217  /* rotate */
218  this->getAbsDir ().matrix (matrix);
219  glMultMatrixf((float*)matrix);
220
221  if (this->model)
222    this->model->draw();
223  glPopMatrix();
224}
225
226
227/**
228   \brief this handles incoming command messages
229   \param cmd: a pointer to the incoming Command structure
230   
231   Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
232   to send commands from one WorldEntity to another.
233*/
234void WorldEntity::command (Command* cmd)
235{
236}
Note: See TracBrowser for help on using the repository browser.