PlayerView::PlayerView(const boost::shared_ptr<Configuration> cfg,
		const boost::shared_ptr<GameLog> log) {

			this->cfg = cfg;
			this->log = log;

			goat = boost::shared_ptr<WorldObject> (
				new WorldObject("animal",
				"/Game/Data/Goat/goatAnim",
				cfg, log, "/Game/Data/Goat/Goat.png", 19));
			goat->setOffset(-1.2f, -1.0f, -4.0f);
			goat->startAnimating();
			scene = boost::shared_ptr<vector<boost::shared_ptr<WorldObject> > >(
				new vector<boost::shared_ptr<WorldObject> >());
			scene->push_back(goat);

			rotation = 0.0f;

			renderer = boost::shared_ptr<Renderer>(new Renderer(cfg, log));
			renderer->init(640, 480, false);

			boost::scoped_ptr<Image> groundTexture (
				new Image("/Game/Data/OtherTextures/grass.png", cfg, log));
			renderer->generateTexture("ground", groundTexture->getData(), groundTexture->getWidth(), groundTexture->getHeight());

			boost::scoped_ptr<Image> skyTexture (
				new Image("/Game/Data/OtherTextures/sky.png", cfg, log));
			renderer->generateTexture("sky", skyTexture->getData(), skyTexture->getWidth(), skyTexture->getHeight());

	}
