[Orxonox-commit 3299] r7988 - code/branches/usability/src/orxonox/graphics
landauf at orxonox.net
landauf at orxonox.net
Sun Feb 27 12:48:50 CET 2011
Author: landauf
Date: 2011-02-27 12:48:50 +0100 (Sun, 27 Feb 2011)
New Revision: 7988
Modified:
code/branches/usability/src/orxonox/graphics/Camera.cc
code/branches/usability/src/orxonox/graphics/Camera.h
Log:
- FOV and pixel aspect ratio are now configurable
- aspect ratio and FOV of the camera are automatically adjusted if the window is resized (note: hud and gui still scale with the window which is fine I guess)
- the config value for FOV defines FOVx which is more convenient than FOVy
- default FOVx is now 80 degree (it was ~57.5 degree before, so the field of view is now much larger and the ship seems more distant).
Modified: code/branches/usability/src/orxonox/graphics/Camera.cc
===================================================================
--- code/branches/usability/src/orxonox/graphics/Camera.cc 2011-02-27 10:32:08 UTC (rev 7987)
+++ code/branches/usability/src/orxonox/graphics/Camera.cc 2011-02-27 11:48:50 UTC (rev 7988)
@@ -68,12 +68,13 @@
this->bHasFocus_ = false;
this->bDrag_ = false;
- this->nearClipDistance_ = 1;
this->lastDtLagged_ = false;
this->setSyncMode(0x0);
this->setConfigValues();
+
+ this->configvaluecallback_changedFovAndAspectRatio();
this->configvaluecallback_changedNearClipDistance();
}
@@ -96,14 +97,44 @@
void Camera::setConfigValues()
{
- SetConfigValue(nearClipDistance_, 1.0f).callback(this, &Camera::configvaluecallback_changedNearClipDistance);
+ SetConfigValue(fov_, 80.0f)
+ .description("Horizontal field of view in degrees")
+ .callback(this, &Camera::configvaluecallback_changedFovAndAspectRatio);
+ SetConfigValue(aspectRatio_, 1.0f)
+ .description("Aspect ratio of pixels (width / height)")
+ .callback(this, &Camera::configvaluecallback_changedFovAndAspectRatio);
+ SetConfigValue(nearClipDistance_, 1.0f)
+ .description("Distance from the camera where close objects will be clipped")
+ .callback(this, &Camera::configvaluecallback_changedNearClipDistance);
}
+ /**
+ @brief Update FOV and the aspect ratio of the camera after the config values or the window's size have changed.
+ */
+ void Camera::configvaluecallback_changedFovAndAspectRatio()
+ {
+ // the aspect ratio of the window (width / height) has to be multiplied with the pixels aspect ratio (this->aspectRatio_)
+ float aspectRatio = this->aspectRatio_ * this->getWindowWidth() / this->getWindowHeight();
+ this->camera_->setAspectRatio(aspectRatio);
+
+ // Since we use horizontal FOV, we have to calculate FOVy by dividing by the aspect ratio and using some tangents
+ Radian fovy(2 * atan(tan(Degree(this->fov_).valueRadians() / 2) / aspectRatio));
+ this->camera_->setFOVy(fovy);
+ }
+
void Camera::configvaluecallback_changedNearClipDistance()
{
this->camera_->setNearClipDistance(this->nearClipDistance_);
}
+ /**
+ @brief Inherited from WindowEventListener.
+ */
+ void Camera::windowResized(unsigned int newWidth, unsigned int newHeight)
+ {
+ this->configvaluecallback_changedFovAndAspectRatio();
+ }
+
void Camera::tick(float dt)
{
SUPER(Camera, tick, dt);
Modified: code/branches/usability/src/orxonox/graphics/Camera.h
===================================================================
--- code/branches/usability/src/orxonox/graphics/Camera.h 2011-02-27 10:32:08 UTC (rev 7987)
+++ code/branches/usability/src/orxonox/graphics/Camera.h 2011-02-27 11:48:50 UTC (rev 7988)
@@ -32,13 +32,14 @@
#include "OrxonoxPrereqs.h"
#include "util/OgreForwardRefs.h"
+#include "core/WindowEventListener.h"
#include "tools/interfaces/Tickable.h"
#include "tools/interfaces/TimeFactorListener.h"
#include "worldentities/StaticEntity.h"
namespace orxonox
{
- class _OrxonoxExport Camera : public StaticEntity, public Tickable, public TimeFactorListener
+ class _OrxonoxExport Camera : public StaticEntity, public Tickable, public TimeFactorListener, public WindowEventListener
{
friend class CameraManager;
@@ -65,14 +66,20 @@
private:
void removeFocus();
void setFocus();
+
+ void configvaluecallback_changedFovAndAspectRatio();
void configvaluecallback_changedNearClipDistance();
+ void windowResized(unsigned int newWidth, unsigned int newHeight);
+
Ogre::Camera* camera_;
Ogre::SceneNode* cameraNode_;
float nearClipDistance_;
bool bHasFocus_;
bool bDrag_;
bool lastDtLagged_;
+ float fov_;
+ float aspectRatio_;
};
}
More information about the Orxonox-commit
mailing list