📄 ogrepaginglandscapescenemanager.cpp
字号:
/***************************************************************************
OgrePagingLandScapeSceneManager.cpp - description
-------------------
begin : Mon May 12 2003
copyright : (C) 2003 by Jose A Milan
email : spoke2@supercable.es
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
#include "OgreSceneManager.h"
#include "OgreVector3.h"
#include "OgreColourValue.h"
#include "OgreMovableObject.h"
#include "OgreAxisAlignedBox.h"
#include "OgreCamera.h"
#include "OgreStringConverter.h"
#include "OgreSceneNode.h"
#include "OgreSimpleRenderable.h"
#include "OgreSDDataChunk.h"
#include "OgrePagingLandScapeOptions.h"
#include "OgrePagingLandScapeCamera.h"
#include "OgrePagingLandScapeData2DManager.h"
#include "OgrePagingLandScapeData2D.h"
#include "OgrePagingLandScapeRenderableManager.h"
#include "OgrePagingLandScapeRenderable.h"
#include "OgrePagingLandScapeTextureManager.h"
#include "OgrePagingLandScapePage.h"
#include "OgrePagingLandScapePageManager.h"
#include "OgrePagingLandScapeTile.h"
#include "OgrePagingLandScapeTileInfo.h"
#include "OgrePagingLandScapeTileManager.h"
#include "OgrePagingLandScapeRenderable.h"
#include "OgrePagingLandScapeRenderableManager.h"
#include "OgrePagingLandScapeIntersectionSceneQuery.h"
#include "OgrePagingLandScapeRaySceneQuery.h"
#include "OgrePagingLandScapeCamera.h"
#include "OgrePagingLandScapeSceneManager.h"
namespace Ogre
{
//-----------------------------------------------------------------------
PagingLandScapeSceneManager::PagingLandScapeSceneManager() : SceneManager( )
{
//showBoundingBoxes(true);
//setDisplaySceneNodes(true);
mTileManager = 0;
mRenderableManager = 0;
mTextureManager = 0;
mData2DManager = 0;
mPageManager = 0;
mNeedOptionsUpdate = false;
//JEFF
mWorldGeomIsSetup = false;
}
//-----------------------------------------------------------------------
PagingLandScapeSceneManager::~PagingLandScapeSceneManager()
{
clearScene();
}
//-----------------------------------------------------------------------
Camera * PagingLandScapeSceneManager::createCamera( const String &name )
{
Camera * c = new PagingLandscapeCamera( name, this );
mCameras.insert( CameraList::value_type( name, c ) );
return c;
}
//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::setWorldGeometry( const String& filename )
{
if ( mWorldGeomIsSetup == true )
{
clearScene();
}
// Load the configuration file
mOptions.load( filename );
// Create the Tile and Renderable and 2D Data Manager
mTileManager = new PagingLandScapeTileManager();
mRenderableManager = new PagingLandScapeRenderableManager();
mTextureManager = new PagingLandScapeTextureManager();
mData2DManager = new PagingLandScapeData2DManager();
mPageManager = new PagingLandScapePageManager(mSceneRoot);
mWorldGeomIsSetup = true;
}
//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::clearScene(void)
{
if ( mWorldGeomIsSetup == true )
{
mWorldGeomIsSetup = false;
// Delete the Managers
if ( mPageManager )
{
delete mPageManager;
mPageManager = 0;
}
if ( mTileManager )
{
delete mTileManager;
mTileManager = 0;
}
if ( mRenderableManager )
{
delete mRenderableManager;
mRenderableManager = 0;
}
if ( mTextureManager )
{
delete mTextureManager;
mTextureManager = 0;
}
if ( mData2DManager )
{
delete mData2DManager;
mData2DManager = 0;
}
}
//Call the default
SceneManager::clearScene();
}
//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::_updateSceneGraph( Camera * cam )
{
// entry into here could come before setWorldGeometry
// got called which could be disastrous
// so check for init
if(mWorldGeomIsSetup)
{
mPageManager->update( cam );
mRenderableManager->resetVisibles ();
}
// Call the default
SceneManager::_updateSceneGraph( cam );
}
/*
//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::_renderVisibleObjects( void )
{
SceneManager::_renderVisibleObjects();
}
//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::_findVisibleObjects ( Camera * cam, bool onlyShadowCasters )
{
SceneManager::_findVisibleObjects( cam, onlyShadowCasters );
}
*/
//----------------------------------------------------------------------------
IntersectionSceneQuery* PagingLandScapeSceneManager::createIntersectionQuery(unsigned long mask)
{
PagingLandScapeIntersectionSceneQuery* q = new PagingLandScapeIntersectionSceneQuery(this);
q->setQueryMask(mask);
return q;
}
//----------------------------------------------------------------------------
RaySceneQuery* PagingLandScapeSceneManager::createRayQuery(const Ray& ray, unsigned long mask)
{
PagingLandScapeRaySceneQuery* q = new PagingLandScapeRaySceneQuery(this);
q->setRay(ray);
q->setQueryMask(mask);
return q;
}
//-------------------------------------------------------------------------
bool PagingLandScapeSceneManager::intersectSegment( const Vector3 & begin,
const Vector3 & end,
Vector3 * result,
bool modif)
{
Vector3 start = begin;
Vector3 dir = end - start;
dir.normalise();
PagingLandScapeTile * t = mPageManager->getTile (start);
if ( t == 0 )
{
// if you want to be able to intersect from a point outside the canvas
int pageSize = mOptions.PageSize - 1;
Real W = mOptions.world_width * 0.5f * pageSize * mOptions.scale.x;
Real H = mOptions.world_height * 0.5f * pageSize * mOptions.scale.z;
while (start.y > 0.0f && start.y < 999999.0f &&
((start.x < -W || start.x > W) ||
(start.z < -H || start.z > H)))
start += dir;
if (start.y < 0.0f || start.y > 999999.0f)
{
*result = Vector3( -1, -1, -1 );
return false;
}
t = mPageManager->getTile (start);
// if you don't want to be able to intersect from a point outside the canvas
// *result = Vector3( -1, -1, -1 );
// return false;
}
bool impact = false;
//special case...
if ( dir.x == 0 && dir.z == 0 )
{
if (start.y <= mData2DManager->getRealWorldHeight( start.x, start.z, t->getInfo ()))
{
*result = start;
impact = true;
}
}
else
{
// dir.x = dir.x * mOptions.scale.x;
// dir.y = dir.y * mOptions.scale.y;
// dir.z = dir.z * mOptions.scale.z;
impact = t -> intersectSegment( start, dir, result );
}
// deformation
if (impact && modif)
{
int X = int (result->x / mOptions.scale.x);
int Z = int ( result->z / mOptions.scale.z);
int pageSize = mOptions.PageSize - 1;
int W = int (mOptions.world_width * 0.5f * pageSize);
int H = int (mOptions.world_height * 0.5f * pageSize);
if (X < -W || X > W || Z < -H || Z > H)
return true;
mImpact = *result;
const int radius = 7;
// Calculate the minimum X value
// make sure it is still on the height map
int Xmin = -radius;
if (Xmin + X < -W)
Xmin = - X - W;
// Calculate the maximum X value
// make sure it is still on the height map
int Xmax = radius;
if (Xmax + X > W)
Xmax = W - X;
// Main loop to draw the circle on the height map
// (goes through each X value)
for (int Xcurr = Xmin; Xcurr <= radius; Xcurr++)
{
const Real Precalc = (radius * radius) - (Xcurr * Xcurr);
if (Precalc > 1.0f)
{
// Determine the minimum and maximum Z value for that
// line in the circle (that X value)
int Zmax = (int) Math::Sqrt( Precalc );
int Zmin = -Zmax;
// Makes sure the values found are both on the height map
if (Zmin + Z < -H)
Zmin = - Z -H;
if (Zmax + Z > H)
Zmax = H - Z;
// For each of those Z values, calculate the new Y value
for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
{
// get results by page index ?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -