init
This commit is contained in:
1 parent
b299a8d8a2
commit
edda71212c
941 files changed
+272423
-31
No files matched your search
@@ -4,6 +4,9 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
const float CAMERA_HEIGHT = 1.7f;
|
||||
const float GRAVITY = 18.6f; // Should be in m/s^2 but it doesn't really work out with 9.8 so we double it
|
||||
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
@@ -59,17 +62,21 @@ class Camera
|
||||
|
||||
glm::mat4 getView()
|
||||
{
|
||||
return glm::lookAt(this->position,
|
||||
glm::mat4 v = glm::lookAt(this->position,
|
||||
this->target + this->position,
|
||||
this->worldUp);
|
||||
|
||||
v = glm::translate(v, glm::vec3(0.0f, -CAMERA_HEIGHT, 0.0f));
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void move(float time) // time passed in seconds since last move
|
||||
{
|
||||
if (this->position.y > 0)
|
||||
this->vertical_velocity.y -= (9.8 * time); // gravity is 9.8m/s^2 no way! physics reference?
|
||||
bool in_air = this->position.y > 0;
|
||||
|
||||
std::cout << "pos: " << this->position.x << " " << this->position.y << " " << this->position.z << std::endl;
|
||||
if (this->position.y > 0)
|
||||
this->vertical_velocity.y -= (GRAVITY * time); // no way! physics reference?
|
||||
|
||||
glm::vec3 velocity = this->forward_velocity + this->horizontal_velocity + this->vertical_velocity;
|
||||
|
||||
@@ -77,11 +84,12 @@ class Camera
|
||||
this->position += movement;
|
||||
|
||||
// Don't want to clip into the ground right
|
||||
if (this->position.y < 0)
|
||||
if (this->position.y <= 0 && in_air)
|
||||
{
|
||||
this->position.y = 0;
|
||||
this->vertical_velocity.y = 0;
|
||||
this->position.y = 0.0f;
|
||||
this->vertical_velocity.y = 0.0f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user