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  Ray& operator=(const Ray& ray) {
59  set(ray);
60  return *this;
61  }
62 
63  GETTERSETTER(::Vector3, Position, position)
64  GETTERSETTER(::Vector3, Direction, direction)
65 
69  inline Ray& Draw(::Color color) {
70  DrawRay(*this, color);
71  return *this;
72  }
73 
77  inline bool CheckCollisionSphere(::Vector3 center, float radius) const {
78  return CheckCollisionRaySphere(*this, center, radius);
79  }
80 
84  inline bool CheckCollisionSphere(::Vector3 center, float radius,
85  ::Vector3 *collisionPoint) const {
86  return CheckCollisionRaySphereEx(*this, center, radius, collisionPoint);
87  }
88 
92  inline bool CheckCollision(const ::BoundingBox& box) const {
93  return CheckCollisionRayBox(*this, box);
94  }
95 
99  inline RayHitInfo GetCollision(const ::Model& model) {
100  return GetCollisionRayModel(*this, model);
101  }
102 
107  return GetCollisionRayTriangle(*this, p1, p2, p3);
108  }
109 
113  inline RayHitInfo GetCollisionGround(float groundHeight) {
114  return GetCollisionRayGround(*this, groundHeight);
115  }
116 
117  protected:
118  inline void set(const ::Ray& ray) {
119  position = ray.position;
120  direction = ray.direction;
121  }
122 };
123 } // namespace raylib
124 
125 #endif // RAYLIB_CPP_INCLUDE_RAY_HPP_
raylib::Ray::Draw
Ray & Draw(::Color color)
Draw a ray line.
Definition: Ray.hpp:69
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:92
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:77
raylib::Ray::operator=
Ray & operator=(const Ray &ray)
Definition: Ray.hpp:58
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:106
raylib::Ray::GetCollision
RayHitInfo GetCollision(const ::Model &model)
Get collision info between ray and model.
Definition: Ray.hpp:99
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:84
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:113
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:118
raylib::Ray::Ray
Ray(const ::Ray &ray)
Definition: Ray.hpp:40