Exemple #2
0
int main()
{

	glm::vec3 cross = glm::cross(glm::vec3(2.5, 2.5, 0),glm::vec3(0, 2.5, 0));
	try
	{
		GLfloat currentFrame;

		GLFWwindow *window = JPGLHelper::InitEverything(HEIGHT, WIDTH);
		glfwSetKeyCallback(window, keyCallback);
		
		if (glewInit() != GLEW_OK)
			throw std::runtime_error("glewInit() failed");

		ShaderCompiler shaderGround("ground.vert", "ground.frag");
		ShaderCompiler shaderTrain("train.vert", "train.frag");

		MatrixWrapper	modelPlane(shaderGround.GetProgramID(), "model"),
			modelIdentity(shaderTrain.GetProgramID(), "model"),
						projection(shaderGround.GetProgramID(), "projection");

		modelPlane.mat4	= glm::rotate(modelPlane.mat4, glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
		projection.mat4 = glm::perspective(glm::radians(45.0f), (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 2500.0f);

		Camera camera(-180.0f, 180.0f, 0.0f, 360.0f, 5.0f, shaderGround.GetProgramID(), 25.0f);
		
		camera.UpdateTargetPosition(glm::vec3(0.0f, 0.0f, 0.0f));

		modelPlane.mat4 = glm::scale(modelPlane.mat4, glm::vec3(300.0f,300.0f, 1.0f));
		modelIdentity.mat4 = glm::mat4(1.0f);
		
		Plane ground(shaderGround.GetProgramID(),32);
		Train train(shaderTrain.GetProgramID());
		Light light;
	
		TextureWrapper groundTexture(GL_TEXTURE0, shaderGround.GetProgramID(), "ground.png", "Texture0");

		keyboardManager.RegisterKey(GLFW_KEY_ESCAPE, std::bind(glfwSetWindowShouldClose, window, GL_TRUE));
		keyboardManager.RegisterKey(GLFW_KEY_H, std::bind(&Camera::YawDown, std::ref(camera)));
		keyboardManager.RegisterKey(GLFW_KEY_J, std::bind(&Camera::PitchDown, std::ref(camera)));
		keyboardManager.RegisterKey(GLFW_KEY_K, std::bind(&Camera::PitchUp, std::ref(camera)));
		keyboardManager.RegisterKey(GLFW_KEY_L, std::bind(&Camera::YawUp, std::ref(camera)));
		keyboardManager.RegisterKey(GLFW_KEY_U, std::bind(&Camera::DistanceUp, std::ref(camera)));
		keyboardManager.RegisterKey(GLFW_KEY_I, std::bind(&Camera::DistanceDown, std::ref(camera)));

		keyboardManager.RegisterKey(GLFW_KEY_A, std::bind(&Train::Go, std::ref(train)));
		keyboardManager.RegisterKey(GLFW_KEY_Z, std::bind(&Train::Back, std::ref(train)));


		keyboardManager.RegisterKey(GLFW_KEY_S, std::bind(&Light::AmbientUp, std::ref(light)));
		keyboardManager.RegisterKey(GLFW_KEY_X, std::bind(&Light::AmbientDown, std::ref(light)));
		keyboardManager.RegisterKey(GLFW_KEY_D, std::bind(&Light::DiffuseUp, std::ref(light)));
		keyboardManager.RegisterKey(GLFW_KEY_C, std::bind(&Light::DiffuseDown, std::ref(light)));

		glEnable(GL_MULTISAMPLE);
		glEnable(GL_DEPTH_TEST);
		glEnable(GL_CULL_FACE);

		while (!glfwWindowShouldClose(window))
		{
			currentFrame = glfwGetTime();
			JPGLHelper::deltaTime = currentFrame - JPGLHelper::lastTime;
			JPGLHelper::lastTime = currentFrame;

			glfwPollEvents();
			keyboardManager.ProcessKeys();
			
			camera.UpdateTargetPosition(train.GetLocation());
			train.DoPhysics();

			glClearColor(light.InterpolateR(), light.InterpolateG(), light.InterpolateB(), 1.0f);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			/*
			
				rysowanie p³aszczyzny

			*/

			groundTexture.SendToGPU();

			shaderGround.Execute();

			light.UpdateLight(shaderGround.GetProgramID(), camera.cameraPosition);

			camera.UpdateShader(shaderGround.GetProgramID());
			camera.SendUpdatedMatrix();
			
			projection.SetShader(shaderGround.GetProgramID());
			projection.SendToGPU();

			ground.Draw(modelPlane);


			/*
			
				rysowanie poci¹gu
			
			*/

			shaderTrain.Execute();
			light.UpdateLight(shaderTrain.GetProgramID(), camera.cameraPosition);
			camera.UpdateShader(shaderGround.GetProgramID());
			camera.SendUpdatedMatrix();
			
			projection.SetShader(shaderTrain.GetProgramID());
			projection.SendToGPU();

			
			train.Draw();

		
			
			glfwSwapBuffers(window);
		}

	
	}
	catch (std::exception &e)
	{
		std::cout << e.what() << std::endl;
		system("pause");
	}

	glfwTerminate();
	return 0;
}
Exemple #3
0
int main(int argc, char **argv) {
    static_assert(std::is_pod<FVector3>::value, "FVector must be a POD!");
    static_assert(std::is_pod<Oscillator>::value, "Oscillator must be a POD!");

    // initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    glutCreateWindow("Fountain");

    // textures
    std::unique_ptr<Texture> pebbleTexture(new Texture);
    std::unique_ptr<Texture> basinTexture(new Texture);
    std::unique_ptr<Texture> groundTexture(new Texture);
    std::unique_ptr<Texture[]> skyTextures(new Texture[SKY_BOX_FACES]);

    pebbleTexture->load("resource/pebbles.bmp");
    basinTexture->load("resource/wall.bmp");
    groundTexture->load("resource/grass.bmp");

    skyTextures[SKY_FRONT].load("resource/skybox/front.bmp", GL_CLAMP_TO_EDGE);
    skyTextures[SKY_RIGHT].load("resource/skybox/right.bmp", GL_CLAMP_TO_EDGE);
    skyTextures[SKY_LEFT].load("resource/skybox/left.bmp", GL_CLAMP_TO_EDGE);
    skyTextures[SKY_BACK].load("resource/skybox/back.bmp", GL_CLAMP_TO_EDGE);
    skyTextures[SKY_UP].load("resource/skybox/up.bmp", GL_CLAMP_TO_EDGE);
    skyTextures[SKY_DOWN].load("resource/skybox/down.bmp", GL_CLAMP_TO_EDGE);

    // initialize the scene
    skybox.initialize(-SKY_BOX_SIZE, SKY_BOX_SIZE,
                      -SKY_BOX_SIZE, SKY_BOX_SIZE,
                      -SKY_BOX_SIZE, SKY_BOX_SIZE, std::move(skyTextures));

    pool.initialize(OSCILLATORS_NUM_X, OSCILLATORS_NUM_Z, POOL_HEIGHT,
                    OSCILLATOR_DISTANCE, OSCILLATOR_WEIGHT,
                    OSCILLATOR_DAMPING, OSCILLATOR_SPLASH,
                    POOL_TEX_REPEAT_X, POOL_TEX_REPEAT_Z,
                    std::move(pebbleTexture));

    fountain.initialize(initializers[0]);

    basin.initialize(BASIN_BORDER_HEIGHT + POOL_HEIGHT, BASIN_BORDER_WIDTH,
                     BASIN_INNER_X, BASIN_INNER_Z, std::move(basinTexture));

    ground.initialize(-GROUND_SIZE, GROUND_SIZE,
                      -GROUND_SIZE, GROUND_SIZE,
                      std::move(groundTexture), GROUND_TEX_REPEAT);

    // place the fountain in the center of the pool
    fountain.center.set(BASIN_INNER_X / 2.0f, POOL_HEIGHT, BASIN_INNER_Z / 2.0f);

    // initialize camera:
    FVector3 cposition, crotation;
    cposition.set(CAMERA_POSITION[0], CAMERA_POSITION[1], CAMERA_POSITION[2]);
    camera.move(cposition);
    crotation.set(CAMERA_ROTATION[0], CAMERA_ROTATION[1], CAMERA_ROTATION[2]);
    camera.rotate(crotation);

    // enable vertex array
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);

    // solid rendering
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glEnable(GL_DEPTH_TEST);

    // lighting
    glLightfv(GL_LIGHT1, GL_AMBIENT, LIGHT_AMBIENT_1);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, LIGHT_DIFFUSE_1);
    glLightfv(GL_LIGHT1, GL_POSITION, LIGHT_POSITION_1);
    glEnable(GL_LIGHT1);

    glLightfv(GL_LIGHT2, GL_AMBIENT, LIGHT_AMBIENT_2);
    glLightfv(GL_LIGHT2, GL_DIFFUSE, LIGHT_DIFFUSE_2);
    glLightfv(GL_LIGHT2, GL_POSITION, LIGHT_POSITION_2);
    glEnable(GL_LIGHT2);

    glEnable(GL_LIGHTING);

    glEnable(GL_COLOR_MATERIAL);

    // settings
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glFrontFace(GL_CCW);   // orientation should be the front face
    glShadeModel(GL_SMOOTH);

    // blending
    glEnable(GL_BLEND);
    glEnable(GL_POINT_SMOOTH);
    glEnable(GL_POLYGON_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    // seed
    srand((unsigned)time(NULL));

    printf("1 - 8:\tChange the shape of the fountain\n");
    printf("f:\tToggle fullscreen\n");
    printf("c:\tSwitch between mouse mode / keyboard mode\n");

    printf("----------- Keyboard Mode -----------------\n");
    printf("up, down:\tMove camera forward / backword\n");
    printf("left, right:\tTurn camera right / left\n");
    printf("r, v:\tTurn camera up / down\n");
    printf("w, s:\tMove camera up / down\n");
    printf("a, d:\tMove camera left / right\n");

    printf("----------- Mouse Mode -----------------\n");
    printf("Mouse move:\tRotate camera\n");
    printf("Mouse scroll:\tMove forward / backward\n");

    printf("ESC:\tExit\n");

    // register callbacks
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyDown);
    glutPassiveMotionFunc(mouseMove);
    glutSpecialFunc(spKeyDown);
    glutMouseFunc(mouseButton);
    glutIdleFunc(idle);

    // hide cursor
    glutSetCursor(GLUT_CURSOR_NONE);

    // start
    glutMainLoop();

    return 0;
}