KlassischeKeplerKriege/game/util.hpp

49 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
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);
/**
* 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;
};
}