Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: now PNodes can be rendered in Debug-Mode

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