+ | Portal almost done

This commit is contained in:
RedShip
2025-02-06 19:52:12 +01:00
parent 9669526296
commit 473b4a247d
7 changed files with 24 additions and 16 deletions

View File

@ -29,6 +29,6 @@ Pos=1556,610
Size=284,382
[Window][Settings]
Pos=1567,9
Pos=1582,12
Size=340,941

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 19:12:51 by ycontre #+# #+# */
/* Updated: 2025/02/06 18:09:03 by ycontre ### ########.fr */
/* Updated: 2025/02/06 19:46:12 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */
@ -52,6 +52,7 @@ class Portal : public Object
_rotation = glm::mat3(right, up, forward);
_normal = forward * (_invert_normal ? -1.0f : 1.0f);
std::cout << glm::to_string(_normal) << std::endl;
_linked_portal = -1;
_mat_index = mat_index;

View File

@ -8,7 +8,7 @@ qu -5 5 -5 0 0 10 10 0 0 0 0
MAT 255 100 100 1.0 0.0 0.0 //1 red
MAT 100 100 255 1.0 0.0 0.0 //2 blue
po -0.75 1.5 5 0 1.5 0 1.5 0 0 1 2
po -0.75 1.5 5 0 1.5 0 1.5 0 0 0 2
po -0.75 10 2.4 0 1.5 0 1.5 0 0 0 1
@ -16,7 +16,7 @@ MAT 200 200 200 0. 0. 0. // 3 white
MAT 255 255 255 1. 0. 0. // 4 light
cu 0 10 0 5 5 5 3
sp 0 10 0 1 4
sp -1.5 10 0 1 4
OBJ obj/lambo.obj 0 1.5 0 1 0 0 0

View File

@ -17,7 +17,7 @@ qu 1.5 0 -5 0 3 0 0 0 10 0 1
qu -1.5 3 -5 3 0 0 0 0 10 0 1
# long tunnel entrance
po -1.5 0 5 3 0 0 0 3 0 0 2
po -1.5 0 5 3 0 0 0 3 0 0 2
po 9.5 0 0.95 3 0 0 0 3 0 1 2
# long tunnel entrance behind
@ -36,14 +36,14 @@ qu 9.5 3 -1 3 0 0 0 0 2 0 1
# #small tunnel entrace behind
# po 9.5 2 -1 3 0 0 0 3 0 1 5
# po -1.5 2 -4 3 0 0 0 3 0 0 5
# po -1.5 2 -4 3 0 0 0 3 0 0 5
#top portals
po -6 1 0 3 0 0 0 0 3 1 1
po -10 1 0 0 3 0 0 0 3 0 1
sp -0.75 1.5 9 0.5 1
po 1 1.5 10 1.5 0 0 0 0 1.5 1 1
po -1 1.5 10 1.5 0 0 0 1.5 0 1 1
po -0.75 1.5 10 0 1.5 0 1.5 0 0 0 1
po 7 1.5 10 0 1.5 0 1.5 0 0 0 1

View File

@ -15,7 +15,7 @@ Ray portalRay(Ray ray, hitInfo hit)
if (dot(portal_1.normal, portal_2.normal) > 0.0)
{
mat3 reflection = mat3(1.0) - 2.0 * outerProduct(portal_2.normal, portal_2.normal);
mat3 reflection = mat3(1.0) - 2.0 * outerProduct(portal_1.normal, portal_2.normal);
rotation *= reflection;
}

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 14:00:38 by TheRed #+# #+# */
/* Updated: 2025/02/06 18:02:23 by ycontre ### ########.fr */
/* Updated: 2025/02/06 19:45:46 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */
@ -97,20 +97,27 @@ int Camera::portalTeleport(Scene *scene, float delta_time)
float distance_portal = glm::length(point_projected - _position);
float imprecision = 0.1f;
if (distance_portal <= distance_future_pos && glm::dot(glm::normalize(future_pos - _position), obj.normal) > 0.0f)
{
std::cout << "Teleport" << std::endl;
GPUObject linked_portal = scene->getObjectData()[obj.radius];
glm::mat4 portal_transform = linked_portal.transform * glm::inverse(obj.transform);
glm::mat3 portal_transform = glm::mat3(linked_portal.transform) * glm::inverse(glm::mat3(obj.transform));
if (dot(obj.normal, linked_portal.normal) > 0.0)
{
glm::mat3 reflection = glm::mat3(1.0) - 2.0f * glm::outerProduct(linked_portal.normal, linked_portal.normal);
portal_transform *= reflection;
}
//teleportation
glm::vec3 relative_pos = _position - obj.position;
glm::vec3 transformed_relative_pos = glm::vec3(portal_transform * glm::vec4(relative_pos, 1.0f));
glm::vec3 transformed_relative_pos = portal_transform * relative_pos;
float remaining_distance = distance_future_pos - distance_portal + imprecision;
glm::vec3 new_movement = remaining_distance * glm::vec3(portal_transform * glm::vec4(linked_portal.normal, 0.0f));
glm::vec3 new_movement = remaining_distance * portal_transform * linked_portal.normal;
_position = linked_portal.position + transformed_relative_pos - new_movement;
// _position = (linked_portal.position) + (_position - obj.position) - (((distance_future_pos - distance_portal + imprecision)) * linked_portal.normal);

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/13 20:21:13 by ycontre #+# #+# */
/* Updated: 2025/01/30 22:29:39 by tomoron ### ########.fr */
/* Updated: 2025/02/06 19:48:22 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */