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 "./RayHitInfo.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, ::Vector3 Direction) {
19  position = Position;
20  direction = Direction;
21  }
22 
23  Ray(::Vector2 mousePosition, ::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 bool CheckCollisionSphere(::Vector3 center, float radius) const {
47  return CheckCollisionRaySphere(*this, center, radius);
48  }
49 
53  inline bool CheckCollisionSphere(::Vector3 center, float radius,
54  ::Vector3 *collisionPoint) const {
55  return CheckCollisionRaySphereEx(*this, center, radius, collisionPoint);
56  }
57 
61  inline bool CheckCollision(const ::BoundingBox& box) const {
62  return CheckCollisionRayBox(*this, box);
63  }
64 
68  inline RayHitInfo GetCollision(const ::Model& model) const {
69  return GetCollisionRayModel(*this, model);
70  }
71 
75  inline RayHitInfo GetCollisionTriangle(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const {
76  return GetCollisionRayTriangle(*this, p1, p2, p3);
77  }
78 
82  inline RayHitInfo GetCollisionGround(float groundHeight) const {
83  return GetCollisionRayGround(*this, groundHeight);
84  }
85 
86  private:
87  inline void set(const ::Ray& ray) {
88  position = ray.position;
89  direction = ray.direction;
90  }
91 };
92 } // namespace raylib
93 
94 #endif // RAYLIB_CPP_INCLUDE_RAY_HPP_
raylib::Ray::Draw
Ray & Draw(::Color color)
Draw a ray line.
Definition: Ray.hpp:38
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::Ray::CheckCollision
bool CheckCollision(const ::BoundingBox &box) const
Detect collision between ray and box.
Definition: Ray.hpp:61
raylib::Ray::GetCollision
RayHitInfo GetCollision(const ::Model &model) const
Get collision info between ray and model.
Definition: Ray.hpp:68
raylib::Ray
Ray type (useful for raycast)
Definition: Ray.hpp:12
raylib::Ray::CheckCollisionSphere
bool CheckCollisionSphere(::Vector3 center, float radius) const
Detect collision between ray and sphere.
Definition: Ray.hpp:46
raylib::Vector3
Vector3 type.
Definition: Vector3.hpp:16
raylib::Camera3D
Camera type, defines a camera position/orientation in 3d space.
Definition: Camera3D.hpp:12
raylib::Vector2
Vector2 type.
Definition: Vector2.hpp:16
raylib::Ray::GetCollisionTriangle
RayHitInfo GetCollisionTriangle(::Vector3 p1, ::Vector3 p2, ::Vector3 p3) const
Get collision info between ray and triangle.
Definition: Ray.hpp:75
raylib::Ray::CheckCollisionSphere
bool CheckCollisionSphere(::Vector3 center, float radius, ::Vector3 *collisionPoint) const
Detect collision between ray and sphere, returns collision point.
Definition: Ray.hpp:53
raylib::Color
Color type, RGBA (32bit)
Definition: Color.hpp:14
raylib::RayHitInfo
Raycast hit information.
Definition: RayHitInfo.hpp:11
raylib::Ray::GetCollisionGround
RayHitInfo GetCollisionGround(float groundHeight) const
Get collision info between ray and ground plane (Y-normal plane)
Definition: Ray.hpp:82