int HelmHandlerBackFrontWind::runHandler(Coordinate const& cor)
{

    float boatFlagAxe = cor.calculateBoatFlagAxe(cor.getBoueApLat(), cor.getBoueApLon(), cor.getLatitude(), cor.getLongitude());
    float alpha = calculateAlpha(boatFlagAxe, cor.getAxeRef());
    float distanceBM = distanceBoatMark(cor.getBoueApLat(), cor.getBoueApLon(), cor.getLatitude(), cor.getLongitude());
    float beta = calculatebeta(cor.getAxeRef(), cor.getAxeBoat());
    float turn = corridor(alpha, distanceBM, corridorValue(beta));
    if(turn == false)
    {
        int res = calculateNewHelm(cor, m_rotation);
        cout<<"Return of helm handler back wind "<<res<<endl;
        res += 125;
        return res;
    }

    else if(turn == true)
    {
        m_rotation *= -1;
        int res = calculateNewHelm(cor, m_rotation);
        cout<<"Return of helm handler back wind "<<res<<endl;
        res += 125;
        return res;
    }

    else
    {
        return 0;
    }
}
//	float get(float threshold, size_t inputs)
//	{
//		size_t alphIndex=(size_t)trunc(threshold*100.0f);
//
//		if(inputs>alphaTable.size())
//			alphaTable.resize(inputs);
//
//		std::vector<float> &table=alphaTable[inputs];
//
//		if(table.empty())
//			table.resize(1000, 0.0f);
//
//		if(table[alphIndex] == 0.0f)
//			table[alphIndex]=calculateAlpha(threshold);
//		return table[alphIndex];
//	}
//	
//	std::vector<std::vector<float>> alphaTable;
	float get(float threshold, size_t inputs)
	{
		if((lastThreshold!=threshold)||(lastInputs!=inputs))
		{
			alpha=calculateAlpha(threshold, inputs);
			lastThreshold=threshold;
			lastInputs=inputs;
		}
		return alpha;
	}
