OpenGL에서 제어 가능한 공을 만들려고합니다. 내 자신의 행렬 클래스를 사용하여 객체 행렬을 변환하지만 Rotation 권한을 얻을 수없는 것 같습니다. 나는 항상 로컬 축을 중심으로 회전하는 공으로 끝납니다. 이것은 지금 보이는 방법입니다. https://gfycat.com/LongKindBassethound. 긴 선은 로컬 축입니다.세계 축을 중심으로 한 물체의 회전 OpenGL
그래서 공이 앞으로 움직이면 다음 사이드 운동이 잘못 될 것입니다.
Matrix& Matrix::rotationAxis(const Vector& Axis, float Angle) {
const float Si = sin(Angle);
const float Co = cos(Angle);
const float OMCo = 1 - Co;
Vector Ax = Axis;
Ax.normalize();
m00= (Ax.X * Ax.X) * OMCo + Co;
m01= (Ax.X * Ax.Y) * OMCo - (Ax.Z * Si);
m02= (Ax.X * Ax.Z) * OMCo + (Ax.Y * Si);
m03= 0;
m10= (Ax.Y * Ax.X) * OMCo + (Ax.Z * Si);
m11= (Ax.Y * Ax.Y) * OMCo + Co;
m12= (Ax.Y * Ax.Z) * OMCo - (Ax.X * Si);
m13= 0;
m20= (Ax.Z * Ax.X) * OMCo - (Ax.Y * Si);
m21= (Ax.Z * Ax.Y) * OMCo + (Ax.X * Si);
m22= (Ax.Z * Ax.Z) * OMCo + Co;
m23= 0;
m30= 0;
m31= 0;
m32= 0;
m33= 1;
return *this;
}
나는 결과를 중심으로 회전 한 후 나는 세상의 방향 벡터를 가지고 객체의 로컬 공간을 변형 할 수있다이 함께 생각하고 : 어떤 축을 중심으로 회전 할 수 있습니다 매트릭스 클래스에서 함수를 프로그래머. 나는 그것을하는 방법을 정말로 모르지만 (공의 행렬 * 월드 벡터? 작동하지 않는다). 나는 쿼터니언을 피하고 싶습니다.하지만 그렇게 할 수 없다면 나는 그 방향으로 제안을 높이 평가할 것입니다.
편집 : 추가 정보
트랜스 포메이션 코드. 당신이 볼 수 있듯이 나는 모두 똑같이하는 다른 방법을 시도했다. 그래서 놀랄 일은 없다. 내 이전 시도가 glRotatef를 사용하려고 시도와
Matrix transM, rotX, rotZ;
rotationX = straight;
rotationZ = side;
if (velocity != Vector(0, 0, 0)) {
velocity.X = -0.0005 * DeltaTime;
velocity.X = clamp(velocity.X, 0, FLT_MAX);
velocity.Z = -0.0005 * DeltaTime;
velocity.Z = clamp(velocity.Z, 0, FLT_MAX);
}
velocity.X += speed * -side * DeltaTime;
velocity.Z += speed * straight * DeltaTime;
transM.translation(velocity.X, 0, velocity.Z);
if (velocity.Z != 0 || velocity.X != 0) {
//http://mathworld.wolfram.com/EulerAngles.html
//http://gamedev.stackexchange.com/questions/67199/how-to-rotate-an-object-around-world-aligned-axes
Vector localAxisX = m_Ball * Vector(1, 0, 0);
Vector localAxisZ = m_Ball * Vector(0, 0, 1);
rotX.rotationAxis(Vector(1, 0, 0), 0.5* M_PI * straight * DeltaTime);
rotZ.rotationAxis(Vector(0, 0, 1), 0.5* M_PI * side * DeltaTime);
//rotX.rotationX(0.5* M_PI * straight * DeltaTime * 3);
//rotZ.rotationZ(0.5* M_PI * side * DeltaTime * 3);
//Matrix fullRotation.rotationYawPitchRoll(Vector(0, 0.5* M_PI * straight * DeltaTime, 0.5* M_PI * side * DeltaTime));
m_Ball = transM * m_Ball * (rotX*rotZ);
}
else {
m_Ball = transM * m_Ball;
}
그리기 코드는
void Ball::draw(float DeltaTime) {
glPushMatrix();
glMultMatrixf(m_Ball);
if(rotationX)
glRotatef(0.5* M_PI * rotationX * DeltaTime, 1.0, 0.0, 0.0);
if(rotationZ)
glRotatef(0.5* M_PI * rotationZ * DeltaTime, 0.0, 0.0, 1.0);
g_Model_ball.drawTriangles();
glPopMatrix();
drawAxis();
}
이 함수를 호출하는 위치에서 드라이버 코드를 게시하십시오. 둘째, 자신의 회전 함수를 수정하기위한 요구 사항이 있습니까? –
추가 정보로 편집 – lega
OpenGL 변환이 어떻게 작동하는지 이해하려면이 기사를 참조하십시오. –