我试图在OpenGL中给定一个方向旋转等腰三角形(所有这些在2D中)。例如,如果三角形向上移动,则三角形必须朝上,并且必须在平面中的所有方向(右下侧 - 左侧 - 右侧......等)中应用。
问题是,如何做到这一点?我有平移的点(x,y)和角度(不是弧度)的方向。代码如下。
void Graphics::draw(){
double P[2];
double Direction;
for (int i = 0; i < numBirds; i++)
{
P[0] = flock[i]->Px;
P[1] = flock[i]->Py;
Direction = flock[i]->Dir - 90;
glPushMatrix();
glColor3d(1, 1, 1);
//Operacion para el triangulo
glTranslated(P[0], P[1], 0.0);
glRotated(Direction, 0.0, 0.0, 1.0);
/*
Se mantienen estas proporciones:
Base: 1
Altura: 1.9364916731
Lado (isosceles): 2
*/
glBegin(GL_TRIANGLES); // Inicio del dibujo
glVertex3d(-1.5, 0, 0); // Primer vertice
glVertex3d( 1.5, 0, 0); // Segundo vertice
glVertex3d( 0, 7.9364916731, 0); // Tercer vertice
glEnd(); // Fin del dibujo
// Deshago las operaciones de rotacion y translacion
glRotated(-Direction, 0, 0, 1);
glTranslated(-P[0], -P[1], 0.0);
glPopMatrix();
//cout << "Velocidad pajaro "<< i <<" Graph x: "<<flock[i]->Vx << " Velocidad pajaro Graph Y:"<< flock[i]->Vy<<endl;
//flock[i]->Py
physics.updatePosition(flock, flock[i]);
//cout << "Velocidad update pajaro "<< i <<" Graph x: "<<flock[i]->Vx << " Velocidad pajaro Graph Y:"<< flock[i]->Vy<<endl;
}
}
在这个版本的代码中,三角形在某个方向(x,y)上移动,但是三角形没有指向(等腰三角形可以指向一个顶点)到/朝向(?)那个dir 挠度。