Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
ray.h
1 #pragma once
2 
3 #include "vec3.h"
4 #include "aabb.h"
5 
6 namespace smlt {
7 
8 struct Ray {
9  Vec3 start;
10  Vec3 dir;
11  Vec3 dir_inv;
12 
13  Ray() = default;
14 
15  Ray(const Vec3& start, const Vec3& dir):
16  start(start),
17  dir(dir) {
18 
19  dir_inv = Vec3(1.0f / dir.x, 1.0f / dir.y, 1.0f / dir.z);
20  }
21 
22  bool intersects_aabb(const AABB& aabb) const;
23 
24  bool intersects_triangle(
25  const Vec3& v1, const Vec3& v2, const Vec3& v3,
26  Vec3* intersection=nullptr, Vec3* normal=nullptr, float* distance=nullptr
27  ) const;
28 
29  bool intersects_sphere(const Vec3& center, const float radius, Vec3* intersection=nullptr, Vec3* normal = nullptr, float* distance=nullptr) const;
30 };
31 
32 
33 }
smlt::Vec3
Definition: vec3.h:23
smlt::Ray
Definition: ray.h:8
smlt
Definition: animation.cpp:25
smlt::AABB
Definition: aabb.h:22