simplified frustum camera mode, fixed resizeGL in case of frustum being on

This commit is contained in:
ZappoMan 2013-08-07 14:47:36 -07:00
parent a9ee3be0d0
commit d2d8bad241
3 changed files with 26 additions and 22 deletions

View file

@ -439,7 +439,7 @@ void Application::paintGL() {
// myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera
Camera whichCamera = _myCamera; Camera whichCamera = _myCamera;
if (_viewFrustumFromOffset->isChecked() && _frustumOn->isChecked()) { if (_frustumOn->isChecked()) {
// set the camera to third-person view but offset so we can see the frustum // set the camera to third-person view but offset so we can see the frustum
_viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition()); _viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition());
@ -467,32 +467,42 @@ void Application::paintGL() {
_frameCount++; _frameCount++;
} }
void Application::resizeGL(int width, int height) { void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) {
float aspectRatio = ((float)width/(float)height); // based on screen resize float aspectRatio = ((float)width/(float)height); // based on screen resize
// reset the camera FOV to our preference... // reset the camera FOV to our preference...
_myCamera.setFieldOfView(_horizontalFieldOfView); camera.setFieldOfView(_horizontalFieldOfView);
// get the lens details from the current camera
Camera& camera = _viewFrustumFromOffset->isChecked() ? _viewFrustumOffsetCamera : _myCamera;
float nearClip = camera.getNearClip();
float farClip = camera.getFarClip();
float fov;
if (OculusManager::isConnected()) { if (OculusManager::isConnected()) {
// more magic numbers; see Oculus SDK docs, p. 32 // more magic numbers; see Oculus SDK docs, p. 32
camera.setAspectRatio(aspectRatio *= 0.5); camera.setAspectRatio(aspectRatio *= 0.5);
camera.setFieldOfView(fov = 2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); camera.setFieldOfView(2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf));
} else {
camera.setAspectRatio(aspectRatio);
camera.setFieldOfView(_horizontalFieldOfView);
}
}
void Application::resizeGL(int width, int height) {
// tell both cameras about our new size
resetCamerasOnResizeGL(_myCamera, width, height);
resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height);
float aspectRatio = ((float)width/(float)height); // based on screen resize
// get the lens details from the current camera
Camera& camera = _frustumOn->isChecked() ? _viewFrustumOffsetCamera : _myCamera;
float nearClip = camera.getNearClip();
float farClip = camera.getFarClip();
if (OculusManager::isConnected()) {
// resize the render texture // resize the render texture
if (_oculusTextureID != 0) { if (_oculusTextureID != 0) {
glBindTexture(GL_TEXTURE_2D, _oculusTextureID); glBindTexture(GL_TEXTURE_2D, _oculusTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} }
} else {
camera.setAspectRatio(aspectRatio);
camera.setFieldOfView(fov = _horizontalFieldOfView);
} }
// Tell our viewFrustum about this change // Tell our viewFrustum about this change
@ -819,11 +829,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
_colorVoxelMode->trigger(); _colorVoxelMode->trigger();
break; break;
case Qt::Key_O: case Qt::Key_O:
if (isShifted) {
_viewFrustumFromOffset->trigger();
} else {
_selectVoxelMode->trigger(); _selectVoxelMode->trigger();
}
break; break;
case Qt::Key_Slash: case Qt::Key_Slash:
_renderStatsOn->trigger(); _renderStatsOn->trigger();
@ -2060,8 +2066,6 @@ void Application::initMenu() {
QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools"); QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools");
(_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);
_frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F); _frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F);
(_viewFrustumFromOffset = frustumMenu->addAction(
"Use Offset Camera", this, SLOT(setFrustumOffset(bool)), Qt::SHIFT | Qt::Key_O))->setCheckable(true);
_frustumRenderModeAction = frustumMenu->addAction( _frustumRenderModeAction = frustumMenu->addAction(
"Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R); "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R);
updateFrustumRenderModeAction(); updateFrustumRenderModeAction();

View file

@ -211,6 +211,7 @@ private slots:
void toggleFollowMode(); void toggleFollowMode();
private: private:
void resetCamerasOnResizeGL(Camera& camera, int width, int height);
static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes,
const char* nodeTypes, int numNodeTypes); const char* nodeTypes, int numNodeTypes);

View file

@ -38,7 +38,6 @@ Camera::Camera() {
_mode = CAMERA_MODE_THIRD_PERSON; _mode = CAMERA_MODE_THIRD_PERSON;
_tightness = 10.0f; // default _tightness = 10.0f; // default
_fieldOfView = HORIZONTAL_FIELD_OF_VIEW_DEGREES; _fieldOfView = HORIZONTAL_FIELD_OF_VIEW_DEGREES;
_aspectRatio = 16.f/9.f;
_nearClip = 0.08f; // default _nearClip = 0.08f; // default
_farClip = 50.0f * TREE_SCALE; // default _farClip = 50.0f * TREE_SCALE; // default
_upShift = 0.0f; _upShift = 0.0f;