tweaks to some variable names since windows has a problem with them

This commit is contained in:
Brad Hefta-Gaub 2014-01-10 18:28:18 -08:00
parent 5725a92cfe
commit e55e680e66
3 changed files with 140 additions and 140 deletions

View file

@ -46,7 +46,7 @@ ViewFrustum::ViewFrustum() :
_nearBottomRight(0,0,0)
{
}
void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) {
_orientation = orientationAsQuaternion;
_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
// 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/
//
void ViewFrustum::calculate() {
@ -68,13 +68,13 @@ void ViewFrustum::calculate() {
float left, right, bottom, top, nearVal, farVal;
glm::vec4 nearClipPlane, farClipPlane;
computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
// start with the corners of the near frustum window
glm::vec3 topLeft(left, top, -nearVal);
glm::vec3 topRight(right, top, -nearVal);
glm::vec3 bottomLeft(left, bottom, -nearVal);
glm::vec3 bottomRight(right, bottom, -nearVal);
// find the intersections of the rays through the corners with the clip planes in view space,
// then transform them to world space
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));
_nearBottomRight = glm::vec3(worldMatrix * glm::vec4(bottomRight *
(-nearClipPlane.w / glm::dot(bottomRight, glm::vec3(nearClipPlane))), 1.0f));
// compute the offset position and axes in world space
_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));
_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));
// compute the six planes
// 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
// 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
// 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
// is positive, then it is on the right side of the respective plane. If an object is on the
// 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
// 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
// are inside the frustum, facing the plane. Start with any point, and go counter clockwise for
// three consecutive points
_planes[TOP_PLANE ].set3Points(_nearTopRight,_nearTopLeft,_farTopLeft);
_planes[BOTTOM_PLANE].set3Points(_nearBottomLeft,_nearBottomRight,_farBottomRight);
_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)
_ourModelViewProjectionMatrix = projection * view; // Remember, matrix multiplication is the other way around
// Set up our keyhole bounding box...
glm::vec3 corner = _position - _keyholeRadius;
_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 result = INTERSECT;
float distance = glm::distance(point, _position);
if (distance > _keyholeRadius) {
result = OUTSIDE;
} else if (distance < _keyholeRadius) {
result = INSIDE;
}
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
ViewFrustum::location ViewFrustum::sphereInKeyhole(const glm::vec3& center, float radius) const {
ViewFrustum::location result = INTERSECT;
float distance = glm::distance(center, _position);
if (distance > (radius + _keyholeRadius)) {
result = OUTSIDE;
} else if ((distance + radius) < _keyholeRadius) {
result = INSIDE;
}
return result;
}
@ -194,7 +194,7 @@ ViewFrustum::location ViewFrustum::boxInKeyhole(const AABox& box) const {
bool intersects = box.findSpherePenetration(_position, _keyholeRadius, penetration);
ViewFrustum::location result = OUTSIDE;
// if the box intersects the sphere, then it may also be inside... calculate further
if (intersects) {
result = INTERSECT;
@ -208,12 +208,12 @@ ViewFrustum::location ViewFrustum::boxInKeyhole(const AABox& box) const {
break;
}
}
if (allPointsInside) {
result = INSIDE;
}
}
return result;
}
@ -262,7 +262,7 @@ ViewFrustum::location ViewFrustum::sphereInFrustum(const glm::vec3& center, floa
regularResult = INTERSECT;
}
}
return regularResult;
}
@ -287,7 +287,7 @@ ViewFrustum::location ViewFrustum::boxInFrustum(const AABox& box) const {
const glm::vec3& boxVertexN = box.getVertexN(normal);
float planeToBoxVertexNDistance = _planes[i].distance(boxVertexN);
if (planeToBoxVertexPDistance < 0) {
// This is outside the regular frustum, so just return the value from checking the keyhole
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 result =
bool result =
testMatches(compareTo._position, _position) &&
testMatches(compareTo._direction, _direction) &&
testMatches(compareTo._up, _up) &&
@ -327,42 +327,42 @@ bool ViewFrustum::matches(const ViewFrustum& compareTo, bool debug) const {
if (!result && debug) {
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"),
compareTo._position.x, compareTo._position.y, compareTo._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"),
compareTo._direction.x, compareTo._direction.y, compareTo._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"),
compareTo._up.x, compareTo._up.y, compareTo._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"),
compareTo._right.x, compareTo._right.y, compareTo._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"),
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"),
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"),
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"),
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"),
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"),
compareTo._eyeOffsetPosition.x, compareTo._eyeOffsetPosition.y, compareTo._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"),
compareTo._eyeOffsetOrientation.x, compareTo._eyeOffsetOrientation.y,
compareTo._eyeOffsetOrientation.z, compareTo._eyeOffsetOrientation.w,
@ -391,15 +391,15 @@ bool ViewFrustum::isVerySimilar(const ViewFrustum& compareTo, bool debug) const
if (isNaN(angleOrientation)) {
angleOrientation = 0.0f;
}
glm::quat dQEyeOffsetOrientation = _eyeOffsetOrientation * glm::inverse(compareTo._eyeOffsetOrientation);
float angleEyeOffsetOrientation = compareTo._eyeOffsetOrientation == _eyeOffsetOrientation
float angleEyeOffsetOrientation = compareTo._eyeOffsetOrientation == _eyeOffsetOrientation
? 0.0f : glm::angle(dQEyeOffsetOrientation);
if (isNaN(angleEyeOffsetOrientation)) {
angleOrientation = 0.0f;
}
bool result =
bool result =
testMatches(0, positionDistance, POSITION_SIMILAR_ENOUGH) &&
testMatches(0, angleOrientation, ORIENTATION_SIMILAR_ENOUGH) &&
testMatches(compareTo._fieldOfView, _fieldOfView) &&
@ -413,45 +413,45 @@ bool ViewFrustum::isVerySimilar(const ViewFrustum& compareTo, bool debug) const
if (!result && debug) {
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"),
compareTo._position.x, compareTo._position.y, compareTo._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"),
positionDistance);
qDebug("%s -- angleOrientation=%f\n",
qDebug("%s -- angleOrientation=%f\n",
(testMatches(0, angleOrientation, ORIENTATION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
angleOrientation);
qDebug("%s -- compareTo._fieldOfView=%f _fieldOfView=%f\n",
qDebug("%s -- compareTo._fieldOfView=%f _fieldOfView=%f\n",
(testMatches(compareTo._fieldOfView, _fieldOfView) ? "MATCHES " : "NO MATCH"),
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"),
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"),
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"),
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"),
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"),
compareTo._eyeOffsetPosition.x, compareTo._eyeOffsetPosition.y, compareTo._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"),
eyeOffsetpositionDistance);
qDebug("%s -- angleEyeOffsetOrientation=%f\n",
qDebug("%s -- angleEyeOffsetOrientation=%f\n",
(testMatches(0, angleEyeOffsetOrientation, ORIENTATION_SIMILAR_ENOUGH) ? "IS SIMILAR ENOUGH " : "IS NOT SIMILAR ENOUGH"),
angleEyeOffsetOrientation);
}
@ -463,12 +463,12 @@ void ViewFrustum::computePickRay(float x, float y, glm::vec3& origin, glm::vec3&
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 {
// compute our dimensions the usual way
float hheight = _nearClip * tanf(_fieldOfView * 0.5f * PI_OVER_180);
float hwidth = _aspectRatio * hheight;
// get our frustum corners in view space
glm::mat4 eyeMatrix = glm::mat4_cast(glm::inverse(_eyeOffsetOrientation)) * glm::translate(-_eyeOffsetPosition);
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[6] = 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
near = FLT_MAX;
far = -FLT_MAX;
nearValue = FLT_MAX;
farValue = -FLT_MAX;
for (int i = 0; i < 8; i++) {
near = min(near, -corners[i].z);
far = max(far, -corners[i].z);
nearValue = min(nearValue, -corners[i].z);
farValue = max(farValue, -corners[i].z);
}
// make sure the near clip isn't too small to be valid
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
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]));
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);
// get the extents at Z = -near
left = FLT_MAX;
right = -FLT_MAX;
@ -509,7 +509,7 @@ void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom
top = -FLT_MAX;
for (int i = 0; i < 4; i++) {
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);
right = max(right, intersection.x);
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 projectedPointVec4 = _ourModelViewProjectionMatrix * pointVec4;
pointInView = (projectedPointVec4.w > 0); // math! If the w result is negative then the point is behind the viewer
// what happens with w is 0???
float x = projectedPointVec4.x / projectedPointVec4.w;
float y = projectedPointVec4.y / projectedPointVec4.w;
glm::vec2 projectedPoint(x,y);
// if the point is out of view we also need to flip the signs of x and y
if (!pointInView) {
projectedPoint.x = -x;
@ -563,7 +563,7 @@ const int hullVertexLookup[MAX_POSSIBLE_COMBINATIONS][MAX_PROJECTED_POLYGON_VERT
//0
{0}, // inside
{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
//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
//34
{6, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, BOTTOM_LEFT_NEAR, TOP_LEFT_NEAR, TOP_LEFT_FAR, TOP_RIGHT_FAR }, // back, left
{0}, // n/a
//36
{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
{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
//42
{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
int vertexCount = hullVertexLookup[lookUp][0]; //look up number of vertices
OctreeProjectedPolygon projectedPolygon(vertexCount);
bool pointInView = true;
bool allPointsInView = false; // assume the best, but wait till we know we have a vertex
bool anyPointsInView = false; // assume the worst!
@ -658,7 +658,7 @@ OctreeProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const
anyPointsInView = anyPointsInView || pointInView;
projectedPolygon.setVertex(i, projectedPoint);
}
/***
// 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
@ -667,20 +667,20 @@ OctreeProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const
(projectedPolygon.getMaxY() > PolygonClip::TOP_OF_CLIPPING_WINDOW ) ||
(projectedPolygon.getMaxX() < PolygonClip::LEFT_OF_CLIPPING_WINDOW ) ||
(projectedPolygon.getMaxY() < PolygonClip::BOTTOM_OF_CLIPPING_WINDOW) ) {
CoverageRegion::_clippedPolygons++;
glm::vec2* clippedVertices;
int clippedVertexCount;
PolygonClip::clipToScreen(projectedPolygon.getVertices(), vertexCount, clippedVertices, clippedVertexCount);
// Now reset the vertices of our projectedPolygon object
projectedPolygon.setVertexCount(clippedVertexCount);
for(int i = 0; i < clippedVertexCount; i++) {
projectedPolygon.setVertex(i, clippedVertices[i]);
}
delete[] clippedVertices;
lookUp += PROJECTION_CLIPPED;
}
***/
@ -706,26 +706,26 @@ glm::vec3 ViewFrustum::getFurthestPointFromCamera(const AABox& box) const {
glm::vec3 furthestPoint;
if (_position.x < center.x) {
// we are to the right of the center, so the left edge is furthest
furthestPoint.x = topFarLeft.x;
furthestPoint.x = topFarLeft.x;
} else {
// 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) {
// we are below of the center, so the top edge is furthest
furthestPoint.y = topFarLeft.y;
furthestPoint.y = topFarLeft.y;
} else {
// 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) {
// 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 {
// 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;

View file

@ -80,7 +80,7 @@ public:
ViewFrustum::location pointInFrustum(const glm::vec3& point) const;
ViewFrustum::location sphereInFrustum(const glm::vec3& center, float radius) const;
ViewFrustum::location boxInFrustum(const AABox& box) const;
// some frustum comparisons
bool matches(const ViewFrustum& compareTo, bool debug = false) const;
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 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;
void printDebugDetails() const;
glm::vec2 projectPoint(glm::vec3 point, bool& pointInView) const;
OctreeProjectedPolygon getProjectedPolygon(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 sphereInKeyhole(const glm::vec3& center, float radius) const;
ViewFrustum::location boxInKeyhole(const AABox& box) const;
// camera location/orientation attributes
glm::vec3 _position;
glm::quat _orientation;
// calculated for orientation
glm::vec3 _direction;
glm::vec3 _up;
glm::vec3 _right;
// Lens attributes
float _fieldOfView;
float _aspectRatio;
@ -122,12 +122,12 @@ private:
float _focalLength;
glm::vec3 _eyeOffsetPosition;
glm::quat _eyeOffsetOrientation;
// keyhole attributes
float _keyholeRadius;
AABox _keyholeBoundingBox;
// Calculated values
glm::vec3 _offsetPosition;
glm::vec3 _offsetDirection;
@ -143,9 +143,9 @@ private:
glm::vec3 _nearBottomRight;
enum { TOP_PLANE = 0, BOTTOM_PLANE, LEFT_PLANE, RIGHT_PLANE, NEAR_PLANE, FAR_PLANE };
::Plane _planes[6]; // How will this be used?
const char* debugPlaneName (int plane) const;
// Used to project points
glm::mat4 _ourModelViewProjectionMatrix;
};

View file

@ -80,12 +80,12 @@ void outputBits(unsigned char byte, bool withNewLine, bool usePrintf) {
} else {
usePrintf ? (void)printf("[ %d (0x%x): ", byte, byte) : qDebug("[ %d (0x%x): ", byte, byte);
}
for (int i = 0; i < 8; i++) {
usePrintf ? (void)printf("%d", byte >> (7 - i) & 1) : qDebug("%d", byte >> (7 - i) & 1);
}
usePrintf ? (void)printf(" ] ") : qDebug(" ] ");
if (withNewLine) {
usePrintf ? (void)printf("\n") : qDebug("\n");
}
@ -121,11 +121,11 @@ int getSemiNibbleAt(unsigned char& byte, int bitIndex) {
}
int getNthBit(unsigned char byte, int ordinal) {
const int ERROR = -1;
const int ERROR_RESULT = -1;
const int MIN_ORDINAL = 1;
const int MAX_ORDINAL = 8;
if (ordinal < MIN_ORDINAL || ordinal > MAX_ORDINAL) {
return ERROR;
return ERROR_RESULT;
}
int bitsSet = 0;
for (int bitIndex = 0; bitIndex < MAX_ORDINAL; bitIndex++) {
@ -136,11 +136,11 @@ int getNthBit(unsigned char byte, int ordinal) {
return bitIndex;
}
}
return ERROR;
return ERROR_RESULT;
}
bool isBetween(int64_t value, int64_t max, int64_t min) {
return ((value <= max) && (value >= min));
bool isBetween(int64_t value, int64_t max, int64_t min) {
return ((value <= max) && (value >= min));
}
@ -152,7 +152,7 @@ void setSemiNibbleAt(unsigned char& byte, int bitIndex, int value) {
bool isInEnvironment(const char* environment) {
char* environmentString = getenv("HIFI_ENVIRONMENT");
if (environmentString && strcmp(environmentString, environment) == 0) {
return true;
} else {
@ -169,7 +169,7 @@ void switchToResourcesParentIfRequired() {
// error!
}
CFRelease(resourcesURL);
chdir(path);
chdir("..");
#endif
@ -178,7 +178,7 @@ void switchToResourcesParentIfRequired() {
void loadRandomIdentifier(unsigned char* identifierBuffer, int numBytes) {
// seed the the random number generator
srand(time(NULL));
for (int i = 0; i < numBytes; i++) {
identifierBuffer[i] = rand() % 256;
}
@ -230,9 +230,9 @@ void sharedMessageHandler(QtMsgType type, const QMessageLogContext& context, con
//////////////////////////////////////////////////////////////////////////////////////////
// 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
// 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
// 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 MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE 1500
#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) {
bool success = true; // assume the best
int messageSize = MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE; // just a guess for now
unsigned char* messageBuffer = new unsigned char[messageSize];
int numBytesPacketHeader = populateTypeAndVersion(messageBuffer, command);
unsigned short int* sequenceAt = (unsigned short int*) &messageBuffer[numBytesPacketHeader];
*sequenceAt = sequence;
@ -269,9 +269,9 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
// get the coded voxel
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);
int lengthOfVoxelData = bytesRequiredForCodeLength(*voxelData)+SIZE_OF_COLOR_DATA;
// make sure we have room to copy this voxel
if (actualMessageSize + lengthOfVoxelData > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
success = false;
@ -285,19 +285,19 @@ bool createVoxelEditMessage(unsigned char command, short int sequence,
delete[] voxelData;
}
if (success) {
if (success) {
// finally, copy the result to the output
bufferOut = new unsigned char[actualMessageSize];
sizeOut = actualMessageSize;
memcpy(bufferOut, messageBuffer, actualMessageSize);
}
delete[] messageBuffer; // clean up our temporary buffer
return success;
}
/// 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) {
bool success = true; // assume the best
@ -308,9 +308,9 @@ bool encodeVoxelEditMessageDetails(unsigned char command, int voxelCount, VoxelD
// get the coded voxel
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);
int lengthOfVoxelData = bytesRequiredForCodeLength(*voxelData)+SIZE_OF_COLOR_DATA;
// make sure we have room to copy this voxel
if (sizeOut + lengthOfVoxelData > sizeIn) {
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) {
return pointToVoxel(x, y, z, s);
unsigned char* pointToOctalCode(float x, float y, float z, float s) {
return pointToVoxel(x, y, z, s);
}
/// 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
/// 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
/// IMPORTANT: The voxel is returned to you a buffer which you MUST delete when you are
/// done with it.
@ -347,10 +347,10 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
return voxelOut;
}
float xTest, yTest, zTest, sTest;
float xTest, yTest, zTest, sTest;
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.
unsigned int voxelSizeInOctets = 1;
while (sTest > s) {
@ -379,11 +379,11 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
if (x >= xTest) {
//<write 1 bit>
byte = (byte << 1) | true;
xTest += sTest/2.0;
} else {
xTest += sTest/2.0;
} else {
//<write 0 bit;>
byte = (byte << 1) | false;
xTest -= sTest/2.0;
xTest -= sTest/2.0;
}
bitInByteNDX++;
// 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) {
//<write 1 bit>
byte = (byte << 1) | true;
yTest += sTest/2.0;
} else {
yTest += sTest/2.0;
} else {
//<write 0 bit;>
byte = (byte << 1) | false;
yTest -= sTest/2.0;
yTest -= sTest/2.0;
}
bitInByteNDX++;
// 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) {
//<write 1 bit>
byte = (byte << 1) | true;
zTest += sTest/2.0;
} else {
zTest += sTest/2.0;
} else {
//<write 0 bit;>
byte = (byte << 1) | false;
zTest -= sTest/2.0;
zTest -= sTest/2.0;
}
bitInByteNDX++;
// 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++;
sTest /= 2.0;
}
}
// 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.
@ -445,7 +445,7 @@ unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r,
byte = (byte << 1) | false;
bitInByteNDX++;
}
// Copy it into our output buffer
voxelOut[byteNDX]=byte;
byteNDX++;
@ -470,7 +470,7 @@ void printVoxelCode(unsigned char* voxelCode) {
qDebug("voxelSizeInBytes=%d\n",voxelSizeInBytes);
qDebug("voxelSizeInOctets=%d\n",voxelSizeInOctets);
qDebug("voxelBufferSize=%d\n",voxelBufferSize);
for(int i=0;i<voxelBufferSize;i++) {
qDebug("i=%d ",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,
// 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
// originalIndexArray is optional
int insertIntoSortedArrays(void* value, float key, int originalIndex,
void** valueArray, float* keyArray, int* originalIndexArray,
int insertIntoSortedArrays(void* value, float key, int originalIndex,
void** valueArray, float* keyArray, int* originalIndexArray,
int currentCount, int maxCount) {
if (currentCount < maxCount) {
int i = 0;
if (currentCount > 0) {
@ -525,7 +525,7 @@ int insertIntoSortedArrays(void* value, float key, int originalIndex,
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 i = 0;
@ -533,7 +533,7 @@ int removeFromSortedArrays(void* value, void** valueArray, float* keyArray, int*
while (i < currentCount && value != valueArray[i]) {
i++;
}
if (value == valueArray[i] && i < currentCount) {
// i is the location of the item we were looking for
// shift array elements to the left
@ -579,10 +579,10 @@ int unpackFloatVec3FromSignedTwoByteFixed(unsigned char* sourceBuffer, glm::vec3
int packFloatAngleToTwoByte(unsigned char* buffer, float angle) {
const float ANGLE_CONVERSION_RATIO = (std::numeric_limits<uint16_t>::max() / 360.0);
uint16_t angleHolder = floorf((angle + 180) * ANGLE_CONVERSION_RATIO);
memcpy(buffer, &angleHolder, sizeof(uint16_t));
return sizeof(uint16_t);
}
@ -621,7 +621,7 @@ float LARGE_LIMIT = 1000.0;
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()
int16_t ratioHolder;
if (ratio < SMALL_LIMIT) {
const float SMALL_RATIO_CONVERSION_RATIO = (std::numeric_limits<int16_t>::max() / SMALL_LIMIT);
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
assert(clipValue < std::numeric_limits<int16_t>::max());
int16_t holder;
// if the clip is less than 10, then encode it as a positive number scaled from 0 to int16::max()
if (clipValue < SMALL_LIMIT) {
const float SMALL_RATIO_CONVERSION_RATIO = (std::numeric_limits<int16_t>::max() / SMALL_LIMIT);