17#include <OgreCamera.h>
18#include <OgreVector3.h>
87 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"The specified camera is from the wrong SceneManager",
"PagedGeometry::setCamera()");
109 OGRE_EXCEPT(Ogre::Exception::ERR_RENDERINGAPI_ERROR,
"PagedGeometry::setPageSize() cannot be called after detail levels have been added. Call removeDetailLevels() first.",
"PagedGeometry::setPageSize()");
117 OGRE_EXCEPT(Ogre::Exception::ERR_RENDERINGAPI_ERROR,
"PagedGeometry::setInfinite() cannot be called after detail levels have been added. Call removeDetailLevels() first.",
"PagedGeometry::setInfinite()");
125 OGRE_EXCEPT(Ogre::Exception::ERR_RENDERINGAPI_ERROR,
"PagedGeometry::setBounds() cannot be called after detail levels have been added. Call removeDetailLevels() first.",
"PagedGeometry::setBounds()");
126 if (!Math::RealEqual(bounds.width(), bounds.height(), 0.01f))
127 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Bounds must be square",
"PagedGeometry::setBounds()");
128 if (bounds.width() <= 0 || bounds.height() <=0)
129 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Bounds must have positive width and height",
"PagedGeometry::setBounds()");
136 const Vector3 minimum(aab.getMinimum());
137 const Vector3 maximum(aab.getMaximum());
138 return TBounds (minimum.x, minimum.z, maximum.x, maximum.z);
143 std::list<GeometryPageManager *>::iterator it;
162 unsigned long deltaTime, tmp;
163 tmp =
timer.getMilliseconds();
168 Vector3 camPos =
sceneCam->getDerivedPosition();
175 camSpeed = (camPos -
oldCamPos) / deltaTime;
184 bool enableCache =
true;
185 std::list<GeometryPageManager *>::iterator it;
190 mgr->
update(deltaTime, camPos, camSpeed, enableCache, prevMgr);
203 std::list<GeometryPageManager *>::iterator it;
215 std::list<GeometryPageManager *>::iterator it;
228 std::list<GeometryPageManager *>::iterator it;
243 if (localArea.left > localArea.right) std::swap(localArea.left, localArea.right);
244 if (localArea.top > localArea.bottom) std::swap(localArea.top, localArea.bottom);
246 std::list<GeometryPageManager *>::iterator it;
260 if (localArea.left > localArea.right) std::swap(localArea.left, localArea.right);
261 if (localArea.top > localArea.bottom) std::swap(localArea.top, localArea.bottom);
263 std::list<GeometryPageManager *>::iterator it;
275 std::list<GeometryPageManager *>::iterator it;
292 if (maxRange <= minRange){
293 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Closer detail levels must be added before farther ones");
341 const Real cacheDistSq = cacheDist * cacheDist;
353 int shiftX = 0, shiftZ = 0;
356 if (shiftX != 0 || shiftZ != 0)
366 x1 -= shiftX; x2 -= shiftX;
367 z1 -= shiftZ; z2 -= shiftZ;
386 for (
int x = x1;
x <= x2; ++
x){
387 for (
int z = z1;
z <= z2; ++
z){
392 Real distSq = dx * dx + dz * dz;
395 if (distSq <= cacheDistSq){
437 Real speed = Math::Sqrt(camSpeed.x * camSpeed.x + camSpeed.z * camSpeed.z);
439 unsigned long cacheInterval = 0;
449 TPGeometryPages::iterator i1, i2;
453 if (
cacheTimer >= cacheInterval && enableCache){
468 Real distSq = dx * dx + dz * dz;
469 if (distSq <= cacheDistSq){
511 bool visible =
false;
514 Real distSq = dx * dx + dz * dz;
516 Real overlap = 0, tmp;
518 tmp = blk->
_trueBounds.getMaximum().x - halfPageSize;
519 if (tmp > overlap) overlap = tmp;
520 tmp = blk->
_trueBounds.getMaximum().z - halfPageSize;
521 if (tmp > overlap) overlap = tmp;
522 tmp = blk->
_trueBounds.getMinimum().x + halfPageSize;
523 if (tmp > overlap) overlap = tmp;
524 tmp = blk->
_trueBounds.getMinimum().z + halfPageSize;
525 if (tmp > overlap) overlap = tmp;
547 fadeFar = prevManager->
farDist;
552 blk->
setFade(enable, fadeNear, fadeFar);
592 TPGeometryPages::iterator it;
622 TBounds area(center.x - radius, center.z - radius, center.x + radius, center.z + radius);
636 Real radiusSq = radius * radius;
637 for (
int x = x1;
x <= x2; ++
x) {
638 for (
int z = z1;
z <= z2; ++
z) {
642 Real distX = (pos.x - center.x), distZ = (pos.z - center.z);
643 Real distSq = distX * distX + distZ * distZ;
645 if (distSq <= radius) {
669 for (
int x = x1;
x <= x2; ++
x)
671 for (
int z = z1;
z <= z2; ++
z)
687 loadarea.left = area.left -
farDist;
688 loadarea.right = area.right +
farDist;
689 loadarea.top = area.top -
farDist;
690 loadarea.bottom = area.bottom +
farDist;
704 for (
int x = x1;
x <= x2; ++
x) {
705 for (
int z = z1;
z <= z2; ++
z) {
842 for (
int x = 0;
x < shiftX; ++
x){
852 int shiftedMidpoint =
geomGridX - shiftX;
853 for (
int x = 0;
x < shiftedMidpoint; ++
x)
856 for (
int x = 0;
x < shiftX; ++
x){
863 else if (shiftX < 0) {
866 int initialMidpoint =
geomGridX + shiftX;
880 for (
int x = 0;
x < -shiftX; ++
x){
891 for (
int z = 0;
z < shiftZ; ++
z){
901 int shiftedMidpoint =
geomGridZ - shiftZ;
902 for (
int z = 0;
z < shiftedMidpoint; ++
z)
905 for (
int z = 0;
z < shiftZ; ++
z){
912 else if (shiftZ < 0) {
915 int initialMidpoint =
geomGridZ + shiftZ;
929 for (
int z = 0;
z < -shiftZ; ++
z){
951 Ogre::Matrix4 mat(rotation);
953 Ogre::AxisAlignedBox entBounds = ent->getBoundingBox();
954 entBounds.transform(mat);
958 _trueBounds.setMinimum(entBounds.getMinimum() + relPosition);
959 _trueBounds.setMaximum(entBounds.getMaximum() + relPosition);
964 min.makeFloor(entBounds.getMinimum() + relPosition);
965 max.makeCeil(entBounds.getMaximum() + relPosition);
This base-class can be extended to provide different ways of representing entities.
virtual void setFade(bool enabled, Ogre::Real visibleDist=0, Ogre::Real invisibleDist=0)=0
Sets fade behavior for this page.
Ogre::Vector3 _centerPoint
Ogre::AxisAlignedBox _trueBounds
virtual void removeEntities()=0
Remove all geometry/entities from the page completely.
virtual void clearBoundingBox()
Advanced: Reset the bounding box used by addEntityToBoundingBox()
virtual void build()
Perform any final steps to make added entities appear in the scene.
virtual void setVisible(bool visible)=0
Toggle the entire page's visibility.
virtual void update()
Do whatever needs to be done to keep the page geometry up-to-date.
bool _trueBoundsUndefined
std::list< GeometryPage * >::iterator _iter
virtual const Ogre::AxisAlignedBox & getBoundingBox()
Advanced: Return the bounding box computed with addEntityToBoundingBox()
Ogre::Vector3 & getCenterPoint()
Gets the center point of the page.
GeometryPage()
Constructor Initialise everything to zero, false or NULL except for _trueBoundsUndefined that is set ...
unsigned long _inactiveTime
virtual void addEntityToBoundingBox(Ogre::Entity *ent, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, const Ogre::Vector3 &scale)
Advanced: Expand the current bounding box to include the given entity.
virtual void setRegion(Ogre::Real left, Ogre::Real top, Ogre::Real right, Ogre::Real bottom)
Prepare a geometry page for entities.
Manages the rendering of geometry for a detail level type.
void setTransition(Ogre::Real transitionLength)
TPGeometryPages pendingList
void update(unsigned long deltaTime, Ogre::Vector3 &camPos, Ogre::Vector3 &camSpeed, bool &enableCache, GeometryPageManager *prevManager)
Internal function - DO NOT USE.
void reloadGeometryPage(const Ogre::Vector3 &point)
Internal function - DO NOT USE.
GeometryPageManager(PagedGeometry *mainGeom)
Internal function - DO NOT USE.
void _scrollGridPages(int shiftX, int shiftZ)
GeometryPage * _getGridPage(const int x, const int z)
GeometryPage ** scrollBuffer
void _unloadPage(GeometryPage *page)
void setFarRange(Ogre::Real farRange)
Sets the far viewing range of this page manager.
void setCacheSpeed(unsigned long maxCacheInterval=200, unsigned long inactivePageLife=2000)
Customizes the cache behaviour (advanced).
~GeometryPageManager()
Internal function - DO NOT USE.
void setNearRange(Ogre::Real nearRange)
Sets the near viewing range of this page manager.
void preloadGeometry(const TBounds &area)
Internal function - DO NOT USE.
unsigned long inactivePageLife
void _setGridPage(const int x, const int z, GeometryPage *page)
void resetPreloadedGeometry()
Internal function - DO NOT USE.
unsigned long maxCacheInterval
TPGeometryPages loadedList
void _loadPage(GeometryPage *page)
Ogre::Real farTransDistSq
Ogre::Real getFarRange() const
Gets the far viewing range of this page manager.
void reloadGeometryPages(const Ogre::Vector3 ¢er, Ogre::Real radius)
Internal function - DO NOT USE.
void _unloadPageDelayed(GeometryPage *page)
void reloadGeometry()
Internal function - DO NOT USE.
A class which you extend to provide a callback function for loading entities.
virtual void unloadPage(PageInfo &page)
This may be overridden (optional) to unload custom data associated with a page.
virtual void frameUpdate()
Provides a method for you to perform per-frame tasks for your PageLoader if overridden (optional)
virtual void loadPage(PageInfo &page)=0
This should be overridden to load a specified region of entities.
A class providing highly optimized methods for rendering massive amounts of geometry.
Ogre::Real getPageSize()
Gets the current page size.
std::list< GeometryPageManager * > managerList
void reloadGeometryPages(const Ogre::Vector3 ¢er, Ogre::Real radius)
Reloads geometry in the given radius area.
void removeDetailLevels()
Removes all detail levels from the PagedGeometry object.
bool geometryAllowedVisible
void setCamera(Ogre::Camera *cam)
Sets the camera to use when calculating levels of detail.
void setTempDir(Ogre::String dir)
Sets the output directory for the imposter pages.
void preloadGeometry(const TBounds &area)
Preloads a region of geometry (loads once and never loads again)
void reloadGeometryPage(const Ogre::Vector3 &point)
Reloads geometry at the given location.
PagedGeometry(Ogre::Camera *cam=NULL, Ogre::Real pageSize=100, Ogre::SceneNode *groupingSceneNode=NULL, Ogre::RenderQueueGroupID queue=Ogre::RENDER_QUEUE_6)
Initializes a PagedGeometry object.
void setPageLoader(PageLoader *loader)
Assigns a PageLoader object for the PagedGeometry.
Ogre::SceneManager * sceneMgr
bool getVisible()
Returns whether or not geometry managed by this PagedGeometry instance is visible.
void setInfinite()
Switches to infinite mode.
Ogre::Vector3 lastOldCamPos
PageLoader * getPageLoader()
Gets the PageLoader currently being used to load geometry.
Ogre::Camera * lastSceneCam
void resetPreloadedGeometry()
Releases geometry preloaded with preloadGeometry() to be unloaded if necessary.
void setPageSize(Ogre::Real size)
Sets the page size.
Ogre::SceneNode * m_pagedGroupingNode
void _addDetailLevel(GeometryPageManager *mgr, Ogre::Real maxRange, Ogre::Real transitionLength)
void update()
Updates this PagedGeometry object.
void setBounds(const TBounds bounds)
Switches to bounded mode and uses the given boundaries.
TBounds convertAABToTBounds(const Ogre::AxisAlignedBox &aab) const
Convert an Ogre::AxisAlignedBox to a TBounds coplanar to the plane defined by the UP axis.
void reloadGeometry()
Reloads all visible geometry.
static void updateAll(const Ogre::Vector3 &cameraDirection)
Manually updates all StaticBillboardSet objects for a frame.
Ogre::TRect< Ogre::Real > TBounds
Define TBounds as a TRect using Real numeric units.
Useful page information supplied to a pageloader.
int zIndex
The Z index of the page tile.
Ogre::Vector3 centerPoint
The center of the page (simply the middle of the bounds).
TBounds bounds
The page boundaries in which all entities should be placed.
int xIndex
The X index of the page tile.