Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/bsp_model/src/world_entities/spectator.cc @ 8372

Last change on this file since 8372 was 8147, checked in by bensch, 18 years ago

orxonox/trunk: merged the network branche back here
merged with command:
svn merge -r8070:HEAD https://svn.orxonox.net/orxonox/branches/network .
no conflicts

File size: 3.8 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->angleY = rot.getHeading();
74  this->angleX = rot.getAttitude();
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    angleX -= xMouse;
107    angleY -= yMouse;
108   
109    if ( angleY > 2.05 )
110      angleY = 2.05;
111   
112    if ( angleY < -1.15 )
113      angleY = -1.15;
114   
115    this->mouseDir = Quaternion( angleX, Vector( 0, 1, 0 ) ) * Quaternion( angleY, Vector( 0, 0, 1 ) );
116   
117    xMouse = yMouse = 0;
118  }
119 
120  this->setAbsDir( this->mouseDir );
121 
122  Vector velocity;
123 
124  if ( this->bForward )
125  {
126    velocity += this->getAbsDirX();
127  }
128 
129  if ( this->bBackward )
130  {
131    velocity -= this->getAbsDirX();
132  }
133 
134  if ( this->bRight )
135  {
136    velocity += this->getAbsDirZ();
137  }
138 
139  if ( this->bLeft )
140  {
141    velocity -= this->getAbsDirZ();
142  }
143 
144  velocity *= 100;
145 
146  this->shiftCoor( velocity*time );
147}
148
149void Spectator::process( const Event & event )
150{
151  Playable::process(event);
152
153  if( event.type == KeyMapper::PEV_LEFT)
154    this->bLeft = event.bPressed;
155  else if( event.type == KeyMapper::PEV_RIGHT)
156    this->bRight = event.bPressed;
157  else if( event.type == KeyMapper::PEV_FORWARD)
158    this->bForward = event.bPressed; //this->shiftCoor(0,.1,0);
159  else if( event.type == KeyMapper::PEV_BACKWARD)
160    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
161  else if( event.type == EV_MOUSE_MOTION)
162  {
163    this->xMouse += event.xRel;
164    this->yMouse += event.yRel;
165  }
166}
Note: See TracBrowser for help on using the repository browser.