mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 17:53:32 +02:00
adjusts formatting to agreed conventions
This commit is contained in:
parent
284530f7d6
commit
31262340d4
2 changed files with 114 additions and 121 deletions
|
@ -15,95 +15,93 @@
|
|||
|
||||
using namespace glm;
|
||||
|
||||
FieldOfView::FieldOfView()
|
||||
: mat_orientation(mat4(1.0f)),
|
||||
vec_bounds_low(vec3(-1.0f,-1.0f,-1.0f)),
|
||||
vec_bounds_high(vec3(1.0f,1.0f,1.0f)),
|
||||
val_width(256.0f),
|
||||
val_height(256.0f),
|
||||
val_angle(0.61),
|
||||
val_zoom(1.0f),
|
||||
enm_aspect_balancing(expose_less)
|
||||
{
|
||||
FieldOfView::FieldOfView() :
|
||||
_matOrientation(mat4(1.0f)),
|
||||
_vecBoundsLow(vec3(-1.0f,-1.0f,-1.0f)),
|
||||
_vecBoundsHigh(vec3(1.0f,1.0f,1.0f)),
|
||||
_valWidth(256.0f),
|
||||
_valHeight(256.0f),
|
||||
_valAngle(0.61),
|
||||
_valZoom(1.0f),
|
||||
_enmAspectBalancing(expose_less) {
|
||||
}
|
||||
|
||||
mat4 FieldOfView::getViewerScreenXform() const
|
||||
{
|
||||
mat4 FieldOfView::getViewerScreenXform() const {
|
||||
|
||||
mat4 projection;
|
||||
vec3 low, high;
|
||||
getFrustum(low, high);
|
||||
|
||||
// perspective projection? determine correct near distance
|
||||
if (val_angle != 0.0f)
|
||||
{
|
||||
if (_valAngle != 0.0f) {
|
||||
|
||||
projection = translate(
|
||||
frustum(low.x, high.x, low.y, high.y, low.z, high.z),
|
||||
vec3(0.f, 0.f, -low.z) );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
|
||||
projection = ortho(low.x, high.x, low.y, high.y, low.z, high.z);
|
||||
}
|
||||
|
||||
return projection;
|
||||
}
|
||||
|
||||
mat4 FieldOfView::getWorldViewerXform() const
|
||||
{
|
||||
return translate(affineInverse(mat_orientation),
|
||||
vec3(0.0f, 0.0f, -vec_bounds_high.z) );
|
||||
mat4 FieldOfView::getWorldViewerXform() const {
|
||||
|
||||
return translate(affineInverse(_matOrientation),
|
||||
vec3(0.0f, 0.0f, -_vecBoundsHigh.z) );
|
||||
}
|
||||
|
||||
mat4 FieldOfView::getWorldScreenXform() const
|
||||
{
|
||||
mat4 FieldOfView::getWorldScreenXform() const {
|
||||
|
||||
return translate(
|
||||
getViewerScreenXform() * affineInverse(mat_orientation),
|
||||
vec3(0.0f, 0.0f, -vec_bounds_high.z) );
|
||||
getViewerScreenXform() * affineInverse(_matOrientation),
|
||||
vec3(0.0f, 0.0f, -_vecBoundsHigh.z) );
|
||||
}
|
||||
|
||||
mat4 FieldOfView::getViewerWorldXform() const
|
||||
{
|
||||
vec3 n_translate = vec3(0.0f, 0.0f, vec_bounds_high.z);
|
||||
mat4 FieldOfView::getViewerWorldXform() const {
|
||||
|
||||
vec3 n_translate = vec3(0.0f, 0.0f, _vecBoundsHigh.z);
|
||||
|
||||
return 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;
|
||||
getFrustum(low, high);
|
||||
|
||||
return std::min(
|
||||
abs(high.x - low.x) / val_width,
|
||||
abs(high.y - low.y) / val_height);
|
||||
abs(high.x - low.x) / _valWidth,
|
||||
abs(high.y - low.y) / _valHeight);
|
||||
}
|
||||
|
||||
void FieldOfView::getFrustum(vec3& low, vec3& high) const
|
||||
{
|
||||
low = vec_bounds_low;
|
||||
high = vec_bounds_high;
|
||||
void FieldOfView::getFrustum(vec3& low, vec3& high) const {
|
||||
|
||||
low = _vecBoundsLow;
|
||||
high = _vecBoundsHigh;
|
||||
|
||||
// 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;
|
||||
|
||||
// balance aspect
|
||||
if (enm_aspect_balancing != stretch)
|
||||
{
|
||||
float f_aspect = (high.x - low.x) / (high.y - low.y);
|
||||
float vp_aspect = val_width / val_height;
|
||||
if (_enmAspectBalancing != stretch) {
|
||||
|
||||
float f_aspect = (high.x - low.x) / (high.y - low.y);
|
||||
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_less -> f_aspect > vp_aspect <=> adj < 1
|
||||
adj_x = vp_aspect / f_aspect;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
} else {
|
||||
|
||||
// expose_more -> f_aspect > vp_aspect <=> adj > 1
|
||||
// expose_less -> f_aspect <= vp_aspect <=> adj <= 1
|
||||
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
|
||||
float w = high.x - low.x, h = high.y - low.y;
|
||||
high.z -= low.z;
|
||||
low.z = val_angle == 0.0f ? 0.0f :
|
||||
sqrt(w*w+h*h) * 0.5f / tan(val_angle * 0.5f);
|
||||
low.z = _valAngle == 0.0f ? 0.0f :
|
||||
sqrt(w*w+h*h) * 0.5f / tan(_valAngle * 0.5f);
|
||||
high.z += low.z;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,39 +11,35 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
/**
|
||||
* Viewing parameter encapsulation.
|
||||
*/
|
||||
class FieldOfView
|
||||
{
|
||||
glm::mat4 mat_orientation;
|
||||
glm::vec3 vec_bounds_low;
|
||||
glm::vec3 vec_bounds_high;
|
||||
float val_width;
|
||||
float val_height;
|
||||
float val_angle;
|
||||
float val_zoom;
|
||||
int enm_aspect_balancing;
|
||||
//
|
||||
// Viewing parameter encapsulation.
|
||||
//
|
||||
class FieldOfView {
|
||||
|
||||
glm::mat4 _matOrientation;
|
||||
glm::vec3 _vecBoundsLow;
|
||||
glm::vec3 _vecBoundsHigh;
|
||||
float _valWidth;
|
||||
float _valHeight;
|
||||
float _valAngle;
|
||||
float _valZoom;
|
||||
int _enmAspectBalancing;
|
||||
public:
|
||||
|
||||
FieldOfView();
|
||||
|
||||
// mutators
|
||||
|
||||
FieldOfView& setBounds(glm::vec3 const& low, glm::vec3 const& high)
|
||||
{ vec_bounds_low = low; vec_bounds_high = high; return *this; }
|
||||
FieldOfView& setBounds(glm::vec3 const& low, glm::vec3 const& high) {
|
||||
_vecBoundsLow = low; _vecBoundsHigh = high; return *this; }
|
||||
|
||||
FieldOfView& setOrientation(glm::mat4 const& matrix)
|
||||
{ mat_orientation = matrix; return *this; }
|
||||
FieldOfView& setOrientation(glm::mat4 const& matrix) { _matOrientation = matrix; return *this; }
|
||||
|
||||
FieldOfView& setPerspective(float angle)
|
||||
{ val_angle = angle; return *this; }
|
||||
FieldOfView& setPerspective(float angle) { _valAngle = angle; return *this; }
|
||||
|
||||
FieldOfView& setResolution(unsigned width, unsigned height)
|
||||
{ val_width = width; val_height = height; return *this; }
|
||||
FieldOfView& setResolution(unsigned width, unsigned height) { _valWidth = width; _valHeight = height; return *this; }
|
||||
|
||||
FieldOfView& setZoom(float factor)
|
||||
{ val_zoom = factor; return *this; }
|
||||
FieldOfView& setZoom(float factor) { _valZoom = factor; return *this; }
|
||||
|
||||
enum aspect_balancing
|
||||
{
|
||||
|
@ -52,76 +48,75 @@ class FieldOfView
|
|||
stretch
|
||||
};
|
||||
|
||||
FieldOfView& setAspectBalancing(aspect_balancing v)
|
||||
{ enm_aspect_balancing = v; return *this; }
|
||||
FieldOfView& setAspectBalancing(aspect_balancing v) { _enmAspectBalancing = v; return *this; }
|
||||
|
||||
// dumb accessors
|
||||
|
||||
glm::mat4 const& getOrientation() const { return mat_orientation; }
|
||||
float getWidthInPixels() const { return val_width; }
|
||||
float getHeightInPixels() const { return val_height; }
|
||||
float getPerspective() const { return val_angle; }
|
||||
glm::mat4 const& getOrientation() const { return _matOrientation; }
|
||||
float getWidthInPixels() const { return _valWidth; }
|
||||
float getHeightInPixels() const { return _valHeight; }
|
||||
float getPerspective() const { return _valAngle; }
|
||||
|
||||
// matrices
|
||||
|
||||
/**
|
||||
* Returns a full transformation matrix to project world coordinates
|
||||
* onto the screen.
|
||||
*/
|
||||
//
|
||||
// Returns a full transformation matrix to project world coordinates
|
||||
// onto the screen.
|
||||
//
|
||||
glm::mat4 getWorldScreenXform() const;
|
||||
|
||||
/**
|
||||
* Transforms world coordinates to viewer-relative coordinates.
|
||||
*
|
||||
* This matrix can be used as the modelview matrix in legacy GL code
|
||||
* where the projection matrix is kept separately.
|
||||
*/
|
||||
//
|
||||
// Transforms world coordinates to viewer-relative coordinates.
|
||||
//
|
||||
// This matrix can be used as the modelview matrix in legacy GL code
|
||||
// where the projection matrix is kept separately.
|
||||
//
|
||||
glm::mat4 getWorldViewerXform() const;
|
||||
|
||||
/**
|
||||
* Returns the transformation to of viewer-relative coordinates back
|
||||
* to world space.
|
||||
*
|
||||
* This matrix can be used to set up a coordinate system for avatar
|
||||
* rendering.
|
||||
*/
|
||||
//
|
||||
// Returns the transformation to of viewer-relative coordinates back
|
||||
// to world space.
|
||||
//
|
||||
// This matrix can be used to set up a coordinate system for avatar
|
||||
// rendering.
|
||||
//
|
||||
glm::mat4 getViewerWorldXform() const;
|
||||
|
||||
/**
|
||||
* Returns the transformation of viewer-relative coordinates to the
|
||||
* screen.
|
||||
*
|
||||
* This matrix can be used as the projection matrix in legacy GL code.
|
||||
*/
|
||||
//
|
||||
// Returns the transformation of viewer-relative coordinates to the
|
||||
// screen.
|
||||
//
|
||||
// This matrix can be used as the projection matrix in legacy GL code.
|
||||
//
|
||||
glm::mat4 getViewerScreenXform() const;
|
||||
|
||||
|
||||
// other useful information
|
||||
|
||||
/**
|
||||
* Returns the size of a pixel in world space, that is the minimum
|
||||
* in respect to x/y screen directions.
|
||||
*/
|
||||
//
|
||||
// Returns the size of a pixel in world space, that is the minimum
|
||||
// in respect to x/y screen directions.
|
||||
//
|
||||
float getPixelSize() const;
|
||||
|
||||
/**
|
||||
* Returns the frustum as used for the projection matrices.
|
||||
* The result depdends on the bounds, eventually aspect correction
|
||||
* for the current resolution, the perspective angle (specified in
|
||||
* respect to diagonal) and zoom.
|
||||
*/
|
||||
//
|
||||
// Returns the frustum as used for the projection matrices.
|
||||
// The result depdends on the bounds, eventually aspect correction
|
||||
// for the current resolution, the perspective angle (specified in
|
||||
// respect to diagonal) and zoom.
|
||||
//
|
||||
void getFrustum(glm::vec3& low, glm::vec3& high) const;
|
||||
|
||||
/**
|
||||
* Returns the z-offset from the origin to where orientation ia
|
||||
* applied.
|
||||
*/
|
||||
float getTransformOffset() const { return vec_bounds_high.z; }
|
||||
//
|
||||
// Returns the z-offset from the origin to where orientation ia
|
||||
// applied.
|
||||
//
|
||||
float getTransformOffset() const { return _vecBoundsHigh.z; }
|
||||
|
||||
/**
|
||||
* Returns the aspect ratio.
|
||||
*/
|
||||
float getAspectRatio() const { return val_height / val_width; }
|
||||
//
|
||||
// Returns the aspect ratio.
|
||||
//
|
||||
float getAspectRatio() const { return _valHeight / _valWidth; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue