首页 > 其他 > 详细

Camera_练习一

时间:2019-11-29 18:59:12      阅读:67      评论:0      收藏:0      [点我收藏+]

看看你是否能够修改摄像机类,使得其能够变成一个真正的FPS摄像机(也就是说不能够随意飞行);你只能够呆在xz平面上

技术分享图片
 1 // This function is found in the camera class. What we basically do is keep the y position value at 0.0f to force our
 2 // user to stick to the ground.
 3 
 4 ...
 5 // processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
 6 void ProcessKeyboard(Camera_Movement direction, float deltaTime)
 7 {
 8     float velocity = MovementSpeed * deltaTime;
 9     if (direction == FORWARD)
10         Position += Front * velocity;
11     if (direction == BACKWARD)
12         Position -= Front * velocity;
13     if (direction == LEFT)
14         Position -= Right * velocity;
15     if (direction == RIGHT)
16         Position += Right * velocity;
17     // make sure the user stays at the ground level
18     Position.y = 0.0f; // <-- this one-liner keeps the user at the ground level (xz plane)
19 }
20 ...
View Code

鼠标移动的时候可以改变方向向量,但是我们在键盘点击函数里面强行把y坐标设置为0,这样就不会产生y坐标上的移动了

 

2019/11/29

Camera_练习一

原文:https://www.cnblogs.com/ljy08163268/p/11959100.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!