//==============================================================
//==============================================================
//= ROAM.cpp ===================================================
//= Original coders: Trent Polack (trent@voxelsoft.com) and =
//= Mark Duchaineau =
//==============================================================
//= The header file for the ROAM implementation =
//==============================================================
//==============================================================
//--------------------------------------------------------------
//--------------------------------------------------------------
//- HEADERS AND LIBRARIES --------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
#include <windows.h>
#include <math.h>
#include <GL/gl.h>
#include "ROAM.h"
//--------------------------------------------------------------
//--------------------------------------------------------------
//- DEFINITIONS ------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
// Name: CROAM::Init - public
// Description: Initialize the ROAM engine
// Arguments: -iMaxLevel: the maximum iLevel we can recurse down to
// -iPoolSize: size of the diamond pool
// -pCamera: pointer to a camera instance
// Return Value: None
//--------------------------------------------------------------
void CROAM::Init( int iMaxLevel, int iPoolSize, CCAMERA* pCamera )
{
SROAM_DIAMOND* pDmnd, *pTempDmnd0, *pTempDmnd1;
float f;
int iLevel, i, j, k, di, dj, ix, jx, *pInt;
//initialize the ROAM engine
m_iQueueCoarse= 1990; //1990 happened to be the "magic number" for the queue "fineness"
m_iFrameCount = 0;
m_iMaxLevel = iMaxLevel;
m_fpLevelMDSize= new float [m_iMaxLevel+1];
//generate table of displacement sizes versus levels
for( iLevel=0; iLevel <= m_iMaxLevel; iLevel++ )
m_fpLevelMDSize[iLevel]= 255.0f/( ( float )sqrt( ( float )( ( __int64 )1<<iLevel ) ) );
//create diamond store, free list
//allocate diamond and hash table arrays
m_iPoolSize = iPoolSize;
m_pDmndPool= new SROAM_DIAMOND [m_iPoolSize];
m_iMaxTriChunks= TRI_IMAX;
m_ipPDmndIS= new int [m_iMaxTriChunks];
//allocate memory for the vertex/texture coordinates
m_fVertTexBuffer= new float [m_iMaxTriChunks*15];
//start all diamonds on the free list
for( i=0; i + 1 < m_iPoolSize; i++ )
{
pTempDmnd0= m_pDmndPool + i;
pTempDmnd1= m_pDmndPool + ( i + 1 );
pTempDmnd0->m_pNextDmnd= pTempDmnd1;
pTempDmnd1->m_pPrevDmnd= pTempDmnd0;
}
m_pFreeDmnd[0]= m_pDmndPool;
m_pFreeDmnd[1]= m_pDmndPool + ( m_iPoolSize - 1 );
m_pFreeDmnd[0]->m_pPrevDmnd= ( SROAM_DIAMOND* )0;
m_pFreeDmnd[1]->m_pNextDmnd= ( SROAM_DIAMOND* )0;
m_iFreeElements= m_iPoolSize;
//initialize diamonds to be NEW and FREE
for( i=0; i < m_iPoolSize; i++ )
{
pTempDmnd0= m_pDmndPool + i;
pTempDmnd0->m_fBoundRad= -1; //indicated a NEW diamond
pTempDmnd0->m_ucLockCount= 0;
pTempDmnd0->m_ucFlags= 0;
pTempDmnd0->m_ucFrameCount= 255;
pTempDmnd0->m_pParent[2]= pTempDmnd0->m_pParent[3]= ( SROAM_DIAMOND* )0;
pTempDmnd0->m_ucCull= 0;
pTempDmnd0->m_cChildIndex[0]= pTempDmnd0->m_cChildIndex[1]= 0;
pTempDmnd0->m_sQueueIndex= IQMAX/2;
pTempDmnd0->m_pChild[0]= pTempDmnd0->m_pChild[1]= pTempDmnd0->m_pChild[2]= pTempDmnd0->m_pChild[3]= ( SROAM_DIAMOND* )0;
pTempDmnd0->m_cLevel= -100;
pTempDmnd0->m_pParent[0]= pTempDmnd0->m_pParent[1]= ( SROAM_DIAMOND* )0;
pTempDmnd0->m_fErrorRad= 10.0f;
}
//clear the split/merge priority queues
for( i= 0; i < IQMAX; i++ )
{
m_pSplitQueue[i]= m_pMergeQueue[i]= ( SROAM_DIAMOND* )0;
}
m_iPQMax= -1;
m_iPQMin= IQMAX;
//clear the triangle render-list
for( i=0; i<m_iMaxTriChunks; i++ )
m_ipPDmndIS[i]= -1;
m_iFreeTri= 1;
m_iTrisPerFrame= 0;
m_iFreeTriCount= m_iMaxTriChunks - 1;
m_iMaxTris= 30000; //set the default maximum triangle count (max triangles visible per frame)
//generate a LUT for float->int conversations (huge speed-saver later on)
pInt= ( int * )( &f );
for( i=0; i<256; i++ )
{
*pInt= 0x3f800000 + ( i<<15 );
m_iLog2Table[i]= ( int )floor( m_iSize*( log( f )/log( 2.0 ) - ( float )i/256.0 ) + 0.5f )<<12;
}
//allocate base diamonds, and set their information (minus link info)
for( k=0; k<32; k++ )
{
//initialization code for dimaonds 0-15
if( k<16 )
{
j= k/4;
i= k%4;
m_pLevel0Dmnd[j][i]= pDmnd= Create( );
pDmnd->m_fVert[0]= ( 2.0f*( float )( i - 1 ) );
pDmnd->m_fVert[2]= ( 2.0f*( float )( j - 1 ) );
}
//initialization for diamonds 15-31
else
{
j= ( k - 16 )/4;
i= ( k - 16 )%4;
m_pLevel1Dmnd[j][i]= pDmnd= Create( );
pDmnd->m_fVert[0]= ( 2.0f*( float )i - 3.0f );
pDmnd->m_fVert[2]= ( 2.0f*( float )j - 3.0f );
}
//shift the previous coords from [-3, 3] to [0, m_iSize-1]
ShiftCoords( &pDmnd->m_fVert[0], &pDmnd->m_fVert[2] );
//clamp the coordinates to the map size (prevent a buffer overflow)
CLAMP( pDmnd->m_fVert[0], 0, ( m_iSize-1 ) );
CLAMP( pDmnd->m_fVert[2], 0, ( m_iSize-1 ) );
pDmnd->m_fVert[1]= ( float )GetTrueHeightAtPoint( ( int )( fabs( pDmnd->m_fVert[0] ) ),
( int )( fabs( pDmnd->m_fVert[2] ) ) );
pDmnd->m_usTriIndex[0]= pDmnd->m_usTriIndex[1]= 0;
pDmnd->m_fBoundRad= ( float )SQR( m_iSize );
pDmnd->m_fErrorRad= ( float )m_iSize;
//reset all links
pDmnd->m_pParent[0]= pDmnd->m_pParent[1]= pDmnd->m_pParent[2]= pDmnd->m_pParent[3]= ( SROAM_DIAMOND* )0;
pDmnd->m_pChild[0] = pDmnd->m_pChild[1] = pDmnd->m_pChild[2] = pDmnd->m_pChild[3] = ( SROAM_DIAMOND* )0;
pDmnd->m_cLevel= ( k < 16 ? 0 : ( ( ( i^j ) & 1 ) ? -1 : -2 ) );
pDmnd->m_ucCull = 0;
pDmnd->m_ucFlags= 0;
pDmnd->m_ucSplitFlags= 0;
pDmnd->m_sQueueIndex= IQMAX - 1;
if( k<16 && k!=5 )
pDmnd->m_ucFlags|= ROAM_CLIPPED;
if( pDmnd->m_cLevel<0 )
pDmnd->m_ucFlags|= ROAM_SPLIT;
}
//now that all of the diamonds exist, we need to set their links
for( k=0; k<16; k++ )
{
j= k/4;
i= k%4;
//links for the iLevel 0 diamonds
pDmnd=m_pLevel0Dmnd[j][i];
di= ( ( ( i^j ) & 1 ) ? 1 : -1 );
dj= 1;
ix= ( ( 2*i + 1 - di )>>1 )%4;
jx= ( ( 2*j + 1 - dj )>>1 )%4;
pDmnd->m_pParent[0]= m_pLevel1Dmnd[jx][ix];
ix= ( ( 2*i + 1 + di )>>1 )%4;
jx= ( ( 2*j + 1 + dj )>>1 )%4;
pDmnd->m_pParent[1]= m_pLevel1Dmnd[jx][ix];
ix= ( ( 2*i + 1 - dj )>>1 )%4;
jx= ( ( 2*j + 1 + di )>>1 )%4;
pDmnd->m_pParent[2]= m_pLevel1Dmnd[jx][ix];
ix= ( ( 2*i + 1 + dj )>>1 )%4;
jx= ( ( 2*j + 1 - di )>>1 )%4;
pDmnd->m_pParent[3]= m_pLevel1Dmnd[jx][ix];
ix= ( di < 0 ? 0 : 3 );
pDmnd->m_pParent[0]->m_pChild[ix]= pDmnd;
pDmnd->m_cChildIndex[0]= ix;
ix= ( di < 0 ? 2 : 1 );
pDmnd->m_pParent[1]->m_pChild[ix]= pDmnd;
pDmnd->m_cChildIndex[1]= ix;
}
for( k=0; k<16; k++ )
{
j= k/4;
i= k%4;
//links for the iLevel -1 diamonds
pDmnd=m_pLevel1Dmnd[j][i];
pDmnd->m_pParent[3]= m_pLevel1Dmnd[( j+3 )%4][i];
pDmnd->m_pParent[2]= m_pLevel1Dmnd[( j+1 )%4][i];
pDmnd->m_pParent[0]= m_pLevel1Dmnd[j][( i+3 )%4];
pDmnd->m_pParent[1]= m_pLevel1Dmnd[j][( i+1 )%4];
}
//put the top-iLevel diamond on the split queue (and we can work from there
pDmnd= m_pLevel0Dmnd[1][1];
Enqueue( pDmnd, ROAM_SPLITQ, IQMAX-1 );
//get the base tris
AllocateTri( pDmnd, 0 );
AllocateTri( pDmnd, 1 );
//set the class's camera pointer
m_pCamera= pCamera;
}
//--------------------------------------------------------------
// Name: CROAM::Shu
没有合适的资源?快使用搜索试试~ 我知道了~
Premier Press - Focus On 3D Terrain Programming(source code)
共702个文件
h:168个
cpp:150个
tga:44个
5星 · 超过95%的资源 需积分: 12 128 下载量 105 浏览量
2009-11-18
11:50:35
上传
评论 1
收藏 13.87MB ZIP 举报
温馨提示
Focus on 3D Terrain Programming source code
资源推荐
资源详情
资源评论
收起资源包目录
Premier Press - Focus On 3D Terrain Programming(source code) (702个子文件)
resource.aps 80KB
resource.aps 80KB
resource.aps 80KB
resource.aps 80KB
resource.aps 80KB
resource.aps 80KB
resource.aps 79KB
resource.aps 78KB
resource.aps 78KB
resource.aps 77KB
resource.aps 77KB
resource.aps 77KB
resource.aps 77KB
resource.aps 77KB
resource.aps 76KB
resource.aps 75KB
resource.aps 65KB
resource.aps 65KB
resource.aps 65KB
resource.aps 62KB
resource.aps 62KB
resource.aps 62KB
resource.clw 671B
ROAM.cpp 34KB
ROAM.cpp 34KB
ROAM.cpp 34KB
ROAM.cpp 34KB
ROAM.cpp 34KB
ROAM.cpp 34KB
ROAM.cpp 34KB
ROAM.cpp 33KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
terrain.cpp 30KB
quadtree.cpp 29KB
terrain.cpp 29KB
quadtree.cpp 29KB
terrain.cpp 26KB
terrain.cpp 25KB
terrain.cpp 25KB
quadtree.cpp 23KB
main.cpp 21KB
main.cpp 21KB
main.cpp 21KB
gl_app.cpp 20KB
gl_app.cpp 20KB
gl_app.cpp 20KB
gl_app.cpp 20KB
gl_app.cpp 20KB
gl_app.cpp 20KB
gl_app.cpp 20KB
gl_appdemo7_1.cpp 20KB
gl_app.cpp 20KB
main.cpp 20KB
main.cpp 20KB
main.cpp 19KB
main.cpp 19KB
main.cpp 19KB
main.cpp 19KB
ROAM.cpp 17KB
image.cpp 17KB
image.cpp 17KB
image.cpp 17KB
image.cpp 17KB
image.cpp 17KB
image.cpp 17KB
image.cpp 17KB
image.cpp 17KB
skydome.cpp 17KB
skydome.cpp 17KB
skydome.cpp 17KB
skydome.cpp 17KB
skydome.cpp 17KB
skydome.cpp 17KB
terrain.cpp 16KB
terrain.cpp 16KB
geomipmapping.cpp 15KB
geomipmapping.cpp 15KB
geomipmapping.cpp 15KB
geomipmapping.cpp 15KB
main.cpp 15KB
main.cpp 15KB
共 702 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
veimen
- 粉丝: 17
- 资源: 35
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页