本文整理汇总了C++中Landscape::getGridUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ Landscape::getGridUnit方法的具体用法?C++ Landscape::getGridUnit怎么用?C++ Landscape::getGridUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Landscape
的用法示例。
在下文中一共展示了Landscape::getGridUnit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildViewForTestLandscape
ReturnCode LandscapeView::buildViewForTestLandscape(Landscape &objLandscape, LandscapeView &objLandscapeView)
{
//Get number of vertices buffers that will be required (Gridunits * 8 vertices)
//TODO: Update this once we have multiple GridUnits per column
int iNumVertices = getNumVerticesForTestLandscape(objLandscape);
Vertex *objVertexArray = new Vertex[iNumVertices];
//allocate memory for our vertex buffer & generate vertices for each grid unit
int iCurrentVertex = 0;
for(int i=0; i < objLandscape.getGridWidth(); ++i)
{
for (int j=0; j < objLandscape.getGridLength(); ++j)
{
//Fetch grid unit
GridUnit *pobjGridUnit = NULL;
objLandscape.getGridUnit(i, j, pobjGridUnit);
if(!pobjGridUnit)
return RC_ERR_GENERAL;
//TODO: Remove me eventually, I'm just for testing purposes
//Generate a shade of green.
float red, green, blue;
red = ((float)(rand() % (int)(RAND_MAX * 0.3)))/((float)RAND_MAX);
green = ((float)((RAND_MAX*0.7) + rand() % (int)(RAND_MAX * 0.3)))/((float)RAND_MAX);
blue = ((float)(rand() % (int)(RAND_MAX * 0.3)))/((float)RAND_MAX);
D3DXCOLOR color(red, green, blue, 1.0f);
float x = 0.0f, y = 0.0f, z = 0.0f;
//Generate near-left-top vertex
x = (float)i*LANDSCAPEVIEW_TILE_WIDTH;
y = (float)pobjGridUnit->getHeight()*LANDSCAPEVIEW_TILE_HEIGHT;
z = (float)j*LANDSCAPEVIEW_TILE_WIDTH;
objVertexArray[iCurrentVertex].color = color;
objVertexArray[iCurrentVertex++].pos = D3DXVECTOR3(x,y,z);
//Generate far-left-top vertex
x = (float)i*LANDSCAPEVIEW_TILE_WIDTH;
y = (float)pobjGridUnit->getHeight()*LANDSCAPEVIEW_TILE_HEIGHT;
z = (float)j*LANDSCAPEVIEW_TILE_WIDTH + LANDSCAPEVIEW_TILE_WIDTH;
objVertexArray[iCurrentVertex].color = color;
objVertexArray[iCurrentVertex++].pos = D3DXVECTOR3(x,y,z);
//Generate near-right-top vertex
x = (float)i*LANDSCAPEVIEW_TILE_WIDTH + LANDSCAPEVIEW_TILE_WIDTH;
y = (float)pobjGridUnit->getHeight()*LANDSCAPEVIEW_TILE_HEIGHT;
z = (float)j*LANDSCAPEVIEW_TILE_WIDTH;
objVertexArray[iCurrentVertex].color = color;
objVertexArray[iCurrentVertex++].pos = D3DXVECTOR3(x,y,z);
//Generate far-right-top vertex
x = (float)i*LANDSCAPEVIEW_TILE_WIDTH + LANDSCAPEVIEW_TILE_WIDTH;
y = (float)pobjGridUnit->getHeight()*LANDSCAPEVIEW_TILE_HEIGHT;
z = (float)j*LANDSCAPEVIEW_TILE_WIDTH + LANDSCAPEVIEW_TILE_WIDTH;
objVertexArray[iCurrentVertex].color = color;
objVertexArray[iCurrentVertex++].pos = D3DXVECTOR3(x,y,z);
//Generate near-left-bot vertex
x = (float)i*LANDSCAPEVIEW_TILE_WIDTH;
y = (float)pobjGridUnit->getBase()*LANDSCAPEVIEW_TILE_HEIGHT;
z = (float)j*LANDSCAPEVIEW_TILE_WIDTH;
objVertexArray[iCurrentVertex].color = BLACK;
objVertexArray[iCurrentVertex++].pos = D3DXVECTOR3(x,y,z);
//Generate far-left-bot vertex
x = (float)i*LANDSCAPEVIEW_TILE_WIDTH;
y = (float)pobjGridUnit->getBase()*LANDSCAPEVIEW_TILE_HEIGHT;
z = (float)j*LANDSCAPEVIEW_TILE_WIDTH + LANDSCAPEVIEW_TILE_WIDTH;
objVertexArray[iCurrentVertex].color = BLACK;
objVertexArray[iCurrentVertex++].pos = D3DXVECTOR3(x,y,z);
//Generate near-right-bot vertex
x = (float)i*LANDSCAPEVIEW_TILE_WIDTH + LANDSCAPEVIEW_TILE_WIDTH;
y = (float)pobjGridUnit->getBase()*LANDSCAPEVIEW_TILE_HEIGHT;
z = (float)j*LANDSCAPEVIEW_TILE_WIDTH;
objVertexArray[iCurrentVertex].color = BLACK;
objVertexArray[iCurrentVertex++].pos = D3DXVECTOR3(x,y,z);
//Generate far-right-bot vertex
x = (float)i*LANDSCAPEVIEW_TILE_WIDTH + LANDSCAPEVIEW_TILE_WIDTH;
y = (float)pobjGridUnit->getBase()*LANDSCAPEVIEW_TILE_HEIGHT;
z = (float)j*LANDSCAPEVIEW_TILE_WIDTH + LANDSCAPEVIEW_TILE_WIDTH;
objVertexArray[iCurrentVertex].color = BLACK;
objVertexArray[iCurrentVertex++].pos = D3DXVECTOR3(x,y,z);
}
}
//Describe our vertex buffer
D3D10_BUFFER_DESC objBuffDesc;
objBuffDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
objBuffDesc.Usage = D3D10_USAGE_IMMUTABLE;
objBuffDesc.CPUAccessFlags = 0;
objBuffDesc.MiscFlags = 0;
objBuffDesc.ByteWidth = sizeof(Vertex)*iNumVertices;
D3D10_SUBRESOURCE_DATA objBuffData;
objBuffData.pSysMem = objVertexArray;
//Create our vertex buffer and push it to the landscape view
ID3D10Buffer *pobjVertexBuffer = NULL;
HR(BattleViewManager::getInstance()->getDevice()->CreateBuffer(&objBuffDesc, &objBuffData, &pobjVertexBuffer));
//.........这里部分代码省略.........