我有一个物体在地形上移动,第三人称相机跟随它,在我将它向不同方向移动一段距离后,它开始摇晃或振动,即使它没有移动并且相机围绕它旋转,这就是移动对象的代码
double& delta = engine.getDeltaTime();
GLfloat velocity = delta * movementSpeed;
glm::vec3 t(glm::vec3(0, 0, 1) * (velocity * 3.0f));
//translate the objet atri before rendering
matrix = glm::translate(matrix, t);
//get the forward vetor of the matrix
glm::vec3 f(matrix[2][0], matrix[2][1], matrix[2][2]);
f = glm::normalize(f);
f = f * (velocity * 3.0f);
f = -f;
camera.translate(f);
Run Code Online (Sandbox Code Playgroud)
相机旋转是
void Camera::rotate(GLfloat xoffset, GLfloat yoffset, glm::vec3& c, double& delta, GLboolean constrainpitch) {
xoffset *= (delta * this->rotSpeed);
yoffset *= (delta * this->rotSpeed);
pitch += yoffset; …Run Code Online (Sandbox Code Playgroud) 我可以实现AABB的方法来检测碰撞,很容易和便宜,但我想要实现OBB为了更准确,所以我创建边框与模型初始化它是由8个边界顶点和中心,每帧我把一切在顶点与变换矩阵以适应方向包围盒,但我不理解该方法用于检测两个OBBs之间的碰撞和我无法找到的简化和清楚的教程,其与因为我的代码视点不数学解释该算法我不是数学家.
如果我有
struct Box {
glm::vec3 vertices[8];
Box() {
for (int i = 0; i < 8; i++) {
vertices[i] = glm::vec3(0);
}
}
glm::vec3 max;
glm::vec3 min;
glm::vec3 origin;
void reCompute() {
max = vertices[0];
min = vertices[0];
for (int i = 1; i < 8; i++) {
max.x = max.x > vertices[i].x ? max.x : vertices[i].x;
max.y = max.y > vertices[i].y ? max.y : vertices[i].y;
max.z = max.z > vertices[i].z ? max.z : vertices[i].z;
min.x = min.x < …Run Code Online (Sandbox Code Playgroud)