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):
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
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 / |x|
ŷ = y / |y|
then can use x̂ , ŷ coordinate basis camera-relative motion of player. if joystick readings jx , jy, move player
s (jx x̂ + jy ŷ)
where s appropriate scalar value proportional player's speed.
(notice no angles computed @ point in answer!)
Comments
Post a Comment