示例#3
0
static void calculateAlphaPatchMatch(const cv::Mat_<cv::Vec3b> &image,
        const cv::Mat_<uchar> &trimap,
        const std::vector<cv::Point> &foregroundBoundary,
        const std::vector<cv::Point> &backgroundBoundary,
        std::vector<std::vector<Sample> > &samples)
{
    int w = image.cols;
    int h = image.rows;

    samples.resize(h, std::vector<Sample>(w));

    for (int y = 0; y < h; ++y)
        for (int x = 0; x < w; ++x)
        {
            if (trimap(y, x) == 128)
            {
                cv::Point p(x, y);

                samples[y][x].fi = rand() % foregroundBoundary.size();
                samples[y][x].bj = rand() % backgroundBoundary.size();
                samples[y][x].df = nearestDistance(foregroundBoundary, p);
                samples[y][x].db = nearestDistance(backgroundBoundary, p);
                samples[y][x].cost = FLT_MAX;
            }
        }

    std::vector<cv::Point> coords(w * h);
    for (int y = 0; y < h; ++y)
        for (int x = 0; x < w; ++x)
            coords[x + y * w] = cv::Point(x, y);

    for (int iter = 0; iter < 10; ++iter)
    {
        // propagation
        std::random_shuffle(coords.begin(), coords.end());

        for (std::size_t i = 0; i < coords.size(); ++i)
        {
            const cv::Point &p = coords[i];

            int x = p.x;
            int y = p.y;

            if (trimap(y, x) != 128)
                continue;

            const cv::Vec3b &I = image(y, x);

            Sample &s = samples[y][x];

            for (int y2 = y - 1; y2 <= y + 1; ++y2)
                for (int x2 = x - 1; x2 <= x + 1; ++x2)
                {
                    if (x2 < 0 || x2 >= w || y2 < 0 || y2 >= h)
                        continue;

                    if (trimap(y2, x2) != 128)
                        continue;

                    Sample &s2 = samples[y2][x2];

                    const cv::Point &fp = foregroundBoundary[s2.fi];
                    const cv::Point &bp = backgroundBoundary[s2.bj];

                    const cv::Vec3b F = image(fp.y, fp.x);
                    const cv::Vec3b B = image(bp.y, bp.x);

                    float alpha = calculateAlpha(F, B, I);

                    float cost = colorCost(F, B, I, alpha) + distCost(p, fp, s.df) + distCost(p, bp, s.db);

                    if (cost < s.cost)
                    {
                        s.fi = s2.fi;
                        s.bj = s2.bj;
                        s.cost = cost;
                        s.alpha = alpha;
                    }
                }
        }

        // random walk
        int w2 = (int)std::max(foregroundBoundary.size(), backgroundBoundary.size());

        for (int y = 0; y < h; ++y)
            for (int x = 0; x < w; ++x)
            {
                if (trimap(y, x) != 128)
                    continue;

                cv::Point p(x, y);

                const cv::Vec3b &I = image(y, x);

                Sample &s = samples[y][x];

                for (int k = 0; ; k++)
                {
                    float r = w2 * pow(0.5f, k);

                    if (r < 1)
                        break;

                    int di = r * (rand() / (RAND_MAX + 1.f));
                    int dj = r * (rand() / (RAND_MAX + 1.f));

                    int fi = s.fi + di;
                    int bj = s.bj + dj;

                    if (fi < 0 || fi >= foregroundBoundary.size() || bj < 0 || bj >= backgroundBoundary.size())
                        continue;

                    const cv::Point &fp = foregroundBoundary[fi];
                    const cv::Point &bp = backgroundBoundary[bj];

                    const cv::Vec3b F = image(fp.y, fp.x);
                    const cv::Vec3b B = image(bp.y, bp.x);

                    float alpha = calculateAlpha(F, B, I);

                    float cost = colorCost(F, B, I, alpha) + distCost(p, fp, s.df) + distCost(p, bp, s.db);

                    if (cost < s.cost)
                    {
                        s.fi = fi;
                        s.bj = bj;
                        s.cost = cost;
                        s.alpha = alpha;
                    }
                }
            }
    }
}
bool DualPolyhedron_3::lift(Cell_handle cell, unsigned iNearest)
{
	DEBUG_START;
	Vector_3 xOld = cell->info().point - CGAL::Origin();
	std::cout << "Old tangient point: " << xOld << std::endl;
	const auto activeGroup = calculateActiveGroup(cell, iNearest, items);
	if (activeGroup.empty())
	{
		DEBUG_END;
		return false;
	}

	Vector_3 xNew = leastSquaresPoint(activeGroup, items);
	std::cout << "New tangient point: " << xNew << std::endl;

	ASSERT(cell->has_vertex(infinite_vertex()));
	unsigned infinityIndex = cell->index(infinite_vertex());
	std::vector<Vertex_handle> vertices;
	Vertex_handle dominator;
	double alphaMax = 0.;
	double alphaMax2 = 0.;
	for (unsigned i = 0; i < NUM_CELL_VERTICES; ++i)
	{
		if (i == infinityIndex)
			continue;

		vertices.push_back(cell->vertex(i));

		Vertex_handle vertex = mirror_vertex(cell, i);
		Plane_3 plane = ::dual(vertex->point());
		double alpha;
	        bool succeeded;
		std::tie(succeeded, alpha) = calculateAlpha(xOld, xNew, plane);
		if (!succeeded)
			return false;
		std::cout << "Alpha #" << i << ": " << alpha << std::endl;
		ASSERT(alpha <= 1. && "Wrongly computed alpha");
		if (alpha > alphaMax)
		{
			alphaMax2 = alphaMax;
			alphaMax = alpha;
			dominator = vertex;
		}
	}
	
	std::cout << "Maximal alpha: " << alphaMax << std::endl;
	std::cout << "Maximal alpha 2nd: " << alphaMax2 << std::endl;
	ASSERT(alphaMax < 1. && "What to do then?");
	if (alphaMax > 0.)
	{
		std::cout << "Full move is impossible, performing partial move"
			<< std::endl;
		partiallyMove(xOld, xNew, vertices, dominator, alphaMax,
				alphaMax2);
	}
	else
	{
		std::cout << "Performing full move" << std::endl;
		if (!fullyMove(vertices, xNew, activeGroup))
		{
			DEBUG_END;
			return false;
		}
	}
	DEBUG_END;
	return true;
}
void Robot::applyShadow(GLfloat rows, GLfloat columns) {
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
        glDisable(GL_LIGHTING);
         if (calculateAlpha(0, 0, rows, columns) >=0) {
             glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                glTranslatef(xPos, 0.02f, zPos); 
                TextureManager::getInstance()->toggleTextures();
                shadowMatrix(0-xPos, 12, 0-zPos, 1.0f);
                
                glColor4f(0.0, 0.0, 0.0, calculateAlpha(0, 0, rows, columns));
                model->draw();
                //draw();
                TextureManager::getInstance()->toggleTextures();
                
                 glDisable(GL_STENCIL_TEST); 
             glPopMatrix();
         }
            if (calculateAlpha(0, rows, rows, columns) >=0) {
            glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                glTranslatef(xPos, 0.02f, zPos); 
                TextureManager::getInstance()->toggleTextures();
                shadowMatrix(0-xPos, 12, rows-zPos, 1.0f);
                glColor4f(0.0, 0.0, 0.0, calculateAlpha(0, rows, rows, columns));
                model->draw();
                //draw();
                TextureManager::getInstance()->toggleTextures();
                glDisable(GL_STENCIL_TEST); 
             glPopMatrix();
            }
            if (calculateAlpha(columns, 0, rows, columns) >=0) {
            glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                glTranslatef(xPos, 0.02f, zPos); 
                TextureManager::getInstance()->toggleTextures();
                shadowMatrix(columns-xPos, 12, 0-zPos, 1.0f);
                glColor4f(0.0, 0.0, 0.0, calculateAlpha(columns, 0, rows, columns));
                model->draw();
                //draw();
                TextureManager::getInstance()->toggleTextures();
                glDisable(GL_STENCIL_TEST); 
             glPopMatrix();
            }
            if (calculateAlpha(columns, rows, rows, columns) >=0) {
            glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                glTranslatef(xPos, 0.02f, zPos); 
                TextureManager::getInstance()->toggleTextures();
                shadowMatrix(columns-xPos, 12, rows-zPos, 1.0f);
                glColor4f(0.0, 0.0, 0.0, calculateAlpha(columns, rows, rows, columns));
                model->draw();
                //draw();
                TextureManager::getInstance()->toggleTextures();
                glDisable(GL_STENCIL_TEST); 
             glPopMatrix();
            }
    //}
    //glDisable(GL_TEXTURE_2D);
                
                
                
                
                //glDisable(GL_STENCIL_TEST);  
       // glPopMatrix();
                    
        glEnable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
        glEnable(GL_LIGHTING);
        //glEnable(GL_COLOR_MATERIAL);
    //}
    
}
void LevelRenderer::buildMap()
{
    GrassModel::teamNumber = false;
    TextureManager::getInstance()->toggleTextures(true);
    TextureManager::getInstance()->toggleSkins(0);
    //SKIN1 W/OUT TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(2, GL_COMPILE);
    /*for(int i = 0; i < rows; i++) {
    	for(int j = 0; j < columns; j++) {
    		glPushMatrix();

                glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
    			models[ level[i][j] ]->draw();
    		glPopMatrix();
    	}
    }*/
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            glPushMatrix();

            if (level[i][j]==0 || level[i][j]==11)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }

            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            if(level[i][j] >=11) {
                models[0]->draw();
            }

            glDisable(GL_STENCIL_TEST);
            glPopMatrix();
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0f, 0.0f, 0.0f, calculateAlpha((GLfloat)j, (GLfloat)i, 0.0f, 0.0f, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0f, 0.0f, 0.0f, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0.0f, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0.0f, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    //SKIN2 W/OUT TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(6, GL_COMPILE);
    TextureManager::getInstance()->toggleSkins(1);

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            glPushMatrix();

            if (level[i][j]==0 || level[i][j]==11)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }

            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            if(level[i][j] >=11) {
                models[0]->draw();
            }

            glDisable(GL_STENCIL_TEST);
            glPopMatrix();
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0.0f, 0.0f, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0.0f, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0.0f, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    //LIST FOR NO TEXTURES W/OUT TEAM NUMBER ----------------------------------------------------------------------------------------
    BoundingBox* tempBox;
    glNewList(5, GL_COMPILE);
    TextureManager::getInstance()->toggleTextures(false);

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {

            if (level[i][j]==0)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }
            glPushMatrix();
            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            if(level[i][j] >=12) {
                models[0]->draw();
            }
            glPopMatrix();
            glDisable(GL_STENCIL_TEST);
            switch(level[i][j]) {
            case 1:
            case 6:
            case 7: //hills, plain and holloy block
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1), 1.0f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 4:
            case 5: //half blocks
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),0.5f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 2: //mountains
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+2),3.75f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 3: //fence
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),2.75f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 8:
            case 9:
            case 10:
            case 11: //pits and light rubble
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),0.01f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 13://base
                //5.0f,1.25f,4.0f
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+5.0f),1.25f, (GLfloat)(i+2.5f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                tempBox = new BoundingBox((GLfloat)(j+1.0f), 0.0f, (GLfloat)(i+2.5f), (GLfloat)(j+4.0f),0.75f, (GLfloat)(i+4.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 12://factory
                //3.0f,1.25f,2.0f
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)j, (GLfloat)(i+3.0f),1.25f, (GLfloat)(j+1.0f));
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+3.0f),1.25f, (GLfloat)(i+1.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)(j+1.0f), (GLfloat)(i+3.0f),0.75f, (GLfloat)(j+2.0f));
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)(i+1.0f), (GLfloat)(j+3.0f),0.75f, (GLfloat)(i+2.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 14:
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1.0f),8.0f, (GLfloat)(i+1.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)(j+1.0f), (GLfloat)(i+3.0f),0.75f, (GLfloat)(j+2.0f));
                break;
            default:
                break;
            }
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();
    delete tempBox;

    GrassModel::teamNumber = true;
    TextureManager::getInstance()->toggleTextures(true);
    TextureManager::getInstance()->toggleSkins(0);

    //SKIN1 W/ TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(8, GL_COMPILE);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            glPushMatrix();

            if (level[i][j]==0 || level[i][j]==11)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }

            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            if(level[i][j] >=11) {
                models[0]->draw();
            }

            glDisable(GL_STENCIL_TEST);
            glPopMatrix();
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, (GLfloat)rows, (GLfloat)rows,(GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    //SKIN2 W TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(9, GL_COMPILE);
    TextureManager::getInstance()->toggleSkins(1);

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            glPushMatrix();

            if (level[i][j]==0 || level[i][j]==11)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }

            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            /*if(level[i][j] >=11){
            	models[0]->draw();
            }*/

            glDisable(GL_STENCIL_TEST);
            glPopMatrix();
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0,(GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    //LIST FOR NO TEXTURES W/ TEAM NUMBER ----------------------------------------------------------------------------------------
    glNewList(10, GL_COMPILE);
    toggleTeamNumber();
    TextureManager::getInstance()->toggleTextures(false);

    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {

            if (level[i][j]==0)
            {
                glEnable(GL_STENCIL_TEST);
                glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
                glStencilFunc(GL_ALWAYS, 10, ~0);

            }
            glPushMatrix();
            glTranslatef((GLfloat)j, (GLfloat)0, (GLfloat)i);
            models[ level[i][j] ]->draw();

            //also draw a grass tile under models
            /*if(level[i][j] >=12){
            	models[0]->draw();
            }*/
            glPopMatrix();
            glDisable(GL_STENCIL_TEST);
            switch(level[i][j]) {
            case 1:
            case 6:
            case 7: //hills, plain and holloy block
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1), 1.0f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 4:
            case 5: //half blocks
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),0.5f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 2: //mountains
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+2),3.75f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 3: //fence
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),2.75f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 8:
            case 9:
            case 10:
            case 11: //pits and light rubble
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1),0.01f, (GLfloat)(i+1));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 13://base
                //5.0f,1.25f,4.0f
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+5.0f),1.25f, (GLfloat)(i+2.5f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                tempBox = new BoundingBox((GLfloat)(j+1.0f), 0.0f, (GLfloat)(i+2.5f), (GLfloat)(j+4.0f),0.75f, (GLfloat)(i+4.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 12://factory
                //3.0f,1.25f,2.0f
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)j, (GLfloat)(i+3.0f),1.25f, (GLfloat)(j+1.0f));
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+3.0f),1.25f, (GLfloat)(i+1.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)(j+1.0f), (GLfloat)(i+3.0f),0.75f, (GLfloat)(j+2.0f));
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)(i+1.0f), (GLfloat)(j+3.0f),0.75f, (GLfloat)(i+2.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                tempBox->draw();
                break;
            case 14:
                tempBox = new BoundingBox((GLfloat)j, 0.0f, (GLfloat)i, (GLfloat)(j+1.0f),8.0f, (GLfloat)(i+1.0f));
                lrBoxes->staticBoxes.push_back(tempBox);
                //tempBox->hasNukePowerUp = true;
                tempBox->draw();
                //tempBox = new BoundingBox((GLfloat)i, 0.0f, (GLfloat)(j+1.0f), (GLfloat)(i+3.0f),0.75f, (GLfloat)(j+2.0f));
                break;
            default:
                break;
            }
        }
    }
    //SHADOWS-----------------------------------

    //glDisable(GL_LIGHTING);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glEnable(GL_COLOR_MATERIAL);

    glEnable(GL_BLEND);
    for(int i = 0; i < rows; i++) {
        for(int j = 0; j < columns; j++) {
            if(level[i][j]!=0 && level[i][j]!=3 && level[i][j]!= 8 && level[i][j]!= 9 && level[i][j]!= 10) {
                glPushMatrix();
                glEnable(GL_STENCIL_TEST);
                glStencilFunc(GL_EQUAL, 10, ~0);
                glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
                //glColor4f(0.0, 0.0, 0.0, 0.5f);

                glTranslatef((GLfloat)j, (GLfloat)0.02, (GLfloat)i);
                if(i < rows/2 && j < columns/2) {
                    shadowMatrix(light1->getPosX()-j, light1->getPosY()*2, light1->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, 0, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i< rows/2 && j <= columns) {
                    shadowMatrix(light2->getPosX()-j, light2->getPosY()*2, light2->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, 0, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j < columns/2) {
                    shadowMatrix(light4->getPosX()-j, light4->getPosY()*2, light4->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i,0, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));

                }
                else if(i<= rows && j <= columns) {
                    shadowMatrix(light3->getPosX()-j, light3->getPosY()*2, light3->getPosZ()-i, 1.0f);
                    glColor4f(0.0, 0.0, 0.0, calculateAlpha((GLfloat)j, (GLfloat)i, (GLfloat)columns, (GLfloat)rows, (GLfloat)rows, (GLfloat)columns));
                }
                models[ level[i][j] ]->draw();
                glDisable(GL_STENCIL_TEST);
                glPopMatrix();
            }
        }
    }
    //glEnable(GL_DEPTH_TEST);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);

    //-------------------------------------------
    glEndList();

    delete tempBox;

}