#pragma once #include #include #include namespace util { float randf_0_1(); float randf_m1_1(); glm::vec2 randv2_m1_1(); glm::vec2 randv2_0_1(); float deg2rad(float deg); float rad2deg(float rad); // split on whitespace into first token and the rest. // return true if whitespace was found or just the token. bool splitIntoTokenAndRest(const std::string &str, std::string &token, std::string &rest); /** * 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; glm::vec3 pointAtDistance(float d); // 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: bool m_valid; float m_distance; glm::vec3 m_rayPos; glm::vec3 m_rayDir; }; }