Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/levelLoader/src/world_entities/world_entity.cc @ 4233

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

orxonox/branches/levelLoader: loading through Functors.
This should make our lives much more simple, if they are implemented real good.
This will take some time, and i would like you to comment on this.

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