MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
ray.h
Go to the documentation of this file.
1 /*
2  This file is part of the MinGfx Project.
3 
4  Copyright (c) 2017,2018 Regents of the University of Minnesota.
5  All Rights Reserved.
6 
7  Original Author(s) of this File:
8  Dan Keefe, 2018, University of Minnesota
9 
10  Author(s) of Significant Updates/Modifications to the File:
11  ...
12  */
13 
14 #ifndef SRC_RAY_H_
15 #define SRC_RAY_H_
16 
17 #include <iostream>
18 
19 #include "aabb.h"
20 #include "point3.h"
21 #include "vector3.h"
22 #include "mesh.h"
23 
24 
25 namespace mingfx {
26 
27 
54 class Ray {
55 public:
56 
58  Ray();
59 
61  Ray(const Point3 &origin, const Vector3 &direction);
62 
64  virtual ~Ray();
65 
67  bool operator==(const Ray& other) const;
68 
70  bool operator!=(const Ray& other) const;
71 
73  float Length() const;
74 
81  bool IntersectPlane(const Point3 &planePt, const Vector3 &planeNormal,
82  float *iTime, Point3 *iPoint) const;
83 
90  bool IntersectTriangle(const Point3 &v1, const Point3 &v2, const Point3 &v3,
91  float *iTime, Point3 *iPoint) const;
92 
99  bool IntersectQuad(const Point3 &v1, const Point3 &v2, const Point3 &v3, const Point3 &v4,
100  float *iTime, Point3 *iPoint) const;
101 
106  bool IntersectSphere(const Point3 &center, float radius,
107  float *iTime, Point3 *iPoint) const;
108 
114  bool IntersectMesh(const Mesh &mesh, float *iTime,
115  Point3 *iPoint, int *iTriangleID) const;
116 
126  bool FastIntersectMesh(Mesh *mesh, float *iTime,
127  Point3 *iPoint, int *iTriangleID) const;
128 
142  bool IntersectAABB(const AABB &box, float *iTime) const;
143 
145  Point3 origin() const;
146 
149 
151  void set(Point3 newOrigin, Vector3 newDir);
152 
153 private:
154  Point3 p_;
155  Vector3 d_;
156 };
157 
158 
159 // --- Stream operators ---
160 
161 std::ostream & operator<< ( std::ostream &os, const Ray &r);
162 std::istream & operator>> ( std::istream &is, Ray &r);
163 
164 
165 } // end namespace
166 
167 #endif
A 3D axis-aligned bounding box defined by two corners (min and max).
Definition: aabb.h:31
A triangle mesh data structure that can be rendered with a ShaderProgram like DefaultShader.
Definition: mesh.h:127
A 3D Point with floating point coordinates, used for storing vertices and all sorts of other 3D graph...
Definition: point3.h:52
Stores the mathematical object of a ray that begins at an origin (a 3D point) and points in a directi...
Definition: ray.h:54
bool IntersectTriangle(const Point3 &v1, const Point3 &v2, const Point3 &v3, float *iTime, Point3 *iPoint) const
Checks to see if the ray intersects a triangle defined by the vertices v1, v2, and v3.
Point3 origin() const
Returns the origin.
bool IntersectQuad(const Point3 &v1, const Point3 &v2, const Point3 &v3, const Point3 &v4, float *iTime, Point3 *iPoint) const
Checks to see if the ray intersects a quad defined by the vertices v1, v2, v3, and v4.
float Length() const
Returns the length of the direction vector.
bool IntersectAABB(const AABB &box, float *iTime) const
Checks to see if the ray intersects an AABB (Axis-Aligned Bounding Box).
void set(Point3 newOrigin, Vector3 newDir)
Sets a new origin and direction.
bool IntersectMesh(const Mesh &mesh, float *iTime, Point3 *iPoint, int *iTriangleID) const
Checks to see if the ray intersects a triangle mesh.
Vector3 direction() const
Returns the direction.
bool IntersectPlane(const Point3 &planePt, const Vector3 &planeNormal, float *iTime, Point3 *iPoint) const
Checks to see if the ray intersects a plane defined by a point and a normal.
bool operator==(const Ray &other) const
Check for "equality", taking floating point imprecision into account.
bool IntersectSphere(const Point3 &center, float radius, float *iTime, Point3 *iPoint) const
Checks to see if the ray intersects a sphere defined by a center point and a radius.
Ray(const Point3 &origin, const Vector3 &direction)
Creates a ray from a 3D origin and direction.
bool operator!=(const Ray &other) const
Check for "inequality", taking floating point imprecision into account.
virtual ~Ray()
Ray destructor.
bool FastIntersectMesh(Mesh *mesh, float *iTime, Point3 *iPoint, int *iTriangleID) const
Checks to see if the ray intersects a triangle mesh.
Ray()
Defaults to a ray at the origin and pointing in the -Z direction.
A 3D Vector with floating point coordinates, used for storing normals and all sorts of other 3D graph...
Definition: vector3.h:62
Namespace for the MinGfx Toolkit.
Definition: aabb.h:21
std::ostream & operator<<(std::ostream &os, const Color &c)
std::istream & operator>>(std::istream &is, Color &c)