/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Christoph Renner co-programmer: ... */ #include "spectator.h" #include "src/lib/util/loading/factory.h" #include "key_mapper.h" CREATE_FACTORY(Spectator, CL_SPECTATOR); /** * constructor */ Spectator::Spectator( const TiXmlElement * root ) { this->setClassID(CL_SPECTATOR, "Spectator"); bool bLeft; bool bRight; bool bForward; bool bBackward; float xMouse; //!< mouse moved in x-Direction float yMouse; //!< mouse moved in y-Direction this->bLeft = false; this->bRight = false; this->bForward = false; this->bBackward = false; this->xMouse = 0.0f; this->yMouse = 0.0f; registerEvent(KeyMapper::PEV_FORWARD); registerEvent(KeyMapper::PEV_BACKWARD); registerEvent(KeyMapper::PEV_LEFT); registerEvent(KeyMapper::PEV_RIGHT); registerEvent(KeyMapper::PEV_FIRE1); registerEvent(EV_MOUSE_MOTION); registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) ); } /** * destructor */ Spectator::~Spectator( ) { this->setPlayer(NULL); } void Spectator::setPlayDirection( const Quaternion & rot, float speed ) { this->mouseDir = rot; this->rotY = Quaternion( rot.getHeading(), Vector( 0, 1, 0) ); this->rotAxis = Quaternion( rot.getAttitude(), Vector( 0, 0, 1 ) ); } void Spectator::enter( ) { this->attachCamera(); } void Spectator::leave( ) { this->detachCamera(); } /** * collision handling * @param entity other entity * @param location * @todo dont allow spectator to go through walls */ void Spectator::collidesWith( WorldEntity * entity, const Vector & location ) { } void Spectator::tick( float time ) { Playable::tick( time ); if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() ) { xMouse *= time / 10; yMouse *= time / 10; this->rotY *= Quaternion(-M_PI/4.0*this->xMouse, Vector(0,1,0)); this->rotAxis *= Quaternion(-M_PI/4.0*this->yMouse, Vector(0,0,1) ); this->mouseDir = rotY * rotAxis; //this->mouseDir *= Quaternion(-M_PI/4.0*this->yMouse, Vector(0,0,1)); xMouse = yMouse = 0; } this->setAbsDir( this->mouseDir ); } void Spectator::process( const Event & event ) { Playable::process(event); if( event.type == KeyMapper::PEV_LEFT) this->bLeft = event.bPressed; else if( event.type == KeyMapper::PEV_RIGHT) this->bRight = event.bPressed; else if( event.type == KeyMapper::PEV_FORWARD) this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); else if( event.type == KeyMapper::PEV_BACKWARD) this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); else if( event.type == EV_MOUSE_MOTION) { this->xMouse += event.xRel; this->yMouse += event.yRel; } }