📄 ogrepaginglandscapedata2d_spline.cpp
字号:
/********************************************************************************
OgrePagingLandScapeData2D_Spline.cpp
*****************************************************************************
A NURBS-based heightfield generator for use with the paginglandscapeplugin
Note that it could easily be adapted for use as a general NURBS surface
generator.
*****************************************************************************
begin : Sat Nov 9 2003
copyright : (C) 2003 Chris "Antiarc" Heald
email : antiarc@captionthis.com
********************************************************************************/
/********************************************************************************
* *
* 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 "OgrePagingLandScapeData2D.h"
#include "OgrePagingLandScapeOptions.h"
#include "OgrePagingLandScapeData2D_Spline.h"
namespace Ogre
{
PagingLandScapeData2D_Spline::PagingLandScapeData2D_Spline()
: PagingLandScapeData2D()
{
mMaxheight = 256.0f * PagingLandScapeOptions::getSingleton().scale.y;
}
//-----------------------------------------------------------------------
PagingLandScapeData2D_Spline::~PagingLandScapeData2D_Spline()
{
if( mSurface )
delete mSurface;
if( mPoints )
delete[] mPoints;
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D_Spline::_load(const float mX, const float mZ )
{
if (!mIsLoaded)
{
int resolution = PagingLandScapeOptions::getSingleton().PageSize;
mSize = resolution;
mMax = mSize * mSize;
int pCount = 50;
int mDegree = 3;
float MAX = 500;
int tessLevel = mSize;
srand (time(NULL));
int i = 0;
mPoints = new Point4D[pCount * pCount];
const int knotVecSize = pCount + mDegree + 1;
float *knots = new float[knotVecSize];
for (i = 0; i<knotVecSize; i++)
{
if (i < mDegree)
{
knots[i] = 0;
}
else if (i > knotVecSize - mDegree)
{
knots[i] = knotVecSize - (2 * mDegree) + 1;
}
else
{
knots[i] = i - mDegree + 1;
}
}
int dataSize = pCount * pCount;
for(i=0;i<dataSize; i++)
{
mPoints[i].x = (int)i/pCount;
mPoints[i].y = ((double)rand() / (double)(MAX));
mPoints[i].w = 1;
mPoints[i].z = 0;//i % pCount;
}
mSurface = new CDRGNURBSSurface();
mSurface->Init(mDegree, mDegree, pCount, pCount, mPoints, knots, knots, tessLevel, tessLevel);
mSurface->TessellateSurface();
delete[] knots;
delete[] mPoints;
mMaxArrayPos = resolution * resolution;
mHeightData = new Real[mMaxArrayPos];
Real scale = PagingLandScapeOptions::getSingleton().scale.y;
mMaxheight = 0.0f;
for (uint k = 0; k < mMaxArrayPos; k ++ )
{
Real h = (Real) (mSurface->getData(k).y) * scale;
mHeightData[k] = h;
mMaxheight = std::max (h, mMaxheight);
}
mIsLoaded = true;
}
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D_Spline::_load()
{
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D_Spline::_load(Image *newHeightmap)
{
}
//-----------------------------------------------------------------------
void PagingLandScapeData2D_Spline::_unload()
{
if(mSurface != 0)
{
delete mSurface;
}
mIsLoaded = false;
}
} //namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -