Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

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