Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/levelLoader: factory not in stdincl anymore

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