How to make a camera move in the direction it is facing in java? -


i need way(in java) calculate direction camera move forward on x , z axes based on direction camera facing(yaw), , y(the vertical axis), pitch. i'm making own game engine , own camera.

with values defaulting @ zero, moving camera correctly directs movement along positive z axis. however, when pan camera left or right(thereby changing yaw), camera still moves along z axis... how calculate change in direction x, y, , z axes?

the value range on yaw 0(south), 45(southwest), 90(west), 135(northwest), 180(north), 225(northeast), 270(east), 315(southeast), , 360(south, same 0).

what i'm looking compass directions(where '+' or '-' indicates change in value along axis):

south = x, y, z+ southwest = x+, y, z+ west = x+, y, z northwest = x+, y, z- north = x, y, z- northeast = x-, y, z- east = x-, y, z southeast = x-, y, z+ 

the value range on pitch 0.0(middle), 100.0(up way), , -100.0(down way).

if need post code, can, might complicated. hope i'm making kind of sense can me!

suppose want move camera in direction y distance k. sake of simplicity, convert directions angles, 0.0 represents right, pi/2 represents up, pi represents left, 3*pi/2 represents down , so.

edit: y of camera affected pitch. x , z, instead affected both yaw , pitch.

you can calculate new x, y , z following:

float y = // yaw angle float p = // pitch angle float k = // move distance  float xzlength = cos(p) * k; float dx = xzlength * cos(y); float dz = xzlength * sin(y); float dy = k * sin(p);  // update camera: camera.x += dx; camera.y += dy; camera.z += dz; 

obviously, yaw , pitch not change, don't need update them.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -