📄 ogrepaginglandscapedata2d.cpp
字号:
/***************************************************************************
OgrePagingLandScapeData2D.cpp - description
-------------------
begin : Wen Mar 06 2003
copyright : (C) 2003 by Jose A Milan
email : spoke@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 "OgreVector3.h"
#include "OgreColourValue.h"
#include "OgreSphere.h"
#include "OgrePagingLandScapeData2D.h"
#include "OgrePagingLandScapeOptions.h"
#include "OgrePagingLandScapeTileInfo.h"
namespace Ogre
{
PagingLandScapeData2D::PagingLandScapeData2D()
{
mIsLoaded = false;
mHeightData = 0;
mNewHeight.clear();
}
//-----------------------------------------------------------------------
PagingLandScapeData2D::~PagingLandScapeData2D()
{
if (mHeightData)
delete[] mHeightData;
mHeightData = 0;
mNewHeight.clear();
mIsLoaded = false;
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D::load(const float mX,const float mZ)
{
mIsLoaded = true;
_load(mX, mZ);
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D::load()
{
mIsLoaded = true;
_load();
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D::load(Image *newHeightmap)
{
mIsLoaded = true;
_load(newHeightmap);
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D::unload()
{
mIsLoaded = false;
_unload();
}
//-----------------------------------------------------------------------
bool PagingLandScapeData2D::isLoaded()
{
return mIsLoaded;
}
//-----------------------------------------------------------------------
const Real PagingLandScapeData2D::getHeightAbsolute(const float x, const float z,
PagingLandScapeTileInfo* info)
{
if ( mHeightData )
{
int pSize = PagingLandScapeOptions::getSingleton().PageSize;
Vector3 scale = PagingLandScapeOptions::getSingleton().scale;
// adjust x and z to be local to page
int i_x = ((int)(x / scale.x)
- ((int)(info->pageX - PagingLandScapeOptions::getSingleton().world_width * 0.5f) * (pSize)));
int i_z = ((int)(z / scale.z)
- ((int)(info->pageZ - PagingLandScapeOptions::getSingleton().world_height * 0.5f) * (pSize)));
uint arraypos = i_z * mSize + i_x;
if (arraypos < mMaxArrayPos)
return mHeightData[arraypos];
}
return 0.0f;
}
//-----------------------------------------------------------------------
const Real PagingLandScapeData2D::DeformHeight(const Vector3 &deformationPoint,
const Real &modificationHeight,
PagingLandScapeTileInfo* info)
{
if ( mHeightData )
{
int pSize = PagingLandScapeOptions::getSingleton().PageSize;
// adjust x and z to be local to page
int x = int ((deformationPoint.x )
- ((info->pageX - PagingLandScapeOptions::getSingleton().world_width * 0.5f) * (pSize)));
int z = int ((deformationPoint.z )
- ((info->pageZ - PagingLandScapeOptions::getSingleton().world_height * 0.5f) * (pSize)));
uint arraypos = z * mSize + x;
if (arraypos < mMaxArrayPos)
{
if ((mHeightData[arraypos] - modificationHeight) > 0.0f)
mHeightData[arraypos] -= modificationHeight;
else
mHeightData[arraypos] = 0.0f;
return mHeightData[arraypos];
}
}
return 0.0f;
}
//-----------------------------------------------------------------------
const Real PagingLandScapeData2D::DeformHeight(const uint &x,
const uint &z,
const Real &modificationHeight)
{
if ( mHeightData )
{
uint arraypos = z * mSize + x;
if (arraypos < mMaxArrayPos)
{
if ((mHeightData[arraypos] - modificationHeight) > 0.0f)
mHeightData[arraypos] -= modificationHeight;
else
mHeightData[arraypos] = 0.0f;
return mHeightData[arraypos];
}
}
return 0.0f;
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D::setHeight( const uint x, const uint z, const Real h )
{
if ( mHeightData )
{
uint Pos = ( z * mSize )+ x;
if ( mMaxArrayPos > Pos )
mHeightData[ Pos ] = h;
}
}
//-----------------------------------------------------------------------
bool PagingLandScapeData2D::addNewHeight(Sphere newHeight)
{
std::vector<Sphere>::iterator cur, end = mNewHeight.end();
for( cur = mNewHeight.begin(); cur < end; cur++ )
{
if( cur->intersects( newHeight ) == true )
{
// We don磘 allow to heights to intersect
return false;
}
}
mNewHeight.push_back(newHeight);
return true;
}
//-----------------------------------------------------------------------
bool PagingLandScapeData2D::removeNewHeight(Sphere oldHeight)
{
std::vector<Sphere>::iterator cur, end = mNewHeight.end();
for( cur = mNewHeight.begin(); cur < end; cur++ )
{
if( cur->intersects( oldHeight ) == true )
{
// Since we don磘 allow to heights to intersect we can delete this one
mNewHeight.erase(cur);
return true;
}
}
return false;
}
} //namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -