相机运动。如何移动相机?
我目前设置了一个开放式 gl 渲染器,它显示一个 2d 正方形和另一个 2d 形状。通过使用按键,用户可以上下左右移动方块。这是通过根据用户是否按上、下、左、右而改变的值来平移方块来完成的,例如,如果用户按右,则意味着 gl.glTranslatef(rightdisplacement, 0, 0); 的平移;运动工作正常,但我不知道如何让相机在正方形继续移动时跟随它。我想移动正方形并使相机朝同一方向移动。
I currently have an open gl renderer set up which displays a 2d square and another 2d shape. By using the keys the user is able to move the square up down left and right. This is done through translating the square based on values altered by whether the user presses up down left right eg if the user presses right it would mean a translation of gl.glTranslatef(rightdisplacement, 0, 0); etc. The movement works fine but I cant figure out how to get the camera to follow the square as it continues moving. I would like to move the square and have the camera move in the same direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在进行 2D 渲染,您可能会调用 glOrtho 某处定义坐标系。完全是猜测,但您的代码可能类似于:
glOrtho( 0, screenWidth, 0, screenHeight, -1, 1 );
这是您定义相机位置的位置。创建相机位置 x 和 y 位置变量,然后调用
确保每帧都调用此方法,因为相机位置显然会发生变化。您的渲染代码可能类似于
If you're doing 2D rendering you are probably making a call to glOrtho somewhere to define your coordinate system. Total speculation, but your code might look something like:
glOrtho( 0, screenWidth, 0, screenHeight, -1, 1 );
This is where you define your camera position. Create camera position x and y position variables and instead call
Make sure that this is called every frame as the camera position will obviously change. Your render code might look something like