raylib-cpp
C++ object-oriented wrapper library for raylib.
Ray.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_RAY_HPP_
2 #define RAYLIB_CPP_INCLUDE_RAY_HPP_
3 
4 #include "./raylib.hpp"
5 #include "./raylib-cpp-utils.hpp"
6 #include "./RayCollision.hpp"
7 
8 namespace raylib {
12 class Ray : public ::Ray {
13  public:
14  Ray(const ::Ray& ray) {
15  set(ray);
16  }
17 
18  Ray(::Vector3 position = {0.0f, 0.0f, 0.0f}, ::Vector3 direction = {0.0f, 0.0f, 0.0f}) :
19  ::Ray{position, direction} {
20  // Nothing.
21  }
22 
23  Ray(::Vector2 mousePosition, const ::Camera& camera) {
24  set(::GetMouseRay(mousePosition, camera));
25  }
26 
27  Ray& operator=(const ::Ray& ray) {
28  set(ray);
29  return *this;
30  }
31 
32  GETTERSETTER(::Vector3, Position, position)
33  GETTERSETTER(::Vector3, Direction, direction)
34 
38  inline void Draw(::Color color) const {
39  DrawRay(*this, color);
40  }
41 
45  inline RayCollision GetCollision(::Vector3 center, float radius) const {
46  return ::GetRayCollisionSphere(*this, center, radius);
47  }
48 
52  inline RayCollision GetCollision(const ::BoundingBox& box) const {
53  return ::GetRayCollisionBox(*this, box);
54  }
55 
59  inline RayCollision GetCollision(const ::Mesh& mesh, const ::Matrix& transform) const {
60  return ::GetRayCollisionMesh(*this, mesh, transform);
61  }
62 
66  inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const {
67  return ::GetRayCollisionTriangle(*this, p1, p2, p3);
68  }
69 
73  inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3, ::Vector3 p4) const {
74  return ::GetRayCollisionQuad(*this, p1, p2, p3, p4);
75  }
76 
80  inline static Ray GetMouse(::Vector2 mousePosition, const ::Camera& camera) {
81  return ::GetMouseRay(mousePosition, camera);
82  }
83 
87  inline static Ray GetMouse(const ::Camera& camera) {
88  return ::GetMouseRay(::GetMousePosition(), camera);
89  }
90 
91  private:
92  inline void set(const ::Ray& ray) {
93  position = ray.position;
94  direction = ray.direction;
95  }
96 };
97 } // namespace raylib
98 
99 using RRay = raylib::Ray;
100 
101 #endif // RAYLIB_CPP_INCLUDE_RAY_HPP_
Color type, RGBA (32bit)
Definition: Color.hpp:14
Raycast hit information.
Ray type (useful for raycast)
Definition: Ray.hpp:12
RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3, ::Vector3 p4) const
Get collision info between ray and quad.
Definition: Ray.hpp:73
static Ray GetMouse(::Vector2 mousePosition, const ::Camera &camera)
Get a ray trace from mouse position.
Definition: Ray.hpp:80
RayCollision GetCollision(::Vector3 center, float radius) const
Get collision information between ray and sphere.
Definition: Ray.hpp:45
RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const
Get collision info between ray and triangle.
Definition: Ray.hpp:66
void Draw(::Color color) const
Draw a ray line.
Definition: Ray.hpp:38
static Ray GetMouse(const ::Camera &camera)
Get a ray trace from mouse position.
Definition: Ray.hpp:87
RayCollision GetCollision(const ::Mesh &mesh, const ::Matrix &transform) const
Get collision information between ray and mesh.
Definition: Ray.hpp:59
RayCollision GetCollision(const ::BoundingBox &box) const
Detect collision between ray and box.
Definition: Ray.hpp:52
Vector2 type.
Definition: Vector2.hpp:16
Vector3 type.
Definition: Vector3.hpp:16
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8