raylib-cpp
C++ object-oriented wrapper library for raylib.
Ray.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_RAY_HPP_
26 #define RAYLIB_CPP_INCLUDE_RAY_HPP_
27 
28 #include "./raylib.hpp"
29 
30 #include "./raylib-cpp-utils.hpp"
31 
32 #include "./RayHitInfo.hpp"
33 
34 namespace raylib {
38 class Ray : public ::Ray {
39  public:
40  Ray(const ::Ray& ray) {
41  set(ray);
42  }
43 
44  Ray(::Vector3 Position, ::Vector3 Direction) {
45  position = Position;
46  direction = Direction;
47  }
48 
49  Ray(::Vector2 mousePosition, ::Camera camera) {
50  set(GetMouseRay(mousePosition, camera));
51  }
52 
53  Ray& operator=(const ::Ray& ray) {
54  set(ray);
55  return *this;
56  }
57 
58  GETTERSETTER(::Vector3, Position, position)
59  GETTERSETTER(::Vector3, Direction, direction)
60 
64  inline Ray& Draw(::Color color) {
65  DrawRay(*this, color);
66  return *this;
67  }
68 
72  inline bool CheckCollisionSphere(::Vector3 center, float radius) const {
73  return CheckCollisionRaySphere(*this, center, radius);
74  }
75 
79  inline bool CheckCollisionSphere(::Vector3 center, float radius,
80  ::Vector3 *collisionPoint) const {
81  return CheckCollisionRaySphereEx(*this, center, radius, collisionPoint);
82  }
83 
87  inline bool CheckCollision(const ::BoundingBox& box) const {
88  return CheckCollisionRayBox(*this, box);
89  }
90 
94  inline RayHitInfo GetCollision(const ::Model& model) {
95  return GetCollisionRayModel(*this, model);
96  }
97 
102  return GetCollisionRayTriangle(*this, p1, p2, p3);
103  }
104 
108  inline RayHitInfo GetCollisionGround(float groundHeight) {
109  return GetCollisionRayGround(*this, groundHeight);
110  }
111 
112  protected:
113  inline void set(const ::Ray& ray) {
114  position = ray.position;
115  direction = ray.direction;
116  }
117 };
118 } // namespace raylib
119 
120 #endif // RAYLIB_CPP_INCLUDE_RAY_HPP_
raylib::Ray::Draw
Ray & Draw(::Color color)
Draw a ray line.
Definition: Ray.hpp:64
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Ray::CheckCollision
bool CheckCollision(const ::BoundingBox &box) const
Detect collision between ray and box.
Definition: Ray.hpp:87
raylib::Ray
Ray type (useful for raycast)
Definition: Ray.hpp:38
raylib::Ray::CheckCollisionSphere
bool CheckCollisionSphere(::Vector3 center, float radius) const
Detect collision between ray and sphere.
Definition: Ray.hpp:72
raylib::Ray::Ray
Ray(::Vector3 Position, ::Vector3 Direction)
Definition: Ray.hpp:44
raylib::Vector3
Definition: Vector3.hpp:37
raylib::Camera3D
Definition: Camera3D.hpp:33
raylib::Ray::Ray
Ray(::Vector2 mousePosition, ::Camera camera)
Definition: Ray.hpp:49
raylib::Ray::GetCollisionTriangle
RayHitInfo GetCollisionTriangle(::Vector3 p1, ::Vector3 p2, ::Vector3 p3)
Get collision info between ray and triangle.
Definition: Ray.hpp:101
raylib::Ray::GetCollision
RayHitInfo GetCollision(const ::Model &model)
Get collision info between ray and model.
Definition: Ray.hpp:94
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Ray::CheckCollisionSphere
bool CheckCollisionSphere(::Vector3 center, float radius, ::Vector3 *collisionPoint) const
Detect collision between ray and sphere, returns collision point.
Definition: Ray.hpp:79
raylib::Color
Definition: Color.hpp:35
raylib::Ray::GetCollisionGround
RayHitInfo GetCollisionGround(float groundHeight)
Get collision info between ray and ground plane (Y-normal plane)
Definition: Ray.hpp:108
raylib::RayHitInfo
Raycast hit information.
Definition: RayHitInfo.hpp:35
raylib::Ray::operator=
Ray & operator=(const ::Ray &ray)
Definition: Ray.hpp:53
raylib::Ray::set
void set(const ::Ray &ray)
Definition: Ray.hpp:113
raylib::Ray::Ray
Ray(const ::Ray &ray)
Definition: Ray.hpp:40