Plane.h#

Parent directory (math)

A Plane3d class containing functionality for representing and working with 3D Planes.

Includes#

  • PVRCore/glm.h

Namespaces#

Classes#

Source Code#

#pragma once
#include "PVRCore/glm.h"

namespace pvr {
class Plane3d
{
public:
    Plane3d(const glm::vec3& normal, float dist) : _norm(normal), _dist(dist) {}

    Plane3d(const glm::vec3& normal, const glm::vec3& pointOnPlane) : _norm(normal) { _dist = glm::length(pointOnPlane); }

    Plane3d(const glm::vec3& point0, const glm::vec3& point1, const glm::vec3& point2) { set(point0, point1, point2); }

    void set(const glm::vec3& normal, float dist) { _norm = normal, _dist = dist; }

    void set(const glm::vec3& normal, const glm::vec3& pointOnPlane)
    {
        _dist = glm::length(pointOnPlane);
        _norm = normal;
    }

    void set(const glm::vec3& point0, const glm::vec3& point1, const glm::vec3& point2)
    {
        glm::vec3 edge0 = point0 - point1;
        glm::vec3 edge1 = point2 - point1;

        _norm = glm::normalize(glm::cross(edge0, edge1));
        _dist = -glm::dot(_norm, point0);
    }

    float distanceTo(const glm::vec3& point) { return glm::dot(_norm, point) - _dist; }

    float getDistance() const { return _dist; }

    glm::vec3 getNormal() const { return _norm; }

    void transform(glm::mat4& transMtx) { glm::transpose(glm::inverse(transMtx)) * glm::vec4(_norm, _dist); }

private:
    glm::vec3 _norm;
    float _dist;
};
} // namespace pvr