bool CC3Billboard::doesIntersectBounds( const CCRect& bounds ) { if (m_pBoundingVolume) { bool intersects = getBoundingVolume()->doesIntersectBounds( bounds ); //LogTrace(@"%@ bounded by %@ %@ %@", self, _boundingVolume, // (intersects ? @"intersects" : @"does not intersect"), NSStringFromCGRect(bounds)); // Uncomment and change name to verify culling: // if (!intersects && ([self.name isEqualToString: @"MyNodeName"])) { // LogDebug(@"%@ bounded by %@ does not intersect %@", // self, _boundingVolume, NSStringFromCGRect(bounds)); // } return intersects; } return true; }
bool Tile::isVisible(const G3MRenderContext *rc, const TileRenderContext* trc, const Planet* planet, const Vector3D& cameraNormalizedPosition, double cameraAngle2HorizonInRadians, const Frustum* cameraFrustumInModelCoordinates) { //// const BoundingVolume* boundingVolume = getTessellatorMesh(rc, trc)->getBoundingVolume(); // const BoundingVolume* boundingVolume = getBoundingVolume(rc, trc); // if (boundingVolume == NULL) { // return false; // } // // if (!boundingVolume->touchesFrustum(cameraFrustumInModelCoordinates)) { // return false; // } // // // test if sector is back oriented with respect to the camera // return !_sector.isBackOriented(rc, // getMinHeight(), // planet, // cameraNormalizedPosition, // cameraAngle2HorizonInRadians); // test if sector is back oriented with respect to the camera if (_sector.isBackOriented(rc, getMinHeight(), planet, cameraNormalizedPosition, cameraAngle2HorizonInRadians)) { return false; } const BoundingVolume* boundingVolume = getBoundingVolume(rc, trc); return ((boundingVolume != NULL) && boundingVolume->touchesFrustum(cameraFrustumInModelCoordinates)); }
Mesh *Mesh::createBoundingBox() { Mesh *mesh = new Mesh("float3 a_position"); getBoundingVolume(); // Make sure bounding_volume is valid glm::vec3 min_corner = bounding_volume.min_corner(); glm::vec3 max_corner = bounding_volume.max_corner(); float min_x = min_corner[0]; float min_y = min_corner[1]; float min_z = min_corner[2]; float max_x = max_corner[0]; float max_y = max_corner[1]; float max_z = max_corner[2]; float positions[24] = {min_x, min_y, min_z, max_x, min_y, min_z, min_x, max_y, min_z, max_x, max_y, min_z, min_x, min_y, max_z, max_x, min_y, max_z, min_x, max_y, max_z, max_x, max_y, max_z}; unsigned short indices[] = {0, 2, 1, 1, 2, 3, 1, 3, 7, 1, 7, 5, 4, 5, 6, 5, 7, 6, 0, 6, 2, 0, 4, 6, 0, 1, 5, 0, 5, 4, 2, 7, 3, 2, 6, 7}; mesh->setVertices(positions, sizeof(positions) / (8 * sizeof(float))); mesh->setTriangles(indices, sizeof(indices) / (sizeof(short))); return mesh; }
Mesh* Mesh::getBoundingBox() { Mesh* mesh = new Mesh(); getBoundingVolume(); // Make sure bounding_volume is valid glm::vec3 min_corner = bounding_volume.min_corner(); glm::vec3 max_corner = bounding_volume.max_corner(); float min_x = min_corner[0]; float min_y = min_corner[1]; float min_z = min_corner[2]; float max_x = max_corner[0]; float max_y = max_corner[1]; float max_z = max_corner[2]; mesh->vertices_.push_back(glm::vec3(min_x, min_y, min_z)); mesh->vertices_.push_back(glm::vec3(max_x, min_y, min_z)); mesh->vertices_.push_back(glm::vec3(min_x, max_y, min_z)); mesh->vertices_.push_back(glm::vec3(max_x, max_y, min_z)); mesh->vertices_.push_back(glm::vec3(min_x, min_y, max_z)); mesh->vertices_.push_back(glm::vec3(max_x, min_y, max_z)); mesh->vertices_.push_back(glm::vec3(min_x, max_y, max_z)); mesh->vertices_.push_back(glm::vec3(max_x, max_y, max_z)); mesh->indices_.push_back(0); mesh->indices_.push_back(2); mesh->indices_.push_back(1); mesh->indices_.push_back(1); mesh->indices_.push_back(2); mesh->indices_.push_back(3); mesh->indices_.push_back(1); mesh->indices_.push_back(3); mesh->indices_.push_back(7); mesh->indices_.push_back(1); mesh->indices_.push_back(7); mesh->indices_.push_back(5); mesh->indices_.push_back(4); mesh->indices_.push_back(5); mesh->indices_.push_back(6); mesh->indices_.push_back(5); mesh->indices_.push_back(7); mesh->indices_.push_back(6); mesh->indices_.push_back(0); mesh->indices_.push_back(6); mesh->indices_.push_back(2); mesh->indices_.push_back(0); mesh->indices_.push_back(4); mesh->indices_.push_back(6); mesh->indices_.push_back(0); mesh->indices_.push_back(1); mesh->indices_.push_back(5); mesh->indices_.push_back(0); mesh->indices_.push_back(5); mesh->indices_.push_back(4); mesh->indices_.push_back(2); mesh->indices_.push_back(7); mesh->indices_.push_back(3); mesh->indices_.push_back(2); mesh->indices_.push_back(6); mesh->indices_.push_back(7); return mesh; }
void Mesh::getTransformedBoundingBoxInfo(glm::mat4 *Mat, float *transformed_bounding_box) { if (have_bounding_volume_ == false) { getBoundingVolume(); } glm::mat4 M = *Mat; float a, b; //Inspired by Graphics Gems - TransBox.c //Transform the AABB to the correct position in world space //Generate a new AABB from the non axis aligned bounding box transformed_bounding_box[0] = M[3].x; transformed_bounding_box[3] = M[3].x; transformed_bounding_box[1] = M[3].y; transformed_bounding_box[4] = M[3].y; transformed_bounding_box[2] = M[3].z; transformed_bounding_box[5] = M[3].z; glm::vec3 min_corner = bounding_volume.min_corner(); glm::vec3 max_corner = bounding_volume.max_corner(); for (int i = 0; i < 3; i++) { //x coord a = M[i].x * min_corner.x; b = M[i].x * max_corner.x; if (a < b) { transformed_bounding_box[0] += a; transformed_bounding_box[3] += b; } else { transformed_bounding_box[0] += b; transformed_bounding_box[3] += a; } //y coord a = M[i].y * min_corner.y; b = M[i].y * max_corner.y; if (a < b) { transformed_bounding_box[1] += a; transformed_bounding_box[4] += b; } else { transformed_bounding_box[1] += b; transformed_bounding_box[4] += a; } //z coord a = M[i].z * min_corner.z; b = M[i].z * max_corner.z; if (a < b) { transformed_bounding_box[2] += a; transformed_bounding_box[5] += b; } else { transformed_bounding_box[2] += b; transformed_bounding_box[5] += a; } } }
void Model::updateBounds() { bounds = mesh->getBoundingVolume(); }