java - 'adding' two angles -


alright, got 2 angles. 1 joystick's angle, , other camera player angle. camera's angle. want when press on joystick moves player away camera. how this? , there easy way in java or ardor3d?

edit: here code of how angles.

float camdegree = (float) math.todegrees(math.atan2(                      _canvas.getcanvasrenderer().getcamera().getlocation().getxf() - colladanode.gettranslation().getxf(),                      _canvas.getcanvasrenderer().getcamera().getlocation().getyf()) - colladanode.gettranslation().getyf());              player.angle = (float) math.todegrees(math.atan2(padx, pady));             quaternion camq = new quaternion().fromangleaxis(camdegree, vector3.unit_y); 

i have don't understand question, seems how implement camera-relative control using joystick.

the important piece of advice can give it's better not compute angles, work directly vectors.

suppose camera looking in direction v (in types of game vector pointing directly @ player, not types of game, , not always):

the vector camera player can resolved vertical , horizontal components

typically don't care vertical component of vector, remove horizontal component, i'll call y reasons become apparent later:

y = v − (v · up) up

where up unit vector pointing vertically upwards.

we can find horizontal vector that's perpendicular y using cross product (and remembering right hand rule):

x = v × up

the vectors x , y form horizontal coordinate basis

now can see y vector in plane pointing forwards (away camera), , x vector in plane pointing right (sideway respect camera). if normalise these vectors:

= x / |x|

ŷ = y / |y|

then can use , ŷ coordinate basis camera-relative motion of player. if joystick readings jx , jy, move player

s (jx + jy ŷ)

where s appropriate scalar value proportional player's speed.

(notice no angles computed @ point in answer!)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -