Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4423 in orxonox.OLD


Ignore:
Timestamp:
May 31, 2005, 7:10:01 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: space craft can be controled via keys, nothing new yet

Location:
orxonox/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/coord/pilot_node.cc

    r4422 r4423  
    1919#include "pilot_node.h"
    2020#include "command_node.h"
     21#include "event_handler.h"
    2122#include "event.h"
    2223
     
    3334   this->setClassID(CL_PILOT_PARENT, "PilotNode");
    3435
    35    
     36   travelSpeed = 60.0;
     37   velocity = new Vector();
     38   bUp = bDown = bLeft = bRight = false;
    3639}
    3740
     
    4851
    4952
    50 void PilotNode::command(Command* cmd)
     53void PilotNode::tick(float time)
    5154{
    52 
    53 
    54   //this->setAbsDir(Quaternion(M_PI * 0.4, Vector(1, 0, 0)));
     55  this->move(time);
    5556}
    5657
    5758
     59/**
     60   \brief action if player moves
     61   \param time the timeslice since the last frame
     62*/
     63void PilotNode::move (float time)
     64{
     65  Vector accel(0.0, 0.0, 0.0);
     66  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
     67  /* calculate the direction in which the craft is heading  */
     68  Vector direction (1.0, 0.0, 0.0);
     69  //direction = this->absDirection.apply (direction);
     70  Vector orthDirection (0.0, 0.0, 1.0);
     71  //orthDirection = orthDirection.cross (direction);
     72
     73  if( this->bUp)
     74    accel = accel+(direction*acceleration);
     75  if( this->bDown)
     76    accel = accel -(direction*acceleration);
     77  if( this->bLeft)
     78    accel = accel - (orthDirection*acceleration);
     79  if( this->bRight)
     80    accel = accel + (orthDirection*acceleration);
     81
     82  Vector move = accel * time;
     83  this->shiftCoor (move);
     84}
     85
    5886void PilotNode::process( const Event &event)
    5987{
    60   PRINTF(0)("Mouse moved by %d,%d to (%d,%d)\n", event.xRel, event.yRel,
    61          event.x, event.y);
     88  if( event.type == KeyMapper::PEV_UP)
     89    {
     90      this->bUp = event.bPressed;
     91    }
     92  else if( event.type == KeyMapper::PEV_DOWN)
     93    {
     94      this->bDown = event.bPressed;
     95    }
     96  else if( event.type == KeyMapper::PEV_RIGHT)
     97    {
     98      this->bRight= event.bPressed;
     99    }
     100  else if( event.type == KeyMapper::PEV_LEFT)
     101    {
     102      this->bLeft = event.bPressed;
     103    }
     104  else if( event.type == EV_MOUSE_MOTION)
     105    {
     106      PRINTF(0)("Mouse moved by %d,%d to (%d,%d)\n", event.xRel, event.yRel,
     107            event.x, event.y);
     108    }
    62109}
  • orxonox/trunk/src/lib/coord/pilot_node.h

    r4418 r4423  
    99
    1010#include "comincl.h"
    11 #include "p_node.h"
     11#include "world_entity.h"
    1212#include "event_listener.h"
    1313
    1414class Event;
    1515
    16 class PilotNode : public PNode, public EventListener {
     16class PilotNode : public WorldEntity, public EventListener {
    1717
    1818 public:
    1919  PilotNode ();
    2020  virtual ~PilotNode ();
    21  
    22   void command(Command* cmd);
     21
     22  void tick(float time);
    2323
    2424  void process(const Event &event);
     25
     26 private:
     27  void move(float time);
     28
     29 private:
     30  bool bUp;              //!< up button pressed.
     31  bool bDown;            //!< down button pressed.
     32  bool bLeft;            //!< left button pressed.
     33  bool bRight;           //!< right button pressed.
     34
     35  Vector* velocity;       //!< the velocity of the player.
     36  float travelSpeed;     //!< the current speed of the player (to make soft movement)
     37  float acceleration;    //!< the acceleration of the player.
     38
    2539
    2640};
  • orxonox/trunk/src/story_entities/world.cc

    r4422 r4423  
    601601
    602602
    603         this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_UP);
    604         this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_DOWN);
    605         this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_LEFT);
    606         this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_RIGHT);
    607603        this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_FIRE1);
    608604        this->eventHandler->subscribe(this->localPlayer, ES_GAME, KeyMapper::PEV_NEXT_WEAPON);
     
    639635
    640636        this->pilotNode = new PilotNode();
     637        this->spawn(this->pilotNode);
     638        this->pilotNode->setAbsCoor(Vector(150, -35, 5));
    641639        this->pilotNode->addChild(this->localPlayer);
    642640        this->pilotNode->addChild(this->localCamera);
    643         this->localCamera->lookAt(this->localPlayer);
    644 
     641        this->localCamera->lookAt(this->pilotNode);
     642
     643        this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_UP);
     644        this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_DOWN);
     645        this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_LEFT);
     646        this->eventHandler->subscribe(this->pilotNode, ES_GAME, KeyMapper::PEV_RIGHT);
    645647        this->eventHandler->subscribe(this->pilotNode, ES_GAME, EV_MOUSE_MOTION);
    646648
     
    11641166  else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW4)) this->localCamera->setViewMode(VIEW_RIGHT);
    11651167  else if( !strcmp( cmd->cmd, CONFIG_NAME_VIEW5)) this->localCamera->setViewMode(VIEW_TOP);
    1166   else if(this->pilotNode != NULL) if( !strcmp( cmd->cmd, "cursor")) this->pilotNode->command(cmd);
    11671168  return false;
    11681169}
Note: See TracChangeset for help on using the changeset viewer.