예제 #1
0
파일: Path.cpp 프로젝트: mertkasar/orbit-td
void Path::clear() {
    _waypoints.clear();

    _nextWaypoint = WayPoint();
    _currentWaypoint = WayPoint();
    _index = 0;
}
예제 #2
0
vector<SPoint> CBobsMap::FixToBestPath(const vector<WayPoint> &waypoints)
{

	vector<WayPoint> vecPath=waypoints;
	Coordinate cord(m_spA,m_spB);
	//push the last point
	SPoint endPoint=cord.GetRelativePoint(m_spB.x,m_spB.y);
	vecPath.push_back(WayPoint(m_spB,endPoint));
	
	//fix waypoint
	SPoint preAbs,fBRel,fCRel,fAbs;
	preAbs=m_spA;

	vector<SPoint>bestPath;
	//push start point 
	bestPath.push_back(m_spA);

	int i=0;
	int index=0;
	int vecPathSize = vecPath.size();
	for(int q=0;q<vecPathSize;q++)
	{
		fBRel=vecPath[q].relativeXY;
		fAbs =vecPath[q].absoluteXY;
		for(i=q+1;i<vecPath.size();i++)
		{
			fCRel=vecPath[i].relativeXY;
			
			if(abs(fBRel.y)>abs(fCRel.y)||Equal(fBRel.y,fCRel.y))
			{
				bool log = BarrierIntersection(preAbs,vecPath[i].absoluteXY);
				if(!log)
				{
					fBRel = fCRel;
					fAbs =vecPath[i].absoluteXY;
					q=i;
				}
			}

		}

		bestPath.push_back(fAbs);
		preAbs=fAbs;
	}


	return bestPath;
}
예제 #3
0
void Road::readRoadFromFile(const std::shared_ptr<InnerModel> &innerModel, std::string name)
{
	clear();
	std::ifstream file(name.c_str(), std::ios_base::in);
	if (file.is_open())
	{
		QVec rPos = innerModel->transformS("world", robotname);
		append(WayPoint(rPos));

		while (file.eof() == false)
		{
			WayPoint w(QVec::zeros(3));
			file >> w.pos[0] >> w.pos[2];
			append(w);
		}
// 		qDebug() << "SpecificWorker::ReadFromFile:: " << QString::fromStdString(name) << "read with" << size() << "points";
	}
예제 #4
0
bool Transport::GenerateWaypoints(uint32 pathid, std::set<uint32> &mapids)
{
    if (pathid >= sTaxiPathNodesByPath.size())
        return false;

    TaxiPathNodeList const& path = sTaxiPathNodesByPath[pathid];

    std::vector<keyFrame> keyFrames;
    int mapChange = 0;
    mapids.clear();
    for (size_t i = 1; i < path.size() - 1; ++i)
    {
        if (mapChange == 0)
        {
            TaxiPathNodeEntry const& node_i = path[i];
            if (node_i.mapid == path[i+1].mapid)
            {
                keyFrame k(node_i);
                keyFrames.push_back(k);
                mapids.insert(k.node->mapid);
            }
            else
            {
                mapChange = 1;
            }
        }
        else
        {
            --mapChange;
        }
    }

    int lastStop = -1;
    int firstStop = -1;

    // first cell is arrived at by teleportation :S
    keyFrames[0].distFromPrev = 0;
    if (keyFrames[0].node->actionFlag == 2)
    {
        lastStop = 0;
    }

    // find the rest of the distances between key points
    for (size_t i = 1; i < keyFrames.size(); ++i)
    {
        if ((keyFrames[i].node->actionFlag == 1) || (keyFrames[i].node->mapid != keyFrames[i-1].node->mapid))
        {
            keyFrames[i].distFromPrev = 0;
        }
        else
        {
            keyFrames[i].distFromPrev =
                sqrt(pow(keyFrames[i].node->x - keyFrames[i - 1].node->x, 2) +
                    pow(keyFrames[i].node->y - keyFrames[i - 1].node->y, 2) +
                    pow(keyFrames[i].node->z - keyFrames[i - 1].node->z, 2));
        }
        if (keyFrames[i].node->actionFlag == 2)
        {
            // remember first stop frame
            if (firstStop == -1)
                firstStop = i;
            lastStop = i;
        }
    }

    float tmpDist = 0;
    for (size_t i = 0; i < keyFrames.size(); ++i)
    {
        int j = (i + lastStop) % keyFrames.size();
        if (keyFrames[j].node->actionFlag == 2)
            tmpDist = 0;
        else
            tmpDist += keyFrames[j].distFromPrev;
        keyFrames[j].distSinceStop = tmpDist;
    }

    for (int i = int(keyFrames.size()) - 1; i >= 0; i--)
    {
        int j = (i + (firstStop+1)) % keyFrames.size();
        tmpDist += keyFrames[(j + 1) % keyFrames.size()].distFromPrev;
        keyFrames[j].distUntilStop = tmpDist;
        if (keyFrames[j].node->actionFlag == 2)
            tmpDist = 0;
    }

    for (size_t i = 0; i < keyFrames.size(); ++i)
    {
        if (keyFrames[i].distSinceStop < (30 * 30 * 0.5f))
            keyFrames[i].tFrom = sqrt(2 * keyFrames[i].distSinceStop);
        else
            keyFrames[i].tFrom = ((keyFrames[i].distSinceStop - (30 * 30 * 0.5f)) / 30) + 30;

        if (keyFrames[i].distUntilStop < (30 * 30 * 0.5f))
            keyFrames[i].tTo = sqrt(2 * keyFrames[i].distUntilStop);
        else
            keyFrames[i].tTo = ((keyFrames[i].distUntilStop - (30 * 30 * 0.5f)) / 30) + 30;

        keyFrames[i].tFrom *= 1000;
        keyFrames[i].tTo *= 1000;
    }

    //    for (int i = 0; i < keyFrames.size(); ++i) {
    //        sLog->outInfo(LOG_FILTER_TRANSPORTS, "%f, %f, %f, %f, %f, %f, %f", keyFrames[i].x, keyFrames[i].y, keyFrames[i].distUntilStop, keyFrames[i].distSinceStop, keyFrames[i].distFromPrev, keyFrames[i].tFrom, keyFrames[i].tTo);
    //    }

    // Now we're completely set up; we can move along the length of each waypoint at 100 ms intervals
    // speed = max(30, t) (remember x = 0.5s^2, and when accelerating, a = 1 unit/s^2
    int t = 0;
    bool teleport = false;
    if (keyFrames[keyFrames.size() - 1].node->mapid != keyFrames[0].node->mapid)
        teleport = true;

    m_WayPoints[0] = WayPoint(keyFrames[0].node->mapid, keyFrames[0].node->x, keyFrames[0].node->y, keyFrames[0].node->z, teleport, 0,
        keyFrames[0].node->arrivalEventID, keyFrames[0].node->departureEventID);

    t += keyFrames[0].node->delay * 1000;

    uint32 cM = keyFrames[0].node->mapid;
    for (size_t i = 0; i < keyFrames.size() - 1; ++i)
    {
        float d = 0;
        float tFrom = keyFrames[i].tFrom;
        float tTo = keyFrames[i].tTo;

        // keep the generation of all these points; we use only a few now, but may need the others later
        if (((d < keyFrames[i + 1].distFromPrev) && (tTo > 0)))
        {
            while ((d < keyFrames[i + 1].distFromPrev) && (tTo > 0))
            {
                tFrom += 100;
                tTo -= 100;

                if (d > 0)
                {
                    float newX = keyFrames[i].node->x + (keyFrames[i + 1].node->x - keyFrames[i].node->x) * d / keyFrames[i + 1].distFromPrev;
                    float newY = keyFrames[i].node->y + (keyFrames[i + 1].node->y - keyFrames[i].node->y) * d / keyFrames[i + 1].distFromPrev;
                    float newZ = keyFrames[i].node->z + (keyFrames[i + 1].node->z - keyFrames[i].node->z) * d / keyFrames[i + 1].distFromPrev;

                    teleport = false;
                    if (keyFrames[i].node->mapid != cM)
                    {
                        teleport = true;
                        cM = keyFrames[i].node->mapid;
                    }

                    //                    sLog->outInfo(LOG_FILTER_TRANSPORTS, "T: %d, D: %f, x: %f, y: %f, z: %f", t, d, newX, newY, newZ);
                    if (teleport)
                        m_WayPoints[t] = WayPoint(keyFrames[i].node->mapid, newX, newY, newZ, teleport, 0);
                }

                if (tFrom < tTo)                            // caught in tFrom dock's "gravitational pull"
                {
                    if (tFrom <= 30000)
                    {
                        d = 0.5f * (tFrom / 1000) * (tFrom / 1000);
                    }
                    else
                    {
                        d = 0.5f * 30 * 30 + 30 * ((tFrom - 30000) / 1000);
                    }
                    d = d - keyFrames[i].distSinceStop;
                }
                else
                {
                    if (tTo <= 30000)
                    {
                        d = 0.5f * (tTo / 1000) * (tTo / 1000);
                    }
                    else
                    {
                        d = 0.5f * 30 * 30 + 30 * ((tTo - 30000) / 1000);
                    }
                    d = keyFrames[i].distUntilStop - d;
                }
                t += 100;
            }
            t -= 100;
        }

        if (keyFrames[i + 1].tFrom > keyFrames[i + 1].tTo)
            t += 100 - ((long)keyFrames[i + 1].tTo % 100);
        else
            t += (long)keyFrames[i + 1].tTo % 100;

        teleport = false;
        if ((keyFrames[i + 1].node->actionFlag == 1) || (keyFrames[i + 1].node->mapid != keyFrames[i].node->mapid))
        {
            teleport = true;
            cM = keyFrames[i + 1].node->mapid;
        }

        m_WayPoints[t] = WayPoint(keyFrames[i + 1].node->mapid, keyFrames[i + 1].node->x, keyFrames[i + 1].node->y, keyFrames[i + 1].node->z, teleport,
            0, keyFrames[i + 1].node->arrivalEventID, keyFrames[i + 1].node->departureEventID);
        //        sLog->outInfo(LOG_FILTER_TRANSPORTS, "T: %d, x: %f, y: %f, z: %f, t:%d", t, pos.x, pos.y, pos.z, teleport);

        t += keyFrames[i + 1].node->delay * 1000;
    }

    uint32 timer = t;

    //    sLog->outInfo(LOG_FILTER_TRANSPORTS, "    Generated %lu waypoints, total time %u.", (unsigned long)m_WayPoints.size(), timer);

    m_curr = m_WayPoints.begin();
    m_next = GetNextWayPoint();
    m_pathTime = timer;

    m_nextNodeTime = m_curr->first;

    return true;
}
예제 #5
0
int main(int argc, char *argv[]){
	//Initialise GLFW
	if (!glfwInit()) {
		fprintf(stderr, "There was a problem initializing glfw");
		exit(EXIT_FAILURE);
	}

	//glfw hints
	glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
	glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	//Open a window
	if (!glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) {
		fprintf(stderr, "There was a problem opening a window");
		exit(EXIT_FAILURE);
	}

	//Turn on experimental features to prevent seg fault
	glewExperimental = GL_TRUE;

	//Intitialize GLEW
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "There was a problem initialising GLEW");
		exit(EXIT_FAILURE);
	}

	//various glfw settings
	glfwEnable(GLFW_STICKY_KEYS);
	glfwSetKeyCallback(&key_callback);
	glfwSetWindowTitle(TITLE);	
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_DEPTH_CLAMP);

	//Create text generator
	GLuint textShaderID = setupShaders("shaders/text/vert.gls", "shaders/text/frag.gls");
	TextGenerator tg((char*)"textures/font.png", textShaderID, ' ', '~', 16, 8, WINDOW_WIDTH, WINDOW_HEIGHT);
	loading(&tg);

	//Load in and set program (Shaders)
	// GLuint simpleShaderID = setupShaders("shaders/simple/vert.gls", "shaders/simple/frag.gls");
	// GLuint phongShaderID = setupShaders("shaders/phong/vert.gls", "shaders/phong/frag.gls");
	GLuint perFragmentShaderID = setupShaders("shaders/perFragment/vert.gls", "shaders/perFragment/frag.gls");

	//Load in terrain and sky box
	HeightMapLoader groundObj = HeightMapLoader("textures", "img2.png");
	ObjLoader skyboxObj = ObjLoader("models","skybox.obj");

	Object ground(&groundObj, perFragmentShaderID, viewer, GL_FILL);
	Skybox skybox(&skyboxObj, perFragmentShaderID, viewer, GL_FILL);
	loading(&tg);

	//Load in thunder birds
	ObjLoader thunderBird1Obj = ObjLoader("models", "thunderbird1.obj");
	ObjLoader t2ContainerObj = ObjLoader("models","t2container.obj");
	ObjLoader thunderBird2Obj = ObjLoader("models","thunderbird2.obj");
	ObjLoader thunderBird3Obj = ObjLoader("models","thunderbird3.obj");
	ObjLoader eggObj = ObjLoader("models", "egg.obj");

	Object thunderBird1(&thunderBird1Obj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird1B(&thunderBird1Obj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird1C(&thunderBird1Obj, perFragmentShaderID, viewer, GL_FILL);

	Object t2container(&t2ContainerObj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird2(&thunderBird2Obj, perFragmentShaderID, viewer, GL_FILL);
	Object t2containerB(&t2ContainerObj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird2B(&thunderBird2Obj, perFragmentShaderID, viewer, GL_FILL);

	Object thunderBird3(&thunderBird3Obj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird3B(&thunderBird3Obj, perFragmentShaderID, viewer, GL_FILL);
	Object thunderBird3C(&thunderBird3Obj, perFragmentShaderID, viewer, GL_FILL);
	loading(&tg);

	//Set up collisions
	viewer->addTerrain(&ground);

	loading(&tg);

	thunderBird1.setPosition(glm::vec3(-2,0.1,0));

	t2container.setPosition(glm::vec3(-7.5,0.15,5));
	t2container.setScale(glm::vec3(0.2,0.2,0.2));
	t2container.setRotation(90, glm::vec3(0,1,0));

	thunderBird2.setPosition(glm::vec3(-7.5,0.15,5));
	thunderBird2.setScale(glm::vec3(0.2,0.2,0.2));
	thunderBird2.setRotation(90, glm::vec3(0,1,0));

	t2containerB.setPosition(glm::vec3(-13.7941, 0.0, -11.716));
	t2containerB.setScale(glm::vec3(0.2,0.2,0.2));
	t2containerB.setRotation(120, glm::vec3(0,1,0));

	thunderBird2B.setPosition(glm::vec3(-13.7941, 0.0, -11.716));
	thunderBird2B.setScale(glm::vec3(0.2,0.2,0.2));
	thunderBird2B.setRotation(120, glm::vec3(0,1,0));


	thunderBird3.setPosition(glm::vec3(2,2,12.5));
	thunderBird3.setScale(glm::vec3(0.4,0.4,0.4));
	thunderBird3.setRotation(-90, glm::vec3(1,0,0));

	thunderBird3B.setPosition(glm::vec3(22.3989, 0.541667, -5.00961));
	thunderBird3B.setScale(glm::vec3(0.4,0.4,0.4));
	thunderBird3B.setRotation(-90, glm::vec3(1,0,0));

	thunderBird3B.setPosition(glm::vec3(2,2,12.5));
	thunderBird3B.setScale(glm::vec3(0.4,0.4,0.4));
	thunderBird3B.setRotation(-90, glm::vec3(1,0,0));


	ground.setScale(glm::vec3(0.35,0.025,0.35));
	ground.setPosition(glm::vec3(-groundObj.width/2 * 0.35,0,-groundObj.height/2 * 0.35));

	std::vector<glm::vec3> positions;

	positions.push_back(glm::vec3(-6.42059,0.25837,4.494014));
	positions.push_back(glm::vec3(-3.85007,0.1,7.12377));
	positions.push_back(glm::vec3(-0.601204,0.1,3.592329));
	positions.push_back(glm::vec3(8.2538,0.1,2.5428));
	positions.push_back(glm::vec3(10.6809,0.38337,-3.84069));
	positions.push_back(glm::vec3(-5.13897,0.1,-11.4451));
	positions.push_back(glm::vec3(-14.3374,0.1,-8.11471));
	positions.push_back(glm::vec3(-20.2777, 0.1, 8.26625));
	positions.push_back(glm::vec3(-22.3929, 1.35833,19.6362));
	positions.push_back(glm::vec3(1.64004, 0.1, 33.6688));
	positions.push_back(glm::vec3(30.9513, 0.683333, 18.214));
	positions.push_back(glm::vec3(32.9145, 1.56667, -11.0445));
	positions.push_back(glm::vec3(31.17666, 0.808333, -22.8479));
	positions.push_back(glm::vec3(-29.7966, 0.35, -27.9126));
	positions.push_back(glm::vec3(-33.6018, 0.433333, -25.1177));
	positions.push_back(glm::vec3(-29.1175, 2.39167, -17.2737));
	positions.push_back(glm::vec3(-27.6434, 2.1833, -14.5711));
	positions.push_back(glm::vec3(-33.0654, 3.5, 2.62864));
	positions.push_back(glm::vec3(-20.6909, 4, 3.49496));
	positions.push_back(glm::vec3(-3.85007, 3.5 , 7.12377));
	positions.push_back(glm::vec3(1.42417, 2.116667, 0.276567));



	WayPoint w1 = WayPoint(positions[0], positions[1] - positions[0]);
	WayPoint w2 = WayPoint(positions[1], positions[2] - positions[1]);
	WayPoint w3 = WayPoint(positions[2], positions[3] - positions[2]);
	WayPoint w4 = WayPoint(positions[3], positions[4] - positions[3]);
	WayPoint w5 = WayPoint(positions[4], positions[5] - positions[4]);
	WayPoint w6 = WayPoint(positions[5], positions[6] - positions[5]);
	WayPoint w7 = WayPoint(positions[6], positions[7] - positions[6]);
	WayPoint w8 = WayPoint(positions[7], positions[8] - positions[7]);
	WayPoint w9 = WayPoint(positions[8], positions[9] - positions[8]);
	WayPoint w10 = WayPoint(positions[9], positions[10] - positions[9]);
	WayPoint w11 = WayPoint(positions[10], positions[11] - positions[10]);
	WayPoint w12 = WayPoint(positions[11], positions[12] - positions[11]);
	WayPoint w13 = WayPoint(positions[12], positions[13] - positions[12]);
	WayPoint w14 = WayPoint(positions[13], positions[14] - positions[13]);
	WayPoint w15 = WayPoint(positions[14], positions[15] - positions[14]);
	WayPoint w16 = WayPoint(positions[15], positions[16] - positions[15]);
	WayPoint w17 = WayPoint(positions[16], positions[17] - positions[16]);
	WayPoint w18 = WayPoint(positions[17], positions[18] - positions[17]);
	WayPoint w19 = WayPoint(positions[18], positions[19] - positions[18]);
	WayPoint w20 = WayPoint(positions[19], positions[20] - positions[19]);
	WayPoint w21 = WayPoint(positions[20], glm::vec3(0,0,1));

	t.addWayPoint(0.0, &w1, 1);
	t.addWayPoint(2.0, &w2, 1);
	t.addWayPoint(4.0, &w3, 1);
	t.addWayPoint(6.0, &w4, 1);
	t.addWayPoint(8.0, &w5, 1);
	t.addWayPoint(10.0, &w6, 1);
	t.addWayPoint(12.0, &w7, 1);
	t.addWayPoint(14.0, &w8, 1);
	t.addWayPoint(16.0, &w9, 1);
	t.addWayPoint(18.0, &w10, 1);
	t.addWayPoint(20.0, &w11, 1);
	t.addWayPoint(22.0, &w12, 1);
	t.addWayPoint(24.0, &w13, 1);
	t.addWayPoint(26.0, &w14, 1);
	t.addWayPoint(28.0, &w15, 1);
	t.addWayPoint(30.0, &w16, 1);
	t.addWayPoint(32.0, &w17, 1);
	t.addWayPoint(34.0, &w18, 1);
	t.addWayPoint(36.0, &w19, 1);
	t.addWayPoint(38.0, &w20, 1);
	t.addWayPoint(40.0, &w21, 1);

	Animutator* tb1Anim = new Animutator();

	KeyFrame tb1KF1 = KeyFrame(glm::vec3(0,1,1), 90, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1KF2 = KeyFrame(glm::vec3(10,1,1), 90, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1KF3 = KeyFrame(glm::vec3(10,1,1), -90, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5)); 
	KeyFrame tb1KF4 = KeyFrame(glm::vec3(0,1,1), -90, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));

	tb1Anim->addKeyFrame(0.0, &tb1KF1);
	tb1Anim->addKeyFrame(10.0, &tb1KF2);
	tb1Anim->addKeyFrame(12.5, &tb1KF3);
	tb1Anim->addKeyFrame(22.5, &tb1KF4);
	tb1Anim->addKeyFrame(25.0, &tb1KF1);

	thunderBird1.addAnimutator(tb1Anim);


	Animutator* tb1BAnim = new Animutator();

	KeyFrame tb1BKF1 = KeyFrame(glm::vec3(-23.027, 1.35, 16.35409), -110.328, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF2 = KeyFrame(glm::vec3(-24.5907, 2.29167, 15.7748), -110.328, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF3 = KeyFrame(glm::vec3(-24.5907, 2.29167, 15.7748), -38.604, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF4 = KeyFrame(glm::vec3(-32.497, 1, 25.6773), -38.604, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5)); 
	KeyFrame tb1BKF5 = KeyFrame(glm::vec3(-32.497, 1, 25.6773), 5.98309, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5)); 
	KeyFrame tb1BKF6 = KeyFrame(glm::vec3(-31.8602, 1.55833, 31.7533), 5.98309, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF7 = KeyFrame(glm::vec3(-31.8602, 1.55833, 31.7533), 38.384, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF8 = KeyFrame(glm::vec3(-28.5349, 1, 35.9512), 38.384, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF9 = KeyFrame(glm::vec3(-28.5349, 1, 35.9512), 99.0798, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF10 = KeyFrame(glm::vec3(-13.2714, 1, 33.5119), 99.0798, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF11 = KeyFrame(glm::vec3(-13.2714, 1, 33.5119), -150.378, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1BKF12 = KeyFrame(glm::vec3(-23.027, 1.35, 16.35409), -150.378, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));

	tb1BAnim->addKeyFrame(0.0, &tb1BKF1);
	tb1BAnim->addKeyFrame(5.0, &tb1BKF2);
	tb1BAnim->addKeyFrame(5.5, &tb1BKF3);
	tb1BAnim->addKeyFrame(10.5, &tb1BKF4);
	tb1BAnim->addKeyFrame(11.0, &tb1BKF5);
	tb1BAnim->addKeyFrame(16.0, &tb1BKF6);
	tb1BAnim->addKeyFrame(16.5, &tb1BKF7);
	tb1BAnim->addKeyFrame(21.5, &tb1BKF8);
	tb1BAnim->addKeyFrame(22.0, &tb1BKF9);
	tb1BAnim->addKeyFrame(27.0, &tb1BKF10);
	tb1BAnim->addKeyFrame(27.5, &tb1BKF11);
	tb1BAnim->addKeyFrame(32.5, &tb1BKF12);
	tb1BAnim->addKeyFrame(33.0, &tb1BKF1);

	thunderBird1B.addAnimutator(tb1BAnim);

	Animutator* tb1CAnim = new Animutator();

	KeyFrame tb1CKF1 = KeyFrame(glm::vec3(25.7527, 1.5, -29.4807), -77.7031, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1CKF2 = KeyFrame(glm::vec3(-24.549, 2.76667, -18.516), -77.7031, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));
	KeyFrame tb1CKF3 = KeyFrame(glm::vec3(-24.549, 2.76667, -18.516), 102.297, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5)); 
	KeyFrame tb1CKF4 = KeyFrame(glm::vec3(25.7527, 1.5, -29.4807), 102.297, glm::vec3(0,1,0), glm::vec3(0.5,0.5,0.5));

	tb1CAnim->addKeyFrame(0.0, &tb1CKF1);
	tb1CAnim->addKeyFrame(7.5, &tb1CKF2);
	tb1CAnim->addKeyFrame(9, &tb1CKF3);
	tb1CAnim->addKeyFrame(16.5, &tb1CKF4);
	tb1CAnim->addKeyFrame(18, &tb1CKF1);

	thunderBird1C.addAnimutator(tb1CAnim);


	Animutator* tb2cAnim = new Animutator();

	KeyFrame tbc2KF1 = KeyFrame(glm::vec3(-7.5, 0.15, 5), 90, glm::vec3(0,1,0), glm::vec3(0.2,0.2,0.2));
	KeyFrame tbc2KF2 = KeyFrame(glm::vec3(-7.5, -0.3, 5), 90, glm::vec3(0,1,0), glm::vec3(0.2,0.2,0.2));

	tb2cAnim->addKeyFrame(0.0, &tbc2KF1);
	tb2cAnim->addKeyFrame(5.0, &tbc2KF2);
	tb2cAnim->addKeyFrame(5.5, &tbc2KF2);
	tb2cAnim->addKeyFrame(10.0, &tbc2KF1);
	tb2cAnim->addKeyFrame(10.5, &tbc2KF1);

	t2container.addAnimutator(tb2cAnim);

	Animutator* tb2cBAnim = new Animutator();

	KeyFrame tbc2BKF1 = KeyFrame(glm::vec3(-13.7941, 0.0, -11.716), 120, glm::vec3(0,1,0), glm::vec3(0.2,0.2,0.2));
	KeyFrame tbc2BKF2 = KeyFrame(glm::vec3(-13.7941, -0.4, -11.716), 120, glm::vec3(0,1,0), glm::vec3(0.2,0.2,0.2));

	tb2cBAnim->addKeyFrame(0.0, &tbc2BKF1);
	tb2cBAnim->addKeyFrame(5.0, &tbc2BKF2);
	tb2cBAnim->addKeyFrame(5.5, &tbc2BKF2);
	tb2cBAnim->addKeyFrame(10.0, &tbc2BKF1);
	tb2cBAnim->addKeyFrame(10.5, &tbc2BKF1);

	t2containerB.addAnimutator(tb2cBAnim);


	Animutator* tb3cAnim = new Animutator();
	KeyFrame tb3KF1 = KeyFrame(glm::vec3(2, 1.90, 12.5), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));
	KeyFrame tb3KF2 = KeyFrame(glm::vec3(2, 4, 12.5), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));

	tb3cAnim->addKeyFrame(0.0, &tb3KF1);
	tb3cAnim->addKeyFrame(5.0, &tb3KF2);
	tb3cAnim->addKeyFrame(10.0, &tb3KF1);

	thunderBird3.addAnimutator(tb3cAnim);

	Animutator* tb3BcAnim = new Animutator();
	KeyFrame tb3BKF1 = KeyFrame(glm::vec3(22.3989, 2, -5.00961), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));
	KeyFrame tb3BKF2 = KeyFrame(glm::vec3(22.3989, 4.5, -5.00961), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));

	tb3BcAnim->addKeyFrame(0.0, &tb3BKF1);
	tb3BcAnim->addKeyFrame(5.0, &tb3BKF2);
	tb3BcAnim->addKeyFrame(10.0, &tb3BKF1);

	thunderBird3B.addAnimutator(tb3BcAnim);

	Animutator* tb3CcAnim = new Animutator();
	KeyFrame tb3CKF1 = KeyFrame(glm::vec3(-30.3314, 1.9, 2.7756), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));
	KeyFrame tb3CKF2 = KeyFrame(glm::vec3(-30.3314, 4.6, 2.7756), -90, glm::vec3(1,0,0), glm::vec3(0.4,0.4,0.4));

	tb3CcAnim->addKeyFrame(0.0, &tb3CKF1);
	tb3CcAnim->addKeyFrame(5.0, &tb3CKF2);
	tb3CcAnim->addKeyFrame(10.0, &tb3CKF1);

	thunderBird3C.addAnimutator(tb3CcAnim);

	int frame_count = 0;
	int last_fps = 0; 
	GLfloat lastTime = glfwGetTime();

	loading(&tg);

	do {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

		if(tour){
			t.update();
		} else {
			viewer->update();
		}

		thunderBird1.draw();
		thunderBird1B.draw();
		thunderBird1C.draw();

		thunderBird2.draw();
		t2container.draw();
		thunderBird2B.draw();
		t2containerB.draw();

		thunderBird3.draw();
		thunderBird3B.draw();
		thunderBird3C.draw();

		ground.draw();
		skybox.draw();

		if(glfwGetTime() - lastTime < 1) {
			frame_count++;
		} else {
			lastTime = glfwGetTime();
			last_fps = frame_count;
			frame_count = 0;
		}

		if(show_help){
			showHelp(tg, last_fps);
		}

		glfwSwapBuffers();
	} while ( (glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS) && 
			(glfwGetKey('q') != GLFW_PRESS) &&
			(glfwGetKey('Q') != GLFW_PRESS) &&
			(glfwGetWindowParam( GLFW_OPENED )) );

	glfwTerminate();

	//Everything was okay, return success
	exit(EXIT_SUCCESS);
}
예제 #6
0
void TKlingonBC::Do_ai()
{
	// Destruction rules
	if (m_lstHealth[HLT_HULL]<=0)
	{
		Explode();
	}
	else
	{

		double tsx,tsy;
        m_blPhaserOn = false;
        if (m_lstHealth[HLT_SENSOR]<30)
		{
			m_pTarget=NULL;
		}
		else
		{
			if ((m_nTask==TSK_CONTACT)||(m_nTask==TSK_STRIKE))
			{
				m_pTarget=(TShip *) m_pEngine->Seek(ID_PLAYER,m_dViewDistance,m_dX,m_dY);
			}
			else
			{
				m_pTarget = (TShip *) m_pEngine->Seek(MEM_KLINGON,true,m_dViewDistance,m_dX,m_dY);
			}

			if ((m_pTarget!=NULL)&&(m_pTarget->m_blDestroyed)) m_pTarget=NULL;
		}

        if (((m_pTarget!=NULL)&&((m_pTarget->m_blDestroyed)||(m_pTarget->m_CloakState == CS_CLOAKED)))||(m_lstHealth[HLT_SENSOR]<30)||(m_lstHealth[HLT_COMPUTER]<30)) m_pTarget=NULL;

		if ((m_pTarget==NULL)||(m_pTarget->m_blDocked==true))
		{
			if ((m_AI==AI_CHASE)||(m_AI==AI_EVADE))
			{
				m_AI=AI_WANDER;
			}
	   }
	   else
	   {
			m_dTargetDistance = Distance(m_dX,m_dY,m_pTarget->GetX(),m_pTarget->GetY());
			if (m_AI==AI_WANDER) m_AI=AI_CHASE;

            if (m_nTask==TSK_STANDARD)
			{
				if ((m_lstHealth[HLT_PHOTON]<50)&&(m_lstHealth[HLT_PHASER]<=20)) m_AI=AI_EVADE;
            }
   }

if ((m_lstHealth[HLT_PHOTON]<40)||(m_nTorpedoes==0))
   {
	  if (! TryEnterDocking())
      {
          m_AI=AI_EVADE;
      }
   }
   else if (m_pTarget==NULL)
   {
       bool blShouldDock = false;
       for (size_t i=0;i<m_lstHealth.size();i++)
       {
           if (m_lstHealth[i] < (m_nMaxHealth-50)) blShouldDock = true;
           if (m_nTorpedoes<50) blShouldDock = true;
       }
       if (blShouldDock)
       {
           if(! TryEnterDocking())
           {
                 m_dWaypointX=rand() % SECTORSIZE;
                 m_dWaypointY=rand() % SECTORSIZE;
                 m_AI=AI_WANDER;
           }
       }
   }





switch(m_AI)
      {
      case AI_WANDER:
		  {
           SetSpeed(100);
           m_dAngleSeek=WayPoint(m_dWaypointX,m_dWaypointY);
		   double dDistance = Distance(m_dX,m_dY,m_dWaypointX,m_dWaypointY);
		   if (dDistance<40)
           {
                m_dWaypointX=rand() % SECTORSIZE;
                m_dWaypointY=rand() % SECTORSIZE;
           }
		   if ((m_nCloakCharge>=CLOAK_DELAY)&&((m_lstHealth[HLT_CLOAK]>60)||(m_nEnergy>500))&&((m_CloakState == CS_UNCLOAKED)||(m_CloakState == CS_DECLOAKING)))
			  {
					m_CloakState = CS_CLOAKING;
			  }
		  }
      break;

      case AI_CHASE:
        if (m_pTarget!=NULL)
           {
              if (((m_CloakState == CS_CLOAKED)||(m_CloakState == CS_CLOAKING))&&(m_dTargetDistance<1000))
			  {
					m_CloakState = CS_DECLOAKING;
					m_nCloakCharge=0;
			  }

			  tsx=m_pTarget->GetX()+cos(m_pTarget->GetAngle())*m_pTarget->GetSpeed();
              tsy=m_pTarget->GetY()+sin(m_pTarget->GetAngle())*m_pTarget->GetSpeed();
              m_dAngleSeek=WayPoint(tsx,tsy);
              SetSpeed(m_dTargetDistance/4);

			  double t=m_dAngleSeek-m_dAngle;
              if (t<0) t=-t;


			  if (m_nTask!=TSK_CONTACT)
			  {
                 if ((m_dTargetDistance<=600)&&(m_dTargetDistance>150)&&(t<0.1))
                 {
				     fire_photon();
				 }

                 if (m_dTargetDistance<100) m_AI=AI_EVADE;
			  }

           }
        else
           {
					m_dWaypointX=rand() % SECTORSIZE;
                    m_dWaypointY=rand() % SECTORSIZE;
					m_AI=AI_WANDER;
           }
      break;

      case AI_EVADE:
        if (m_pTarget!=NULL)
           {
              if (((m_CloakState == CS_CLOAKED)||(m_CloakState == CS_CLOAKING))&&(m_dTargetDistance<1000))
			  {
					m_CloakState = CS_DECLOAKING;
					m_nCloakCharge=0;
			  }


			  tsx=m_pTarget->GetX()+cos(m_pTarget->GetAngle())*m_pTarget->GetSpeed();
              tsy=m_pTarget->GetY()+sin(m_pTarget->GetAngle())*m_pTarget->GetSpeed();
              m_dAngleSeek=WayPoint(tsx,tsy);
              SetSpeed(m_dMaxSpeed);
			  double t=m_dAngleSeek-m_dAngle;
              if (t<0) t=-t;

			  if (m_nTask!=TSK_CONTACT)
			  {
                 if ((m_dTargetDistance<=600)&&(m_dTargetDistance>100)&&(t<0.1))
                 {
				     fire_photon();
				 }

                 if (m_dTargetDistance>400) m_AI=AI_CHASE;
			  }
			 m_dAngleSeek-=PI;
           }
        else
           {
               m_dWaypointX=rand() % SECTORSIZE;
               m_dWaypointY=rand() % SECTORSIZE;
               m_AI=AI_WANDER;
           }
      break;


    case AI_DOCK:
          if (! m_blDocked)
          {
              m_pBaseTarget = (TShip *) m_pEngine->Seekstarbase(m_Member,false,SECTORSIZE * 2,m_dX,m_dY);
              if ((m_pBaseTarget!=NULL) && ( !Dock(m_pBaseTarget) ))
              {
                  m_dAngleSeek=WayPoint(m_pBaseTarget->GetX(),m_pBaseTarget->GetY());
              }
          }
          else
          {
              bool can_go=true;
              if (m_blNoRelease) can_go=false;
              for (size_t i=0;i<m_lstHealth.size();i++)
              {
                 if (m_lstHealth[i]<m_nMaxHealth) can_go=false;
                 if (m_nTorpedoes<50) can_go=false;
              }

              if (can_go)
              {
                 m_blDocked = false;
                 m_blDocking = false;
                 m_blReleasing = true;
                 m_AI=AI_RELEASE;
              }
          }
    break;

     case AI_RELEASE:
          if (m_blReleasing)
          {
              Release(m_pBaseTarget);
          }
          else
          {
              m_blDocked = false;
              m_blDocking = false;
              m_blReleasing = false;
              m_dWaypointX=rand() % SECTORSIZE;
              m_dWaypointY=rand() % SECTORSIZE;
              m_AI=AI_WANDER;
          }
     break;


     default:

     break;

     }


//*******************************************************************************

DoEngineering();


if (m_nEnergy>0)
   {
      m_dSteer = m_lstHealth[HLT_THRUSTER]*0.0003;

      m_dAngleSeek = GetEvasiveAngle(m_dAngleSeek);

      Control();
   }
   else if (m_lstHealth[HLT_WARPCORE]<20)
   {
       m_lstHealth[HLT_HULL]=0;
   }
}

if (((m_nEnergy<20)||(m_lstHealth[HLT_CLOAK]<50))&&((m_CloakState == CS_CLOAKED)||(m_CloakState == CS_CLOAKING)))
{
	m_CloakState = CS_DECLOAKING;
	m_nCloakCharge=0;
}

if (m_dSpeed>(m_dMaxSpeed*m_lstHealth[HLT_IMPULSE])/100)
    {
        m_dSpeed=(m_dMaxSpeed*m_lstHealth[HLT_IMPULSE])/100;
    }

    if (m_dSpeed <0)
    {
        m_dSpeed =0;
    }

    if ((m_blDocked)&&
        ((m_pBaseTarget==NULL)||((m_pBaseTarget!=NULL)&&
        (m_pBaseTarget->m_blDestroyed))))
    {
       Die();
    }


}
예제 #7
0
void PathPlanner::slotComputePath(const QVector3D& vehiclePosition, const WayPointList& wayPointList)
{
    Q_ASSERT(!wayPointList.isEmpty());

    if(!mIsInitialized) initialize();

    WayPointList wayPointsWithHighInformationGain = wayPointList;
    wayPointsWithHighInformationGain.prepend(WayPoint(vehiclePosition, 0));

    qDebug() << __PRETTY_FUNCTION__ << "computing path for waypointlist" << wayPointsWithHighInformationGain.toString();

    // mDeviceOccupancyGrid points to device memory filled with grid-values of quint8.
    // After fillOccupancyGrid(), empty cells contain a 0, occupied cells contain a 254/255.
    // The cell containing the start is set to 1. Then, one thread is launched per cell,
    // looking into the neighboring cells. If a neighboring cell (26 3d-neighbors) contains
    // a value other than 0 or 254/255, the current cell is set to min(neighbor)+1.
    // This is executed often, so that all cells reachable from start get filled with the
    // distance TO start

    alignPathPlannerGridToColliderCloud();

    QTime t;
    t.start();

    WayPointList computedPath;

    copyParametersToGpu(&mParametersPathPlanner);

    const bool haveToMapGridOccupancyTemplate = checkAndMapGridOccupancy(mCudaVboResourceGridOccupancyTemplate);
    const bool haveToMapGridOccupancyPathPlanner = checkAndMapGridOccupancy(mCudaVboResourceGridPathPlanner);

    // Only re-creates the occupancy grid if the collider cloud's content changed
    populateOccupancyGrid();

    // The first path leads from vehicle position to first waypoint. Clear the occupancy grid above the vehicle!
    // This is currently necessary, because we also scan bernd and the fishing rod, occupying our own cells.
    clearOccupancyGridAboveVehiclePosition(
        mGridOccupancyPathPanner,
        vehiclePosition.x(),
        vehiclePosition.y(),
        vehiclePosition.z(),
        &mCudaStream);

    // We have freed the occupancy grid a little to make path planning easier/possible. Restore it to the real grid asap.
    mRepopulateOccupanccyGrid = true;

    // Make some room for waypoints in host memory. The first float4's x=y=z=w will store just the number of waypoints
    float* waypointsHost = new float[mMaxWaypoints * 4];

    // Find a path between every pair of waypoints
    quint32 indexWayPointStart = 0;
    quint32 indexWayPointGoal = 1;
    quint32 pathNumber = 0;
    do
    {
        mParametersPathPlanner.start = CudaHelper::convert(wayPointsWithHighInformationGain.at(indexWayPointStart));
        mParametersPathPlanner.goal = CudaHelper::convert(wayPointsWithHighInformationGain.at(indexWayPointGoal));

        qDebug() << __PRETTY_FUNCTION__ << "now computing path from" << indexWayPointStart << ":" << wayPointsWithHighInformationGain.at(indexWayPointStart).toString() << "to" << indexWayPointGoal << ":" << wayPointsWithHighInformationGain.at(indexWayPointGoal).toString();

        copyParametersToGpu(&mParametersPathPlanner);

        // Copy the populated and dilated occupancy grid into the PathFinder's domain
        cudaSafeCall(cudaMemcpy(
                         mGridOccupancyPathPanner,
                         mGridOccupancyTemplate,
                         mParametersPathPlanner.grid.getCellCount(),
                         cudaMemcpyDeviceToDevice));

        // Now start path planning.
        markStartCell(mGridOccupancyPathPanner, &mCudaStream);

        growGrid(
            mGridOccupancyPathPanner,
            &mParametersPathPlanner,
            &mCudaStream);

        // We must set the waypoints-array on the device to a special value because
        // a bug can lead to some waypoints not being written. This is ok
        // as long as we can detect this. When memsetting with 0, we can,
        // otherwise we'd find a waypoint from a previous run and couldn't
        // detect this incidence.
        cudaSafeCall(cudaMemset(
                         (void*)mDeviceWaypoints,
                         255, // interpreted as float, should be NaN!
                         4 * mMaxWaypoints * sizeof(float)));

        retrievePath(
            mGridOccupancyPathPanner,
            mDeviceWaypoints,
            &mCudaStream);

        cudaSafeCall(cudaMemcpy(
                         (void*)waypointsHost,
                         (void*)mDeviceWaypoints,
                         4 * mMaxWaypoints * sizeof(float),
                         cudaMemcpyDeviceToHost));

        if(fabs(waypointsHost[0]) < 0.001 && fabs(waypointsHost[1]) < 0.001 && fabs(waypointsHost[2]) < 0.001)
        {
            qDebug() << __PRETTY_FUNCTION__ << "found NO path from" << indexWayPointStart << ":" << wayPointsWithHighInformationGain.at(indexWayPointStart).toString() << "to" << indexWayPointGoal << ":" << wayPointsWithHighInformationGain.at(indexWayPointGoal).toString();
            // When no path was found, we try to find a path to the next waypoint, skipping the problematic one.
            indexWayPointGoal++;
        }
        else
        {
            qDebug() << __PRETTY_FUNCTION__ << "found path with" << waypointsHost[0] << "waypoints";
            // The first waypoint isn't one, it only contains the number of waypoints
            for(int i=1; i<=waypointsHost[0]; i++)
            {
                // workaround for the no-waypoint-bug, which will show values of NaN/NaN/NaN/NaN due to the 255-memset above
                if(isnan(waypointsHost[4*i+3]))
                {
                    qDebug() << __PRETTY_FUNCTION__ << "ignoring waypoint that was skpped in retrievePath due to bug in growGrid.";
                    continue;
                }

                WayPoint newWayPoint;

                if(i == 1)
                {
                    newWayPoint = wayPointsWithHighInformationGain.at(indexWayPointStart);
                }
                else if(i == (int)waypointsHost[0])
                {
                    newWayPoint = wayPointsWithHighInformationGain.at(indexWayPointGoal);
                }
                else
                {
                    newWayPoint = WayPoint(QVector3D(waypointsHost[4*i+0], waypointsHost[4*i+1], waypointsHost[4*i+2]), 0);
                }

                // Append all points of the first path, and then only starting at the second point of the following paths.
                // Otherwise, we have the end of path A and the beginning of path B in the list, although they're the same.
                if(pathNumber == 0 || i > 1)
                {
                    computedPath.append(newWayPoint);
                }
            }

            qDebug() << __PRETTY_FUNCTION__ << "found path between" << wayPointsWithHighInformationGain.at(indexWayPointStart).toString() << "and" << wayPointsWithHighInformationGain.at(indexWayPointGoal).toString() << ":" << computedPath.toString();

            pathNumber++;
            indexWayPointStart = indexWayPointGoal;
            indexWayPointGoal++;
        }
    } while(indexWayPointGoal < wayPointsWithHighInformationGain.size());

    delete waypointsHost;

    if(haveToMapGridOccupancyTemplate) checkAndUnmapGridOccupancy(mCudaVboResourceGridOccupancyTemplate);
    //    cudaGraphicsUnmapResources(1, &mCudaVboResourceGridPathFinder, 0);

    if(haveToMapGridOccupancyPathPlanner) checkAndUnmapGridOccupancy(mCudaVboResourceGridPathPlanner);
    //    cudaGraphicsUnmapResources(1, &mCudaVboResourceGridOccupancy, 0);

    emit path(computedPath.list(), WayPointListSource::WayPointListSourceFlightPlanner);

    qDebug() << __PRETTY_FUNCTION__ << "took" << t.elapsed() << "ms.";
}