Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: objectName is now a property of BaseObject, because pNode has nothing to do with a name

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