//-------------------------------------------------------------------------
    bool TerrainSceneManager::intersectSegment( const Vector3 & start, 
        const Vector3 & end, Vector3 * result )
    {
        TerrainRenderable * t = getTerrainTile( start );

        if ( t == 0 )
        {
            *result = Vector3( -1, -1, -1 );
            return false;
        }

        return t -> intersectSegment( start, end, result );
    }
示例#2
0
void Tile::blitGround(int xPos, int yPos) {
    SDL_Rect	source = { getTerrainTile()*world2zoomedWorld(TILESIZE), 0, world2zoomedWorld(TILESIZE), world2zoomedWorld(TILESIZE) };
    SDL_Rect    drawLocation = { xPos, yPos, world2zoomedWorld(TILESIZE), world2zoomedWorld(TILESIZE) };

    if((hasANonInfantryGroundObject() == false) || (getNonInfantryGroundObject()->isAStructure() == false)) {

        //draw terrain
        if(destroyedStructureTile == DestroyedStructure_None || destroyedStructureTile == DestroyedStructure_Wall) {
            SDL_BlitSurface(sprite[currentZoomlevel], &source, screen, &drawLocation);
        }

        if(destroyedStructureTile != DestroyedStructure_None) {
            SDL_Surface** pDestroyedStructureSurface = pGFXManager->getObjPic(ObjPic_DestroyedStructure);
            SDL_Rect source2 = { destroyedStructureTile*world2zoomedWorld(TILESIZE), 0, world2zoomedWorld(TILESIZE), world2zoomedWorld(TILESIZE) };
            SDL_BlitSurface(pDestroyedStructureSurface[currentZoomlevel], &source2, screen, &drawLocation);
        }

        if(!isFogged(pLocalHouse->getHouseID())) {
            // tracks
            for(int i=0; i<NUM_ANGLES; i++) {
                if(tracksCounter[i] > 0) {
                    source.x = ((10-i)%8)*world2zoomedWorld(TILESIZE);
                    SDL_BlitSurface(pGFXManager->getObjPic(ObjPic_Terrain_Tracks)[currentZoomlevel], &source, screen, &drawLocation);
                }
            }

            // damage
            for(std::vector<DAMAGETYPE>::const_iterator iter = damage.begin(); iter != damage.end(); ++iter) {
                source.x = iter->tile*world2zoomedWorld(TILESIZE);
                SDL_Rect dest = {   screenborder->world2screenX(iter->realPos.x) - world2zoomedWorld(TILESIZE)/2,
                                    screenborder->world2screenY(iter->realPos.y) - world2zoomedWorld(TILESIZE)/2,
                                    world2zoomedWorld(TILESIZE),
                                    world2zoomedWorld(TILESIZE)
                                };

                if(iter->damageType == Terrain_RockDamage) {
                    SDL_BlitSurface(pGFXManager->getObjPic(ObjPic_RockDamage)[currentZoomlevel], &source, screen, &dest);
                } else {
                    SDL_BlitSurface(pGFXManager->getObjPic(ObjPic_SandDamage)[currentZoomlevel], &source, screen, &drawLocation);
                }
            }
        }
    }

}
    //-------------------------------------------------------------------------
    float TerrainSceneManager::getHeightAt( float x, float z )
    {


        Vector3 pt( x, 0, z );

        TerrainRenderable * t = getTerrainTile( pt );

        if ( t == 0 )
        {
            //  printf( "No tile found for point\n" );
            return -1;
        }

        float h = t -> getHeightAt( x, z );

        // printf( "Height is %f\n", h );
        return h;

    }