コード例 #1
0
ファイル: Simulation.cpp プロジェクト: alon/track
void Simulation::enterMovieMode()
{
    std::cout << "MovieMode: Entered\n";
	mode = MovieMode;	// change mode to MovieMode
	aimCamera(camera_object);	// aim camera at object
	mywriteframes = 1;	// start to capture frames
}
コード例 #2
0
ファイル: automate.cpp プロジェクト: alon/track
void AutoEventFinish::Action(dReal curTime)
{
	aimCamera(cameraBody);
	switch (state) {
	case 0:
		if (curTime - startTime > event_time) {
			machine->Event();	// this should make a right turn. it can also be anything
			state = 1;
		};
		break;
	case 1:
		if (curTime - startTime > finish_time) {
			state = 2;
			finished = 1;
			if (finish_machine)
				finish_machine->Event();
		};
		break;
	};
}
コード例 #3
0
ファイル: Simulation.cpp プロジェクト: alon/track
void Simulation::command(int cmd)
{
	dMass mass;
	static int view;	// which view was set last
	static std::string input = "";	// input string ("" initially)
	//static dJointID tagging_joint = 0;            // joint that keeps one link static


	if (cmd >= 'A' && cmd <= 'B')
		cmd = cmd + 'a' - 'A';	// lower case
	if (mode == KeyMode) {
		switch (cmd) {
		case keyWriteFrame:
			mywriteframes ^= 1;
			break;
		case keyCreateMainBody:
			if (car->body_obj == 0) {
				car->createBody(center);
				objbin.Add(car->body_obj);
			};
			break;
			// switch mode to input
		case keyInputMode:
			mode = InputMode;
            std::cout << "input: ";
            std::cout.flush();
			break;
			// abandon ship
		case keyBreakWheel:
			car->breakWheel();
			break;
			// change speed
		case keyZeroSpeed:
			s_speed[0] = 0;
			s_speed[1] = 0;
			break;
		case keyRightSpeedIncrease:
			s_speed[1] += 0.1;
			break;
		case keyRightSpeedDecrease:
			s_speed[1] -= 0.1;
			break;
		case keyRightSpeedMax:
			s_speed[1] = max_speed;
			break;
		case keyRightSpeedMin:
			s_speed[1] = min_speed;
			break;
		case keyLeftSpeedIncrease:
			s_speed[0] += 0.1;
			break;
		case keyLeftSpeedDecrease:
			s_speed[0] -= 0.1;
			break;
		case keyLeftSpeedMax:
			s_speed[0] = max_speed;
			break;
		case keyLeftSpeedMin:
			s_speed[0] = min_speed;
			break;
		case keyBothSpeedIncrease:
			s_speed[0] += 0.1;
			s_speed[1] += 0.1;
			break;
		case keyBothSpeedDecrease:
			s_speed[0] -= 0.1;
			s_speed[1] -= 0.1;
			break;
		case keyBothSpeedMax:
			s_speed[0] = max_speed;
			s_speed[1] = max_speed;
			break;
		case keyBothSpeedMin:
			s_speed[0] = min_speed;
			s_speed[1] = min_speed;
			break;
			// do the twitch
		case keyTwitchToggle:
			twitch_flag = 1 - twitch_flag;
			break;
		case keyTwitchHertzHalf:
			twitch_hertz /= 2.0;
			break;
		case keyTwitchHertzDouble:
			twitch_hertz *= 2.0;
			break;
			// camera views change
		case keyAimCamera:
			aimCamera(camera_object);
			break;
		case keyLockCameraToVehicle: // only pos, not orientation so far
			lockCamera = 1 - lockCamera;
			float xyz[3], hpr[3];
			dsGetViewpoint(xyz, hpr);
			dBodyGetPosRelPoint(camera_object, xyz[0], xyz[1], xyz[2], cameraRelVec);	// returns point in body relative coordinates
			break;
		case keyIncreaseViewByTwoMod:
			view = (view + 2) % set_view(-1);
			set_view(view);
			break;
		case keyIncreaseViewByOneMod:
			view = (view + 1) % set_view(-1);
			set_view(view);
			break;
			// show speed and wanted speed (uncorrect when in twitch mode)
		case keyDisplayWheels:
			for (int i = 0 ; i  < 4 ; ++i)
				car->wheel_obj[i]->toggleDrawFlag();
		case keyPrintSprocketMass:
			car->getSprocketMass(&mass);
			printf("mass %3.3f %3.3f %3.3f %3.3f\n",
			       mass.mass, mass.I[0], mass.I[5],
			       mass.I[10]);
			break;
		case keyPrintManyVariables:
			printf
			    ("s_speed %3.3f | actual %3.3f | hertz %3.3f | time %3.3f | lv %d\n",
			     s_speed[0], car->getSprocketSpeed(),
			     twitch_hertz, dStopwatchTime(&timer), view);
			break;
		case keyEnterMovieMode:
			enterMovieMode();
			automat = new AutoEventFinish(simTime, event_time, m_myMachine, finish_time, m_exitMachine, camera_object);	// create automat
			break;
		};
		if (cmd >= '0' && cmd < ('0' + LINK_PARTS))
			Chain::showbit[cmd - '0'] =
			    1 - Chain::showbit[cmd - '0'];
		for (int i = 0; i < 2; ++i)
			s_speed[i] =
			    BRACKET(s_speed[i], min_speed, max_speed);
	} else if (mode == InputMode) {
		// switch mode to single key
		if (cmd == ' ') {
			mode = KeyMode;
			//process (input);
            std::istringstream s(input);
			int tagged_link;
			s >> tagged_link;
			/*
			   tagged_link = BRACKET(tagged_link, 0, chain_obj[0]->b_num - 1);
			   if (tagging_joint != 0) // delete old
			   dJointDestroy(tagging_joint);
			   tagging_joint = dJointCreateFixed(world, 0);
			   dJointAttach(tagging_joint, chain_obj[0]->body[tagged_link], 0);
			   dJointSetFixed(tagging_joint);
			 */
            std::cout << "\n";
			// reset input
			input = "";
		} else {
コード例 #4
0
int main(int argc, char** argv)
{
	bool run = GL_TRUE;

    if(!glfwInit())
    {
        exit(EXIT_FAILURE);
    }

    if(!glfwOpenWindow(window_width, window_height, 8, 8, 8, 8, 24, 0, GLFW_WINDOW))
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glewInit();
    if (!glewIsSupported( "GL_VERSION_2_0 " 
        "GL_ARB_pixel_buffer_object"
        )) {
            fprintf( stderr, "ERROR: Support for necessary OpenGL extensions missing.");
            fflush( stderr);
            return false;
    }

    initShader("./Shader/vert.glsl", "./Shader/frag.glsl");

    glfwSetKeyCallback(keypress);
    glfwSetMouseButtonCallback(mouseClick);
    glfwSetMousePosCallback(mouseMotion);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glViewport(0, 0, window_width, window_height);

    VBO vbo_handle;
    Scene scene("../Scene/test_scene.xml");
    // TODO: change here if you want to use a smaller iteration number.
    ClothSim cloth_sim(10);
    // TODO: change here if you want to modify the dimension.
    cloth_sim.initialize(20, 20, glm::vec3(-5.0f, 10.0f, -5.0f), glm::vec3(5.0f, 10.0f, 5.0f));
	//cloth_sim.initialize(30, 30, glm::vec3(-5.0f, 10.0f, -5.0f), glm::vec3(5.0f, 10.0f, 5.0f));


    lastTime = glfwGetTime();
    while(run)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        aimCamera();

        if(!pause)
            cloth_sim.update(&scene, 0.006325f);
        if(flip_draw_mode)
        {
            cloth_sim.flip_draw_mode();
            flip_draw_mode = false;
        }
        activate_shaderprog(m_shaderprog_handle);
        cloth_sim.draw(vbo_handle);
        scene.draw(vbo_handle);
        deactivate_shaderprog(m_shaderprog_handle);

        drawAxes();
        if(!pause && record)
            grabScreen();
        frame_num++;

        now = glfwGetTime();
        char fpsInfo[256];
        sprintf(fpsInfo, "%f", 1.0f / (now - lastTime));
        lastTime = now;
        glfwSetWindowTitle(fpsInfo);

        glfwSwapBuffers();

        run = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }
    
    cleanupShader();
    glfwTerminate();
    exit(EXIT_SUCCESS);
}