Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/spectator.cc @ 9932

Last change on this file since 9932 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 5.2 KB
RevLine 
[8067]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Christoph Renner
13   co-programmer: ...
14
15*/
16
17#include "spectator.h"
18
19#include "src/lib/util/loading/factory.h"
20#include "key_mapper.h"
21
[8708]22#include "shared_network_data.h"
[8067]23
[9869]24#include "class_id_DEPRECATED.h"
25ObjectListDefinitionID(Spectator, CL_SPECTATOR);
26CREATE_FACTORY(Spectator);
[8067]27
28
29/**
[8228]30 *  destructs the Spectator, deletes alocated memory
[8067]31 */
[8228]32Spectator::~Spectator ()
[8067]33{
[8228]34  this->setPlayer(NULL);
35}
36
37
38/**
39 *  creates a new Spectator from Xml Data
40 * @param root the xml element containing Spectator data
41
42   @todo add more parameters to load
43 */
44Spectator::Spectator(const TiXmlElement* root)
45{
46  this->init();
47  if (root != NULL)
48    this->loadParams(root);
49
50}
51
52
53/**
54 * initializes a Spectator
55 */
56void Spectator::init()
57{
58//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
[9869]59  this->registerObject(this, Spectator::_objectList);
[8067]60
[8228]61  this->getWeaponManager().changeWeaponConfig(1);
62
[8067]63  this->bLeft = false;
64  this->bRight = false;
65  this->bForward = false;
66  this->bBackward = false;
67  this->xMouse = 0.0f;
68  this->yMouse = 0.0f;
[8228]69
70  this->setHealthMax(100);
71  this->setHealth(80);
72
73  this->mouseDir = this->getAbsDir();
74
75  //add events to the eventlist
[8067]76  registerEvent(KeyMapper::PEV_FORWARD);
77  registerEvent(KeyMapper::PEV_BACKWARD);
78  registerEvent(KeyMapper::PEV_LEFT);
79  registerEvent(KeyMapper::PEV_RIGHT);
80  registerEvent(KeyMapper::PEV_FIRE1);
81  registerEvent(EV_MOUSE_MOTION);
[8228]82
83  this->getWeaponManager().setSlotCount(0);
84
85  this->getWeaponManager().getFixedTarget()->setParent(this);
86  this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0);
87
88  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
89
[9869]90
[8067]91  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
92  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
93  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
94  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
95  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) );
96}
97
[8228]98
[8067]99/**
[8228]100 * loads the Settings of a Spectator from an XML-element.
101 * @param root the XML-element to load the Spaceship's properties from
[8067]102 */
[8228]103void Spectator::loadParams(const TiXmlElement* root)
[8067]104{
[8228]105  Playable::loadParams(root);
[8067]106}
107
[8228]108void Spectator::setPlayDirection(const Quaternion& quat, float speed)
[8067]109{
[8228]110  this->mouseDir = quat;
111  this->angleY = quat.getHeading();
112  this->angleX = quat.getAttitude();
[8067]113}
114
[8228]115
116void Spectator::reset()
[8067]117{
[8228]118  this->bLeft = false;
119  this->bRight = false;
120  this->bForward = false;
121  this->bBackward = false;
122  this->xMouse = 0.0f;
123  this->yMouse = 0.0f;
124
125  this->setHealth(80);
126}
127
128
129void Spectator::enter()
130{
131  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false );
[8067]132  this->attachCamera();
133}
134
[8228]135void Spectator::leave()
[8067]136{
[8228]137  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
[8067]138  this->detachCamera();
139}
140
[8228]141
[8067]142/**
[8228]143 *  this function is called, when two entities collide
144 * @param entity: the world entity with whom it collides
145 *
146 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
147 * @todo dont let Spectator fly through walls
[8067]148 */
[8228]149void Spectator::collidesWith(WorldEntity* entity, const Vector& location)
[8067]150{
151}
152
[8228]153
154
155/**
156 *  the function called for each passing timeSnap
157 * @param time The timespan passed since last update
158 */
159void Spectator::tick (float time)
[8067]160{
161  Playable::tick( time );
[9869]162
[8708]163  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == SharedNetworkData::getInstance()->getHostID() )
[8067]164  {
165    xMouse *= time / 10;
166    yMouse *= time / 10;
[9869]167
[8147]168    angleX -= xMouse;
169    angleY -= yMouse;
[9869]170
[8147]171    if ( angleY > 2.05 )
172      angleY = 2.05;
[9869]173
[8147]174    if ( angleY < -1.15 )
175      angleY = -1.15;
[9869]176
[8147]177    this->mouseDir = Quaternion( angleX, Vector( 0, 1, 0 ) ) * Quaternion( angleY, Vector( 0, 0, 1 ) );
[9869]178
[8067]179    xMouse = yMouse = 0;
180  }
[9869]181
[8067]182  this->setAbsDir( this->mouseDir );
[9869]183
[8147]184  Vector velocity;
[9869]185
[8147]186  if ( this->bForward )
187  {
188    velocity += this->getAbsDirX();
189  }
[9869]190
[8147]191  if ( this->bBackward )
192  {
193    velocity -= this->getAbsDirX();
194  }
[9869]195
[8147]196  if ( this->bRight )
197  {
198    velocity += this->getAbsDirZ();
199  }
[9869]200
[8147]201  if ( this->bLeft )
202  {
203    velocity -= this->getAbsDirZ();
204  }
[9869]205
[8147]206  velocity *= 100;
[9869]207
[8147]208  this->shiftCoor( velocity*time );
[8067]209}
210
[8228]211/**
212 * @todo switch statement ??
213 */
214void Spectator::process(const Event &event)
[8067]215{
216  Playable::process(event);
217
218  if( event.type == KeyMapper::PEV_LEFT)
219    this->bLeft = event.bPressed;
220  else if( event.type == KeyMapper::PEV_RIGHT)
221    this->bRight = event.bPressed;
222  else if( event.type == KeyMapper::PEV_FORWARD)
223    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
224  else if( event.type == KeyMapper::PEV_BACKWARD)
225    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
226  else if( event.type == EV_MOUSE_MOTION)
227  {
228    this->xMouse += event.xRel;
229    this->yMouse += event.yRel;
230  }
231}
[8228]232
233
234
235
Note: See TracBrowser for help on using the repository browser.