diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index b7fae39ca5..477e049e93 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -47,55 +47,59 @@ void ViewFrustum::calculateViewFrustum(glm::vec3 position, glm::vec3 direction, this->_farHeight = 2 * tan(fovHalfAngle) * this->_farDist; this->_farWidth = this->_farHeight * ratio; - this->_farCenter = this->_position+front*this->_farDist; - this->_farTopLeft = this->_farCenter + (this->_up*this->_farHeight*0.5f) - (this->_right*this->_farWidth*0.5f); - this->_farTopRight = this->_farCenter + (this->_up*this->_farHeight*0.5f) + (this->_right*this->_farWidth*0.5f); - this->_farBottomLeft = this->_farCenter - (this->_up*this->_farHeight*0.5f) - (this->_right*this->_farWidth*0.5f); - this->_farBottomRight = this->_farCenter - (this->_up*this->_farHeight*0.5f) + (this->_right*this->_farWidth*0.5f); + float farHalfHeight = this->_farHeight * 0.5f; + float farHalfWidth = this->_farWidth * 0.5f; + this->_farCenter = this->_position+front * this->_farDist; + this->_farTopLeft = this->_farCenter + (this->_up * farHalfHeight) - (this->_right * farHalfWidth); + this->_farTopRight = this->_farCenter + (this->_up * farHalfHeight) + (this->_right * farHalfWidth); + this->_farBottomLeft = this->_farCenter - (this->_up * farHalfHeight) - (this->_right * farHalfWidth); + this->_farBottomRight = this->_farCenter - (this->_up * farHalfHeight) + (this->_right * farHalfWidth); - this->_nearCenter = this->_position+front*this->_nearDist; - this->_nearTopLeft = this->_nearCenter + (this->_up*this->_nearHeight*0.5f) - (this->_right*this->_nearWidth*0.5f); - this->_nearTopRight = this->_nearCenter + (this->_up*this->_nearHeight*0.5f) + (this->_right*this->_nearWidth*0.5f); - this->_nearBottomLeft = this->_nearCenter - (this->_up*this->_nearHeight*0.5f) - (this->_right*this->_nearWidth*0.5f); - this->_nearBottomRight = this->_nearCenter - (this->_up*this->_nearHeight*0.5f) + (this->_right*this->_nearWidth*0.5f); + float nearHalfHeight = this->_nearHeight * 0.5f; + float nearHalfWidth = this->_nearWidth * 0.5f; + this->_nearCenter = this->_position+front * this->_nearDist; + this->_nearTopLeft = this->_nearCenter + (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth); + this->_nearTopRight = this->_nearCenter + (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth); + this->_nearBottomLeft = this->_nearCenter - (this->_up * nearHalfHeight) - (this->_right * nearHalfWidth); + this->_nearBottomRight = this->_nearCenter - (this->_up * nearHalfHeight) + (this->_right * nearHalfWidth); } void ViewFrustum::dump() { - printf("position.x=%f, position.y=%f, position.z=%f\n",this->_position.x,this->_position.y,this->_position.z); - printf("direction.x=%f, direction.y=%f, direction.z=%f\n",this->_direction.x,this->_direction.y,this->_direction.z); - printf("up.x=%f, up.y=%f, up.z=%f\n",this->_up.x,this->_up.y,this->_up.z); - printf("right.x=%f, right.y=%f, right.z=%f\n",this->_right.x,this->_right.y,this->_right.z); + printf("position.x=%f, position.y=%f, position.z=%f\n", this->_position.x, this->_position.y, this->_position.z); + printf("direction.x=%f, direction.y=%f, direction.z=%f\n", this->_direction.x, this->_direction.y, this->_direction.z); + printf("up.x=%f, up.y=%f, up.z=%f\n", this->_up.x, this->_up.y, this->_up.z); + printf("right.x=%f, right.y=%f, right.z=%f\n", this->_right.x, this->_right.y, this->_right.z); - printf("farDist=%f\n",this->_farDist); - printf("farHeight=%f\n",this->_farHeight); - printf("farWidth=%f\n",this->_farWidth); + printf("farDist=%f\n", this->_farDist); + printf("farHeight=%f\n", this->_farHeight); + printf("farWidth=%f\n", this->_farWidth); - printf("nearDist=%f\n",this->_nearDist); - printf("nearHeight=%f\n",this->_nearHeight); - printf("nearWidth=%f\n",this->_nearWidth); + printf("nearDist=%f\n", this->_nearDist); + printf("nearHeight=%f\n", this->_nearHeight); + printf("nearWidth=%f\n", this->_nearWidth); printf("farCenter.x=%f, farCenter.y=%f, farCenter.z=%f\n", - this->_farCenter.x,this->_farCenter.y,this->_farCenter.z); + this->_farCenter.x, this->_farCenter.y, this->_farCenter.z); printf("farTopLeft.x=%f, farTopLeft.y=%f, farTopLeft.z=%f\n", - this->_farTopLeft.x,this->_farTopLeft.y,this->_farTopLeft.z); + this->_farTopLeft.x, this->_farTopLeft.y, this->_farTopLeft.z); printf("farTopRight.x=%f, farTopRight.y=%f, farTopRight.z=%f\n", - this->_farTopRight.x,this->_farTopRight.y,this->_farTopRight.z); + this->_farTopRight.x, this->_farTopRight.y, this->_farTopRight.z); printf("farBottomLeft.x=%f, farBottomLeft.y=%f, farBottomLeft.z=%f\n", - this->_farBottomLeft.x,this->_farBottomLeft.y,this->_farBottomLeft.z); + this->_farBottomLeft.x, this->_farBottomLeft.y, this->_farBottomLeft.z); printf("farBottomRight.x=%f, farBottomRight.y=%f, farBottomRight.z=%f\n", - this->_farBottomRight.x,this->_farBottomRight.y,this->_farBottomRight.z); + this->_farBottomRight.x, this->_farBottomRight.y, this->_farBottomRight.z); printf("nearCenter.x=%f, nearCenter.y=%f, nearCenter.z=%f\n", - this->_nearCenter.x,this->_nearCenter.y,this->_nearCenter.z); + this->_nearCenter.x, this->_nearCenter.y, this->_nearCenter.z); printf("nearTopLeft.x=%f, nearTopLeft.y=%f, nearTopLeft.z=%f\n", - this->_nearTopLeft.x,this->_nearTopLeft.y,this->_nearTopLeft.z); + this->_nearTopLeft.x, this->_nearTopLeft.y, this->_nearTopLeft.z); printf("nearTopRight.x=%f, nearTopRight.y=%f, nearTopRight.z=%f\n", - this->_nearTopRight.x,this->_nearTopRight.y,this->_nearTopRight.z); + this->_nearTopRight.x, this->_nearTopRight.y, this->_nearTopRight.z); printf("nearBottomLeft.x=%f, nearBottomLeft.y=%f, nearBottomLeft.z=%f\n", - this->_nearBottomLeft.x,this->_nearBottomLeft.y,this->_nearBottomLeft.z); + this->_nearBottomLeft.x, this->_nearBottomLeft.y, this->_nearBottomLeft.z); printf("nearBottomRight.x=%f, nearBottomRight.y=%f, nearBottomRight.z=%f\n", - this->_nearBottomRight.x,this->_nearBottomRight.y,this->_nearBottomRight.z); + this->_nearBottomRight.x, this->_nearBottomRight.y, this->_nearBottomRight.z); }