简体   繁体   English

lwjgl根据地面的坡度旋转物体

[英]lwjgl rotate object according to the slope of the ground

Good evening, I have a problem with the LWJGL library, my idea is to make a procedural ground where a vehicle can move, I've already built both ground and vehicle management to make it stick to the ground each time it moves, To do this, the height of the ground is calculated according to the new position and the object is placed at the altitude just calculated but what I can not do is to rotate the vehicle according to the slope of the ground. 晚上好,我对LWJGL库有问题,我的想法是为车辆可以移动的程序化地面,我已经建立了地面和车辆管理系统,以便每次移动时都可以附着在地面上,这样,将根据新位置计算出地面的高度,然后将物体放置在刚刚计算出的高度上,但我不能根据地面的坡度旋转车辆。 I have already tried to calculate the altitudes at the edge of the vehicle and use them to get the rotation angles (x axis, z) but I managed to run it only for one direction but if the object rotates around the axis y it will not work more. 我已经尝试过计算车辆边缘的海拔高度,并使用它们来获取旋转角度(x轴,z),但是我设法仅在一个方向上运行它,但是如果物体绕着y轴旋转,它将不会工作更多。 I tried to use quaternions but they also failed. 我尝试使用四元数,但它们也失败了。

Here is the class that realizes the terrain https://github.com/maurizioterreni/OpenGL/blob/master/src/com/unifi/ing/engine/terrains/Terrain.java 这是实现地形的类https://github.com/maurizioterreni/OpenGL/blob/master/src/com/unifi/ing/engine/terrains/Terrain.java

While here the class that manages the vehicle https://github.com/maurizioterreni/OpenGL/blob/master/src/com/unifi/ing/engine/entity/Rover.java 在这里,管理车辆的类https://github.com/maurizioterreni/OpenGL/blob/master/src/com/unifi/ing/engine/entity/Rover.java

The up vector of your object should be in line with the normal vector of the terrain. 对象的向上向量应与地形的法线向量一致。 By doing this, the game object/entity will then be orthogonal/perpendicular to the terrain. 通过这样做,游戏对象/实体将与地形正交/垂直。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM