ThirdPersonMouseLook with one new property

Hi,

i tried to have a behaviour similar to world of warcraft. Rotating of the camera around the character by pressing the second mouse button and zooming in /out using the mousewheel.

Seems ThirdPersonMouseLook is the best choice.



There is no property however for that kind of behaviour.



So i would propose a new property

public static final String PROP_MOUSEBUTTON_FOR_LOOKING = "lookButton";

public static final int DEFAULT_MOUSEBUTTON_FOR_LOOKING = -1;

protected int lookMouse = DEFAULT_MOUSEBUTTON_FOR_LOOKING;





we add in :

public void updateProperties(HashMap props) {



lookMouse = InputHandler.getIntProp(props,

PROP_MOUSEBUTTON_FOR_LOOKING, DEFAULT_MOUSEBUTTON_FOR_LOOKING);

}



performAction would then be changed to:



public void performAction(InputActionEvent event) {
if (!enabled)
return;
float time = event.getTime();
if (lookMouse == -1 || MouseInput.get().isButtonDown(lookMouse)) {

if (mouse.getLocalTranslation().x != 0) {
float amount = time * mouse.getLocalTranslation().x;
rotateRight(amount, time);
updated = true;
} else if (rotateTarget)
rotateRight(0, time);
if (!lockAscent && mouse.getLocalTranslation().y != 0) {
float amount = time * mouse.getLocalTranslation().y;
rotateUp(amount);
updated = true;
}
}
int wdelta = MouseInput.get().getWheelDelta();
if (wdelta != 0) {
float amount = time * -wdelta;
rollIn(amount);
updated = true;
}

if (updated)
camera.getCamera().onFrameChange();

}

Thanks, this is useful.  I'd suggest adding this to the cvs.

Got it in, thanks

Good idea. The thrid person mouse looks is still somewhat jumpy, but I guess it's just a matter of tweaking it a bit. Anyway, shouldn't DEFAULT_MOUSEBUTTON_FOR_LOOKING be a boolean value? Its equaliant variables are, and having this being an integer value seems inconsistent. Unless more mouse looking modes are to be supported by this variable in the future? (They should get their own variables anyway, IMH).

Sion said:

Good idea. The thrid person mouse looks is still somewhat jumpy, but I guess it's just a matter of tweaking it a bit. Anyway, shouldn't DEFAULT_MOUSEBUTTON_FOR_LOOKING be a boolean value? Its equaliant variables are, and having this being an integer value seems inconsistent. Unless more mouse looking modes are to be supported by this variable in the future? (They should get their own variables anyway, IMH).

The reason why its an integer is simply to allow for all three buttons to function as the button that needs to be pressed in order to have the look around.
If you used a boolean then you would have to use a variable for each possible button, you would have to check for all of them and you would have to use a different name for the variable like "LEFT_BUTTON_USED_FOR_LOOKING" etc...
This way its faster and in my more intuitive also when it comes to naming.

Thanks for the reply. It makes good sense using an integer value now, I didn't realize that you could specify different buttons to use for mouse look. As I recall, the code only checks if the variable is 1, but prehaps I'm mistaken. Anyway, thanks for clearing this up for me.



EDIT: Do'h! The code is in this thread  And I was mistaking. The code checks if the variable is -1, otherwise the respective value is used to check the state of the mouse button.