mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Almost pixel perfect portals tp
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/15 13:59:57 by TheRed #+# #+# */
|
/* Created: 2024/10/15 13:59:57 by TheRed #+# #+# */
|
||||||
/* Updated: 2024/12/23 17:42:18 by ycontre ### ########.fr */
|
/* Updated: 2025/02/05 19:05:45 by ycontre ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ class Camera
|
|||||||
|
|
||||||
void updateCameraVectors();
|
void updateCameraVectors();
|
||||||
|
|
||||||
void portalTeleport(Scene *scene);
|
int portalTeleport(Scene *scene, float delta_time);
|
||||||
|
|
||||||
glm::vec3 getPosition();
|
glm::vec3 getPosition();
|
||||||
glm::vec2 getDirection();
|
glm::vec2 getDirection();
|
||||||
|
@ -24,8 +24,8 @@ pl 0 -2 0 0 1 0 2 // floor
|
|||||||
|
|
||||||
qu -1 1.999 -1 0 0 2 2 0 0 1 6
|
qu -1 1.999 -1 0 0 2 2 0 0 1 6
|
||||||
|
|
||||||
OBJ scenes/obj/Dragon_800K.obj -0.5 0 0.55 5 0 90 0
|
OBJ obj/Dragon_800K.obj -0.5 0 0.55 5 0 90 0
|
||||||
OBJ scenes/obj/Dragon_800K.obj 0.5 0 -0.55 5 0 -90 0
|
OBJ obj/Dragon_800K.obj 0.5 0 -0.55 5 0 -90 0
|
||||||
|
|
||||||
po -1.99 -0.5 -0.5 0 1 0 0 0 1 0 4
|
po -1.99 -0.5 -0.5 0 1 0 0 0 1 0 4
|
||||||
po 1.99 -0.5 -0.5 0 1 0 0 0 1 1 4
|
po 1.99 -0.5 -0.5 0 1 0 0 0 1 1 4
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
CAM 0 2.59881 7 -4.8 -89.9996 0 1 90 5
|
CAM -2.43549 3.10568 -6.50845 -16.4 53.8007 0 1 90 5
|
||||||
|
|
||||||
MAT 100 200 100 0.0 0.0 0.0 // 0
|
MAT 100 200 100 0.0 0.0 0.0 // 0
|
||||||
MAT 200 200 200 0.0 0.0 0.0 // 1
|
MAT 200 200 200 0.0 0.0 0.0 // 1
|
||||||
@ -30,10 +30,10 @@ qu 9.5 0 -1 0 3 0 0 0 2 0 1
|
|||||||
qu 12.5 0 -1 0 3 0 0 0 2 0 1
|
qu 12.5 0 -1 0 3 0 0 0 2 0 1
|
||||||
qu 9.5 3 -1 3 0 0 0 0 2 0 1
|
qu 9.5 3 -1 3 0 0 0 0 2 0 1
|
||||||
|
|
||||||
# small tunnel entrance
|
# # small tunnel entrance
|
||||||
# po 9.5 0 1 3 0 0 0 3 0 0 4
|
# po 9.5 2 1 3 0 0 0 3 0 0 4
|
||||||
# po -1.5 0 4.99 3 0 0 0 3 0 1 4
|
# po -1.5 2 4 3 0 0 0 3 0 1 4
|
||||||
|
|
||||||
# #small tunnel entrace behind
|
# #small tunnel entrace behind
|
||||||
# po 9.5 0 -1 3 0 0 0 3 0 1 5
|
# po 9.5 2 -1 3 0 0 0 3 0 1 5
|
||||||
# po -1.5 0 -4.99 3 0 0 0 3 0 0 5
|
# po -1.5 2 -4 3 0 0 0 3 0 0 5
|
10
srcs/RT.cpp
10
srcs/RT.cpp
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/02/04 22:10:33 by tomoron ### ########.fr */
|
/* Updated: 2025/02/05 18:44:28 by ycontre ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,11 +15,11 @@
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Arguments args(argc, argv);
|
Arguments args(argc, argv);
|
||||||
if(args.error())
|
if (args.error())
|
||||||
return(1);
|
return (1);
|
||||||
Scene scene(args.getSceneName());
|
Scene scene(args.getSceneName());
|
||||||
if(scene.fail())
|
if (scene.fail())
|
||||||
return(1);
|
return (1);
|
||||||
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0, args);
|
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0, args);
|
||||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
||||||
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/15 14:00:38 by TheRed #+# #+# */
|
/* Created: 2024/10/15 14:00:38 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/01/28 02:15:41 by tomoron ### ########.fr */
|
/* Updated: 2025/02/05 20:09:58 by ycontre ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -42,20 +42,20 @@ void Camera::update(Scene *scene, float delta_time)
|
|||||||
|
|
||||||
_velocity += _acceleration * delta_time;
|
_velocity += _acceleration * delta_time;
|
||||||
|
|
||||||
if (glm::length(_acceleration) < 0.1f)
|
if (glm::length(_acceleration) < 0.1f)
|
||||||
_velocity *= std::max(0.0f, 1.0f - _deceleration_rate * delta_time);
|
_velocity *= std::max(0.0f, 1.0f - _deceleration_rate * delta_time);
|
||||||
|
|
||||||
float speed = glm::length(_velocity);
|
float speed = glm::length(_velocity);
|
||||||
if (speed > _maxSpeed)
|
if (speed > _maxSpeed)
|
||||||
_velocity = glm::normalize(_velocity) * _maxSpeed;
|
_velocity = glm::normalize(_velocity) * _maxSpeed;
|
||||||
|
|
||||||
_position += _velocity * delta_time;
|
if (glm::length(_velocity) > 0.0f && !this->portalTeleport(scene, delta_time))
|
||||||
_acceleration = glm::vec3(0.0f);
|
_position += _velocity * delta_time;
|
||||||
|
|
||||||
this->portalTeleport(scene);
|
_acceleration = glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::portalTeleport(Scene *scene)
|
int Camera::portalTeleport(Scene *scene, float delta_time)
|
||||||
{
|
{
|
||||||
for (const GPUObject &obj : scene->getObjectData())
|
for (const GPUObject &obj : scene->getObjectData())
|
||||||
{
|
{
|
||||||
@ -74,22 +74,26 @@ void Camera::portalTeleport(Scene *scene)
|
|||||||
glm::dot(point_projected - obj.position, obj.vertex1),
|
glm::dot(point_projected - obj.position, obj.vertex1),
|
||||||
glm::dot(point_projected - obj.position, obj.vertex2)
|
glm::dot(point_projected - obj.position, obj.vertex2)
|
||||||
);
|
);
|
||||||
glm::vec2 alphaBeta = glm::inverse(A) * b;
|
glm::vec2 alphaBeta = glm::inverse(A) * b;
|
||||||
|
|
||||||
if (alphaBeta.x >= 0.0f && alphaBeta.x <= 1.0f && alphaBeta.y >= 0.0f && alphaBeta.y <= 1.0f)
|
if (alphaBeta.x >= 0.0f && alphaBeta.x <= 1.0f && alphaBeta.y >= 0.0f && alphaBeta.y <= 1.0f)
|
||||||
{
|
{
|
||||||
float distance = glm::length(point_projected - _position);
|
glm::vec3 future_pos = _position + _velocity * delta_time;
|
||||||
if (distance < 0.1f)
|
|
||||||
|
float distance_future_pos = glm::length(future_pos - _position);
|
||||||
|
float distance_portal = glm::length(point_projected - _position);
|
||||||
|
|
||||||
|
if (distance_portal <= distance_future_pos && glm::dot(glm::normalize(future_pos - _position), obj.normal) > 0.0f)
|
||||||
{
|
{
|
||||||
GPUObject linked_portal = scene->getObjectData()[obj.radius];
|
GPUObject linked_portal = scene->getObjectData()[obj.radius];
|
||||||
std::cout << glm::to_string(point_projected) << std::endl;
|
_position = (linked_portal.position) + (_position - obj.position) - (((distance_future_pos - distance_portal)) * linked_portal.normal);
|
||||||
_position = linked_portal.position + (_position - obj.position) - linked_portal.normal * 0.1f;
|
|
||||||
std::cout << "Teleporting to " << glm::to_string(_position) << std::endl;
|
|
||||||
|
|
||||||
break ;
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::processMouse(float xoffset, float yoffset, bool constraint_pitch = true)
|
void Camera::processMouse(float xoffset, float yoffset, bool constraint_pitch = true)
|
||||||
@ -115,16 +119,16 @@ void Camera::processKeyboard(bool forward, bool backward, bool left, bool right
|
|||||||
glm::vec3 acceleration(0.0f);
|
glm::vec3 acceleration(0.0f);
|
||||||
|
|
||||||
if (forward) acceleration += _forward;
|
if (forward) acceleration += _forward;
|
||||||
if (backward) acceleration -= _forward;
|
if (backward) acceleration -= _forward;
|
||||||
if (right) acceleration += _right;
|
if (right) acceleration += _right;
|
||||||
if (left) acceleration -= _right;
|
if (left) acceleration -= _right;
|
||||||
if (up) acceleration += _up;
|
if (up) acceleration += _up;
|
||||||
if (down) acceleration -= _up;
|
if (down) acceleration -= _up;
|
||||||
|
|
||||||
if (glm::length(acceleration) > 0.1f)
|
if (glm::length(acceleration) > 0.1f)
|
||||||
acceleration = glm::normalize(acceleration) * _acceleration_rate;
|
acceleration = glm::normalize(acceleration) * _acceleration_rate;
|
||||||
|
|
||||||
_acceleration = acceleration;
|
_acceleration = acceleration;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 Camera::getViewMatrix()
|
glm::mat4 Camera::getViewMatrix()
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
|
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/02/04 16:46:29 by tomoron ### ########.fr */
|
/* Updated: 2025/02/05 20:01:29 by ycontre ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user