mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-19 10:18:43 +02:00
reorder data members, remove cruft, 744->616 bytes
This commit is contained in:
parent
71b2d647e8
commit
2cbc771eba
2 changed files with 16 additions and 73 deletions
|
@ -54,11 +54,11 @@ static const glm::vec4 NDC_VALUES[NUM_FRUSTUM_CORNERS] = {
|
|||
|
||||
void ViewFrustum::setProjection(const glm::mat4& projection) {
|
||||
_projection = projection;
|
||||
_inverseProjection = glm::inverse(projection);
|
||||
glm::mat4 inverseProjection = glm::inverse(projection);
|
||||
|
||||
// compute our dimensions the usual way
|
||||
for (int i = 0; i < NUM_FRUSTUM_CORNERS; ++i) {
|
||||
_corners[i] = _inverseProjection * NDC_VALUES[i];
|
||||
_corners[i] = inverseProjection * NDC_VALUES[i];
|
||||
_corners[i] /= _corners[i].w;
|
||||
}
|
||||
_nearClip = -_corners[BOTTOM_LEFT_NEAR].z;
|
||||
|
@ -66,12 +66,12 @@ void ViewFrustum::setProjection(const glm::mat4& projection) {
|
|||
_aspectRatio = (_corners[TOP_RIGHT_NEAR].x - _corners[BOTTOM_LEFT_NEAR].x) /
|
||||
(_corners[TOP_RIGHT_NEAR].y - _corners[BOTTOM_LEFT_NEAR].y);
|
||||
|
||||
glm::vec4 top = _inverseProjection * vec4(0.0f, 1.0f, -1.0f, 1.0f);
|
||||
glm::vec4 top = inverseProjection * vec4(0.0f, 1.0f, -1.0f, 1.0f);
|
||||
top /= top.w;
|
||||
_fieldOfView = abs(glm::degrees(2.0f * abs(glm::angle(vec3(0.0f, 0.0f, -1.0f), glm::normalize(vec3(top))))));
|
||||
}
|
||||
|
||||
// ViewFrustum::calculateViewFrustum()
|
||||
// ViewFrustum::calculate()
|
||||
//
|
||||
// Description: this will calculate the view frustum bounds for a given position and direction
|
||||
//
|
||||
|
@ -112,9 +112,6 @@ void ViewFrustum::calculate() {
|
|||
// Projection matrix : Field of View, ratio, display range : near to far
|
||||
glm::vec3 lookAt = _position + _direction;
|
||||
glm::mat4 view = glm::lookAt(_position, lookAt, _up);
|
||||
|
||||
// Our ModelViewProjection : multiplication of our 3 matrices (note: model is identity, so we can drop it)
|
||||
_ourModelViewProjectionMatrix = _projection * view; // Remember, matrix multiplication is the other way around
|
||||
}
|
||||
|
||||
//enum { TOP_PLANE = 0, BOTTOM_PLANE, LEFT_PLANE, RIGHT_PLANE, NEAR_PLANE, FAR_PLANE };
|
||||
|
@ -460,52 +457,3 @@ void ViewFrustum::invalidate() {
|
|||
}
|
||||
_centerSphereRadius = -1.0e6f; // -10^6 should be negative enough
|
||||
}
|
||||
|
||||
/*
|
||||
float calculateRenderAccuracy(const AABox& bounds, float octreeSizeScale, float maxScale, int boundaryLevelAdjust) const {
|
||||
float distanceToCamera = glm::length(bounds.calcCenter() - getPosition());
|
||||
float largestDimension = bounds.getLargestDimension();
|
||||
|
||||
float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, octreeSizeScale) / OCTREE_TO_MESH_RATIO;
|
||||
|
||||
static std::once_flag once;
|
||||
static QMap<float, float> shouldRenderTable;
|
||||
std::call_once(once, [&] {
|
||||
float SMALLEST_SCALE_IN_TABLE = 0.001f; // 1mm is plenty small
|
||||
float scale = maxScale;
|
||||
float factor = 1.0f;
|
||||
|
||||
while (scale > SMALLEST_SCALE_IN_TABLE) {
|
||||
scale /= 2.0f;
|
||||
factor /= 2.0f;
|
||||
shouldRenderTable[scale] = factor;
|
||||
}
|
||||
});
|
||||
|
||||
float closestScale = maxScale;
|
||||
float visibleDistanceAtClosestScale = visibleDistanceAtMaxScale;
|
||||
QMap<float, float>::const_iterator lowerBound = shouldRenderTable.lowerBound(largestDimension);
|
||||
if (lowerBound != shouldRenderTable.constEnd()) {
|
||||
closestScale = lowerBound.key();
|
||||
visibleDistanceAtClosestScale = visibleDistanceAtMaxScale * lowerBound.value();
|
||||
}
|
||||
|
||||
if (closestScale < largestDimension) {
|
||||
visibleDistanceAtClosestScale *= 2.0f;
|
||||
}
|
||||
|
||||
// FIXME - for now, it's either visible or not visible. We want to adjust this to eventually return
|
||||
// a floating point for objects that have small angular size to indicate that they may be rendered
|
||||
// with lower preciscion
|
||||
return (distanceToCamera <= visibleDistanceAtClosestScale) ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
float boundaryDistanceForRenderLevel(unsigned int renderLevel, float voxelSizeScale) {
|
||||
return voxelSizeScale / powf(2, renderLevel);
|
||||
}
|
||||
|
||||
float getAccuracyAngle(float octreeSizeScale, float maxScale, int boundaryLevelAdjust) const {
|
||||
float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, octreeSizeScale) / OCTREE_TO_MESH_RATIO;
|
||||
return atan(maxScale / visibleDistanceAtMaxScale);
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -132,38 +132,33 @@ public:
|
|||
|
||||
void invalidate(); // causes all reasonable intersection tests to fail
|
||||
private:
|
||||
// camera location/orientation attributes
|
||||
glm::vec3 _position; // the position in world-frame
|
||||
glm::quat _orientation;
|
||||
glm::mat4 _view;
|
||||
|
||||
// Lens attributes
|
||||
glm::mat4 _projection;
|
||||
|
||||
// calculated for orientation
|
||||
::Plane _planes[NUM_FRUSTUM_PLANES]; // plane normals point inside frustum
|
||||
|
||||
glm::vec3 _position; // position in world-frame
|
||||
glm::quat _orientation; // orientation in world-frame
|
||||
|
||||
// calculated from orientation
|
||||
glm::vec3 _direction = IDENTITY_FRONT;
|
||||
glm::vec3 _up = IDENTITY_UP;
|
||||
glm::vec3 _right = IDENTITY_RIGHT;
|
||||
|
||||
// calculated from projection
|
||||
glm::vec4 _corners[NUM_FRUSTUM_CORNERS];
|
||||
glm::vec3 _cornersWorld[NUM_FRUSTUM_CORNERS];
|
||||
float _centerSphereRadius = DEFAULT_CENTER_SPHERE_RADIUS;
|
||||
|
||||
// Calculated values
|
||||
glm::mat4 _inverseProjection;
|
||||
float _width { 1.0f };
|
||||
float _height { 1.0f };
|
||||
float _aspectRatio { 1.0f };
|
||||
float _nearClip { DEFAULT_NEAR_CLIP };
|
||||
float _farClip { DEFAULT_FAR_CLIP };
|
||||
float _focalLength { 0.25f };
|
||||
float _fieldOfView { DEFAULT_FIELD_OF_VIEW_DEGREES };
|
||||
glm::vec4 _corners[NUM_FRUSTUM_CORNERS];
|
||||
glm::vec3 _cornersWorld[NUM_FRUSTUM_CORNERS];
|
||||
::Plane _planes[NUM_FRUSTUM_PLANES]; // plane normals point inside frustum
|
||||
|
||||
float _nearClip { DEFAULT_NEAR_CLIP };
|
||||
float _farClip { DEFAULT_FAR_CLIP };
|
||||
|
||||
const char* debugPlaneName (int plane) const;
|
||||
|
||||
// Used to project points
|
||||
glm::mat4 _ourModelViewProjectionMatrix;
|
||||
};
|
||||
using ViewFrustumPointer = std::shared_ptr<ViewFrustum>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue