add vertical movement
This commit is contained in:
parent
79f7a84e60
commit
8470efa3b8
@ -1,4 +1,4 @@
|
||||
#include "glew.h"
|
||||
#include "glew.h"
|
||||
#include "freeglut.h"
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
@ -11,6 +11,7 @@
|
||||
#include "Camera.h"
|
||||
#include "Texture.h"
|
||||
#include "SOIL/stb_image_aug.h"
|
||||
#include "PsString.h"
|
||||
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
@ -103,6 +104,7 @@ char lastClickedButtonAngle = 's';
|
||||
float vehicleSpeed = 0.0f;
|
||||
float lastVehicleAngle = 0.0f;
|
||||
float vehicleAngleSpeed = 0.0f;
|
||||
float vehicleVerticalSpeed = 0.0f;
|
||||
bool directionChanged = false;
|
||||
|
||||
void keyboard(unsigned char key, int x, int y)
|
||||
@ -111,11 +113,11 @@ void keyboard(unsigned char key, int x, int y)
|
||||
float angleSpeed = 0.1f;
|
||||
float moveSpeed = 0.1f;
|
||||
//lastClickedButton = key;
|
||||
if (key == 'w' || key == 's')
|
||||
if (key == 'w' || key == 's')
|
||||
{
|
||||
lastClickedButtonFrontal = key;
|
||||
}
|
||||
|
||||
|
||||
|
||||
printf("%c", key);
|
||||
|
||||
@ -125,8 +127,8 @@ void keyboard(unsigned char key, int x, int y)
|
||||
case 'd': vehicleAngleSpeed += 0.001f; break;
|
||||
case 'w': vehicleSpeed += 0.001f; break;
|
||||
case 's': vehicleSpeed -= 0.001f; break;
|
||||
case 'z': vehiclePos += vehicleSide * moveSpeed; break;
|
||||
case 'x': vehiclePos -= vehicleSide * moveSpeed; break;
|
||||
case 'z': vehicleVerticalSpeed += 0.001f; break;
|
||||
case 'x': vehicleVerticalSpeed -= 0.001f; break;
|
||||
//case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(1, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break;
|
||||
//case 'h': rotation_y = glm::quat(1, 0, 0, 0); rotation_x = glm::quat(1, 0, 0, 0); rotationCamera = glm::quat(1, 0, 0, 0); break;
|
||||
|
||||
@ -142,6 +144,9 @@ void keyboard(unsigned char key, int x, int y)
|
||||
//rot_y = glm::angleAxis(vehicleAngle * 0.01f, glm::vec3(0, 1, 0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void changeVehicleSpeed() {
|
||||
|
||||
if (vehicleAngleSpeed > 0.01f) {
|
||||
@ -158,17 +163,31 @@ void changeVehicleSpeed() {
|
||||
vehicleSpeed = -0.01f;
|
||||
}
|
||||
|
||||
if (vehicleVerticalSpeed > 0.001f) {
|
||||
vehicleSpeed = 0.001f;
|
||||
}
|
||||
if (vehicleVerticalSpeed < -0.001f) {
|
||||
vehicleSpeed = -0.001f;
|
||||
}
|
||||
|
||||
vehiclePos.y = vehiclePos.y + vehicleVerticalSpeed;
|
||||
|
||||
|
||||
switch (lastClickedButtonFrontal)
|
||||
{
|
||||
case 'w': vehiclePos += vehicleDir * vehicleSpeed; break;
|
||||
case 's': vehiclePos -= vehicleDir * -vehicleSpeed; break;
|
||||
}
|
||||
|
||||
|
||||
vehicleAngle += vehicleAngleSpeed;
|
||||
|
||||
|
||||
printf("vehicleSpeed: %.4f\n", vehicleSpeed);
|
||||
printf("vehicleAngleSpeed: %.4f\n", vehicleAngleSpeed);
|
||||
printf("vehicleVerticalSpeed: %.4f\n", vehicleVerticalSpeed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void mouse(int x, int y)
|
||||
{
|
||||
if (mouseXPositionLast >= 0) {
|
||||
@ -183,7 +202,7 @@ bool freecam = false;
|
||||
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
//trzymanie freecama do usuniêcia
|
||||
//trzymanie freecama do usuni<EFBFBD>cia
|
||||
freecam = false;
|
||||
//delta_x = delta_x + vehicleAngle;
|
||||
glm::quat rot_x = glm::angleAxis(delta_y, glm::vec3(1, 0, 0));
|
||||
@ -434,6 +453,8 @@ void drawScene()
|
||||
drawObjectTexture(fishContext, modelMatrix, textureFish01);
|
||||
}
|
||||
|
||||
|
||||
|
||||
drawPlaneTexture(planeContext, glm::rotate(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)), groundTexture);
|
||||
|
||||
glUseProgram(skyboxTexture);
|
||||
@ -461,7 +482,7 @@ void drawScene()
|
||||
glDepthFunc(GL_LESS); // set depth function back to default
|
||||
glUseProgram(0);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -469,21 +490,21 @@ void drawSceneLight(int pass)
|
||||
{
|
||||
|
||||
|
||||
/* Set current color to "white" and disable lighting
|
||||
to emulate OpenGL 1.1's GL_REPLACE texture environment. */
|
||||
/* Set current color to "white" and disable lighting
|
||||
to emulate OpenGL 1.1's GL_REPLACE texture environment. */
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
/* Generate the S & T coordinates for the caustic textures
|
||||
from the object coordinates. */
|
||||
/* Generate the S & T coordinates for the caustic textures
|
||||
from the object coordinates. */
|
||||
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
|
||||
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
|
||||
|
||||
|
||||
drawScene();
|
||||
}
|
||||
|
||||
@ -495,7 +516,7 @@ void renderScene()
|
||||
changeVehicleSpeed();
|
||||
cameraMatrix = createCameraMatrix();
|
||||
perspectiveMatrix = Core::createPerspectiveMatrix();
|
||||
// changeVehicleSpeed();
|
||||
// changeVehicleSpeed();
|
||||
|
||||
int startTime, endTime;
|
||||
startTime = glutGet(GLUT_ELAPSED_TIME);
|
||||
@ -613,7 +634,7 @@ void renderScene()
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
glBindVertexArray(0);
|
||||
|
||||
//Próba mg³y
|
||||
//Pr<EFBFBD>ba mg<6D>y
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // We'll Clear To The Color Of The Fog ( Modified )
|
||||
float color[] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
glFogi(GL_FOG_MODE, GL_EXP2); // Fog Mode
|
||||
|
Loading…
Reference in New Issue
Block a user