mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 19:16:56 +02:00
tweaks to some variable names since windows has a problem with them
This commit is contained in:
parent
5725a92cfe
commit
e55e680e66
3 changed files with 140 additions and 140 deletions
|
@ -46,7 +46,7 @@ ViewFrustum::ViewFrustum() :
|
||||||
_nearBottomRight(0,0,0)
|
_nearBottomRight(0,0,0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) {
|
void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) {
|
||||||
_orientation = orientationAsQuaternion;
|
_orientation = orientationAsQuaternion;
|
||||||
_right = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_RIGHT, 0.0f));
|
_right = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_RIGHT, 0.0f));
|
||||||
|
@ -60,7 +60,7 @@ void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) {
|
||||||
// Description: this will calculate the view frustum bounds for a given position
|
// Description: this will calculate the view frustum bounds for a given position
|
||||||
// and direction
|
// and direction
|
||||||
//
|
//
|
||||||
// Notes on how/why this works:
|
// Notes on how/why this works:
|
||||||
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/view-frustums-shape/
|
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/view-frustums-shape/
|
||||||
//
|
//
|
||||||
void ViewFrustum::calculate() {
|
void ViewFrustum::calculate() {
|
||||||
|
@ -68,13 +68,13 @@ void ViewFrustum::calculate() {
|
||||||
float left, right, bottom, top, nearVal, farVal;
|
float left, right, bottom, top, nearVal, farVal;
|
||||||
glm::vec4 nearClipPlane, farClipPlane;
|
glm::vec4 nearClipPlane, farClipPlane;
|
||||||
computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||||
|
|
||||||
// start with the corners of the near frustum window
|
// start with the corners of the near frustum window
|
||||||
glm::vec3 topLeft(left, top, -nearVal);
|
glm::vec3 topLeft(left, top, -nearVal);
|
||||||
glm::vec3 topRight(right, top, -nearVal);
|
glm::vec3 topRight(right, top, -nearVal);
|
||||||
glm::vec3 bottomLeft(left, bottom, -nearVal);
|
glm::vec3 bottomLeft(left, bottom, -nearVal);
|
||||||
glm::vec3 bottomRight(right, bottom, -nearVal);
|
glm::vec3 bottomRight(right, bottom, -nearVal);
|
||||||
|
|
||||||
// find the intersections of the rays through the corners with the clip planes in view space,
|
// find the intersections of the rays through the corners with the clip planes in view space,
|
||||||
// then transform them to world space
|
// then transform them to world space
|
||||||
glm::mat4 worldMatrix = glm::translate(_position) * glm::mat4(glm::mat3(_right, _up, -_direction)) *
|
glm::mat4 worldMatrix = glm::translate(_position) * glm::mat4(glm::mat3(_right, _up, -_direction)) *
|
||||||
|
@ -95,25 +95,25 @@ void ViewFrustum::calculate() {
|
||||||
(-nearClipPlane.w / glm::dot(bottomLeft, glm::vec3(nearClipPlane))), 1.0f));
|
(-nearClipPlane.w / glm::dot(bottomLeft, glm::vec3(nearClipPlane))), 1.0f));
|
||||||
_nearBottomRight = glm::vec3(worldMatrix * glm::vec4(bottomRight *
|
_nearBottomRight = glm::vec3(worldMatrix * glm::vec4(bottomRight *
|
||||||
(-nearClipPlane.w / glm::dot(bottomRight, glm::vec3(nearClipPlane))), 1.0f));
|
(-nearClipPlane.w / glm::dot(bottomRight, glm::vec3(nearClipPlane))), 1.0f));
|
||||||
|
|
||||||
// compute the offset position and axes in world space
|
// compute the offset position and axes in world space
|
||||||
_offsetPosition = glm::vec3(worldMatrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
_offsetPosition = glm::vec3(worldMatrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
_offsetDirection = glm::vec3(worldMatrix * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f));
|
_offsetDirection = glm::vec3(worldMatrix * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f));
|
||||||
_offsetUp = glm::vec3(worldMatrix * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f));
|
_offsetUp = glm::vec3(worldMatrix * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f));
|
||||||
_offsetRight = glm::vec3(worldMatrix * glm::vec4(1.0f, 0.0f, 0.0f, 0.0f));
|
_offsetRight = glm::vec3(worldMatrix * glm::vec4(1.0f, 0.0f, 0.0f, 0.0f));
|
||||||
|
|
||||||
// compute the six planes
|
// compute the six planes
|
||||||
// The planes are defined such that the normal points towards the inside of the view frustum.
|
// The planes are defined such that the normal points towards the inside of the view frustum.
|
||||||
// Testing if an object is inside the view frustum is performed by computing on which side of
|
// Testing if an object is inside the view frustum is performed by computing on which side of
|
||||||
// the plane the object resides. This can be done computing the signed distance from the point
|
// the plane the object resides. This can be done computing the signed distance from the point
|
||||||
// to the plane. If it is on the side that the normal is pointing, i.e. the signed distance
|
// to the plane. If it is on the side that the normal is pointing, i.e. the signed distance
|
||||||
// is positive, then it is on the right side of the respective plane. If an object is on the
|
// is positive, then it is on the right side of the respective plane. If an object is on the
|
||||||
// right side of all six planes then the object is inside the frustum.
|
// right side of all six planes then the object is inside the frustum.
|
||||||
|
|
||||||
// the function set3Points assumes that the points are given in counter clockwise order, assume you
|
// the function set3Points assumes that the points are given in counter clockwise order, assume you
|
||||||
// are inside the frustum, facing the plane. Start with any point, and go counter clockwise for
|
// are inside the frustum, facing the plane. Start with any point, and go counter clockwise for
|
||||||
// three consecutive points
|
// three consecutive points
|
||||||
|
|
||||||
_planes[TOP_PLANE ].set3Points(_nearTopRight,_nearTopLeft,_farTopLeft);
|
_planes[TOP_PLANE ].set3Points(_nearTopRight,_nearTopLeft,_farTopLeft);
|
||||||
_planes[BOTTOM_PLANE].set3Points(_nearBottomLeft,_nearBottomRight,_farBottomRight);
|
_planes[BOTTOM_PLANE].set3Points(_nearBottomLeft,_nearBottomRight,_farBottomRight);
|
||||||
_planes[LEFT_PLANE ].set3Points(_nearBottomLeft,_farBottomLeft,_farTopLeft);
|
_planes[LEFT_PLANE ].set3Points(_nearBottomLeft,_farBottomLeft,_farTopLeft);
|
||||||
|
@ -129,7 +129,7 @@ void ViewFrustum::calculate() {
|
||||||
|
|
||||||
// Our ModelViewProjection : multiplication of our 3 matrices (note: model is identity, so we can drop it)
|
// 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
|
_ourModelViewProjectionMatrix = projection * view; // Remember, matrix multiplication is the other way around
|
||||||
|
|
||||||
// Set up our keyhole bounding box...
|
// Set up our keyhole bounding box...
|
||||||
glm::vec3 corner = _position - _keyholeRadius;
|
glm::vec3 corner = _position - _keyholeRadius;
|
||||||
_keyholeBoundingBox = AABox(corner,(_keyholeRadius * 2.0f));
|
_keyholeBoundingBox = AABox(corner,(_keyholeRadius * 2.0f));
|
||||||
|
@ -151,14 +151,14 @@ const char* ViewFrustum::debugPlaneName (int plane) const {
|
||||||
ViewFrustum::location ViewFrustum::pointInKeyhole(const glm::vec3& point) const {
|
ViewFrustum::location ViewFrustum::pointInKeyhole(const glm::vec3& point) const {
|
||||||
|
|
||||||
ViewFrustum::location result = INTERSECT;
|
ViewFrustum::location result = INTERSECT;
|
||||||
|
|
||||||
float distance = glm::distance(point, _position);
|
float distance = glm::distance(point, _position);
|
||||||
if (distance > _keyholeRadius) {
|
if (distance > _keyholeRadius) {
|
||||||
result = OUTSIDE;
|
result = OUTSIDE;
|
||||||
} else if (distance < _keyholeRadius) {
|
} else if (distance < _keyholeRadius) {
|
||||||
result = INSIDE;
|
result = INSIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,14 +167,14 @@ ViewFrustum::location ViewFrustum::pointInKeyhole(const glm::vec3& point) const
|
||||||
// If the distance plus the radius of sphere A is less than the radius of sphere B then, sphere A is inside of sphere B
|
// If the distance plus the radius of sphere A is less than the radius of sphere B then, sphere A is inside of sphere B
|
||||||
ViewFrustum::location ViewFrustum::sphereInKeyhole(const glm::vec3& center, float radius) const {
|
ViewFrustum::location ViewFrustum::sphereInKeyhole(const glm::vec3& center, float radius) const {
|
||||||
ViewFrustum::location result = INTERSECT;
|
ViewFrustum::location result = INTERSECT;
|
||||||
|
|
||||||
float distance = glm::distance(center, _position);
|
float distance = glm::distance(center, _position);
|
||||||
if (distance > (radius + _keyholeRadius)) {
|
if (distance > (radius + _keyholeRadius)) {
|
||||||
result = OUTSIDE;
|
result = OUTSIDE;
|
||||||
} else if ((distance + radius) < _keyholeRadius) {
|
} else if ((distance + radius) < _keyholeRadius) {
|
||||||
result = INSIDE;
|
result = INSIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ ViewFrustum::location ViewFrustum::boxInKeyhole(const AABox& box) const {
|
||||||
bool intersects = box.findSpherePenetration(_position, _keyholeRadius, penetration);
|
bool intersects = box.findSpherePenetration(_position, _keyholeRadius, penetration);
|
||||||
|
|
||||||
ViewFrustum::location result = OUTSIDE;
|
ViewFrustum::location result = OUTSIDE;
|
||||||
|
|
||||||
// if the box intersects the sphere, then it may also be inside... calculate further
|
// if the box intersects the sphere, then it may also be inside... calculate further
|
||||||
if (intersects) {
|
if (intersects) {
|
||||||
result = INTERSECT;
|
result = INTERSECT;
|
||||||
|
@ -208,12 +208,12 @@ ViewFrustum::location ViewFrustum::boxInKeyhole(const AABox& box) const {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allPointsInside) {
|
if (allPointsInside) {
|
||||||
result = INSIDE;
|
result = INSIDE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ ViewFrustum::location ViewFrustum::sphereInFrustum(const glm::vec3& center, floa
|
||||||
regularResult = INTERSECT;
|
regularResult = INTERSECT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return regularResult;
|
return regularResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ ViewFrustum::location ViewFrustum::boxInFrustum(const AABox& box) const {
|
||||||
|
|
||||||
const glm::vec3& boxVertexN = box.getVertexN(normal);
|
const glm::vec3& boxVertexN = box.getVertexN(normal);
|
||||||
float planeToBoxVertexNDistance = _planes[i].distance(boxVertexN);
|
float planeToBoxVertexNDistance = _planes[i].distance(boxVertexN);
|
||||||
|
|
||||||
if (planeToBoxVertexPDistance < 0) {
|
if (planeToBoxVertexPDistance < 0) {
|
||||||
// This is outside the regular frustum, so just return the value from checking the keyhole
|
// This is outside the regular frustum, so just return the value from checking the keyhole
|
||||||
return keyholeResult;
|
return keyholeResult;
|
||||||
|
@ -312,7 +312,7 @@ bool testMatches(float lhs, float rhs, float epsilon = EPSILON) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewFrustum::matches(const ViewFrustum& compareTo, bool debug) const {
|
bool ViewFrustum::matches(const ViewFrustum& compareTo, bool debug) const {
|
||||||
bool result =
|
bool result =
|
||||||
testMatches(compareTo._position, _position) &&
|
testMatches(compareTo._position, _position) &&
|
||||||
testMatches(compareTo._direction, _direction) &&
|
testMatches(compareTo._direction, _direction) &&
|
||||||
testMatches(compareTo._up, _up) &&
|
testMatches(compareTo._up, _up) &&
|
||||||
|
@ -327,42 +327,42 @@ bool ViewFrustum::matches(const ViewFrustum& compareTo, bool debug) const {
|
||||||
|
|
||||||
if (!result && debug) {
|
if (!result && debug) {
|
||||||
qDebug("ViewFrustum::matches()... result=%s\n", debug::valueOf(result));
|
qDebug("ViewFrustum::matches()... result=%s\n", debug::valueOf(result));
|
||||||
qDebug("%s -- compareTo._position=%f,%f,%f _position=%f,%f,%f\n",
|
qDebug("%s -- compareTo._position=%f,%f,%f _position=%f,%f,%f\n",
|
||||||
(testMatches(compareTo._position,_position) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._position,_position) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._position.x, compareTo._position.y, compareTo._position.z,
|
compareTo._position.x, compareTo._position.y, compareTo._position.z,
|
||||||
_position.x, _position.y, _position.z );
|
_position.x, _position.y, _position.z );
|
||||||
qDebug("%s -- compareTo._direction=%f,%f,%f _direction=%f,%f,%f\n",
|
qDebug("%s -- compareTo._direction=%f,%f,%f _direction=%f,%f,%f\n",
|
||||||
(testMatches(compareTo._direction, _direction) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._direction, _direction) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._direction.x, compareTo._direction.y, compareTo._direction.z,
|
compareTo._direction.x, compareTo._direction.y, compareTo._direction.z,
|
||||||
_direction.x, _direction.y, _direction.z );
|
_direction.x, _direction.y, _direction.z );
|
||||||
qDebug("%s -- compareTo._up=%f,%f,%f _up=%f,%f,%f\n",
|
qDebug("%s -- compareTo._up=%f,%f,%f _up=%f,%f,%f\n",
|
||||||
(testMatches(compareTo._up, _up) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._up, _up) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._up.x, compareTo._up.y, compareTo._up.z,
|
compareTo._up.x, compareTo._up.y, compareTo._up.z,
|
||||||
_up.x, _up.y, _up.z );
|
_up.x, _up.y, _up.z );
|
||||||
qDebug("%s -- compareTo._right=%f,%f,%f _right=%f,%f,%f\n",
|
qDebug("%s -- compareTo._right=%f,%f,%f _right=%f,%f,%f\n",
|
||||||
(testMatches(compareTo._right, _right) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._right, _right) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._right.x, compareTo._right.y, compareTo._right.z,
|
compareTo._right.x, compareTo._right.y, compareTo._right.z,
|
||||||
_right.x, _right.y, _right.z );
|
_right.x, _right.y, _right.z );
|
||||||
qDebug("%s -- compareTo._fieldOfView=%f _fieldOfView=%f\n",
|
qDebug("%s -- compareTo._fieldOfView=%f _fieldOfView=%f\n",
|
||||||
(testMatches(compareTo._fieldOfView, _fieldOfView) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._fieldOfView, _fieldOfView) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._fieldOfView, _fieldOfView);
|
compareTo._fieldOfView, _fieldOfView);
|
||||||
qDebug("%s -- compareTo._aspectRatio=%f _aspectRatio=%f\n",
|
qDebug("%s -- compareTo._aspectRatio=%f _aspectRatio=%f\n",
|
||||||
(testMatches(compareTo._aspectRatio, _aspectRatio) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._aspectRatio, _aspectRatio) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._aspectRatio, _aspectRatio);
|
compareTo._aspectRatio, _aspectRatio);
|
||||||
qDebug("%s -- compareTo._nearClip=%f _nearClip=%f\n",
|
qDebug("%s -- compareTo._nearClip=%f _nearClip=%f\n",
|
||||||
(testMatches(compareTo._nearClip, _nearClip) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._nearClip, _nearClip) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._nearClip, _nearClip);
|
compareTo._nearClip, _nearClip);
|
||||||
qDebug("%s -- compareTo._farClip=%f _farClip=%f\n",
|
qDebug("%s -- compareTo._farClip=%f _farClip=%f\n",
|
||||||
(testMatches(compareTo._farClip, _farClip) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._farClip, _farClip) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._farClip, _farClip);
|
compareTo._farClip, _farClip);
|
||||||
qDebug("%s -- compareTo._focalLength=%f _focalLength=%f\n",
|
qDebug("%s -- compareTo._focalLength=%f _focalLength=%f\n",
|
||||||
(testMatches(compareTo._focalLength, _focalLength) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._focalLength, _focalLength) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._focalLength, _focalLength);
|
compareTo._focalLength, _focalLength);
|
||||||
qDebug("%s -- compareTo._eyeOffsetPosition=%f,%f,%f _eyeOffsetPosition=%f,%f,%f\n",
|
qDebug("%s -- compareTo._eyeOffsetPosition=%f,%f,%f _eyeOffsetPosition=%f,%f,%f\n",
|
||||||
(testMatches(compareTo._eyeOffsetPosition, _eyeOffsetPosition) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._eyeOffsetPosition, _eyeOffsetPosition) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._eyeOffsetPosition.x, compareTo._eyeOffsetPosition.y, compareTo._eyeOffsetPosition.z,
|
compareTo._eyeOffsetPosition.x, compareTo._eyeOffsetPosition.y, compareTo._eyeOffsetPosition.z,
|
||||||
_eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z);
|
_eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z);
|
||||||
qDebug("%s -- compareTo._eyeOffsetOrientation=%f,%f,%f,%f _eyeOffsetOrientation=%f,%f,%f,%f\n",
|
qDebug("%s -- compareTo._eyeOffsetOrientation=%f,%f,%f,%f _eyeOffsetOrientation=%f,%f,%f,%f\n",
|
||||||
(testMatches(compareTo._eyeOffsetOrientation, _eyeOffsetOrientation) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._eyeOffsetOrientation, _eyeOffsetOrientation) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._eyeOffsetOrientation.x, compareTo._eyeOffsetOrientation.y,
|
compareTo._eyeOffsetOrientation.x, compareTo._eyeOffsetOrientation.y,
|
||||||
compareTo._eyeOffsetOrientation.z, compareTo._eyeOffsetOrientation.w,
|
compareTo._eyeOffsetOrientation.z, compareTo._eyeOffsetOrientation.w,
|
||||||
|
@ -391,15 +391,15 @@ bool ViewFrustum::isVerySimilar(const ViewFrustum& compareTo, bool debug) const
|
||||||
if (isNaN(angleOrientation)) {
|
if (isNaN(angleOrientation)) {
|
||||||
angleOrientation = 0.0f;
|
angleOrientation = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat dQEyeOffsetOrientation = _eyeOffsetOrientation * glm::inverse(compareTo._eyeOffsetOrientation);
|
glm::quat dQEyeOffsetOrientation = _eyeOffsetOrientation * glm::inverse(compareTo._eyeOffsetOrientation);
|
||||||
float angleEyeOffsetOrientation = compareTo._eyeOffsetOrientation == _eyeOffsetOrientation
|
float angleEyeOffsetOrientation = compareTo._eyeOffsetOrientation == _eyeOffsetOrientation
|
||||||
? 0.0f : glm::angle(dQEyeOffsetOrientation);
|
? 0.0f : glm::angle(dQEyeOffsetOrientation);
|
||||||
if (isNaN(angleEyeOffsetOrientation)) {
|
if (isNaN(angleEyeOffsetOrientation)) {
|
||||||
angleOrientation = 0.0f;
|
angleOrientation = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result =
|
bool result =
|
||||||
testMatches(0, positionDistance, POSITION_SIMILAR_ENOUGH) &&
|
testMatches(0, positionDistance, POSITION_SIMILAR_ENOUGH) &&
|
||||||
testMatches(0, angleOrientation, ORIENTATION_SIMILAR_ENOUGH) &&
|
testMatches(0, angleOrientation, ORIENTATION_SIMILAR_ENOUGH) &&
|
||||||
testMatches(compareTo._fieldOfView, _fieldOfView) &&
|
testMatches(compareTo._fieldOfView, _fieldOfView) &&
|
||||||
|
@ -413,45 +413,45 @@ bool ViewFrustum::isVerySimilar(const ViewFrustum& compareTo, bool debug) const
|
||||||
|
|
||||||
if (!result && debug) {
|
if (!result && debug) {
|
||||||
qDebug("ViewFrustum::isVerySimilar()... result=%s\n", debug::valueOf(result));
|
qDebug("ViewFrustum::isVerySimilar()... result=%s\n", debug::valueOf(result));
|
||||||
qDebug("%s -- compareTo._position=%f,%f,%f _position=%f,%f,%f\n",
|
qDebug("%s -- compareTo._position=%f,%f,%f _position=%f,%f,%f\n",
|
||||||
(testMatches(compareTo._position,_position, POSITION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
(testMatches(compareTo._position,_position, POSITION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
||||||
compareTo._position.x, compareTo._position.y, compareTo._position.z,
|
compareTo._position.x, compareTo._position.y, compareTo._position.z,
|
||||||
_position.x, _position.y, _position.z );
|
_position.x, _position.y, _position.z );
|
||||||
|
|
||||||
qDebug("%s -- positionDistance=%f\n",
|
qDebug("%s -- positionDistance=%f\n",
|
||||||
(testMatches(0,positionDistance, POSITION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
(testMatches(0,positionDistance, POSITION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
||||||
positionDistance);
|
positionDistance);
|
||||||
|
|
||||||
qDebug("%s -- angleOrientation=%f\n",
|
qDebug("%s -- angleOrientation=%f\n",
|
||||||
(testMatches(0, angleOrientation, ORIENTATION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
(testMatches(0, angleOrientation, ORIENTATION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
||||||
angleOrientation);
|
angleOrientation);
|
||||||
|
|
||||||
qDebug("%s -- compareTo._fieldOfView=%f _fieldOfView=%f\n",
|
qDebug("%s -- compareTo._fieldOfView=%f _fieldOfView=%f\n",
|
||||||
(testMatches(compareTo._fieldOfView, _fieldOfView) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._fieldOfView, _fieldOfView) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._fieldOfView, _fieldOfView);
|
compareTo._fieldOfView, _fieldOfView);
|
||||||
qDebug("%s -- compareTo._aspectRatio=%f _aspectRatio=%f\n",
|
qDebug("%s -- compareTo._aspectRatio=%f _aspectRatio=%f\n",
|
||||||
(testMatches(compareTo._aspectRatio, _aspectRatio) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._aspectRatio, _aspectRatio) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._aspectRatio, _aspectRatio);
|
compareTo._aspectRatio, _aspectRatio);
|
||||||
qDebug("%s -- compareTo._nearClip=%f _nearClip=%f\n",
|
qDebug("%s -- compareTo._nearClip=%f _nearClip=%f\n",
|
||||||
(testMatches(compareTo._nearClip, _nearClip) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._nearClip, _nearClip) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._nearClip, _nearClip);
|
compareTo._nearClip, _nearClip);
|
||||||
qDebug("%s -- compareTo._farClip=%f _farClip=%f\n",
|
qDebug("%s -- compareTo._farClip=%f _farClip=%f\n",
|
||||||
(testMatches(compareTo._farClip, _farClip) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._farClip, _farClip) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._farClip, _farClip);
|
compareTo._farClip, _farClip);
|
||||||
qDebug("%s -- compareTo._focalLength=%f _focalLength=%f\n",
|
qDebug("%s -- compareTo._focalLength=%f _focalLength=%f\n",
|
||||||
(testMatches(compareTo._focalLength, _focalLength) ? "MATCHES " : "NO MATCH"),
|
(testMatches(compareTo._focalLength, _focalLength) ? "MATCHES " : "NO MATCH"),
|
||||||
compareTo._focalLength, _focalLength);
|
compareTo._focalLength, _focalLength);
|
||||||
|
|
||||||
qDebug("%s -- compareTo._eyeOffsetPosition=%f,%f,%f _eyeOffsetPosition=%f,%f,%f\n",
|
qDebug("%s -- compareTo._eyeOffsetPosition=%f,%f,%f _eyeOffsetPosition=%f,%f,%f\n",
|
||||||
(testMatches(compareTo._eyeOffsetPosition, _eyeOffsetPosition, POSITION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
(testMatches(compareTo._eyeOffsetPosition, _eyeOffsetPosition, POSITION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
||||||
compareTo._eyeOffsetPosition.x, compareTo._eyeOffsetPosition.y, compareTo._eyeOffsetPosition.z,
|
compareTo._eyeOffsetPosition.x, compareTo._eyeOffsetPosition.y, compareTo._eyeOffsetPosition.z,
|
||||||
_eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z);
|
_eyeOffsetPosition.x, _eyeOffsetPosition.y, _eyeOffsetPosition.z);
|
||||||
|
|
||||||
qDebug("%s -- eyeOffsetpositionDistance=%f\n",
|
qDebug("%s -- eyeOffsetpositionDistance=%f\n",
|
||||||
(testMatches(0,eyeOffsetpositionDistance, EYEOFFSET_POSITION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
(testMatches(0,eyeOffsetpositionDistance, EYEOFFSET_POSITION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
||||||
eyeOffsetpositionDistance);
|
eyeOffsetpositionDistance);
|
||||||
|
|
||||||
qDebug("%s -- angleEyeOffsetOrientation=%f\n",
|
qDebug("%s -- angleEyeOffsetOrientation=%f\n",
|
||||||
(testMatches(0, angleEyeOffsetOrientation, ORIENTATION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
(testMatches(0, angleEyeOffsetOrientation, ORIENTATION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
|
||||||
angleEyeOffsetOrientation);
|
angleEyeOffsetOrientation);
|
||||||
}
|
}
|
||||||
|
@ -463,12 +463,12 @@ void ViewFrustum::computePickRay(float x, float y, glm::vec3& origin, glm::vec3&
|
||||||
direction = glm::normalize(origin - (_position + _orientation * _eyeOffsetPosition));
|
direction = glm::normalize(origin - (_position + _orientation * _eyeOffsetPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near, float& far,
|
void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearValue, float& farValue,
|
||||||
glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
|
glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
|
||||||
// compute our dimensions the usual way
|
// compute our dimensions the usual way
|
||||||
float hheight = _nearClip * tanf(_fieldOfView * 0.5f * PI_OVER_180);
|
float hheight = _nearClip * tanf(_fieldOfView * 0.5f * PI_OVER_180);
|
||||||
float hwidth = _aspectRatio * hheight;
|
float hwidth = _aspectRatio * hheight;
|
||||||
|
|
||||||
// get our frustum corners in view space
|
// get our frustum corners in view space
|
||||||
glm::mat4 eyeMatrix = glm::mat4_cast(glm::inverse(_eyeOffsetOrientation)) * glm::translate(-_eyeOffsetPosition);
|
glm::mat4 eyeMatrix = glm::mat4_cast(glm::inverse(_eyeOffsetOrientation)) * glm::translate(-_eyeOffsetPosition);
|
||||||
glm::vec4 corners[8];
|
glm::vec4 corners[8];
|
||||||
|
@ -481,27 +481,27 @@ void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom
|
||||||
corners[5] = eyeMatrix * glm::vec4(hwidth * farScale, -hheight * farScale, -_farClip, 1.0f);
|
corners[5] = eyeMatrix * glm::vec4(hwidth * farScale, -hheight * farScale, -_farClip, 1.0f);
|
||||||
corners[6] = eyeMatrix * glm::vec4(hwidth * farScale, hheight * farScale, -_farClip, 1.0f);
|
corners[6] = eyeMatrix * glm::vec4(hwidth * farScale, hheight * farScale, -_farClip, 1.0f);
|
||||||
corners[7] = eyeMatrix * glm::vec4(-hwidth * farScale, hheight * farScale, -_farClip, 1.0f);
|
corners[7] = eyeMatrix * glm::vec4(-hwidth * farScale, hheight * farScale, -_farClip, 1.0f);
|
||||||
|
|
||||||
// find the minimum and maximum z values, which will be our near and far clip distances
|
// find the minimum and maximum z values, which will be our near and far clip distances
|
||||||
near = FLT_MAX;
|
nearValue = FLT_MAX;
|
||||||
far = -FLT_MAX;
|
farValue = -FLT_MAX;
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
near = min(near, -corners[i].z);
|
nearValue = min(nearValue, -corners[i].z);
|
||||||
far = max(far, -corners[i].z);
|
farValue = max(farValue, -corners[i].z);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the near clip isn't too small to be valid
|
// make sure the near clip isn't too small to be valid
|
||||||
const float MIN_NEAR = 0.01f;
|
const float MIN_NEAR = 0.01f;
|
||||||
near = max(MIN_NEAR, near);
|
nearValue = max(MIN_NEAR, nearValue);
|
||||||
|
|
||||||
// get the near/far normal and use it to find the clip planes
|
// get the near/far normal and use it to find the clip planes
|
||||||
glm::vec4 normal = eyeMatrix * glm::vec4(0.0f, 0.0f, 1.0f, 0.0f);
|
glm::vec4 normal = eyeMatrix * glm::vec4(0.0f, 0.0f, 1.0f, 0.0f);
|
||||||
nearClipPlane = glm::vec4(-normal.x, -normal.y, -normal.z, glm::dot(normal, corners[0]));
|
nearClipPlane = glm::vec4(-normal.x, -normal.y, -normal.z, glm::dot(normal, corners[0]));
|
||||||
farClipPlane = glm::vec4(normal.x, normal.y, normal.z, -glm::dot(normal, corners[4]));
|
farClipPlane = glm::vec4(normal.x, normal.y, normal.z, -glm::dot(normal, corners[4]));
|
||||||
|
|
||||||
// compute the focal proportion (zero is near clip, one is far clip)
|
// compute the focal proportion (zero is near clip, one is far clip)
|
||||||
float focalProportion = (_focalLength - _nearClip) / (_farClip - _nearClip);
|
float focalProportion = (_focalLength - _nearClip) / (_farClip - _nearClip);
|
||||||
|
|
||||||
// get the extents at Z = -near
|
// get the extents at Z = -near
|
||||||
left = FLT_MAX;
|
left = FLT_MAX;
|
||||||
right = -FLT_MAX;
|
right = -FLT_MAX;
|
||||||
|
@ -509,7 +509,7 @@ void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom
|
||||||
top = -FLT_MAX;
|
top = -FLT_MAX;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
glm::vec4 corner = glm::mix(corners[i], corners[i + 4], focalProportion);
|
glm::vec4 corner = glm::mix(corners[i], corners[i + 4], focalProportion);
|
||||||
glm::vec4 intersection = corner * (-near / corner.z);
|
glm::vec4 intersection = corner * (-nearValue / corner.z);
|
||||||
left = min(left, intersection.x);
|
left = min(left, intersection.x);
|
||||||
right = max(right, intersection.x);
|
right = max(right, intersection.x);
|
||||||
bottom = min(bottom, intersection.y);
|
bottom = min(bottom, intersection.y);
|
||||||
|
@ -539,12 +539,12 @@ glm::vec2 ViewFrustum::projectPoint(glm::vec3 point, bool& pointInView) const {
|
||||||
glm::vec4 pointVec4 = glm::vec4(point,1);
|
glm::vec4 pointVec4 = glm::vec4(point,1);
|
||||||
glm::vec4 projectedPointVec4 = _ourModelViewProjectionMatrix * pointVec4;
|
glm::vec4 projectedPointVec4 = _ourModelViewProjectionMatrix * pointVec4;
|
||||||
pointInView = (projectedPointVec4.w > 0); // math! If the w result is negative then the point is behind the viewer
|
pointInView = (projectedPointVec4.w > 0); // math! If the w result is negative then the point is behind the viewer
|
||||||
|
|
||||||
// what happens with w is 0???
|
// what happens with w is 0???
|
||||||
float x = projectedPointVec4.x / projectedPointVec4.w;
|
float x = projectedPointVec4.x / projectedPointVec4.w;
|
||||||
float y = projectedPointVec4.y / projectedPointVec4.w;
|
float y = projectedPointVec4.y / projectedPointVec4.w;
|
||||||
glm::vec2 projectedPoint(x,y);
|
glm::vec2 projectedPoint(x,y);
|
||||||
|
|
||||||
// if the point is out of view we also need to flip the signs of x and y
|
// if the point is out of view we also need to flip the signs of x and y
|
||||||
if (!pointInView) {
|
if (!pointInView) {
|
||||||
projectedPoint.x = -x;
|
projectedPoint.x = -x;
|
||||||
|
@ -563,7 +563,7 @@ const int hullVertexLookup[MAX_POSSIBLE_COMBINATIONS][MAX_PROJECTED_POLYGON_VERT
|
||||||
//0
|
//0
|
||||||
{0}, // inside
|
{0}, // inside
|
||||||
{4, BOTTOM_RIGHT_NEAR, BOTTOM_RIGHT_FAR, TOP_RIGHT_FAR, TOP_RIGHT_NEAR}, // right
|
{4, BOTTOM_RIGHT_NEAR, BOTTOM_RIGHT_FAR, TOP_RIGHT_FAR, TOP_RIGHT_NEAR}, // right
|
||||||
{4, BOTTOM_LEFT_FAR, BOTTOM_LEFT_NEAR, TOP_LEFT_NEAR, TOP_LEFT_FAR }, // left
|
{4, BOTTOM_LEFT_FAR, BOTTOM_LEFT_NEAR, TOP_LEFT_NEAR, TOP_LEFT_FAR }, // left
|
||||||
{0}, // n/a
|
{0}, // n/a
|
||||||
|
|
||||||
//4
|
//4
|
||||||
|
@ -611,8 +611,8 @@ const int hullVertexLookup[MAX_POSSIBLE_COMBINATIONS][MAX_PROJECTED_POLYGON_VERT
|
||||||
{6, BOTTOM_RIGHT_NEAR, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, TOP_LEFT_FAR, TOP_RIGHT_FAR, TOP_RIGHT_NEAR}, // back, right
|
{6, BOTTOM_RIGHT_NEAR, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, TOP_LEFT_FAR, TOP_RIGHT_FAR, TOP_RIGHT_NEAR}, // back, right
|
||||||
//34
|
//34
|
||||||
{6, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, BOTTOM_LEFT_NEAR, TOP_LEFT_NEAR, TOP_LEFT_FAR, TOP_RIGHT_FAR }, // back, left
|
{6, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, BOTTOM_LEFT_NEAR, TOP_LEFT_NEAR, TOP_LEFT_FAR, TOP_RIGHT_FAR }, // back, left
|
||||||
|
|
||||||
|
|
||||||
{0}, // n/a
|
{0}, // n/a
|
||||||
//36
|
//36
|
||||||
{6, BOTTOM_RIGHT_NEAR, BOTTOM_LEFT_NEAR, BOTTOM_LEFT_FAR, TOP_LEFT_FAR, TOP_RIGHT_FAR, BOTTOM_RIGHT_FAR}, // back, bottom
|
{6, BOTTOM_RIGHT_NEAR, BOTTOM_LEFT_NEAR, BOTTOM_LEFT_FAR, TOP_LEFT_FAR, TOP_RIGHT_FAR, BOTTOM_RIGHT_FAR}, // back, bottom
|
||||||
|
@ -624,7 +624,7 @@ const int hullVertexLookup[MAX_POSSIBLE_COMBINATIONS][MAX_PROJECTED_POLYGON_VERT
|
||||||
|
|
||||||
// 40
|
// 40
|
||||||
{6, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, TOP_LEFT_FAR, TOP_LEFT_NEAR, TOP_RIGHT_NEAR, TOP_RIGHT_FAR}, // back, top
|
{6, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, TOP_LEFT_FAR, TOP_LEFT_NEAR, TOP_RIGHT_NEAR, TOP_RIGHT_FAR}, // back, top
|
||||||
|
|
||||||
{6, BOTTOM_RIGHT_NEAR, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, TOP_LEFT_FAR, TOP_LEFT_NEAR, TOP_RIGHT_NEAR}, // back, top, right
|
{6, BOTTOM_RIGHT_NEAR, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, TOP_LEFT_FAR, TOP_LEFT_NEAR, TOP_RIGHT_NEAR}, // back, top, right
|
||||||
//42
|
//42
|
||||||
{6, TOP_RIGHT_NEAR, TOP_RIGHT_FAR, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, BOTTOM_LEFT_NEAR, TOP_LEFT_NEAR}, // back, top, left
|
{6, TOP_RIGHT_NEAR, TOP_RIGHT_FAR, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, BOTTOM_LEFT_NEAR, TOP_LEFT_NEAR}, // back, top, left
|
||||||
|
@ -642,9 +642,9 @@ OctreeProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const
|
||||||
+ ((_position.z > topFarLeft.z ) << 5); // 32 = back/far | planes
|
+ ((_position.z > topFarLeft.z ) << 5); // 32 = back/far | planes
|
||||||
|
|
||||||
int vertexCount = hullVertexLookup[lookUp][0]; //look up number of vertices
|
int vertexCount = hullVertexLookup[lookUp][0]; //look up number of vertices
|
||||||
|
|
||||||
OctreeProjectedPolygon projectedPolygon(vertexCount);
|
OctreeProjectedPolygon projectedPolygon(vertexCount);
|
||||||
|
|
||||||
bool pointInView = true;
|
bool pointInView = true;
|
||||||
bool allPointsInView = false; // assume the best, but wait till we know we have a vertex
|
bool allPointsInView = false; // assume the best, but wait till we know we have a vertex
|
||||||
bool anyPointsInView = false; // assume the worst!
|
bool anyPointsInView = false; // assume the worst!
|
||||||
|
@ -658,7 +658,7 @@ OctreeProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const
|
||||||
anyPointsInView = anyPointsInView || pointInView;
|
anyPointsInView = anyPointsInView || pointInView;
|
||||||
projectedPolygon.setVertex(i, projectedPoint);
|
projectedPolygon.setVertex(i, projectedPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
// Now that we've got the polygon, if it extends beyond the clipping window, then let's clip it
|
// Now that we've got the polygon, if it extends beyond the clipping window, then let's clip it
|
||||||
// NOTE: This clipping does not improve our overall performance. It basically causes more polygons to
|
// NOTE: This clipping does not improve our overall performance. It basically causes more polygons to
|
||||||
|
@ -667,20 +667,20 @@ OctreeProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const
|
||||||
(projectedPolygon.getMaxY() > PolygonClip::TOP_OF_CLIPPING_WINDOW ) ||
|
(projectedPolygon.getMaxY() > PolygonClip::TOP_OF_CLIPPING_WINDOW ) ||
|
||||||
(projectedPolygon.getMaxX() < PolygonClip::LEFT_OF_CLIPPING_WINDOW ) ||
|
(projectedPolygon.getMaxX() < PolygonClip::LEFT_OF_CLIPPING_WINDOW ) ||
|
||||||
(projectedPolygon.getMaxY() < PolygonClip::BOTTOM_OF_CLIPPING_WINDOW) ) {
|
(projectedPolygon.getMaxY() < PolygonClip::BOTTOM_OF_CLIPPING_WINDOW) ) {
|
||||||
|
|
||||||
CoverageRegion::_clippedPolygons++;
|
CoverageRegion::_clippedPolygons++;
|
||||||
|
|
||||||
glm::vec2* clippedVertices;
|
glm::vec2* clippedVertices;
|
||||||
int clippedVertexCount;
|
int clippedVertexCount;
|
||||||
PolygonClip::clipToScreen(projectedPolygon.getVertices(), vertexCount, clippedVertices, clippedVertexCount);
|
PolygonClip::clipToScreen(projectedPolygon.getVertices(), vertexCount, clippedVertices, clippedVertexCount);
|
||||||
|
|
||||||
// Now reset the vertices of our projectedPolygon object
|
// Now reset the vertices of our projectedPolygon object
|
||||||
projectedPolygon.setVertexCount(clippedVertexCount);
|
projectedPolygon.setVertexCount(clippedVertexCount);
|
||||||
for(int i = 0; i < clippedVertexCount; i++) {
|
for(int i = 0; i < clippedVertexCount; i++) {
|
||||||
projectedPolygon.setVertex(i, clippedVertices[i]);
|
projectedPolygon.setVertex(i, clippedVertices[i]);
|
||||||
}
|
}
|
||||||
delete[] clippedVertices;
|
delete[] clippedVertices;
|
||||||
|
|
||||||
lookUp += PROJECTION_CLIPPED;
|
lookUp += PROJECTION_CLIPPED;
|
||||||
}
|
}
|
||||||
***/
|
***/
|
||||||
|
@ -706,26 +706,26 @@ glm::vec3 ViewFrustum::getFurthestPointFromCamera(const AABox& box) const {
|
||||||
glm::vec3 furthestPoint;
|
glm::vec3 furthestPoint;
|
||||||
if (_position.x < center.x) {
|
if (_position.x < center.x) {
|
||||||
// we are to the right of the center, so the left edge is furthest
|
// we are to the right of the center, so the left edge is furthest
|
||||||
furthestPoint.x = topFarLeft.x;
|
furthestPoint.x = topFarLeft.x;
|
||||||
} else {
|
} else {
|
||||||
// we are to the left of the center, so the right edge is furthest (at center ok too)
|
// we are to the left of the center, so the right edge is furthest (at center ok too)
|
||||||
furthestPoint.x = bottomNearRight.x;
|
furthestPoint.x = bottomNearRight.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_position.y < center.y) {
|
if (_position.y < center.y) {
|
||||||
// we are below of the center, so the top edge is furthest
|
// we are below of the center, so the top edge is furthest
|
||||||
furthestPoint.y = topFarLeft.y;
|
furthestPoint.y = topFarLeft.y;
|
||||||
} else {
|
} else {
|
||||||
// we are above the center, so the lower edge is furthest (at center ok too)
|
// we are above the center, so the lower edge is furthest (at center ok too)
|
||||||
furthestPoint.y = bottomNearRight.y;
|
furthestPoint.y = bottomNearRight.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_position.z < center.z) {
|
if (_position.z < center.z) {
|
||||||
// we are to the near side of the center, so the far side edge is furthest
|
// we are to the near side of the center, so the far side edge is furthest
|
||||||
furthestPoint.z = topFarLeft.z;
|
furthestPoint.z = topFarLeft.z;
|
||||||
} else {
|
} else {
|
||||||
// we are to the far side of the center, so the near side edge is furthest (at center ok too)
|
// we are to the far side of the center, so the near side edge is furthest (at center ok too)
|
||||||
furthestPoint.z = bottomNearRight.z;
|
furthestPoint.z = bottomNearRight.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return furthestPoint;
|
return furthestPoint;
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
ViewFrustum::location pointInFrustum(const glm::vec3& point) const;
|
ViewFrustum::location pointInFrustum(const glm::vec3& point) const;
|
||||||
ViewFrustum::location sphereInFrustum(const glm::vec3& center, float radius) const;
|
ViewFrustum::location sphereInFrustum(const glm::vec3& center, float radius) const;
|
||||||
ViewFrustum::location boxInFrustum(const AABox& box) const;
|
ViewFrustum::location boxInFrustum(const AABox& box) const;
|
||||||
|
|
||||||
// some frustum comparisons
|
// some frustum comparisons
|
||||||
bool matches(const ViewFrustum& compareTo, bool debug = false) const;
|
bool matches(const ViewFrustum& compareTo, bool debug = false) const;
|
||||||
bool matches(const ViewFrustum* compareTo, bool debug = false) const { return matches(*compareTo, debug); }
|
bool matches(const ViewFrustum* compareTo, bool debug = false) const { return matches(*compareTo, debug); }
|
||||||
|
@ -90,11 +90,11 @@ public:
|
||||||
|
|
||||||
void computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const;
|
void computePickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const;
|
||||||
|
|
||||||
void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near, float& far,
|
void computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearValue, float& farValue,
|
||||||
glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const;
|
glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const;
|
||||||
|
|
||||||
void printDebugDetails() const;
|
void printDebugDetails() const;
|
||||||
|
|
||||||
glm::vec2 projectPoint(glm::vec3 point, bool& pointInView) const;
|
glm::vec2 projectPoint(glm::vec3 point, bool& pointInView) const;
|
||||||
OctreeProjectedPolygon getProjectedPolygon(const AABox& box) const;
|
OctreeProjectedPolygon getProjectedPolygon(const AABox& box) const;
|
||||||
glm::vec3 getFurthestPointFromCamera(const AABox& box) const;
|
glm::vec3 getFurthestPointFromCamera(const AABox& box) const;
|
||||||
|
@ -104,16 +104,16 @@ private:
|
||||||
ViewFrustum::location pointInKeyhole(const glm::vec3& point) const;
|
ViewFrustum::location pointInKeyhole(const glm::vec3& point) const;
|
||||||
ViewFrustum::location sphereInKeyhole(const glm::vec3& center, float radius) const;
|
ViewFrustum::location sphereInKeyhole(const glm::vec3& center, float radius) const;
|
||||||
ViewFrustum::location boxInKeyhole(const AABox& box) const;
|
ViewFrustum::location boxInKeyhole(const AABox& box) const;
|
||||||
|
|
||||||
// camera location/orientation attributes
|
// camera location/orientation attributes
|
||||||
glm::vec3 _position;
|
glm::vec3 _position;
|
||||||
glm::quat _orientation;
|
glm::quat _orientation;
|
||||||
|
|
||||||
// calculated for orientation
|
// calculated for orientation
|
||||||
glm::vec3 _direction;
|
glm::vec3 _direction;
|
||||||
glm::vec3 _up;
|
glm::vec3 _up;
|
||||||
glm::vec3 _right;
|
glm::vec3 _right;
|
||||||
|
|
||||||
// Lens attributes
|
// Lens attributes
|
||||||
float _fieldOfView;
|
float _fieldOfView;
|
||||||
float _aspectRatio;
|
float _aspectRatio;
|
||||||
|
@ -122,12 +122,12 @@ private:
|
||||||
float _focalLength;
|
float _focalLength;
|
||||||
glm::vec3 _eyeOffsetPosition;
|
glm::vec3 _eyeOffsetPosition;
|
||||||
glm::quat _eyeOffsetOrientation;
|
glm::quat _eyeOffsetOrientation;
|
||||||
|
|
||||||
// keyhole attributes
|
// keyhole attributes
|
||||||
float _keyholeRadius;
|
float _keyholeRadius;
|
||||||
AABox _keyholeBoundingBox;
|
AABox _keyholeBoundingBox;
|
||||||
|
|
||||||
|
|
||||||
// Calculated values
|
// Calculated values
|
||||||
glm::vec3 _offsetPosition;
|
glm::vec3 _offsetPosition;
|
||||||
glm::vec3 _offsetDirection;
|
glm::vec3 _offsetDirection;
|
||||||
|
@ -143,9 +143,9 @@ private:
|
||||||
glm::vec3 _nearBottomRight;
|
glm::vec3 _nearBottomRight;
|
||||||
enum { TOP_PLANE = 0, BOTTOM_PLANE, LEFT_PLANE, RIGHT_PLANE, NEAR_PLANE, FAR_PLANE };
|
enum { TOP_PLANE = 0, BOTTOM_PLANE, LEFT_PLANE, RIGHT_PLANE, NEAR_PLANE, FAR_PLANE };
|
||||||
::Plane _planes[6]; // How will this be used?
|
::Plane _planes[6]; // How will this be used?
|
||||||
|
|
||||||
const char* debugPlaneName (int plane) const;
|
const char* debugPlaneName (int plane) const;
|
||||||
|
|
||||||
// Used to project points
|
// Used to project points
|
||||||
glm::mat4 _ourModelViewProjectionMatrix;
|
glm::mat4 _ourModelViewProjectionMatrix;
|
||||||
};
|
};
|
||||||
|
|
|
@ -80,12 +80,12 @@ void outputBits(unsigned char byte, bool withNewLine, bool usePrintf) {
|
||||||
} else {
|
} else {
|
||||||
usePrintf ? (void)printf("[ %d (0x%x): ", byte, byte) : qDebug("[ %d (0x%x): ", byte, byte);
|
usePrintf ? (void)printf("[ %d (0x%x): ", byte, byte) : qDebug("[ %d (0x%x): ", byte, byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
usePrintf ? (void)printf("%d", byte >> (7 - i) & 1) : qDebug("%d", byte >> (7 - i) & 1);
|
usePrintf ? (void)printf("%d", byte >> (7 - i) & 1) : qDebug("%d", byte >> (7 - i) & 1);
|
||||||
}
|
}
|
||||||
usePrintf ? (void)printf(" ] ") : qDebug(" ] ");
|
usePrintf ? (void)printf(" ] ") : qDebug(" ] ");
|
||||||
|
|
||||||
if (withNewLine) {
|
if (withNewLine) {
|
||||||
usePrintf ? (void)printf("\n") : qDebug("\n");
|
usePrintf ? (void)printf("\n") : qDebug("\n");
|
||||||
}
|
}
|
||||||
|
@ -121,11 +121,11 @@ int getSemiNibbleAt(unsigned char& byte, int bitIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNthBit(unsigned char byte, int ordinal) {
|
int getNthBit(unsigned char byte, int ordinal) {
|
||||||
const int ERROR = -1;
|
const int ERROR_RESULT = -1;
|
||||||
const int MIN_ORDINAL = 1;
|
const int MIN_ORDINAL = 1;
|
||||||
const int MAX_ORDINAL = 8;
|
const int MAX_ORDINAL = 8;
|
||||||
if (ordinal < MIN_ORDINAL || ordinal > MAX_ORDINAL) {
|
if (ordinal < MIN_ORDINAL || ordinal > MAX_ORDINAL) {
|
||||||
return ERROR;
|
return ERROR_RESULT;
|
||||||
}
|
}
|
||||||
int bitsSet = 0;
|
int bitsSet = 0;
|
||||||
for (int bitIndex = 0; bitIndex < MAX_ORDINAL; bitIndex++) {
|
for (int bitIndex = 0; bitIndex < MAX_ORDINAL; bitIndex++) {
|
||||||
|
@ -136,11 +136,11 @@ int getNthBit(unsigned char byte, int ordinal) {
|
||||||
return bitIndex;
|
return bitIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ERROR;
|
return ERROR_RESULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBetween(int64_t value, int64_t max, int64_t min) {
|
bool isBetween(int64_t value, int64_t max, int64_t min) {
|
||||||
return ((value <= max) && (value >= min));
|
return ((value <= max) && (value >= min));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ void setSemiNibbleAt(unsigned char& byte, int bitIndex, int value) {
|
||||||
|
|
||||||
bool isInEnvironment(const char* environment) {
|
bool isInEnvironment(const char* environment) {
|
||||||
char* environmentString = getenv("HIFI_ENVIRONMENT");
|
char* environmentString = getenv("HIFI_ENVIRONMENT");
|
||||||
|
|
||||||
if (environmentString && strcmp(environmentString, environment) == 0) {
|
if (environmentString && strcmp(environmentString, environment) == 0) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -169,7 +169,7 @@ void switchToResourcesParentIfRequired() {
|
||||||
// error!
|
// error!
|
||||||
}
|
}
|
||||||
CFRelease(resourcesURL);
|
CFRelease(resourcesURL);
|
||||||
|
|
||||||
chdir(path);
|
chdir(path);
|
||||||
chdir("..");
|
chdir("..");
|
||||||
#endif
|
#endif
|
||||||
|
@ -178,7 +178,7 @@ void switchToResourcesParentIfRequired() {
|
||||||
void loadRandomIdentifier(unsigned char* identifierBuffer, int numBytes) {
|
void loadRandomIdentifier(unsigned char* identifierBuffer, int numBytes) {
|
||||||
// seed the the random number generator
|
// seed the the random number generator
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
for (int i = 0; i < numBytes; i++) {
|
for (int i = 0; i < numBytes; i++) {
|
||||||
identifierBuffer[i] = rand() % 256;
|
identifierBuffer[i] = rand() % 256;
|
||||||
}
|
}
|
||||||
|
@ -230,9 +230,9 @@ void sharedMessageHandler(QtMsgType type, const QMessageLogContext& context, con
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Function: createVoxelEditMessage()
|
// Function: createVoxelEditMessage()
|
||||||
// Description: creates an "insert" or "remove" voxel message for a voxel code
|
// Description: creates an "insert" or "remove" voxel message for a voxel code
|
||||||
// corresponding to the closest voxel which encloses a cube with
|
// corresponding to the closest voxel which encloses a cube with
|
||||||
// lower corners at x,y,z, having side of length S.
|
// lower corners at x,y,z, having side of length S.
|
||||||
// The input values x,y,z range 0.0 <= v < 1.0
|
// The input values x,y,z range 0.0 <= v < 1.0
|
||||||
// message should be either 'S' for SET or 'E' for ERASE
|
// message should be either 'S' for SET or 'E' for ERASE
|
||||||
//
|
//
|
||||||
|
@ -246,13 +246,13 @@ void sharedMessageHandler(QtMsgType type, const QMessageLogContext& context, con
|
||||||
#define GUESS_OF_VOXELCODE_SIZE 10
|
#define GUESS_OF_VOXELCODE_SIZE 10
|
||||||
#define MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE 1500
|
#define MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE 1500
|
||||||
#define SIZE_OF_COLOR_DATA sizeof(rgbColor)
|
#define SIZE_OF_COLOR_DATA sizeof(rgbColor)
|
||||||
bool createVoxelEditMessage(unsigned char command, short int sequence,
|
bool createVoxelEditMessage(unsigned char command, short int sequence,
|
||||||
int voxelCount, VoxelDetail* voxelDetails, unsigned char*& bufferOut, int& sizeOut) {
|
int voxelCount, VoxelDetail* voxelDetails, unsigned char*& bufferOut, int& sizeOut) {
|
||||||
|
|
||||||
bool success = true; // assume the best
|
bool success = true; // assume the best
|
||||||
int messageSize = MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE; // just a guess for now
|
int messageSize = MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE; // just a guess for now
|
||||||
unsigned char* messageBuffer = new unsigned char[messageSize];
|
unsigned char* messageBuffer = new unsigned char[messageSize];
|
||||||
|
|
||||||
int numBytesPacketHeader = populateTypeAndVersion(messageBuffer, command);
|
int numBytesPacketHeader = populateTypeAndVersion(messageBuffer, command);
|
||||||
unsigned short int* sequenceAt = (unsigned short int*) &messageBuffer[numBytesPacketHeader];
|
unsigned short int* sequenceAt = (unsigned short int*) &messageBuffer[numBytesPacketHeader];
|
||||||
*sequenceAt = sequence;
|
*sequenceAt = sequence;
|
||||||
|
@ -269,9 +269,9 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
|
||||||
// get the coded voxel
|
// get the coded voxel
|
||||||
unsigned char* voxelData = pointToVoxel(voxelDetails[i].x,voxelDetails[i].y,voxelDetails[i].z,
|
unsigned char* voxelData = pointToVoxel(voxelDetails[i].x,voxelDetails[i].y,voxelDetails[i].z,
|
||||||
voxelDetails[i].s,voxelDetails[i].red,voxelDetails[i].green,voxelDetails[i].blue);
|
voxelDetails[i].s,voxelDetails[i].red,voxelDetails[i].green,voxelDetails[i].blue);
|
||||||
|
|
||||||
int lengthOfVoxelData = bytesRequiredForCodeLength(*voxelData)+SIZE_OF_COLOR_DATA;
|
int lengthOfVoxelData = bytesRequiredForCodeLength(*voxelData)+SIZE_OF_COLOR_DATA;
|
||||||
|
|
||||||
// make sure we have room to copy this voxel
|
// make sure we have room to copy this voxel
|
||||||
if (actualMessageSize + lengthOfVoxelData > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
|
if (actualMessageSize + lengthOfVoxelData > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
|
||||||
success = false;
|
success = false;
|
||||||
|
@ -285,19 +285,19 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
|
||||||
delete[] voxelData;
|
delete[] voxelData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// finally, copy the result to the output
|
// finally, copy the result to the output
|
||||||
bufferOut = new unsigned char[actualMessageSize];
|
bufferOut = new unsigned char[actualMessageSize];
|
||||||
sizeOut = actualMessageSize;
|
sizeOut = actualMessageSize;
|
||||||
memcpy(bufferOut, messageBuffer, actualMessageSize);
|
memcpy(bufferOut, messageBuffer, actualMessageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] messageBuffer; // clean up our temporary buffer
|
delete[] messageBuffer; // clean up our temporary buffer
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// encodes the voxel details portion of a voxel edit message
|
/// encodes the voxel details portion of a voxel edit message
|
||||||
bool encodeVoxelEditMessageDetails(unsigned char command, int voxelCount, VoxelDetail* voxelDetails,
|
bool encodeVoxelEditMessageDetails(unsigned char command, int voxelCount, VoxelDetail* voxelDetails,
|
||||||
unsigned char* bufferOut, int sizeIn, int& sizeOut) {
|
unsigned char* bufferOut, int sizeIn, int& sizeOut) {
|
||||||
|
|
||||||
bool success = true; // assume the best
|
bool success = true; // assume the best
|
||||||
|
@ -308,9 +308,9 @@ bool encodeVoxelEditMessageDetails(unsigned char command, int voxelCount, VoxelD
|
||||||
// get the coded voxel
|
// get the coded voxel
|
||||||
unsigned char* voxelData = pointToVoxel(voxelDetails[i].x,voxelDetails[i].y,voxelDetails[i].z,
|
unsigned char* voxelData = pointToVoxel(voxelDetails[i].x,voxelDetails[i].y,voxelDetails[i].z,
|
||||||
voxelDetails[i].s,voxelDetails[i].red,voxelDetails[i].green,voxelDetails[i].blue);
|
voxelDetails[i].s,voxelDetails[i].red,voxelDetails[i].green,voxelDetails[i].blue);
|
||||||
|
|
||||||
int lengthOfVoxelData = bytesRequiredForCodeLength(*voxelData)+SIZE_OF_COLOR_DATA;
|
int lengthOfVoxelData = bytesRequiredForCodeLength(*voxelData)+SIZE_OF_COLOR_DATA;
|
||||||
|
|
||||||
// make sure we have room to copy this voxel
|
// make sure we have room to copy this voxel
|
||||||
if (sizeOut + lengthOfVoxelData > sizeIn) {
|
if (sizeOut + lengthOfVoxelData > sizeIn) {
|
||||||
success = false;
|
success = false;
|
||||||
|
@ -328,13 +328,13 @@ bool encodeVoxelEditMessageDetails(unsigned char command, int voxelCount, VoxelD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned char* pointToOctalCode(float x, float y, float z, float s) {
|
unsigned char* pointToOctalCode(float x, float y, float z, float s) {
|
||||||
return pointToVoxel(x, y, z, s);
|
return pointToVoxel(x, y, z, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a universal point with location x,y,z this will return the voxel
|
/// Given a universal point with location x,y,z this will return the voxel
|
||||||
/// voxel code corresponding to the closest voxel which encloses a cube with
|
/// voxel code corresponding to the closest voxel which encloses a cube with
|
||||||
/// lower corners at x,y,z, having side of length S.
|
/// lower corners at x,y,z, having side of length S.
|
||||||
/// The input values x,y,z range 0.0 <= v < 1.0
|
/// The input values x,y,z range 0.0 <= v < 1.0
|
||||||
/// IMPORTANT: The voxel is returned to you a buffer which you MUST delete when you are
|
/// IMPORTANT: The voxel is returned to you a buffer which you MUST delete when you are
|
||||||
/// done with it.
|
/// done with it.
|
||||||
|
@ -347,10 +347,10 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
|
||||||
return voxelOut;
|
return voxelOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
float xTest, yTest, zTest, sTest;
|
float xTest, yTest, zTest, sTest;
|
||||||
xTest = yTest = zTest = sTest = 0.5f;
|
xTest = yTest = zTest = sTest = 0.5f;
|
||||||
|
|
||||||
// First determine the voxelSize that will properly encode a
|
// First determine the voxelSize that will properly encode a
|
||||||
// voxel of size S.
|
// voxel of size S.
|
||||||
unsigned int voxelSizeInOctets = 1;
|
unsigned int voxelSizeInOctets = 1;
|
||||||
while (sTest > s) {
|
while (sTest > s) {
|
||||||
|
@ -379,11 +379,11 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
|
||||||
if (x >= xTest) {
|
if (x >= xTest) {
|
||||||
//<write 1 bit>
|
//<write 1 bit>
|
||||||
byte = (byte << 1) | true;
|
byte = (byte << 1) | true;
|
||||||
xTest += sTest/2.0;
|
xTest += sTest/2.0;
|
||||||
} else {
|
} else {
|
||||||
//<write 0 bit;>
|
//<write 0 bit;>
|
||||||
byte = (byte << 1) | false;
|
byte = (byte << 1) | false;
|
||||||
xTest -= sTest/2.0;
|
xTest -= sTest/2.0;
|
||||||
}
|
}
|
||||||
bitInByteNDX++;
|
bitInByteNDX++;
|
||||||
// If we've reached the last bit of the byte, then we want to copy this byte
|
// If we've reached the last bit of the byte, then we want to copy this byte
|
||||||
|
@ -398,11 +398,11 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
|
||||||
if (y >= yTest) {
|
if (y >= yTest) {
|
||||||
//<write 1 bit>
|
//<write 1 bit>
|
||||||
byte = (byte << 1) | true;
|
byte = (byte << 1) | true;
|
||||||
yTest += sTest/2.0;
|
yTest += sTest/2.0;
|
||||||
} else {
|
} else {
|
||||||
//<write 0 bit;>
|
//<write 0 bit;>
|
||||||
byte = (byte << 1) | false;
|
byte = (byte << 1) | false;
|
||||||
yTest -= sTest/2.0;
|
yTest -= sTest/2.0;
|
||||||
}
|
}
|
||||||
bitInByteNDX++;
|
bitInByteNDX++;
|
||||||
// If we've reached the last bit of the byte, then we want to copy this byte
|
// If we've reached the last bit of the byte, then we want to copy this byte
|
||||||
|
@ -417,11 +417,11 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
|
||||||
if (z >= zTest) {
|
if (z >= zTest) {
|
||||||
//<write 1 bit>
|
//<write 1 bit>
|
||||||
byte = (byte << 1) | true;
|
byte = (byte << 1) | true;
|
||||||
zTest += sTest/2.0;
|
zTest += sTest/2.0;
|
||||||
} else {
|
} else {
|
||||||
//<write 0 bit;>
|
//<write 0 bit;>
|
||||||
byte = (byte << 1) | false;
|
byte = (byte << 1) | false;
|
||||||
zTest -= sTest/2.0;
|
zTest -= sTest/2.0;
|
||||||
}
|
}
|
||||||
bitInByteNDX++;
|
bitInByteNDX++;
|
||||||
// If we've reached the last bit of the byte, then we want to copy this byte
|
// If we've reached the last bit of the byte, then we want to copy this byte
|
||||||
|
@ -435,7 +435,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
|
||||||
|
|
||||||
octetsDone++;
|
octetsDone++;
|
||||||
sTest /= 2.0;
|
sTest /= 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've got here, and we didn't fill the last byte, we need to zero pad this
|
// If we've got here, and we didn't fill the last byte, we need to zero pad this
|
||||||
// byte before we copy it into our buffer.
|
// byte before we copy it into our buffer.
|
||||||
|
@ -445,7 +445,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
|
||||||
byte = (byte << 1) | false;
|
byte = (byte << 1) | false;
|
||||||
bitInByteNDX++;
|
bitInByteNDX++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy it into our output buffer
|
// Copy it into our output buffer
|
||||||
voxelOut[byteNDX]=byte;
|
voxelOut[byteNDX]=byte;
|
||||||
byteNDX++;
|
byteNDX++;
|
||||||
|
@ -470,7 +470,7 @@ void printVoxelCode(unsigned char* voxelCode) {
|
||||||
qDebug("voxelSizeInBytes=%d\n",voxelSizeInBytes);
|
qDebug("voxelSizeInBytes=%d\n",voxelSizeInBytes);
|
||||||
qDebug("voxelSizeInOctets=%d\n",voxelSizeInOctets);
|
qDebug("voxelSizeInOctets=%d\n",voxelSizeInOctets);
|
||||||
qDebug("voxelBufferSize=%d\n",voxelBufferSize);
|
qDebug("voxelBufferSize=%d\n",voxelBufferSize);
|
||||||
|
|
||||||
for(int i=0;i<voxelBufferSize;i++) {
|
for(int i=0;i<voxelBufferSize;i++) {
|
||||||
qDebug("i=%d ",i);
|
qDebug("i=%d ",i);
|
||||||
outputBits(voxelCode[i]);
|
outputBits(voxelCode[i]);
|
||||||
|
@ -491,13 +491,13 @@ void printVoxelCode(unsigned char* voxelCode) {
|
||||||
|
|
||||||
// Inserts the value and key into three arrays sorted by the key array, the first array is the value,
|
// Inserts the value and key into three arrays sorted by the key array, the first array is the value,
|
||||||
// the second array is a sorted key for the value, the third array is the index for the value in it original
|
// the second array is a sorted key for the value, the third array is the index for the value in it original
|
||||||
// non-sorted array
|
// non-sorted array
|
||||||
// returns -1 if size exceeded
|
// returns -1 if size exceeded
|
||||||
// originalIndexArray is optional
|
// originalIndexArray is optional
|
||||||
int insertIntoSortedArrays(void* value, float key, int originalIndex,
|
int insertIntoSortedArrays(void* value, float key, int originalIndex,
|
||||||
void** valueArray, float* keyArray, int* originalIndexArray,
|
void** valueArray, float* keyArray, int* originalIndexArray,
|
||||||
int currentCount, int maxCount) {
|
int currentCount, int maxCount) {
|
||||||
|
|
||||||
if (currentCount < maxCount) {
|
if (currentCount < maxCount) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (currentCount > 0) {
|
if (currentCount > 0) {
|
||||||
|
@ -525,7 +525,7 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex,
|
||||||
return -1; // error case
|
return -1; // error case
|
||||||
}
|
}
|
||||||
|
|
||||||
int removeFromSortedArrays(void* value, void** valueArray, float* keyArray, int* originalIndexArray,
|
int removeFromSortedArrays(void* value, void** valueArray, float* keyArray, int* originalIndexArray,
|
||||||
int currentCount, int maxCount) {
|
int currentCount, int maxCount) {
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -533,7 +533,7 @@ int removeFromSortedArrays(void* value, void** valueArray, float* keyArray, int*
|
||||||
while (i < currentCount && value != valueArray[i]) {
|
while (i < currentCount && value != valueArray[i]) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == valueArray[i] && i < currentCount) {
|
if (value == valueArray[i] && i < currentCount) {
|
||||||
// i is the location of the item we were looking for
|
// i is the location of the item we were looking for
|
||||||
// shift array elements to the left
|
// shift array elements to the left
|
||||||
|
@ -579,10 +579,10 @@ int unpackFloatVec3FromSignedTwoByteFixed(unsigned char* sourceBuffer, glm::vec3
|
||||||
|
|
||||||
int packFloatAngleToTwoByte(unsigned char* buffer, float angle) {
|
int packFloatAngleToTwoByte(unsigned char* buffer, float angle) {
|
||||||
const float ANGLE_CONVERSION_RATIO = (std::numeric_limits<uint16_t>::max() / 360.0);
|
const float ANGLE_CONVERSION_RATIO = (std::numeric_limits<uint16_t>::max() / 360.0);
|
||||||
|
|
||||||
uint16_t angleHolder = floorf((angle + 180) * ANGLE_CONVERSION_RATIO);
|
uint16_t angleHolder = floorf((angle + 180) * ANGLE_CONVERSION_RATIO);
|
||||||
memcpy(buffer, &angleHolder, sizeof(uint16_t));
|
memcpy(buffer, &angleHolder, sizeof(uint16_t));
|
||||||
|
|
||||||
return sizeof(uint16_t);
|
return sizeof(uint16_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,7 +621,7 @@ float LARGE_LIMIT = 1000.0;
|
||||||
int packFloatRatioToTwoByte(unsigned char* buffer, float ratio) {
|
int packFloatRatioToTwoByte(unsigned char* buffer, float ratio) {
|
||||||
// if the ratio is less than 10, then encode it as a positive number scaled from 0 to int16::max()
|
// if the ratio is less than 10, then encode it as a positive number scaled from 0 to int16::max()
|
||||||
int16_t ratioHolder;
|
int16_t ratioHolder;
|
||||||
|
|
||||||
if (ratio < SMALL_LIMIT) {
|
if (ratio < SMALL_LIMIT) {
|
||||||
const float SMALL_RATIO_CONVERSION_RATIO = (std::numeric_limits<int16_t>::max() / SMALL_LIMIT);
|
const float SMALL_RATIO_CONVERSION_RATIO = (std::numeric_limits<int16_t>::max() / SMALL_LIMIT);
|
||||||
ratioHolder = floorf(ratio * SMALL_RATIO_CONVERSION_RATIO);
|
ratioHolder = floorf(ratio * SMALL_RATIO_CONVERSION_RATIO);
|
||||||
|
@ -651,7 +651,7 @@ int packClipValueToTwoByte(unsigned char* buffer, float clipValue) {
|
||||||
// Clip values must be less than max signed 16bit integers
|
// Clip values must be less than max signed 16bit integers
|
||||||
assert(clipValue < std::numeric_limits<int16_t>::max());
|
assert(clipValue < std::numeric_limits<int16_t>::max());
|
||||||
int16_t holder;
|
int16_t holder;
|
||||||
|
|
||||||
// if the clip is less than 10, then encode it as a positive number scaled from 0 to int16::max()
|
// if the clip is less than 10, then encode it as a positive number scaled from 0 to int16::max()
|
||||||
if (clipValue < SMALL_LIMIT) {
|
if (clipValue < SMALL_LIMIT) {
|
||||||
const float SMALL_RATIO_CONVERSION_RATIO = (std::numeric_limits<int16_t>::max() / SMALL_LIMIT);
|
const float SMALL_RATIO_CONVERSION_RATIO = (std::numeric_limits<int16_t>::max() / SMALL_LIMIT);
|
||||||
|
|
Loading…
Reference in a new issue