Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8131 was 8068, checked in by patrick, 19 years ago

trunk: merged the network branche back to trunk

File size: 3.5 KB
Line 
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
22
23CREATE_FACTORY(Spectator, CL_SPECTATOR);
24
25
26/**
27 * constructor
28 */
29Spectator::Spectator( const TiXmlElement * root )
30{
31  this->setClassID(CL_SPECTATOR, "Spectator");
32 
33  bool                  bLeft;
34  bool                  bRight;
35  bool                  bForward;
36  bool                  bBackward;
37   
38  float                 xMouse;             //!< mouse moved in x-Direction
39  float                 yMouse;             //!< mouse moved in y-Direction
40
41  this->bLeft = false;
42  this->bRight = false;
43  this->bForward = false;
44  this->bBackward = false;
45  this->xMouse = 0.0f;
46  this->yMouse = 0.0f;
47   
48  registerEvent(KeyMapper::PEV_FORWARD);
49  registerEvent(KeyMapper::PEV_BACKWARD);
50  registerEvent(KeyMapper::PEV_LEFT);
51  registerEvent(KeyMapper::PEV_RIGHT);
52  registerEvent(KeyMapper::PEV_FIRE1);
53  registerEvent(EV_MOUSE_MOTION);
54 
55  registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );
56  registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );
57  registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );
58  registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );
59  registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) );
60}
61
62/**
63 * destructor
64 */
65Spectator::~Spectator( )
66{
67  this->setPlayer(NULL);
68}
69
70void Spectator::setPlayDirection( const Quaternion & rot, float speed )
71{
72  this->mouseDir =  rot;
73  this->rotY = Quaternion( rot.getHeading(), Vector( 0, 1, 0) );
74  this->rotAxis = Quaternion( rot.getAttitude(), Vector( 0, 0, 1 ) );
75}
76
77void Spectator::enter( )
78{
79  this->attachCamera();
80}
81
82void Spectator::leave( )
83{
84  this->detachCamera();
85}
86
87/**
88 * collision handling
89 * @param entity other entity
90 * @param location
91 * @todo dont allow spectator to go through walls
92 */
93void Spectator::collidesWith( WorldEntity * entity, const Vector & location )
94{
95}
96
97void Spectator::tick( float time )
98{
99  Playable::tick( time );
100 
101  if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() )
102  {
103    xMouse *= time / 10;
104    yMouse *= time / 10;
105   
106    this->rotY *= Quaternion(-M_PI/4.0*this->xMouse, Vector(0,1,0));
107    this->rotAxis *= Quaternion(-M_PI/4.0*this->yMouse, Vector(0,0,1) );
108
109    this->mouseDir = rotY * rotAxis;
110    //this->mouseDir *= Quaternion(-M_PI/4.0*this->yMouse, Vector(0,0,1));
111    xMouse = yMouse = 0;
112  }
113 
114  this->setAbsDir( this->mouseDir );
115}
116
117void Spectator::process( const Event & event )
118{
119  Playable::process(event);
120
121  if( event.type == KeyMapper::PEV_LEFT)
122    this->bLeft = event.bPressed;
123  else if( event.type == KeyMapper::PEV_RIGHT)
124    this->bRight = event.bPressed;
125  else if( event.type == KeyMapper::PEV_FORWARD)
126    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
127  else if( event.type == KeyMapper::PEV_BACKWARD)
128    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
129  else if( event.type == EV_MOUSE_MOTION)
130  {
131    this->xMouse += event.xRel;
132    this->yMouse += event.yRel;
133  }
134}
Note: See TracBrowser for help on using the repository browser.