本文整理汇总了C++中Terrain类的典型用法代码示例。如果您正苦于以下问题:C++ Terrain类的具体用法?C++ Terrain怎么用?C++ Terrain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Terrain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Intersect
//check intersection of an axis-aligned box with the terrain
bool Intersect(const Terrain &t, const WFMath::AxisBox<3> &bbox)
{
float max, min=bbox.lowCorner()[2];
int res = t.getResolution();
//determine which segments are involved
//usually will just be one
int xlow = (int) floor(bbox.lowCorner()[0] / res);
int xhigh = (int) gridceil(bbox.highCorner()[0] / res);
int ylow = (int) floor(bbox.lowCorner()[1] / res);
int yhigh = (int) gridceil(bbox.highCorner()[1] / res);
//loop across all tiles covered by this bbox
for (int x = xlow; x < xhigh; x++) {
for (int y = ylow; y < yhigh; y++) {
//check the bbox against the extent of each tile
//as an early rejection
Segment *thisSeg=t.getSegment(x,y);
if (thisSeg)
max=thisSeg->getMax();
else
max=Terrain::defaultLevel;
if (max > min) {
//entity bbox overlaps with the extents of this tile
//now check each tile point covered by the entity bbox
//clip the points to be tested against the bbox
int min_x = (int) floor(bbox.lowCorner()[0] - (x * res));
if (min_x < 0) min_x = 0;
int max_x = (int) gridceil(bbox.highCorner()[0] - (x * res));
if (max_x > res) min_x = res;
int min_y = (int) floor(bbox.lowCorner()[1] - (y * res));
if (min_y < 0) min_y = 0;
int max_y = (int) gridceil(bbox.highCorner()[1] - (y * res));
if (max_y > res) min_y = res;
//loop over each point and see if it is greater than the minimum
//of the bbox. If all points are below, the the bbox does NOT
//intersect. If a single point is above, then the bbox MIGHT
//intersect.
for (int xpt = min_x; xpt <= max_x; xpt++) {
for (int ypt = min_y; ypt <= max_y; ypt++) {
if (thisSeg) {
if (thisSeg->get(xpt,ypt) > min) return true;
}
else if (Terrain::defaultLevel > min) return true;
}
}
}
}
}
return false;
}
示例2: glClear
void Viewer::draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(backgroundCol.x(), backgroundCol.y(), backgroundCol.z(), 1.0f);
if (mySky.wantSky())
mySky.Render( );
glEnable(GL_LIGHTING);
if (applyGLSL)
{
glEnable(GL_VERTEX_PROGRAM_ARB);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
light.position[3] = 1;
light.setLight();
}
else{
light.position[3] = 0;
light.setLight();
}
QVector4D ltmp(light.position[0],light.position[1],light.position[2],light.position[3]);
ltmp.normalize();
GLfloat lpos[4] = {ltmp.x(),ltmp.y(),ltmp.z(),ltmp.w()};
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, lpos);
// Draws a terrain
if (curTerr>=0 && curTerr<terrains.size()){
Terrain * terrain = terrains[curTerr];
if (applyTexture) glBindTexture( GL_TEXTURE_2D, terrain->texid );
else glBindTexture( GL_TEXTURE_2D, 0);
terrain->Draw();
//glLineWidth(10.0);
//glPointSize(10.0);
//glColor3f(1.0f,0.0f,0.0f);
for (int i=0; i<terrain->artifacts.size(); i++){
glColor3f(terrain->severity[i]/2.2f, 0.0f, 0.0f);
drawFlag(terrain->artifacts[i]);
}
}
glDisable(GL_VERTEX_PROGRAM_ARB);
glDisable(GL_FRAGMENT_PROGRAM_ARB);
glDisable(GL_LIGHTING);
//glLineWidth(1.0);
//glPointSize(1.0);
}
示例3: getTerrainHeightData
float* SnowTerrain::getTerrainHeightData()
{
Terrain *t = mTerrainGroup->getTerrain(0,0);
// Get terrain height data using official method
float* terrainHeightData = t->getHeightData();
return terrainHeightData;
}
示例4: getTerrainUnderUnit
bool Map::deleteUnit(Unit* unit)
{
Terrain* pos = getTerrainUnderUnit(unit->getID());
m_unitList.erase(unit->getID());
pos->setUnit(NULL);
delete unit;
return true;
}
示例5: Terrain_PatchExists_uint_uint
static duk_ret_t Terrain_PatchExists_uint_uint(duk_context* ctx)
{
Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
uint patchX = (uint)duk_require_number(ctx, 0);
uint patchY = (uint)duk_require_number(ctx, 1);
bool ret = thisObj->PatchExists(patchX, patchY);
duk_push_boolean(ctx, ret);
return 1;
}
示例6: Terrain_GetPoint_uint_uint
static duk_ret_t Terrain_GetPoint_uint_uint(duk_context* ctx)
{
Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
uint x = (uint)duk_require_number(ctx, 0);
uint y = (uint)duk_require_number(ctx, 1);
float ret = thisObj->GetPoint(x, y);
duk_push_number(ctx, ret);
return 1;
}
示例7: GetTerrainAtPoint
bool ParaTerrain::TerrainLattice::IsHole( float x, float y )
{
Terrain *pTerrain = GetTerrainAtPoint(x, y);
if(pTerrain!=NULL)
{
return pTerrain->IsHoleW(x,y);
}
return false;
}
示例8: Terrain_SetPointHeight_uint_uint_float
static duk_ret_t Terrain_SetPointHeight_uint_uint_float(duk_context* ctx)
{
Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
uint x = (uint)duk_require_number(ctx, 0);
uint y = (uint)duk_require_number(ctx, 1);
float height = (float)duk_require_number(ctx, 2);
thisObj->SetPointHeight(x, y, height);
return 0;
}
示例9: SETELEVATION
void TerrainLattice::SetVertexElevation(float x, float y, float newElevation, bool recalculate_geometry)
{
/* some vertex on border needs to be duplicated. This macro set the vertex on the given terrain tile.
* it is just to make the code easy to understand
*/
#define SETELEVATION(indexX, indexY) \
pTerrain = GetTerrain((indexX), (indexY));\
if(pTerrain && (!pTerrain->IsEmpty())){\
int nIndex = pTerrain->GetVertexW(x,y);\
pTerrain->SetVertexElevation(nIndex, newElevation,recalculate_geometry);\
pTerrain->SetModified(true, MODIFIED_HEIGHTMAP);\
}
Terrain *pTerrain = NULL;
if(x<0 || y<0)
return;
int indexX = (int)(x / m_TerrainWidth);
int indexY = (int)(y / m_TerrainHeight);
SETELEVATION(indexX, indexY);
float dX = x-indexX*m_TerrainWidth;
float dY = y-indexY*m_TerrainHeight;
float fRadius = pTerrain->GetVertexSpacing()/2;
if(dX<fRadius)
{
SETELEVATION(indexX-1, indexY);
if(dY<fRadius)
{
SETELEVATION(indexX-1, indexY-1);
}
else if(dY>m_TerrainHeight-fRadius)
{
SETELEVATION(indexX-1, indexY+1);
}
}
else if(dX>m_TerrainWidth-fRadius)
{
SETELEVATION(indexX+1, indexY);
if(dY<fRadius)
{
SETELEVATION(indexX+1, indexY-1);
}
else if(dY>m_TerrainHeight-fRadius)
{
SETELEVATION(indexX+1, indexY+1);
}
}
if(dY<fRadius)
{
SETELEVATION(indexX, indexY-1);
}
else if(dY>m_TerrainHeight-fRadius)
{
SETELEVATION(indexX, indexY+1);
}
}
示例10: Terrain_MakePatchFlat_uint_uint_float
static duk_ret_t Terrain_MakePatchFlat_uint_uint_float(duk_context* ctx)
{
Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
uint patchX = (uint)duk_require_number(ctx, 0);
uint patchY = (uint)duk_require_number(ctx, 1);
float heightValue = (float)duk_require_number(ctx, 2);
thisObj->MakePatchFlat(patchX, patchY, heightValue);
return 0;
}
示例11: Terrain_ShouldBeSerialized_bool_bool
static duk_ret_t Terrain_ShouldBeSerialized_bool_bool(duk_context* ctx)
{
Terrain* thisObj = GetThisWeakObject<Terrain>(ctx);
bool serializeTemporary = duk_require_boolean(ctx, 0);
bool serializeLocal = duk_require_boolean(ctx, 1);
bool ret = thisObj->ShouldBeSerialized(serializeTemporary, serializeLocal);
duk_push_boolean(ctx, ret);
return 1;
}
示例12: sync
void TerrainEditTool::sync(Level *level)
{
// Generate Terrain object
Terrain terrain;
for(int i = 0; i < _items.size(); i++) {
terrain.append(_items.at(i)->getPolygon());
}
level->setTerrain(terrain);
}
示例13: create
Terrain* Terrain::create(b2World* world,Hero* hero)
{
Terrain* terrain = new Terrain;
if (terrain && terrain->init(world,hero))
{
terrain->autorelease();
return terrain;
}
return NULL;
}
示例14: isValidLevelMove
/*
* @param xpos and ypos: The amount in pixels to check if is valid move
*/
bool Entity::isValidLevelMove(int xpos, int ypos) {
if (xpos / 32 < 0 || ypos / 32 < 0 || xpos/32 >= MAX_TERRAINS_ROW || ypos/32 >= MAX_TERRAINS_COL) return false;
Terrain* terrain = current_level->getTerrain(xpos/32, ypos/32);
if (terrain != NULL && terrain->isWalkable() && !terrain->isWater()) return true;
return false;
}
示例15: SetTerrainImage
void TilesetEditor::setTerrainImage(Tile *tile)
{
Terrain *terrain = mTerrainDock->currentTerrain();
if (!terrain)
return;
mCurrentTilesetDocument->undoStack()->push(new SetTerrainImage(mCurrentTilesetDocument,
terrain->id(),
tile->id()));
}