+ | Portals now handled correctly + support

This commit is contained in:
TheRedShip
2025-01-07 22:22:07 +01:00
parent 9df8b78d6d
commit b3e2a0ed34
4 changed files with 50 additions and 29 deletions

View File

@ -24,7 +24,9 @@ class Portal : public Object
float x, y, z;
float x1, y1, z1;
float x2, y2, z2;
int linked_portal;
bool invert_normal;
int mat_index;
if (!(line >> x >> y >> z))
@ -36,8 +38,8 @@ class Portal : public Object
if (!(line >> x2 >> y2 >> z2))
throw std::runtime_error("Missing Portal's second edge");
if (!(line >> linked_portal))
throw std::runtime_error("Missing Portal's linked index");
if (!(line >> invert_normal))
throw std::runtime_error("Missing invert_normal");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
@ -53,12 +55,9 @@ class Portal : public Object
up = normalize(glm::cross(forward, right));
_transform = glm::mat3(right, up, forward);
_normal = forward;
_normal = forward * (invert_normal ? -1.0f : 1.0f);
std::cout << "Portal Transform Matrix:" << std::endl;
std::cout << glm::to_string(_transform) << std::endl;
_linked_portal = linked_portal;
_linked_portal = -1;
_mat_index = mat_index;
}
@ -67,6 +66,25 @@ class Portal : public Object
Portal(const glm::vec3 &position, const glm::vec3 &edge1, const glm::vec3 &edge2, const int linked_portal, const int mat_index)
: Object(position, mat_index), _edge1(edge1), _edge2(edge2), _linked_portal(linked_portal) {}
Quad *createSupportQuad() const
{
float extension = 0.2f;
glm::vec3 right_dir = glm::normalize(_edge1);
glm::vec3 up_dir = glm::normalize(_edge2);
float right_length = glm::length(_edge1) + extension;
float up_length = glm::length(_edge2) + extension;
glm::vec3 center_offset = -(right_dir * (extension / 2.0f) + up_dir * (extension / 2.0f));
glm::vec3 position = _position + _normal * -0.001f + center_offset;
glm::vec3 right = right_dir * right_length;
glm::vec3 up = up_dir * up_length;
return (new Quad(position, right, up, _mat_index));
}
glm::vec3 getEdge1() const { return (_edge1); }
glm::vec3 getEdge2() const { return (_edge2); }
glm::vec3 getNormal() const { return (_normal); }
@ -74,6 +92,7 @@ class Portal : public Object
glm::mat3 getTransform() const { return (_transform); }
int getLinkedPortalIndex() const { return (_linked_portal); }
void setLinkedPortalIndex(int index) { _linked_portal = index; }
Type getType() const override { return Type::PORTAL; }