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