bool Octree::setupNewLayerOfOctree() { if (lifeLeft < 1) { isLeaf = true; return false; } nodes = new Octree[8]; GLfloat dimHalf_x = (aabb.max_x - aabb.min_x) / 2.0f; GLfloat dimHalf_y = (aabb.max_y - aabb.min_y) / 2.0f; GLfloat dimHalf_z = (aabb.max_z - aabb.min_z) / 2.0f; GLfloat center_x = aabb.min_x + dimHalf_x; GLfloat center_y = aabb.min_y + dimHalf_y; GLfloat center_z = aabb.min_z + dimHalf_z; nodes[0] = Octree(aabb.max_x, aabb.max_y, aabb.max_z, center_x, center_y, center_z, lifeLeft - 1, this); nodes[1] = Octree(center_x, center_y, center_z, aabb.min_x, aabb.min_y, aabb.min_z, lifeLeft - 1, this); nodes[2] = Octree(center_x, aabb.max_y, center_z, aabb.min_x, center_y, aabb.min_z, lifeLeft - 1, this); nodes[3] = Octree(aabb.max_x, center_y, aabb.max_z, center_x, aabb.min_y, center_z, lifeLeft - 1, this); nodes[4] = Octree(center_x, center_y, aabb.max_z, aabb.min_x, aabb.min_y, center_z, lifeLeft - 1, this); nodes[5] = Octree(center_x, aabb.max_y, aabb.max_z, aabb.min_x, center_y, center_z, lifeLeft - 1, this); nodes[6] = Octree(aabb.max_x, center_y, center_z, center_x, aabb.min_y, aabb.min_z, lifeLeft - 1, this); nodes[7] = Octree(aabb.max_x, aabb.max_y, center_z, center_x, center_y, aabb.min_z, lifeLeft - 1, this); return true; }
void Octree::newNode( int depth, double x, double y, double z ) { double extent = boundingBox.xExtent / 2.0; Vec3d center; center.x() = boundingBox.center.x() + (extent * x); center.y() = boundingBox.center.y() + (extent * y); center.z() = boundingBox.center.z() + (extent * z); BoundingBox bb(center, extent, extent, extent); // Add child children.push_back(Octree()); Octree * child = &children.back(); child->boundingBox = bb; child->trianglePerNode = this->trianglePerNode; // Collect triangles inside child's bounding box for(StdVector<BaseTriangle*>::iterator it = this->triangleData.begin(); it != this->triangleData.end(); it++) { BaseTriangle* face = *it; if( bb.containsTriangle(face->vec(0), face->vec(1), face->vec(2)) ) { child->triangleData.push_back(face); } } child->build(depth + 1); // build it }
void OctreeSceneManager::resize( const AxisAlignedBox &box ) { list< SceneNode * >::type nodes; list< SceneNode * >::type ::iterator it; _findNodes( mOctree->mBox, nodes, 0, true, mOctree ); OGRE_DELETE mOctree; mOctree = OGRE_NEW Octree( 0 ); mOctree->mBox = box; const Vector3 &min = box.getMinimum(); const Vector3 &max = box.getMaximum(); mOctree->mHalfSize = ( max - min ) * 0.5f; it = nodes.begin(); while ( it != nodes.end() ) { OctreeNode * on = static_cast < OctreeNode * > ( *it ); on -> setOctant( 0 ); _updateOctreeNode( on ); ++it; } }
Physic::Physic(Camera* cam) : __octree(Octree(Vec3f(-1000.f, -1000.f, -1000.f), Vec3f(1000.f, 1000.f, 1000.f), 1)), __nb_newton_objs(0), __camera(cam) { cam->GenerateHitBox(); this->AddObject((SolidObj*)cam); }
void OctreeSceneManager::init( AxisAlignedBox &box, int depth ) { if ( mOctree != 0 ) OGRE_DELETE mOctree; mOctree = OGRE_NEW Octree( 0 ); mMaxDepth = depth; mBox = box; mOctree -> mBox = box; Vector3 min = box.getMinimum(); Vector3 max = box.getMaximum(); mOctree -> mHalfSize = ( max - min ) / 2; mShowBoxes = false; mNumObjects = 0; Vector3 v( 1.5, 1.5, 1.5 ); mScaleFactor.setScale( v ); // setDisplaySceneNodes( true ); // setShowBoxes( true ); // //mSceneRoot isn't put into the octree since it has no volume. }
void OctreeSceneManager::_addOctreeNode( OctreeNode * n, Octree *octant, int depth ) { // Skip if octree has been destroyed (shutdown conditions) if (!mOctree) return; const AxisAlignedBox& bx = n -> _getWorldAABB(); //if the octree is twice as big as the scene node, //we will add it to a child. if ( ( depth < mMaxDepth ) && octant -> _isTwiceSize( bx ) ) { int x, y, z; octant -> _getChildIndexes( bx, &x, &y, &z ); if ( octant -> mChildren[ x ][ y ][ z ] == 0 ) { octant -> mChildren[ x ][ y ][ z ] = OGRE_NEW Octree( octant ); const Vector3& octantMin = octant -> mBox.getMinimum(); const Vector3& octantMax = octant -> mBox.getMaximum(); Vector3 min, max; if ( x == 0 ) { min.x = octantMin.x; max.x = ( octantMin.x + octantMax.x ) / 2; } else { min.x = ( octantMin.x + octantMax.x ) / 2; max.x = octantMax.x; } if ( y == 0 ) { min.y = octantMin.y; max.y = ( octantMin.y + octantMax.y ) / 2; } else { min.y = ( octantMin.y + octantMax.y ) / 2; max.y = octantMax.y; } if ( z == 0 ) { min.z = octantMin.z; max.z = ( octantMin.z + octantMax.z ) / 2; } else { min.z = ( octantMin.z + octantMax.z ) / 2; max.z = octantMax.z; } octant -> mChildren[ x ][ y ][ z ] -> mBox.setExtents( min, max ); octant -> mChildren[ x ][ y ][ z ] -> mHalfSize = ( max - min ) / 2; } _addOctreeNode( n, octant -> mChildren[ x ][ y ][ z ], ++depth ); } else { octant -> _addNode( n ); } }