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 Ray& Draw(::Color color) {
39  DrawRay(*this, color);
40  return *this;
41  }
42 
46  inline RayCollision GetCollision(::Vector3 center, float radius) const {
47  return ::GetRayCollisionSphere(*this, center, radius);
48  }
49 
53  inline RayCollision GetCollision(const ::BoundingBox& box) const {
54  return ::GetRayCollisionBox(*this, box);
55  }
56 
60  inline RayCollision GetCollision(const ::Mesh& mesh, const ::Matrix& transform) const {
61  return ::GetRayCollisionMesh(*this, mesh, transform);
62  }
63 
67  inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const {
68  return ::GetRayCollisionTriangle(*this, p1, p2, p3);
69  }
70 
74  inline RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3, ::Vector3 p4) const {
75  return ::GetRayCollisionQuad(*this, p1, p2, p3, p4);
76  }
77 
81  inline static Ray GetMouse(::Vector2 mousePosition, const ::Camera& camera) {
82  return ::GetMouseRay(mousePosition, camera);
83  }
84 
88  inline static Ray GetMouse(const ::Camera& camera) {
89  return ::GetMouseRay(::GetMousePosition(), camera);
90  }
91 
92  private:
93  inline void set(const ::Ray& ray) {
94  position = ray.position;
95  direction = ray.direction;
96  }
97 };
98 } // namespace raylib
99 
100 using RRay = raylib::Ray;
101 
102 #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:74
static Ray GetMouse(::Vector2 mousePosition, const ::Camera &camera)
Get a ray trace from mouse position.
Definition: Ray.hpp:81
RayCollision GetCollision(::Vector3 center, float radius) const
Get collision information between ray and sphere.
Definition: Ray.hpp:46
Ray & Draw(::Color color)
Draw a ray line.
Definition: Ray.hpp:38
RayCollision GetCollision(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const
Get collision info between ray and triangle.
Definition: Ray.hpp:67
static Ray GetMouse(const ::Camera &camera)
Get a ray trace from mouse position.
Definition: Ray.hpp:88
RayCollision GetCollision(const ::Mesh &mesh, const ::Matrix &transform) const
Get collision information between ray and mesh.
Definition: Ray.hpp:60
RayCollision GetCollision(const ::BoundingBox &box) const
Detect collision between ray and box.
Definition: Ray.hpp:53
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