Ich habe ein Problem, wo ich das gewünschte Objekt in perspektivischer Projektion sehen kann, während ich das Objekt in orthogonaler Projektion nicht sehen kann, auch wenn sich die Kamera in denselben Koordinaten befindet und dasselbe betrachtet Koordinate.Glut Ortho2D Projektion wird nicht angezeigt
Ich weiß, dass das Objekt korrekt wiedergegeben wird, da sie korrekt in der perspektivischen Ansicht wie so zeigen:
die Ebene mit dem Ursprung mit einer Höhe von 10 angeordnet ist, eine Breite von 50, und keine Tiefe. Es ist positioniert bei (0, -10, 0)
Ich würde gerne in der Lage sein, dies in orthographischer Projektion zu sehen. So wie ich es eingerichtet ist, wie dies in meinem CameraManager Klasse:
void CameraManager::UpdateCamera() {
// exit in erroneous situations
if (m_screenWidth == 0 && m_screenHeight == 0)
return;
switch (m_projectionType)
{
case TWO_DIMENSIONAL:
SetupOrthographicCamera();
break;
case THREE_DIMENSIONAL:
SetupPerspectiveCamera();
break;
default:
break;
}
SetupModelView();
}
Da ist in meinem SetupOrthographicCamera() ich dies tun:
void CameraManager::SetupOrthographicCamera() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//float aspectRatio = m_screenWidth/(float)m_screenHeight;
gluOrtho2D(-50, 50, -100, 100);
/*
m_cameraPosition = btVector3(0, 0, -1);
glMatrixMode(GL_MODELVIEW);
gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2], m_cameraTarget[0], m_cameraTarget[1], m_cameraTarget[2], m_upVector.getX(), m_upVector.getY(), m_upVector.getZ());
*/
}
Das ist meine Perspektive der Kamera:
void CameraManager::SetupPerspectiveCamera() {
// select the projection matrix
glMatrixMode(GL_PROJECTION);
// set it to the matrix-equivalent of 1
glLoadIdentity();
// determine the aspect ratio of the screen
float aspectRatio = m_screenWidth/(float)m_screenHeight;
// create a viewing frustum based on the aspect ratio and the
// boundaries of the camera
glFrustum(-aspectRatio * m_nearPlane, aspectRatio * m_nearPlane, -m_nearPlane, m_nearPlane, m_nearPlane, m_farPlane);
// the projection matrix is now set
}
Und das ist meine SetupModelView():
void CameraManager::SetupModelView() {
// select the view matrix
glMatrixMode(GL_MODELVIEW);
// set it to '1'
glLoadIdentity();
// our values represent the angles in degrees, but 3D
// math typically demands angular values are in radians.
float pitch = m_cameraPitch * RADIANS_PER_DEGREE;
float yaw = m_cameraYaw * RADIANS_PER_DEGREE;
// create a quaternion defining the angular rotation
// around the up vector
btQuaternion rotation(m_upVector, yaw);
// set the camera's position to 0,0,0, then move the 'z'
// position to the current value of m_cameraDistance.
btVector3 cameraPosition(0, 0, 0);
cameraPosition[2] = -m_cameraDistance;
// create a Bullet Vector3 to represent the camera
// position and scale it up if its value is too small.
btVector3 forward(cameraPosition[0], cameraPosition[1], cameraPosition[2]);
if (forward.length2() < SIMD_EPSILON) {
forward.setValue(1.f, 0.f, 0.f);
}
// figure out the 'right' vector by using the cross
// product on the 'forward' and 'up' vectors
btVector3 right = m_upVector.cross(forward);
// create a quaternion that represents the camera's roll
btQuaternion roll(right, -pitch);
// turn the rotation (around the Y-axis) and roll (around
// the forward axis) into transformation matrices and
// apply them to the camera position. This gives us the
// final position
cameraPosition = btMatrix3x3(rotation) * btMatrix3x3(roll) * cameraPosition;
// save our new position in the member variable, and
// shift it relative to the target position (so that we
// orbit it)
m_cameraPosition[0] = cameraPosition.getX();
m_cameraPosition[1] = cameraPosition.getY();
m_cameraPosition[2] = cameraPosition.getZ();
m_cameraPosition += m_cameraTarget;
// create a view matrix based on the camera's position and where it's
// looking
//printf("Camera Position = %f, %f, %f\n", cameraPosition[0], cameraPosition[1], cameraPosition[2]);
// the view matrix is now set
gluLookAt(m_cameraPosition[0], m_cameraPosition[1], m_cameraPosition[2], m_cameraTarget[0], m_cameraTarget[1], m_cameraTarget[2], m_upVector.getX(), m_upVector.getY(), m_upVector.getZ());
}
Ich bin mir nicht sicher, was ich vermisse.
Seien Sie sich bewusst, dass das Objekt eine sehr unterschiedliche Größe in der Perspektive und orthografischen Darstellungen hat, es sei denn, Sie die Grenzen sehr sorgfältig gewählt. Es kann einfach sein, dass das Objekt nicht auf dem Bildschirm ist (weil alles wirklich groß ist) oder so winzig, dass man es nicht sehen kann (weil alles wirklich klein ist). Ich bemerke, dass Ihre Kamera nicht direkt auf das Objekt zeigt, weil die Mitte des Bildschirms (in der perspektivischen Darstellung) blau und nicht grün ist. – immibis