mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:12:53 +02:00
makes FieldOfView store the view matrix instead of its inverse
This commit is contained in:
parent
7c2cff824f
commit
77832dbcb4
2 changed files with 45 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
//
|
//
|
||||||
// FieldOfView.cpp
|
// FieldOfView.cpp
|
||||||
// interface
|
// hifi
|
||||||
//
|
//
|
||||||
// Created by Tobias Schwinger on 3/21/13.
|
// Created by Tobias Schwinger on 3/21/13.
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
FieldOfView::FieldOfView() :
|
FieldOfView::FieldOfView() :
|
||||||
_matOrientation(mat4(1.0f)),
|
_matView(mat4(1.0f)),
|
||||||
_vecBoundsLow(vec3(-1.0f,-1.0f,-1.0f)),
|
_vecBoundsLow(vec3(-1.0f,-1.0f,-1.0f)),
|
||||||
_vecBoundsHigh(vec3(1.0f,1.0f,1.0f)),
|
_vecBoundsHigh(vec3(1.0f,1.0f,1.0f)),
|
||||||
_valWidth(256.0f),
|
_valWidth(256.0f),
|
||||||
|
@ -26,6 +26,17 @@ FieldOfView::FieldOfView() :
|
||||||
_enmAspectBalancing(expose_less) {
|
_enmAspectBalancing(expose_less) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FieldOfView& FieldOfView::setOrientation(mat4 const& matrix) {
|
||||||
|
|
||||||
|
_matView = affineInverse(matrix);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
mat4 FieldOfView::getOrientation() const {
|
||||||
|
|
||||||
|
return affineInverse(_matView);
|
||||||
|
}
|
||||||
|
|
||||||
mat4 FieldOfView::getViewerScreenXform() const {
|
mat4 FieldOfView::getViewerScreenXform() const {
|
||||||
|
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
|
@ -48,14 +59,14 @@ mat4 FieldOfView::getViewerScreenXform() const {
|
||||||
|
|
||||||
mat4 FieldOfView::getWorldViewerXform() const {
|
mat4 FieldOfView::getWorldViewerXform() const {
|
||||||
|
|
||||||
return translate(affineInverse(_matOrientation),
|
return translate(_matView,
|
||||||
vec3(0.0f, 0.0f, -_vecBoundsHigh.z) );
|
vec3(0.0f, 0.0f, -_vecBoundsHigh.z) );
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 FieldOfView::getWorldScreenXform() const {
|
mat4 FieldOfView::getWorldScreenXform() const {
|
||||||
|
|
||||||
return translate(
|
return translate(
|
||||||
getViewerScreenXform() * affineInverse(_matOrientation),
|
getViewerScreenXform() * _matView,
|
||||||
vec3(0.0f, 0.0f, -_vecBoundsHigh.z) );
|
vec3(0.0f, 0.0f, -_vecBoundsHigh.z) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +76,7 @@ mat4 FieldOfView::getViewerWorldXform() const {
|
||||||
|
|
||||||
return translate(
|
return translate(
|
||||||
translate(mat4(1.0f), n_translate)
|
translate(mat4(1.0f), n_translate)
|
||||||
* _matOrientation, -n_translate );
|
* affineInverse(_matView), -n_translate );
|
||||||
}
|
}
|
||||||
|
|
||||||
float FieldOfView::getPixelSize() const {
|
float FieldOfView::getPixelSize() const {
|
||||||
|
|
|
@ -1,22 +1,30 @@
|
||||||
//
|
//
|
||||||
// FieldOfView.h
|
// FieldOfView.h
|
||||||
// interface
|
// hifi
|
||||||
//
|
//
|
||||||
// Created by Tobias Schwinger on 3/21/13.
|
// Created by Tobias Schwinger on 3/21/13.
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef __interface__FieldOfView__
|
#ifndef __hifi__FieldOfView__
|
||||||
#define __interface__FieldOfView__
|
#define __hifi__FieldOfView__
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
//
|
//
|
||||||
// Viewing parameter encapsulation.
|
// Viewing parameter encapsulation.
|
||||||
//
|
//
|
||||||
|
// Once configured provides transformation matrices between different coordinate spaces, such as
|
||||||
|
//
|
||||||
|
// o world space,
|
||||||
|
// o viewer space (orientation of local viewer, no projective transforms), and
|
||||||
|
// o screen space (as Viewer space + projection).
|
||||||
|
//
|
||||||
|
// Also provides information about the mapping of the screen space coordinates onto the screen.
|
||||||
|
//
|
||||||
class FieldOfView {
|
class FieldOfView {
|
||||||
|
|
||||||
glm::mat4 _matOrientation;
|
glm::mat4 _matView;
|
||||||
glm::vec3 _vecBoundsLow;
|
glm::vec3 _vecBoundsLow;
|
||||||
glm::vec3 _vecBoundsHigh;
|
glm::vec3 _vecBoundsHigh;
|
||||||
float _valWidth;
|
float _valWidth;
|
||||||
|
@ -33,7 +41,9 @@ class FieldOfView {
|
||||||
FieldOfView& setBounds(glm::vec3 const& low, glm::vec3 const& high) {
|
FieldOfView& setBounds(glm::vec3 const& low, glm::vec3 const& high) {
|
||||||
_vecBoundsLow = low; _vecBoundsHigh = high; return *this; }
|
_vecBoundsLow = low; _vecBoundsHigh = high; return *this; }
|
||||||
|
|
||||||
FieldOfView& setOrientation(glm::mat4 const& matrix) { _matOrientation = matrix; return *this; }
|
FieldOfView& setView(glm::mat4 const& matrix) { _matView = matrix; return *this; }
|
||||||
|
|
||||||
|
FieldOfView& setOrientation(glm::mat4 const& matrix);
|
||||||
|
|
||||||
FieldOfView& setPerspective(float angle) { _valAngle = angle; return *this; }
|
FieldOfView& setPerspective(float angle) { _valAngle = angle; return *this; }
|
||||||
|
|
||||||
|
@ -52,13 +62,20 @@ class FieldOfView {
|
||||||
|
|
||||||
// dumb accessors
|
// dumb accessors
|
||||||
|
|
||||||
glm::mat4 const& getOrientation() const { return _matOrientation; }
|
glm::mat4 const& getView() const { return _matView; }
|
||||||
float getWidthInPixels() const { return _valWidth; }
|
float getWidthInPixels() const { return _valWidth; }
|
||||||
float getHeightInPixels() const { return _valHeight; }
|
float getHeightInPixels() const { return _valHeight; }
|
||||||
float getPerspective() const { return _valAngle; }
|
float getPerspective() const { return _valAngle; }
|
||||||
|
|
||||||
// matrices
|
// matrices
|
||||||
|
|
||||||
|
//
|
||||||
|
// Returns a matrix representing the camera position and rotation in
|
||||||
|
// space. Similar to getViewerWorldXform but without translation offset
|
||||||
|
// applied.
|
||||||
|
//
|
||||||
|
glm::mat4 getOrientation() const;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Returns a full transformation matrix to project world coordinates
|
// Returns a full transformation matrix to project world coordinates
|
||||||
// onto the screen.
|
// onto the screen.
|
||||||
|
@ -100,7 +117,8 @@ class FieldOfView {
|
||||||
float getPixelSize() const;
|
float getPixelSize() const;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Returns the frustum as used for the projection matrices.
|
// Returns the frustum as used for the projection matrices. That
|
||||||
|
// is the one that applies when the current orientation is at identity.
|
||||||
// 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.
|
||||||
|
@ -109,7 +127,8 @@ class FieldOfView {
|
||||||
|
|
||||||
//
|
//
|
||||||
// Returns the z-offset from the origin to where orientation ia
|
// Returns the z-offset from the origin to where orientation ia
|
||||||
// applied.
|
// applied (in negated form equivalent to the 'near' parameter of
|
||||||
|
// gluPerspective).
|
||||||
//
|
//
|
||||||
float getTransformOffset() const { return _vecBoundsHigh.z; }
|
float getTransformOffset() const { return _vecBoundsHigh.z; }
|
||||||
|
|
||||||
|
@ -119,5 +138,5 @@ class FieldOfView {
|
||||||
float getAspectRatio() const { return _valHeight / _valWidth; }
|
float getAspectRatio() const { return _valHeight / _valWidth; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /* defined(__hifi__FieldOfView__) */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue