2016-09-27 16:23:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <glm/vec2.hpp>
|
2016-10-02 18:10:43 +00:00
|
|
|
#include <glm/vec3.hpp>
|
2016-09-27 16:23:58 +00:00
|
|
|
|
|
|
|
namespace util {
|
|
|
|
|
|
|
|
float randf_0_1();
|
|
|
|
float randf_m1_1();
|
|
|
|
|
|
|
|
glm::vec2 randv2_m1_1();
|
|
|
|
glm::vec2 randv2_0_1();
|
2016-09-28 09:35:56 +00:00
|
|
|
|
|
|
|
float deg2rad(float deg);
|
|
|
|
float rad2deg(float rad);
|
2016-10-02 18:10:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for intersection in positive direction of a ray.
|
|
|
|
* TODO: support inside?
|
|
|
|
*/
|
|
|
|
class IntersectionTest {
|
|
|
|
public:
|
|
|
|
IntersectionTest();
|
|
|
|
|
|
|
|
// creates a valid intersection point at distance d
|
|
|
|
IntersectionTest(float d);
|
|
|
|
|
|
|
|
// intersection distance
|
|
|
|
float distance() const;
|
|
|
|
|
2016-10-02 19:06:02 +00:00
|
|
|
glm::vec3 pointAtDistance(float d);
|
|
|
|
|
2016-10-02 18:10:43 +00:00
|
|
|
// returns true if there's an interseciton.
|
|
|
|
bool valid() const;
|
|
|
|
|
|
|
|
// return true if there's an intersection. then intersectionPoint is filled
|
|
|
|
// with details.
|
|
|
|
bool raySphere(
|
|
|
|
const glm::vec3 &rayPos, const glm::vec3 &rayDir,
|
|
|
|
const glm::vec3 &spherePos, float sphereRadius);
|
|
|
|
|
|
|
|
private:
|
2016-10-02 19:06:02 +00:00
|
|
|
bool m_valid;
|
|
|
|
float m_distance;
|
|
|
|
glm::vec3 m_rayPos;
|
|
|
|
glm::vec3 m_rayDir;
|
2016-10-02 18:10:43 +00:00
|
|
|
};
|
2016-09-27 16:23:58 +00:00
|
|
|
}
|