Exemplo n.º 1
0
void cameraMouseMove(sf::RenderWindow & window,gameMap_t * self){

    //Up Left
    if (sf::IntRect(0, 0, 200, 200).contains(sf::Mouse::getPosition(window))){
            cameraUp(self);
            cameraLeft(self);
    }
    //Up
   if (sf::IntRect(200, 0, 1290, 200).contains(sf::Mouse::getPosition(window))){
       cameraUp(self);
   }
  // Left
     if (sf::IntRect(0, 200, 200, 680).contains(sf::Mouse::getPosition(window))){
    cameraLeft(self);
  }
   //Down
    if (sf::IntRect(200, 880, 1520, 200).contains(sf::Mouse::getPosition(window))){
       cameraDown(self);
   }
   //Right
   // if (sf::IntRect(1720, 200, 200, 680).contains(sf::Mouse::getPosition(window))){
   //    cameraRight(self);
   // }
   //dDown Left
  if (sf::IntRect(0, 880, 200, 200).contains(sf::Mouse::getPosition(window))){
       cameraDown(self);
       cameraLeft(self);
}

}
Exemplo n.º 2
0
void MainWindow::keyPressEvent(QKeyEvent *e)
{
    switch (e->key())
    {
    case Qt::Key_W:
        carForward();
        break;
    case Qt::Key_A:
        carLeft();
        break;
    case Qt::Key_S:
        carBack();
        break;
    case Qt::Key_D:
        carRight();
        break;
    case Qt::Key_I:
        cameraUp();
        break;
    case Qt::Key_K:
        cameraDown();
        break;
    case Qt::Key_J:
        cameraLeft();
        break;
    case Qt::Key_L:
        cameraRight();
        break;
    }
}
Exemplo n.º 3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //init flags
    cameraDownFlag = false;
    cameraUpFlag = false;
    cameraLeftFlag = false;
    cameraRightFlag = false;
    carForwardFlag = false;
    carBackFlag = false;
    carLeftFlag = false;
    carRightFlag = false;

    ui->setupUi(this);

    _instance = new VlcInstance(VlcCommon::args(), this);
    _player = new VlcMediaPlayer(_instance);
    _player->setVideoWidget(ui->video);

    ui->video->setMediaPlayer(_player);

    connect(ui->actionOpen_Local_File, SIGNAL(triggered()), this, SLOT(openLocal()));
    connect(ui->actionOpen_URL, SIGNAL(triggered()), this, SLOT(openUrl()));
    connect(ui->actionCar_Address, SIGNAL(triggered()), this, SLOT(setCarAddr()));

    connect(ui->cameraDown, SIGNAL(pressed()), this, SLOT(cameraDown()));
    connect(ui->cameraUp, SIGNAL(pressed()), this, SLOT(cameraUp()));
    connect(ui->cameraLeft, SIGNAL(pressed()), this, SLOT(cameraLeft()));
    connect(ui->cameraRight, SIGNAL(pressed()), this, SLOT(cameraRight()));
    connect(ui->carForward, SIGNAL(pressed()), this, SLOT(carForward()));
    connect(ui->carBack, SIGNAL(pressed()), this, SLOT(carBack()));
    connect(ui->carLeft, SIGNAL(pressed()), this, SLOT(carLeft()));
    connect(ui->carRight, SIGNAL(pressed()), this, SLOT(carRight()));
    connect(ui->cameraDown, SIGNAL(released()), this, SLOT(cameraDownRelease()));
    connect(ui->cameraUp, SIGNAL(released()), this, SLOT(cameraUpRelease()));
    connect(ui->cameraLeft, SIGNAL(released()), this, SLOT(cameraLeftRelease()));
    connect(ui->cameraRight, SIGNAL(released()), this, SLOT(cameraRightRelease()));
    connect(ui->carForward, SIGNAL(released()), this, SLOT(carForwardRelease()));
    connect(ui->carBack, SIGNAL(released()), this, SLOT(carBackRelease()));
    connect(ui->carLeft, SIGNAL(released()), this, SLOT(carLeftRelease()));
    connect(ui->carRight, SIGNAL(released()), this, SLOT(carRightRelease()));



    sender = new MsgSender();


}
Exemplo n.º 4
0
void mouseEvents(sf::RenderWindow & window,gameMap_t * self){
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
            cameraUp(self);

    }
     if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
            cameraLeft(self);

    }
     if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
            cameraDown(self);

    }
     if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
            cameraRight(self);

    }

      if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
            pauseMenu(window);

    }
}
Exemplo n.º 5
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowSmd)
{
	FileSystem fileSystem("../../Resources");
	Console console(fileSystem, false);
	
	ResourceManager resourceManager(fileSystem, console);

	InputDevice input(console);

	Window window("Void", console, input, resourceManager, fileSystem, 1280, 720, true, false);
	//Window window("Void", console, input, resourceManager, fileSystem);
	if(window.Initialise()) return 0;

	ConsoleEvent shouldQuitConsole(console, input, "Game.Quit");
	input.addDefaultBinding(Key::Q, shouldQuitConsole);
	input.addDefaultBinding(Key::Escape, shouldQuitConsole);

	ConsoleEvent cameraForward(console, input, "Camera.Move.Forward");
	input.addDefaultBinding(Key::W, cameraForward);
	ConsoleEvent cameraBackward(console, input, "Camera.Move.Backward");
	input.addDefaultBinding(Key::S, cameraBackward);
	ConsoleEvent cameraLeft(console, input, "Camera.Move.Left");
	input.addDefaultBinding(Key::A, cameraLeft);
	ConsoleEvent cameraRight(console, input, "Camera.Move.Right");
	input.addDefaultBinding(Key::D, cameraRight);
	ConsoleEvent cameraUp(console, input, "Camera.Move.Up");
	input.addDefaultBinding(Key::Space, cameraUp);
	ConsoleEvent cameraDown(console, input, "Camera.Move.Down");
	input.addDefaultBinding(Key::LCtrl, cameraDown);
	ConsoleEvent cameraSprint(console, input, "Camera.Move.Sprint");
	input.addDefaultBinding(Key::LShift, cameraSprint);

	window.GetGraphicsDevice().getRenderer3D().setSkybox(resourceManager.getResourceReference<TextureResource>("[Texture] Clouds.dds"));

	Camera &camera = window.GetGraphicsDevice().getRenderer3D().getCamera();
	camera.rotateY(Math::DegreesToRadians(90));
	camera.setPosition(-1100.0f, -170.0f, 0.0f);

	std::vector<PointLight> lights;

	ResourceReference<ModelResource> visibleLion = resourceManager.getResourceReference<ModelResource>("[Model] Lion.smdf");

	std::vector<ResourceReference<MaterialResource>> materials;
#define add_model(x) materials.push_back(resourceManager.getResourceReference<MaterialResource>("[Material] " x ".smtf"))
	add_model("Lion");add_model("Lionbackground"); add_model("VaseRound"); add_model("Ceiling");
	add_model("ColumnA"); add_model("ColumnB"); add_model("ColumnC"); add_model("Floor"); add_model("FabricGreen");
	add_model("FabricBlue"); add_model("FabricRed"); add_model("CurtainBlue"); add_model("CurtainRed");
	add_model("CurtainGreen"); add_model("VaseHanging"); add_model("Vase"); add_model("Bricks");
	add_model("Arch"); add_model("Details"); add_model("Roof");	add_model("VasePlant");
	add_model("Chain"); add_model("Thorn");add_model("Vase");

	Timer gameTime;

	bool isMousePressed = false;
	int oldMouseX = 0;
	int oldMouseY = 0;

	for(;;)
	{
		uint64 frameTime = gameTime.getElapsedReset();
		float frameSeconds = frameTime / 1000.0f;

		resourceManager.Update();
		console.update();

		if(window.Update()) break;
		input.Update();

		if(shouldQuitConsole.isPress()) break;

		if(isMousePressed != input.IsKeyDown(Key::LButton))
		{
			isMousePressed = !isMousePressed;
			if(isMousePressed)
			{
				window.setMouseClipping(true);
				oldMouseX = input.GetMouseXPositionAbsolute();
				oldMouseY = input.GetMouseYPositionAbsolute();
				window.setMouseVisibility(true);
			}
			else
			{
				window.setMouseClipping(false);
				window.SetMousePosition(oldMouseX, oldMouseY);
				window.setMouseVisibility(false);
			}
		}

		if(isMousePressed)
		{
			camera.rotateY(Math::DegreesToRadians(input.GetMouseXPositionRelative()));
			camera.rotateX(Math::DegreesToRadians(input.GetMouseYPositionRelative()));
		}

		float distance = 100.0f * frameSeconds;
		if(cameraSprint.isHeld()) distance *= 6;

		if(cameraForward.isHeld()) camera.moveX(distance);
		if(cameraBackward.isHeld()) camera.moveX(-distance);
		if(cameraRight.isHeld()) camera.moveZ(distance);
		if(cameraLeft.isHeld()) camera.moveZ(-distance);
		if(cameraUp.isHeld()) camera.moveY(distance);
		if(cameraDown.isHeld()) camera.moveY(-distance);

		visibleLion->Render();

		if(resourceManager.isLoading())
		{
			if(lights.empty())
				fillLightsGrid(lights, window);
		}
		else if(!lights.empty())
			lights.clear();

		if(input.IsKeyPress(Key::Num1))
			fillLightsGrid(lights, window);

		Vector3 lightChange;
		if(input.IsKeyDown(Key::Up)) lightChange.y += distance;
		if(input.IsKeyDown(Key::Down)) lightChange.y -= distance;
		if(input.IsKeyDown(Key::Left)) lightChange.x += distance;
		if(input.IsKeyDown(Key::Right)) lightChange.x -= distance;

		if(lightChange != Vector3::Zero)
		{
			for(PointLight &light : lights)
				light.setPosition(light.getPosition() + lightChange);
		}
			
		if(window.Render()) break;
	}

	return 0;
}
/**
 * Function that listens for event input from keyboard.
 */
