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
RevLine 
[2036]1
2
[4570]3/*
[2036]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
[2190]15   co-programmer: Christian Meyer
[2036]16*/
17
18#include <iostream>
19
20#include "world_entity.h"
[3803]21#include "model.h"
[3608]22#include "list.h"
[3803]23#include "vector.h"
[3608]24
[2036]25using namespace std;
26
[2043]27/**
[4261]28   \brief Loads the WordEntity-specific Part of any derived Class
[2043]29*/
[4261]30WorldEntity::WorldEntity(const TiXmlElement* root)
[2190]31{
[4320]32  this->setClassID(CL_WORLD_ENTITY, "WorldEntity");
[4597]33
[4261]34  this->model = NULL;
35
36  if (root)
37    this->loadParams(root);
38
[2822]39  this->bDraw = true;
[2190]40}
[2043]41
42/**
[3245]43   \brief standard destructor
[2043]44*/
[2190]45WorldEntity::~WorldEntity ()
[2036]46{
[3474]47  // if( collisioncluster != NULL) delete collisioncluster;
[3672]48  if (this->model)
49    ResourceManager::getInstance()->unload(this->model);
[3531]50}
51
[4436]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
[3531]60/**
[4261]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/**
[3583]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
[2043]76*/
[3583]77void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
78{}
[2036]79
[3583]80
[2043]81/**
[3583]82   \brief gets the Character attributes of this worldentity
83   \returns character attributes
[2043]84*/
[3583]85CharacterAttributes* WorldEntity::getCharacterAttributes()
86{}
87
88
[2043]89/**
[2822]90   \brief set the WorldEntity's collision hull
91   \param newhull: a pointer to a completely assembled CollisionCluster
[4570]92
[2822]93   Any previously assigned collision hull will be deleted on reassignment
[2043]94*/
[3474]95/*
[3229]96void WorldEntity::setCollision (CollisionCluster* newhull)
[2036]97{
[2822]98  if( newhull == NULL) return;
99  if( collisioncluster != NULL) delete collisioncluster;
100  collisioncluster = newhull;
[2036]101}
[3474]102*/
[2036]103
104
[4570]105/**
106    \brief process draw function
[3365]107*/
108void WorldEntity::processDraw ()
109{
[3832]110
[3365]111}
112
[3449]113/**
114   \brief sets the drawable state of this entity.
115   \param bDraw TRUE if draweable, FALSE otherwise
116*/
[3365]117void WorldEntity::setDrawable (bool bDraw)
118{
119  this->bDraw = bDraw;
120}
121
122
[2043]123/**
[2822]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
[2043]128
[2822]129   Implement behaviour like damage application or other miscellaneous collision stuff in this function
[2043]130*/
[2190]131void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {}
[2036]132
[3583]133
[2043]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
[2036]138
[2043]139   calculate the damage depending
140*/
[3578]141void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {}
[2043]142
143
144/**
[2822]145   \brief this is called immediately after the Entity has been constructed and initialized
[4570]146
[2822]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.
[2043]149*/
[3229]150void WorldEntity::postSpawn ()
[2190]151{
152}
[2043]153
[3583]154
[2043]155/**
[3583]156   \brief this method is called by the world if the WorldEntity leaves valid gamespace
[4570]157
[3583]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).
[2190]160*/
[3583]161void WorldEntity::leftWorld ()
[2190]162{
163}
[2043]164
[3583]165
[2190]166/**
[3583]167   \brief this method is called every frame
168   \param time: the time in seconds that has passed since the last tick
[4570]169
[3583]170   Handle all stuff that should update with time inside this method (movement, animation, etc.)
[2043]171*/
[4570]172void WorldEntity::tick(float time)
[2190]173{
174}
[3583]175
176
177/**
178   \brief the entity is drawn onto the screen with this function
[4570]179
[3583]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.
[3365]181*/
[4570]182void WorldEntity::draw()
[3803]183{
184  glMatrixMode(GL_MODELVIEW);
185  glPushMatrix();
186  float matrix[4][4];
[4570]187
[3803]188  /* translate */
[4570]189  glTranslatef (this->getAbsCoor ().x,
190                this->getAbsCoor ().y,
191                this->getAbsCoor ().z);
[3803]192  /* rotate */
193  this->getAbsDir ().matrix (matrix);
194  glMultMatrixf((float*)matrix);
[2043]195
[3803]196  if (this->model)
197    this->model->draw();
198  glPopMatrix();
199}
[3583]200
[3803]201
[2043]202/**
[3583]203   \brief this handles incoming command messages
204   \param cmd: a pointer to the incoming Command structure
[4570]205
[3583]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.
[2043]208*/
[3583]209void WorldEntity::command (Command* cmd)
[2190]210{
211}
Note: See TracBrowser for help on using the repository browser.