Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10613 was 10401, checked in by snellen, 18 years ago

last checkin

File size: 6.1 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
[10114]24#include "src/world_entities/creatures/fps_player.h"
25#include "src/world_entities/npcs/generic_npc.h"
26
27
28ObjectListDefinition(Spectator);
[9869]29CREATE_FACTORY(Spectator);
[8067]30
31
[10108]32
33#include "state.h"
34
35
[8067]36/**
[8228]37 *  destructs the Spectator, deletes alocated memory
[8067]38 */
[8228]39Spectator::~Spectator ()
[8067]40{
[8228]41  this->setPlayer(NULL);
42}
43
44
45/**
46 *  creates a new Spectator from Xml Data
47 * @param root the xml element containing Spectator data
48
49   @todo add more parameters to load
50 */
51Spectator::Spectator(const TiXmlElement* root)
52{
53  this->init();
54  if (root != NULL)
55    this->loadParams(root);
56
57}
58
59
60/**
61 * initializes a Spectator
62 */
63void Spectator::init()
64{
65//  this->setRelDir(Quaternion(M_PI, Vector(1,0,0)));
[9869]66  this->registerObject(this, Spectator::_objectList);
[8067]67
[8228]68  this->getWeaponManager().changeWeaponConfig(1);
69
[8067]70  this->bLeft = false;
71  this->bRight = false;
72  this->bForward = false;
73  this->bBackward = false;
74  this->xMouse = 0.0f;
75  this->yMouse = 0.0f;
[8228]76
77  this->setHealthMax(100);
78  this->setHealth(80);
79
80  this->mouseDir = this->getAbsDir();
81
82  //add events to the eventlist
[8067]83  registerEvent(KeyMapper::PEV_FORWARD);
84  registerEvent(KeyMapper::PEV_BACKWARD);
85  registerEvent(KeyMapper::PEV_LEFT);
86  registerEvent(KeyMapper::PEV_RIGHT);
87  registerEvent(KeyMapper::PEV_FIRE1);
[10114]88  registerEvent(KeyMapper::PEV_JUMP);
[8067]89  registerEvent(EV_MOUSE_MOTION);
[8228]90
91  this->getWeaponManager().setSlotCount(0);
92
93  this->getWeaponManager().getFixedTarget()->setParent(this);
94  this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0);
95
96  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
97
[9869]98
[8067]99  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
100  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
101  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
102  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
103  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) );
[10401]104
105  this->setPlayDirection(Quaternion(0,Vector(0,1,0)), 0.);
[8067]106}
107
[8228]108
[8067]109/**
[8228]110 * loads the Settings of a Spectator from an XML-element.
111 * @param root the XML-element to load the Spaceship's properties from
[8067]112 */
[8228]113void Spectator::loadParams(const TiXmlElement* root)
[8067]114{
[8228]115  Playable::loadParams(root);
[8067]116}
117
[8228]118void Spectator::setPlayDirection(const Quaternion& quat, float speed)
[8067]119{
[8228]120  this->mouseDir = quat;
121  this->angleY = quat.getHeading();
122  this->angleX = quat.getAttitude();
[8067]123}
124
[8228]125
126void Spectator::reset()
[8067]127{
[8228]128  this->bLeft = false;
129  this->bRight = false;
130  this->bForward = false;
131  this->bBackward = false;
132  this->xMouse = 0.0f;
133  this->yMouse = 0.0f;
134
135  this->setHealth(80);
136}
137
138
139void Spectator::enter()
140{
141  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false );
[8067]142  this->attachCamera();
143}
144
[8228]145void Spectator::leave()
[8067]146{
[8228]147  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
[8067]148  this->detachCamera();
149}
150
[8228]151
[8067]152/**
[8228]153 *  this function is called, when two entities collide
154 * @param entity: the world entity with whom it collides
155 *
156 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
157 * @todo dont let Spectator fly through walls
[8067]158 */
[8228]159void Spectator::collidesWith(WorldEntity* entity, const Vector& location)
[8067]160{
161}
162
[8228]163
164
165/**
166 *  the function called for each passing timeSnap
167 * @param time The timespan passed since last update
168 */
169void Spectator::tick (float time)
[8067]170{
[10401]171//   Playable::tick( time );
[9869]172
[10108]173  if( ( xMouse != 0 || yMouse != 0 ) && ( !State::isOnline() || this->getOwner() == SharedNetworkData::getInstance()->getHostID() ) )
[8067]174  {
175    xMouse *= time / 10;
176    yMouse *= time / 10;
[9869]177
[8147]178    angleX -= xMouse;
179    angleY -= yMouse;
[9869]180
[10401]181//     if ( angleY > 1.90 )
182//       angleY = 1.95;
183//
184//     if ( angleY < -1.07 )
185//       angleY = -1.07;
186   
187    xMouse = yMouse = 0;
[9869]188
[8147]189    this->mouseDir = Quaternion( angleX, Vector( 0, 1, 0 ) ) * Quaternion( angleY, Vector( 0, 0, 1 ) );
[9869]190
[10401]191   
192   
[8067]193  }
[9869]194
[8067]195  this->setAbsDir( this->mouseDir );
[9869]196
[8147]197  Vector velocity;
[9869]198
[8147]199  if ( this->bForward )
200  {
201    velocity += this->getAbsDirX();
202  }
[9869]203
[8147]204  if ( this->bBackward )
205  {
206    velocity -= this->getAbsDirX();
207  }
[9869]208
[8147]209  if ( this->bRight )
210  {
211    velocity += this->getAbsDirZ();
212  }
[9869]213
[8147]214  if ( this->bLeft )
215  {
216    velocity -= this->getAbsDirZ();
217  }
[9869]218
[8147]219  velocity *= 100;
[9869]220
[8147]221  this->shiftCoor( velocity*time );
[8067]222}
223
[8228]224/**
225 * @todo switch statement ??
226 */
227void Spectator::process(const Event &event)
[8067]228{
229  Playable::process(event);
230
231  if( event.type == KeyMapper::PEV_LEFT)
232    this->bLeft = event.bPressed;
233  else if( event.type == KeyMapper::PEV_RIGHT)
234    this->bRight = event.bPressed;
235  else if( event.type == KeyMapper::PEV_FORWARD)
236    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
237  else if( event.type == KeyMapper::PEV_BACKWARD)
238    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
239  else if( event.type == EV_MOUSE_MOTION)
240  {
241    this->xMouse += event.xRel;
242    this->yMouse += event.yRel;
243  }
[10114]244  else if( event.type == KeyMapper::PEV_JUMP)
245  {
246//     FPSPlayer * fps = new FPSPlayer();
[10401]247//     //GenericNPC* fps = new GenericNPC();
248//     WorldEntity* fps = new WorldEntity();
249//     //WorldEntity * fps = new WorldEntity();
250//
251//     fps->setAbsCoor( this->getAbsCoorX(), this->getAbsCoorY(), this->getAbsCoorZ() );
252//     fps->setAbsDir( this->getAbsDir() );
253//     fps->loadMD2Texture( "doom_guy.png" );
254//     fps->loadModel( "models/creatures/doom_guy.md2", 10.0f );
255//     fps->toList( OM_GROUP_00);
256//     //fps->loadModel( "models/ships/terran_cruizer.obj" );
[10114]257
[10401]258//     ((Playable*)fps)->setPlayDirection(  0, 0, 1, 0 );
[10114]259  }
[8067]260}
[8228]261
262
263
264
Note: See TracBrowser for help on using the repository browser.