void Keyboard(unsigned char key, int x, int y) {

	switch (key){

	/*projection commands*/
	case '1':
		printf("changing projection to orthographic.\n");
		orthographic();
		break;
	case '2':
		printf("changing projection to oblique.\n");
		oblique();
		break;
	case '3':
		printf("changing projection to perspective.\n");
		perspective();
		break;

	/*camera movement*/

	case 'm':
		printf("Camera movement. You can no use w,a,s,d,z,x to move ");
		printf("around.\n");
		currentMode = 'm';
		glutPostRedisplay();
		break;

	case 'w':
		if(useSmooth == true){
			useSmooth = false;
			bezSpeed += 0.25;
			calculateNewBezierCurve(direction,P0,Pref,V0,bezierP,PrefChange,uM,
									uMPrim,bezSpeed);
			bezierPCounter = 0;
			useSmooth = true;
		}else{
			cameraForward(0);
		}
		break;
	case 'a':
		if(useSmooth == true){
			direction = 'l';
			calculateNewBezierCurve(direction,P0,Pref,V0,bezierP,PrefChange,uM,
									uMPrim,bezSpeed);
			bezierPCounter = 0;
		}else{
			cameraLeft();
		}
		break;
	case 's':
		if(useSmooth == true){
			if(bezSpeed > 0.5){
				useSmooth = false;
				bezSpeed -= 0.25;
				calculateNewBezierCurve(direction,P0,Pref,V0,bezierP,PrefChange,
										uM,uMPrim,bezSpeed);
				bezierPCounter = 0;
				useSmooth = true;
			}

		}else{
			cameraBackward();
		}
		break;
	case 'd':
		if(useSmooth == true){
			direction = 'r';
			calculateNewBezierCurve(direction,P0,Pref,V0,bezierP,PrefChange,uM,
									uMPrim,bezSpeed);
			bezierPCounter = 0;
		}else{
			cameraRight();
		}
		break;

	/*object movement*/
	case 'q':
		printf("Closing program.....\n");
		exit(0);
		break;

	case 'v':
		glutFullScreenToggle();
		break;

	case 'o':
		printf("\ncurrent mode: open OFF file.\n");
		currentMode = 'o';
		glutPostRedisplay();
		loadVertices(NULL);
		glutPostRedisplay();
		break;

	case 't':
		printf("current mode: translation.\n");
		currentMode = 't';
		chosenMovement = 'n';
		chosenMovement = 'n';
		glutPostRedisplay();
		printf("In which direction (x,y or z) do you want to move the object?");
		printf("\npress x,y or z button to choose.\n");

		break;

	case 'e':
		printf("current mode: Scaling.\n");
		currentMode = 's';
		glutPostRedisplay();
		chosenMovement = 'n';
		chosenMovement = 'n';
		printf("press + or - button to scale the object.\n");
		break;

	case 'r':
		printf("current mode: Rotating.\n");
		currentMode = 'r';
		glutPostRedisplay();
		chosenMovement = 'n';
		chosenMovement = 'n';
		printf("Press x,y,or z to choose which axis the object should ");
		printf("rotate around.\n");
		break;

	case 'x':

		if(currentMode == 't'){
			printf("X direction chosen. press + or - button ");
			printf("to move the object.\n");
			chosenDirection = 'x';
		}else if(currentMode == 'r'){
			printf("X direction chosen. press + or - button ");
			printf("to rotate the object around the X-axis.\n");
			chosenDirection = 'x';
		}else{
			cameraUp();
		}
		break;

	case 'y':
		if(currentMode == 't'){
			printf("Y direction chosen. press + or - button ");
			printf("to move the object.\n");
			chosenDirection = 'y';
		}else if(currentMode == 'r'){
			printf("Y direction chosen. press + or - button ");
			printf("to rotate the object around the Y-axis.\n");
			chosenDirection = 'y';
		}
		break;

	case 'z':
		if(currentMode == 't'){
			printf("Z direction chosen. press + or - button ");
			printf("to move the object.\n");
			chosenDirection = 'z';
		} else if(currentMode == 'r'){
			printf("Z direction chosen. press + or - button ");
			printf("to rotate the object around the Z-axis.\n");
			chosenDirection = 'z';
		}else{
			cameraDown();
		}
	break;

	case '+':

		if(currentMode == 't'){
			if(chosenDirection == 'x' || chosenDirection == 'y'
					|| chosenDirection == 'z'){
				chosenMovement = '+';
				translateStage();
			}
		}else if(currentMode == 's'){
			chosenMovement = '+';
			scaleStage();
		}else if(currentMode == 'r'){
			chosenMovement = '+';
			rotateStage();
		}

		break;

	case '-':
		if(currentMode == 't'){
			if(chosenDirection == 'x' || chosenDirection == 'y'
					|| chosenDirection == 'z'){
				chosenMovement = '-';
				translateStage();
			}
		}else if(currentMode == 's'){
			chosenMovement = '-';
			scaleStage();
		}else if(currentMode == 'r'){
			chosenMovement = '-';
			rotateStage();
		}

		break;

	case 'f':
		/*changes between line mode and filled mode for the object.*/
		if(objectFilled == false){
			glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
			sendTMatrixToGPU();
			glutPostRedisplay();
			objectFilled = true;
		}else if(objectFilled == true){
			glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
			sendTMatrixToGPU();
			glutPostRedisplay();
			objectFilled = false;
		}
		break;

	case 'h':

		printf("Help:\n----------------------------------------------------\n");
		printf("The allowed keyboard commands are: \n");
		printf("o: open file,		q: quit program,	t: transform object\n");
		printf("e: scale object,	r: rotate object,	m: camera movement.\n");
		printf("f: object fill: on/off	");
		printf("x: choose x-axis. If camera mode: go up.\ny: choose y-axis	");
		printf("z: choose z-axis. If camera mode: go down.\n\n");
		printf("w: move camera forward.		a: move camera left.\n");
		printf("s: move camera backwards.	d: move camera right.\n");
		printf("v: toggle between fullscreenmode..\n");
		printf("1: orthographic projection.	2: oblique projection.\n");
		printf("3: perspective projection.\n");
		printf("You may also use the mouse to move the camera. To enable, ");
		printf("press and hold left\nmouse button and move the mouse.\n");
		printf("Use the mouseScroll to zoom in or out.\n");
		printf("-----------------------------------------------------------\n");
		break;

	default:
		printf("Unknown keyboard command. Press \"h\" for help. \n");
		break;
	}
}