Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: minor cleanup/windowsTest

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