Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: camera movement using keyboard in buffered mode  (Read 1145 times)

Arcanor

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 47
    • View Profile
    • http://arcanoria.com
camera movement using keyboard in buffered mode
« on: February 07, 2007, 05:26:11 PM »

What is the best/recommended way to do keyboard-based movement in buffered mode?  Set a flag at keyPressed(), then unset it at keyReleased()?  Do bitwise operations to manually keep the up/down state of each key at any given time?  Or is there a better way?
Logged
Arcanoria - online medieval fantasy RPG - www.arcanoria.com

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
camera movement using keyboard in buffered mode
« Reply #1 on: February 07, 2007, 05:47:03 PM »

Generally, you don't use a flag per say. What you do, is in the keyDown, you set a movement vector to some direction of travel. And, in your keyUp, you set that movement vector to all 0's. Now, every loop of your main loop (or a framelistener), you translate that object by the movement vector. When it is zero, it has no effect, when it has a value, it will move the object.

For rotations, depending on input device type, you can immediately rotate the object/scenenode - or, you can do the same thing as for movement.

Here is an exmplae (in Squirrel Script) I am using to handle button actions:
https://www.wreckedgames.com/svn/ringo/trunk/bin/media/nuts_test_scene/InputConfig.nut
And here, where I apply the movement changes
https://www.wreckedgames.com/svn/ringo/trunk/bin/media/nuts_test_scene/Actor.nut

(Note, these scripts go along with my wip game engine:
https://www.wreckedgames.com/svn/wge/trunk/

hope that helps.
Logged

Arcanor

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 47
    • View Profile
    • http://arcanoria.com
camera movement using keyboard in buffered mode
« Reply #2 on: February 07, 2007, 05:48:51 PM »

Thanks, I will take a look!
Logged
Arcanoria - online medieval fantasy RPG - www.arcanoria.com

OvermindDL1

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 288
    • View Profile
    • http://www.overminddl1.com/forum/
camera movement using keyboard in buffered mode
« Reply #3 on: February 09, 2007, 02:11:44 PM »

I looked at those nut's there and I have a question.  "class Player extends CollisionActor" indicates that players are actual objects and not just abstractions.  Wouldn't that make it difficult to change the thing the player controls while in-game (think of hopping in a vehicle or so).  This is how my pattern actually goes:
Code: [Select]

class Controller // Base class of all controllers
{
    Actor *m_CurrentControllee;
}
class Actor // Base class of any in-game object
{
    Controller *m_CurrentController
}
class AIController : public Controller;
class PlayerController : public Controller;
class NetworkController : public Controller;

And so forth.  Things like vehicles (or a hovercraft in the demo) do nothing when not controlled, can be pushed around, shot at, etc...  A PlayerController, when not attached to anything is a floating eye, does not interact with the game scene, etc... etc... a FreeCam.  When it is attached it then controls the object, sending commands to move, etc... etc... (if the Actor subclass implements the appropriate callbacks).  If the PlayerController does not have a viewtarget, then the viewtarget is set to the actor is possesses.  When it has a viewtarget, the target itself sets where the view is, can be first person, third person, a follow cam, etc..., can switch in real-time and so forth.  But this makes it so that a person is walking around in nice first-person view, can hop into a hovercraft, which sees the previous controllee as a person class and attaches the person to the seat in the vehicle, and the Controller takes over the vehicle, switching view and all.  Later on the person can hope back out, thus going back to a person, and so on and so forth.  All elegently done and makes it exceedingly easy to make more player controllable objects.  The AIController (not really implemented, but it would be like this) changes itself based on the controllee.  The controllee can specify an ai script for the thing to use, other variables are based around on things, etc... and so forth.  The NetworkController is a proxy to keep things synced with an AI (usually implemented on all clients rather then just one owner) or Player controller across the network to handle command replication, interpolation, etc...
Logged