Compare commits
No commits in common. "fc4960f25d5ce0e43c2d6a01e240bc682149665c" and "111c8f1f6edf9f0c644d10917439c953bd9a49f1" have entirely different histories.
fc4960f25d
...
111c8f1f6e
Binary file not shown.
|
Before Width: | Height: | Size: 57 KiB |
@ -41,9 +41,3 @@ When placing a block, the program now raycasts to place where the camera is look
|
|||||||
It took me a couple of days to fix the ray casting. I forgot that my mesh is offset by 0.5, so 3/4 raycasts looked at least a block off of what the camera was looking at.
|
It took me a couple of days to fix the ray casting. I forgot that my mesh is offset by 0.5, so 3/4 raycasts looked at least a block off of what the camera was looking at.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## 0.7.0 : Physics - 11/18/25
|
|
||||||
|
|
||||||
Woah! The camera doesn't just phase through placed blocks anymore! The camera can also fall into the void for eternity! So cool!
|
|
||||||
|
|
||||||

|
|
||||||
|
|||||||
15
src/Camera.h
15
src/Camera.h
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
|
||||||
const float CAMERA_HEIGHT = 1.8f;
|
const float CAMERA_HEIGHT = 0.0f;
|
||||||
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
|
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
|
class Camera
|
||||||
@ -22,8 +22,6 @@ class Camera
|
|||||||
glm::vec3 forward_velocity;
|
glm::vec3 forward_velocity;
|
||||||
glm::vec3 vertical_velocity;
|
glm::vec3 vertical_velocity;
|
||||||
|
|
||||||
bool grounded;
|
|
||||||
|
|
||||||
float speed;
|
float speed;
|
||||||
|
|
||||||
glm::vec3 worldUp;
|
glm::vec3 worldUp;
|
||||||
@ -44,8 +42,6 @@ class Camera
|
|||||||
|
|
||||||
glm::vec3 right = glm::normalize(glm::cross(up, this->direction));
|
glm::vec3 right = glm::normalize(glm::cross(up, this->direction));
|
||||||
this->up = glm::cross(this->direction, right);
|
this->up = glm::cross(this->direction, right);
|
||||||
|
|
||||||
this->grounded = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera(glm::vec3 pos, glm::vec3 target, float speed)
|
Camera(glm::vec3 pos, glm::vec3 target, float speed)
|
||||||
@ -64,8 +60,6 @@ class Camera
|
|||||||
|
|
||||||
glm::vec3 right = glm::normalize(glm::cross(up, this->direction));
|
glm::vec3 right = glm::normalize(glm::cross(up, this->direction));
|
||||||
this->up = glm::cross(this->direction, right);
|
this->up = glm::cross(this->direction, right);
|
||||||
|
|
||||||
this->grounded = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 getView()
|
glm::mat4 getView()
|
||||||
@ -106,9 +100,8 @@ class Camera
|
|||||||
target_position[axis] += position_delta[axis];
|
target_position[axis] += position_delta[axis];
|
||||||
|
|
||||||
glm::vec3 aabb_center = target_position + aabb_center_offset;
|
glm::vec3 aabb_center = target_position + aabb_center_offset;
|
||||||
glm::vec3 adjusted_center = aabb_center + glm::vec3(0.5f, 0.5f, 0.5f);
|
glm::vec3 min = glm::floor(aabb_center - aabb_half_dims);
|
||||||
glm::vec3 min = glm::floor(adjusted_center - aabb_half_dims);
|
glm::vec3 max = glm::ceil(aabb_center + aabb_half_dims);
|
||||||
glm::vec3 max = glm::ceil(adjusted_center + aabb_half_dims);
|
|
||||||
|
|
||||||
bool collided = false;
|
bool collided = false;
|
||||||
for (int x = min.x; x < max.x && !collided; x++) {
|
for (int x = min.x; x < max.x && !collided; x++) {
|
||||||
@ -127,14 +120,12 @@ class Camera
|
|||||||
this->position[axis] = target_position[axis];
|
this->position[axis] = target_position[axis];
|
||||||
} else if (axis == 1) {
|
} else if (axis == 1) {
|
||||||
y_axis_collided = true;
|
y_axis_collided = true;
|
||||||
grounded = true;
|
|
||||||
this->vertical_velocity.y = 0.0f;
|
this->vertical_velocity.y = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!y_axis_collided) {
|
if (!y_axis_collided) {
|
||||||
this->vertical_velocity.y -= GRAVITY * time;
|
this->vertical_velocity.y -= GRAVITY * time;
|
||||||
grounded = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ const int EDIT_RANGE = 5;
|
|||||||
|
|
||||||
// Jump
|
// Jump
|
||||||
const float JUMP_COOLDOWN = 0.0f;
|
const float JUMP_COOLDOWN = 0.0f;
|
||||||
const float JUMP_POWER = 7.5f; // Initial Jump Speed
|
const float JUMP_POWER = 10.0f; // Initial Jump Speed
|
||||||
float last_jump = 0.0f;
|
float last_jump = 0.0f;
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
@ -193,7 +193,7 @@ void processInput(GLFWwindow *window)
|
|||||||
if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||||
// camera.velocity -= glm::normalize(glm::cross(camera.target, glm::normalize(glm::cross(camera.target, camera.worldUp)))) * camera.speed * 0.5f;
|
// camera.velocity -= glm::normalize(glm::cross(camera.target, glm::normalize(glm::cross(camera.target, camera.worldUp)))) * camera.speed * 0.5f;
|
||||||
{
|
{
|
||||||
if (current_time - last_jump > JUMP_COOLDOWN && camera.grounded)
|
if (current_time - last_jump > JUMP_COOLDOWN && camera.position.y == 0)
|
||||||
{
|
{
|
||||||
camera.vertical_velocity.y = JUMP_POWER;
|
camera.vertical_velocity.y = JUMP_POWER;
|
||||||
last_jump = current_time;
|
last_jump = current_time;
|
||||||
@ -269,7 +269,7 @@ int main() {
|
|||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
// 2. --- Create a Window ---
|
// 2. --- Create a Window ---
|
||||||
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Voxel Engine 0.7.0", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Voxel Engine 0.6.1", NULL, NULL);
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
std::cerr << "Failed to create GLFW window" << std::endl;
|
std::cerr << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user