[Camera] Temporary collision fixes.

This commit is contained in:
Quentin Bazin 2018-06-23 07:48:54 +02:00
parent 60c6eaed3b
commit a03b621a76
2 changed files with 26 additions and 20 deletions

View File

@ -16,7 +16,7 @@
#include <algorithm>
// #include "Vector2.hpp"
#include "Vector2.hpp"
template<typename T>
class Rect {
@ -27,9 +27,9 @@ class Rect {
reset(_x, _y, _width, _height);
}
// Rect(const Vector2<T> &_position, const Vector2<T> &_size) {
// reset(_position.x, _position.y, _size.x, _size.y);
// }
Rect(const Vector2<T> &_position, const Vector2<T> &_size) {
reset(_position.x, _position.y, _size.x, _size.y);
}
template<typename U>
Rect(const Rect<U> &rect)
@ -45,7 +45,7 @@ class Rect {
void reset(Rect<T> rect) { reset(rect.x, rect.y, rect.width, rect.height); }
void move(T _x, T _y) { x += _x; y += _y; }
// void move(Vector2<T> d) { move(d.x, d.y); }
void move(Vector2<T> d) { move(d.x, d.y); }
bool intersects(const Rect<T> &rect) const {
T r1MinX = std::min(x, static_cast<T>(x + width));
@ -93,15 +93,15 @@ class Rect {
}
}
// Vector2<T> position() const { return {x, y}; }
Vector2<T> position() const { return {x, y}; }
// void setPosition(Vector2<T> vector2) { x = vector2.x; y = vector2.y; }
void setPosition(Vector2<T> vector2) { x = vector2.x; y = vector2.y; }
// Rect operator+(const Vector2<T> &vector2) const { return Rect{x + vector2.x, y + vector2.y, width, height}; }
// Rect operator-(const Vector2<T> &vector2) const { return Rect{x - vector2.x, y - vector2.y, width, height}; }
//
// Rect &operator+=(const Vector2<T> &vector2) { *this = operator+(vector2); return *this; }
// Rect &operator-=(const Vector2<T> &vector2) { *this = operator-(vector2); return *this; }
Rect operator+(const Vector2<T> &vector2) const { return Rect{x + vector2.x, y + vector2.y, width, height}; }
Rect operator-(const Vector2<T> &vector2) const { return Rect{x - vector2.x, y - vector2.y, width, height}; }
Rect &operator+=(const Vector2<T> &vector2) { *this = operator+(vector2); return *this; }
Rect &operator-=(const Vector2<T> &vector2) { *this = operator-(vector2); return *this; }
T x = 0;
T y = 0;

View File

@ -112,14 +112,14 @@ void Camera::checkCollisions(const World &world) {
const float PLAYER_HEIGHT = 1.8;
float m_eyeheight = m_y + PLAYER_HEIGHT - 1;
// testPoint(world, glm::vec3(m_x, m_y, m_z), m_velocity);
testPoint(world, glm::vec3(m_x - 0.2, m_eyeheight - PLAYER_HEIGHT - 0.4, m_z - 0.2), m_velocity);
testPoint(world, glm::vec3(m_x + 0.2, m_eyeheight - PLAYER_HEIGHT - 0.4, m_z - 0.2), m_velocity);
testPoint(world, glm::vec3(m_x - 0.2, m_eyeheight - PLAYER_HEIGHT - 0.4, m_z + 0.2), m_velocity);
testPoint(world, glm::vec3(m_x + 0.2, m_eyeheight - PLAYER_HEIGHT - 0.4, m_z + 0.2), m_velocity);
testPoint(world, glm::vec3(m_x - 0.2, m_eyeheight + (2 - PLAYER_HEIGHT - 0.01), m_z - 0.2), m_velocity);
testPoint(world, glm::vec3(m_x + 0.2, m_eyeheight + (2 - PLAYER_HEIGHT - 0.01), m_z - 0.2), m_velocity);
testPoint(world, glm::vec3(m_x - 0.2, m_eyeheight + (2 - PLAYER_HEIGHT - 0.01), m_z + 0.2), m_velocity);
testPoint(world, glm::vec3(m_x + 0.2, m_eyeheight + (2 - PLAYER_HEIGHT - 0.01), m_z + 0.2), m_velocity);
testPoint(world, glm::vec3(m_x - 0.2, m_eyeheight - PLAYER_HEIGHT - 0.4, m_z - 0.2), m_velocity);
testPoint(world, glm::vec3(m_x + 0.2, m_eyeheight - PLAYER_HEIGHT - 0.4, m_z - 0.2), m_velocity);
testPoint(world, glm::vec3(m_x - 0.2, m_eyeheight - PLAYER_HEIGHT - 0.4, m_z + 0.2), m_velocity);
testPoint(world, glm::vec3(m_x + 0.2, m_eyeheight - PLAYER_HEIGHT - 0.4, m_z + 0.2), m_velocity);
testPoint(world, glm::vec3(m_x - 0.2, m_eyeheight - 0.4, m_z - 0.2), m_velocity);
testPoint(world, glm::vec3(m_x + 0.2, m_eyeheight - 0.4, m_z - 0.2), m_velocity);
testPoint(world, glm::vec3(m_x - 0.2, m_eyeheight - 0.4, m_z + 0.2), m_velocity);
testPoint(world, glm::vec3(m_x + 0.2, m_eyeheight - 0.4, m_z + 0.2), m_velocity);
}
void Camera::update() {
@ -134,6 +134,12 @@ bool passable(const World &world, float x, float y, float z) {
}
void Camera::testPoint(const World &world, glm::vec3 pos, glm::vec3 &speed) {
// FIXME: Temporary fix, find the real problem!!!
// FIXME: This causes one layer to be totally fucked up
if (pos.x < 0) --pos.x;
if (pos.y < 1) --pos.y;
if (pos.z < 0) --pos.z;
if(!passable(world, pos.x + speed.x, pos.y, pos.z)) speed.x = 0;
if(!passable(world, pos.x, pos.y, pos.z + speed.z)) speed.z = 0;
if(!passable(world, pos.x, pos.y + speed.y, pos.z)) {