#include #include #include "C_Box.h" #include "typedefs.h" C_Box::C_Box(const char *f_strFileName, GLuint f_uiTexture, MatProps_t f_Mat, int f_iTilesX, int f_iTilesY, C_3DObject *f_pTiles[5]) : C_3DObject(f_strFileName, f_uiTexture, f_Mat), m_pTiles(f_pTiles), m_iTilesX(f_iTilesX), m_iTilesY(f_iTilesY) { m_iNumTiles = m_iTilesX * m_iTilesY; //create a new tiles layout array m_iTilesLayout = new int[m_iNumTiles]; //calculate the tile size (this should be the same //for all tile types) BoundingBox_t l_BBox = m_pTiles[0]->GetBoundingBox(); m_dTileSize = l_BBox.m_Max.x - l_BBox.m_Min.x; //calculate the lower left tile position (in xz plane) m_LowLeftTilePos = Vect3D_t(-m_dTileSize * (double)(m_iTilesX-1)/2.0, 0.0, m_dTileSize * (double)(m_iTilesY-1)/2.0); } C_Box::~C_Box() { delete [] m_iTilesLayout; } void C_Box::RandomizeTiles() { int l_iNumTiles = m_iTilesX * m_iTilesY; //first set the layout to all tiles with no hole for (int i=0; iSetPos(m_LowLeftTilePos.x + (double)col * m_dTileSize, 0.0, m_LowLeftTilePos.z - (double)row * m_dTileSize); } } void C_Box::Render(GLint f_iTexLocation) { // glPushMatrix(); //apply transformation for box TransRotateScale(); //render the box C_3DObject::Render(f_iTexLocation); //render the tiles for(int x=0; x= 0 && l_iTileIndex <= 3) { //tile with a hole glPushMatrix(); m_pTiles[l_iTileIndex]->TransRotateScale(); m_pTiles[l_iTileIndex]->Render(f_iTexLocation); glPopMatrix(); } else { //tile without a hole //set the position m_pTiles[4]->SetPos(m_LowLeftTilePos.x + (double)x * m_dTileSize, 0.0, m_LowLeftTilePos.z - (double)y * m_dTileSize); glPushMatrix(); m_pTiles[4]->TransRotateScale(); m_pTiles[4]->Render(f_iTexLocation); glPopMatrix(); } } glPopMatrix(); }