adjusts formatting to agreed conventions

This commit is contained in:
tosh 2013-04-05 01:24:00 +02:00
parent 284530f7d6
commit 31262340d4
2 changed files with 114 additions and 121 deletions

View file

@ -15,95 +15,93 @@
using namespace glm; using namespace glm;
FieldOfView::FieldOfView() FieldOfView::FieldOfView() :
: mat_orientation(mat4(1.0f)), _matOrientation(mat4(1.0f)),
vec_bounds_low(vec3(-1.0f,-1.0f,-1.0f)), _vecBoundsLow(vec3(-1.0f,-1.0f,-1.0f)),
vec_bounds_high(vec3(1.0f,1.0f,1.0f)), _vecBoundsHigh(vec3(1.0f,1.0f,1.0f)),
val_width(256.0f), _valWidth(256.0f),
val_height(256.0f), _valHeight(256.0f),
val_angle(0.61), _valAngle(0.61),
val_zoom(1.0f), _valZoom(1.0f),
enm_aspect_balancing(expose_less) _enmAspectBalancing(expose_less) {
{
} }
mat4 FieldOfView::getViewerScreenXform() const mat4 FieldOfView::getViewerScreenXform() const {
{
mat4 projection; mat4 projection;
vec3 low, high; vec3 low, high;
getFrustum(low, high); getFrustum(low, high);
// perspective projection? determine correct near distance // perspective projection? determine correct near distance
if (val_angle != 0.0f) if (_valAngle != 0.0f) {
{
projection = translate( projection = translate(
frustum(low.x, high.x, low.y, high.y, low.z, high.z), frustum(low.x, high.x, low.y, high.y, low.z, high.z),
vec3(0.f, 0.f, -low.z) ); vec3(0.f, 0.f, -low.z) );
} } else {
else
{
projection = ortho(low.x, high.x, low.y, high.y, low.z, high.z); projection = ortho(low.x, high.x, low.y, high.y, low.z, high.z);
} }
return projection; return projection;
} }
mat4 FieldOfView::getWorldViewerXform() const mat4 FieldOfView::getWorldViewerXform() const {
{
return translate(affineInverse(mat_orientation), return translate(affineInverse(_matOrientation),
vec3(0.0f, 0.0f, -vec_bounds_high.z) ); vec3(0.0f, 0.0f, -_vecBoundsHigh.z) );
} }
mat4 FieldOfView::getWorldScreenXform() const mat4 FieldOfView::getWorldScreenXform() const {
{
return translate( return translate(
getViewerScreenXform() * affineInverse(mat_orientation), getViewerScreenXform() * affineInverse(_matOrientation),
vec3(0.0f, 0.0f, -vec_bounds_high.z) ); vec3(0.0f, 0.0f, -_vecBoundsHigh.z) );
} }
mat4 FieldOfView::getViewerWorldXform() const mat4 FieldOfView::getViewerWorldXform() const {
{
vec3 n_translate = vec3(0.0f, 0.0f, vec_bounds_high.z); vec3 n_translate = vec3(0.0f, 0.0f, _vecBoundsHigh.z);
return translate( return translate(
translate(mat4(1.0f), n_translate) translate(mat4(1.0f), n_translate)
* mat_orientation, -n_translate ); * _matOrientation, -n_translate );
} }
float FieldOfView::getPixelSize() const float FieldOfView::getPixelSize() const {
{
vec3 low, high; vec3 low, high;
getFrustum(low, high); getFrustum(low, high);
return std::min( return std::min(
abs(high.x - low.x) / val_width, abs(high.x - low.x) / _valWidth,
abs(high.y - low.y) / val_height); abs(high.y - low.y) / _valHeight);
} }
void FieldOfView::getFrustum(vec3& low, vec3& high) const void FieldOfView::getFrustum(vec3& low, vec3& high) const {
{
low = vec_bounds_low; low = _vecBoundsLow;
high = vec_bounds_high; high = _vecBoundsHigh;
// start with uniform zoom // start with uniform zoom
float inv_zoom = 1.0f / val_zoom; float inv_zoom = 1.0f / _valZoom;
float adj_x = inv_zoom, adj_y = inv_zoom; float adj_x = inv_zoom, adj_y = inv_zoom;
// balance aspect // balance aspect
if (enm_aspect_balancing != stretch) if (_enmAspectBalancing != stretch) {
{
float f_aspect = (high.x - low.x) / (high.y - low.y); float f_aspect = (high.x - low.x) / (high.y - low.y);
float vp_aspect = val_width / val_height; float vp_aspect = _valWidth / _valHeight;
if ((_enmAspectBalancing == expose_more)
!= (f_aspect > vp_aspect)) {
if ((enm_aspect_balancing == expose_more)
!= (f_aspect > vp_aspect))
{
// expose_more -> f_aspect <= vp_aspect <=> adj >= 1 // expose_more -> f_aspect <= vp_aspect <=> adj >= 1
// expose_less -> f_aspect > vp_aspect <=> adj < 1 // expose_less -> f_aspect > vp_aspect <=> adj < 1
adj_x = vp_aspect / f_aspect; adj_x = vp_aspect / f_aspect;
}
else } else {
{
// expose_more -> f_aspect > vp_aspect <=> adj > 1 // expose_more -> f_aspect > vp_aspect <=> adj > 1
// expose_less -> f_aspect <= vp_aspect <=> adj <= 1 // expose_less -> f_aspect <= vp_aspect <=> adj <= 1
adj_y = f_aspect / vp_aspect; adj_y = f_aspect / vp_aspect;
@ -121,8 +119,8 @@ void FieldOfView::getFrustum(vec3& low, vec3& high) const
// calc and apply near distance based on near diagonal and perspective // calc and apply near distance based on near diagonal and perspective
float w = high.x - low.x, h = high.y - low.y; float w = high.x - low.x, h = high.y - low.y;
high.z -= low.z; high.z -= low.z;
low.z = val_angle == 0.0f ? 0.0f : low.z = _valAngle == 0.0f ? 0.0f :
sqrt(w*w+h*h) * 0.5f / tan(val_angle * 0.5f); sqrt(w*w+h*h) * 0.5f / tan(_valAngle * 0.5f);
high.z += low.z; high.z += low.z;
} }

View file

@ -11,39 +11,35 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
/** //
* Viewing parameter encapsulation. // Viewing parameter encapsulation.
*/ //
class FieldOfView class FieldOfView {
{
glm::mat4 mat_orientation; glm::mat4 _matOrientation;
glm::vec3 vec_bounds_low; glm::vec3 _vecBoundsLow;
glm::vec3 vec_bounds_high; glm::vec3 _vecBoundsHigh;
float val_width; float _valWidth;
float val_height; float _valHeight;
float val_angle; float _valAngle;
float val_zoom; float _valZoom;
int enm_aspect_balancing; int _enmAspectBalancing;
public: public:
FieldOfView(); FieldOfView();
// mutators // mutators
FieldOfView& setBounds(glm::vec3 const& low, glm::vec3 const& high) FieldOfView& setBounds(glm::vec3 const& low, glm::vec3 const& high) {
{ vec_bounds_low = low; vec_bounds_high = high; return *this; } _vecBoundsLow = low; _vecBoundsHigh = high; return *this; }
FieldOfView& setOrientation(glm::mat4 const& matrix) FieldOfView& setOrientation(glm::mat4 const& matrix) { _matOrientation = matrix; return *this; }
{ mat_orientation = matrix; return *this; }
FieldOfView& setPerspective(float angle) FieldOfView& setPerspective(float angle) { _valAngle = angle; return *this; }
{ val_angle = angle; return *this; }
FieldOfView& setResolution(unsigned width, unsigned height) FieldOfView& setResolution(unsigned width, unsigned height) { _valWidth = width; _valHeight = height; return *this; }
{ val_width = width; val_height = height; return *this; }
FieldOfView& setZoom(float factor) FieldOfView& setZoom(float factor) { _valZoom = factor; return *this; }
{ val_zoom = factor; return *this; }
enum aspect_balancing enum aspect_balancing
{ {
@ -52,76 +48,75 @@ class FieldOfView
stretch stretch
}; };
FieldOfView& setAspectBalancing(aspect_balancing v) FieldOfView& setAspectBalancing(aspect_balancing v) { _enmAspectBalancing = v; return *this; }
{ enm_aspect_balancing = v; return *this; }
// dumb accessors // dumb accessors
glm::mat4 const& getOrientation() const { return mat_orientation; } glm::mat4 const& getOrientation() const { return _matOrientation; }
float getWidthInPixels() const { return val_width; } float getWidthInPixels() const { return _valWidth; }
float getHeightInPixels() const { return val_height; } float getHeightInPixels() const { return _valHeight; }
float getPerspective() const { return val_angle; } float getPerspective() const { return _valAngle; }
// matrices // matrices
/** //
* Returns a full transformation matrix to project world coordinates // Returns a full transformation matrix to project world coordinates
* onto the screen. // onto the screen.
*/ //
glm::mat4 getWorldScreenXform() const; glm::mat4 getWorldScreenXform() const;
/** //
* Transforms world coordinates to viewer-relative coordinates. // Transforms world coordinates to viewer-relative coordinates.
* //
* This matrix can be used as the modelview matrix in legacy GL code // This matrix can be used as the modelview matrix in legacy GL code
* where the projection matrix is kept separately. // where the projection matrix is kept separately.
*/ //
glm::mat4 getWorldViewerXform() const; glm::mat4 getWorldViewerXform() const;
/** //
* Returns the transformation to of viewer-relative coordinates back // Returns the transformation to of viewer-relative coordinates back
* to world space. // to world space.
* //
* This matrix can be used to set up a coordinate system for avatar // This matrix can be used to set up a coordinate system for avatar
* rendering. // rendering.
*/ //
glm::mat4 getViewerWorldXform() const; glm::mat4 getViewerWorldXform() const;
/** //
* Returns the transformation of viewer-relative coordinates to the // Returns the transformation of viewer-relative coordinates to the
* screen. // screen.
* //
* This matrix can be used as the projection matrix in legacy GL code. // This matrix can be used as the projection matrix in legacy GL code.
*/ //
glm::mat4 getViewerScreenXform() const; glm::mat4 getViewerScreenXform() const;
// other useful information // other useful information
/** //
* Returns the size of a pixel in world space, that is the minimum // Returns the size of a pixel in world space, that is the minimum
* in respect to x/y screen directions. // in respect to x/y screen directions.
*/ //
float getPixelSize() const; float getPixelSize() const;
/** //
* Returns the frustum as used for the projection matrices. // Returns the frustum as used for the projection matrices.
* The result depdends on the bounds, eventually aspect correction // The result depdends on the bounds, eventually aspect correction
* for the current resolution, the perspective angle (specified in // for the current resolution, the perspective angle (specified in
* respect to diagonal) and zoom. // respect to diagonal) and zoom.
*/ //
void getFrustum(glm::vec3& low, glm::vec3& high) const; void getFrustum(glm::vec3& low, glm::vec3& high) const;
/** //
* Returns the z-offset from the origin to where orientation ia // Returns the z-offset from the origin to where orientation ia
* applied. // applied.
*/ //
float getTransformOffset() const { return vec_bounds_high.z; } float getTransformOffset() const { return _vecBoundsHigh.z; }
/** //
* Returns the aspect ratio. // Returns the aspect ratio.
*/ //
float getAspectRatio() const { return val_height / val_width; } float getAspectRatio() const { return _valHeight / _valWidth; }
}; };
#endif #endif