How to write my own 3rdperson inputhandler?

Hi there

i m a little bit confused about the inputhandler system and im really not getting through it. I need something like in the testThirdPersonController but my model has to turn around too and the camera should look on a spot a little bit above my model.

To realise this i created a special player node which has a model a camera Pivotpoint a little bit above my model and a camera node. my idea was now to write a standard wasd moving for the playerpivot while you can rotate the cameranode around the camera pivot by moving  the mouse in vertical direction or rotating the whole playernode around itself for horizotal mouse movements.

in the update method the camera gets the globallocation of the cameranode and the direction the camera is looking is the inverted local translation.

My actual problem is to write the input Handler now but i wanted to explain my idea so that you can tell me if the idea itself is already mess.

In the Hellokeyinput tutorial is explained how to bind keys and i thought about realizing the translation movement with it until i noticed that its done very different in the firstperson/thirdperson inputhandler

but i dont understand how it works there and i dont understand the mouseinput either which i need anyway

I would be glad if someone could explain me how it works or give me a simple example

Kinda sounds like a ChaseCamera with stayBehindTarget( true ); (jME already supports this, thats where I would start)

well but how can i manipulate my model with mousemoving then?

Take a look at some of the jME-Tests, specifically ShadowTest and AdvancedVehicleTest; both of them use the built-in chase camera.  Why re-invent the wheel??

well got two main problems with it

  1. i need an accurate camera and not that smoothe one ( me game shall become a 3rd person shooter)

    mabey there is a flag to turn it off didn t really search for it
  2. my main problem is that i need access to the mouse operations couse my model has to turn around when i use my mouse

    maybe i could combine my idea and the chase camera but that would result in an even more complicated code i think

    maybe my idea with the inputlistener and the cameranode has disadvantages i cant see yet, or you have a better idea how to manage it (only a rough idea would be enough i can code it myself - i hope :wink: ), then please tell me


Create model, attach chase camera, rotate model (camera automatically rotates).

Doesn't seem to get much simpler.  :wink:

It's a lot like the matrix "There is no spoon", well here there is no camera; only the model.  In other words try the tactic of manipulating the model to control the camera, not the other way around…

mabey there is a flag to turn it off didn t really search for i

Almost every setting in the chase camera is configurable.

jME has some SWEET math utilities already built into it. Check out creating a blank quaternion and then trying quat.fromAngleAxis().  Also GC can be a killer for jME, although not correct from an engineering standpoint you should use temp global variables for non-primitives like Vector3f and Matrix3f.  This is especially important for any thing that is in an update loop, which can fire 100s of times a second.

The box flickering could be alot of issues, but it might be the vertical sync.  Try setting  display.setVSyncEnabled( true );

yep found those quaternions already. was just used to do it by matrix…

i ve written now my own input handler like i told with the camera node and it works fine with still th option to use chasecamera instead if i dont like it anymore…

what do you mean with GC?

by the way i got anothe issue, with the Quaternions:

float angle = quatY.toAngleAxis(new Vector3f(0,1,0))+dAngle;

quatY.fromAngleAxis(angle, new Vector3f(0,1,0));

this is my code at the moment (i left out some ifs which ensure that thangle is between 0

hmm, maybe you're using the Vector, Matrix and Quaternion objects incorrectly.

If I do this

Quaternion quat = Quaternion().fromAngleAxis( Pi/3, new Vector( 0, 1, 0 );
Spatial spatial1 = new Box();
Spatial spatial2 = new Box();

spatial1.setLocalRotation( quat );
spatial2.setLocalRotation( quat );

Both spatials now have a pointer to quat for it's local rotation. 

Now if I do this:

spatial1.getLocalRotation().multLocal( new Quaternion().fromAngleAxis( Pi/2, new Vector( 0, 1, 0 ) );

Both spatial1 and spatial2 will be updated.

The proper way to manipulate the math objects vectors is by using the get and set methods, and only creating them when necessary.  This is to avoid unnecessary garbage collection.  This is almost critical for good performance in the render and update methods; which can be called 100s of times per second. 

So the first example should be more like this:

final Quaternion tempQuat = new Quaternion();
final Vector3f tempVector = new Vector3f();
final Spatial spatial1;
final Spatial spatial2;

public void createBoxes() {
  spatial1 = new Box();
  spatial2 = new Box();

public void moveBoxes() {
  tempVector.set( 0, 1, 0 );
  tempQuat.fromAngleAxis( Pi/2, tempVector );
  spatial1.getLocalRotation().multLocal( tempQuat );

  tempVector.set( 1, 0, 0 );
  tempQuat.fromAngleAxis( -Pi/2, tempVector );
  spatial2.getLocalRotation().multLocal( tempQuat );

GC = Garbage Collection