Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: model scaleable

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 "list.h"
22#include "vector.h"
23#include "obb_tree.h"
24
25using namespace std;
26
27/**
28 *  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  this->obbTree = NULL;
36
37  if (root)
38    this->loadParams(root);
39
40  this->setVisibiliy(true);
41}
42
43/**
44 *  standard destructor
45*/
46WorldEntity::~WorldEntity ()
47{
48  // if( collisioncluster != NULL) delete collisioncluster;
49  if (this->model)
50    ResourceManager::getInstance()->unload(this->model);
51  if( this->obbTree)
52    delete this->obbTree;
53}
54
55void WorldEntity::loadParams(const TiXmlElement* root)
56{
57  static_cast<PNode*>(this)->loadParams(root);
58  // Model Loading
59  LoadParam<WorldEntity>(root, "model", this, &WorldEntity::loadModel)
60    .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") ;
61}
62
63/**
64 * loads a Model onto a WorldEntity
65 * @param fileName the name of the model to load
66 * @param scaling the Scaling of the model
67*/
68void WorldEntity::loadModelWithScale(const char* fileName, float scaling)
69{
70  if (this->model)
71    ResourceManager::getInstance()->unload(this->model, RP_LEVEL);
72  if (fileName != NULL)
73  {
74    PRINTF(4)("loading %s\n", fileName);
75    if (scaling == 1.0)
76      this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN);
77    else
78      this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, &scaling);
79
80    PRINTF(4)("creating obb tree\n");
81    this->obbTree = new OBBTree(4, (sVec3D*)this->model->getVertexArray(), this->model->getVertexCount());
82  }
83  else
84    this->model = NULL;
85}
86
87
88
89/**
90 * sets the character attributes of a worldentity
91 * @param character attributes
92 *
93 * these attributes don't have to be set, only use them, if you need them
94*/
95void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
96{}
97
98
99/**
100 * gets the Character attributes of this worldentity
101 * @returns character attributes
102*/
103CharacterAttributes* WorldEntity::getCharacterAttributes()
104{}
105
106
107/**
108 *  this function is called, when two entities collide
109 * @param entity: the world entity with whom it collides
110 *
111 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
112 */
113void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location)
114{
115  PRINTF(0)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
116}
117
118/**
119 *  this function is called, when the ship is hit by a waepon
120 * @param weapon: the laser/rocket/shoot that hits.
121 * @param loc: place where it is hit
122 *
123 * calculate the damage depending
124*/
125void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {}
126
127
128/**
129 *  this is called immediately after the Entity has been constructed and initialized
130 *
131 * Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
132 * DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
133*/
134void WorldEntity::postSpawn ()
135{
136}
137
138
139/**
140 *  this method is called by the world if the WorldEntity leaves valid gamespace
141 *
142 * For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
143 * place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
144*/
145void WorldEntity::leftWorld ()
146{
147}
148
149
150/**
151 *  this method is called every frame
152 * @param time: the time in seconds that has passed since the last tick
153 *
154 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
155*/
156void WorldEntity::tick(float time)
157{
158}
159
160/**
161 *  the entity is drawn onto the screen with this function
162 *
163 * This is a central function of an entity: call it to let the entity painted to the screen.
164 * Just override this function with whatever you want to be drawn.
165*/
166void WorldEntity::draw()
167{
168  glMatrixMode(GL_MODELVIEW);
169  glPushMatrix();
170  float matrix[4][4];
171
172  /* translate */
173  glTranslatef (this->getAbsCoor ().x,
174                this->getAbsCoor ().y,
175                this->getAbsCoor ().z);
176  /* rotate */
177  this->getAbsDir ().matrix (matrix);
178  glMultMatrixf((float*)matrix);
179
180  if (this->model)
181    this->model->draw();
182  glPopMatrix();
183}
184
185
186void WorldEntity::drawBVTree(int depth, int drawMode)
187{
188  glMatrixMode(GL_MODELVIEW);
189  glPushMatrix();
190  /* translate */
191  glTranslatef (this->getAbsCoor ().x,
192                this->getAbsCoor ().y,
193                this->getAbsCoor ().z);
194  /* rotate */
195  Vector tmpRot = this->getAbsDir().getSpacialAxis();
196  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
197
198  if (this->obbTree)
199    this->obbTree->drawBV(depth, drawMode);
200  glPopMatrix();
201}
Note: See TracBrowser for help on using the repository browser.