C++ 跟踪移动旋转矩形c++;openGL
基本上我有一辆在二维空间中移动的汽车(矩形)。 跟踪角点,用于与其他对象的基本碰撞检测。 我不能正确地算出我的三角学。 目前我有以下几点:C++ 跟踪移动旋转矩形c++;openGL,c++,opengl,C++,Opengl,基本上我有一辆在二维空间中移动的汽车(矩形)。 跟踪角点,用于与其他对象的基本碰撞检测。 我不能正确地算出我的三角学。 目前我有以下几点: this->FL.x = this->position.x - this->C_width/2*cos(this->spinY*pi/180) + this->C_length/2*sin(this->spinY*pi/180); this->FL.y = this->position.z + this->
this->FL.x = this->position.x - this->C_width/2*cos(this->spinY*pi/180) + this->C_length/2*sin(this->spinY*pi/180);
this->FL.y = this->position.z + this->C_length/2*sin(this->spinY*pi/180) - this->C_width/2*cos(this->spinY*pi/180);
this->FR.x = this->position.x + this->C_width/2*cos(this->spinY*pi/180) + this->C_length/2*sin(this->spinY*pi/180);
this->FR.y = this->position.z + this->C_length/2*sin(this->spinY*pi/180) + this->C_width/2*cos(this->spinY*pi/180);
this->BL.x = this->position.x - this->C_width/2*cos(this->spinY*pi/180) - this->C_length/2*sin(this->spinY*pi/180);
this->BL.y = this->position.z - this->C_length/2*sin(this->spinY*pi/180) - this->C_width/2*cos(this->spinY*pi/180);
this->BR.x = this->position.x + this->C_width/2*cos(this->spinY*pi/180) - this->C_length/2*sin(this->spinY*pi/180);
this->BR.y = this->position.z - this->C_length/2*sin(this->spinY*pi/180) + this->C_width/2*cos(this->spinY*pi/180);
这不是最简单的方法,但始终正确的方法是使用将对象放置在场景中的模型矩阵,并将角点的位置与该矩阵相乘。这将为您处理平移/旋转/缩放及其交互
在OpenGL中,您有MODELVIEW矩阵。即模型矩阵乘以视图矩阵(或摄影机)。您可以重新计算模型矩阵(这里任何矩阵库都会帮助您)。或者将模型视图与反向视图矩阵相乘。您可以使用glGetMatrix获取它们 正如我所看到的,你正在使用opengl,如果你用矩阵旋转/移动它,你也可以在cpu上用它们来获得盒子的坐标。我知道,这真的不重要,但真的需要所有这些
这个->
前缀吗?你的代码非常不可读。