Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

math - Quaternion fps camera movement?

i just did a simple fps camera,everything looks fine,the camera move perfectly with the mouse,now i wanted to move it: for example press w move forward etc....but i'm getting really confused,first of all i tried to get all the vectors from my rotation matrix but i still move on the world axis,and i also tried doing the conjugate of the quat multiplied for the front vec and i get strange results i really have no idea what to do,can someone give me an hint? i didn't understand anything online and i've already spent few days on them..this is my simple code that is working but just to move the mouse:

////NOTE----> MY SYSTEM IS +Z UP///-Y FRONT////-X RIGHT
track_pitch(core_ptr);
track_yaw(core_ptr);
///////
QUAT pitch,yaw;  
quat_from_axis(yaw,deg_to_rad(core_ptr->mouse->yaw),core_ptr->cam->cam_up);  
quat_from_axis(pitch,deg_to_rad(core_ptr->mouse->pitch),core_ptr->cam->cam_right);    

quat_multiply(core_ptr->cam->orientation,yaw,pitch);
quat_normalize(core_ptr->cam->orientation); 

MAT4 quat_rot,tra;
mat4_init(quat_rot);
mat4_from_quat(quat_rot,core_ptr->cam->orientation);  
mat4_init(tra); 
VEC3 neg_pos = {-core_ptr->cam->cam_pos[0],-core_ptr->cam->cam_pos[1],-core_ptr->cam->cam_pos[2]};
mat4_translate(tra,neg_pos);
mat4_multiply(core_ptr->data->ubo_cam->cam_view,quat_rot,tra); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...