From 342403a02f8063903d0f38327430721d4d0ae331 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Mon, 20 Sep 2021 18:15:14 -0500 Subject: do ass1 --- dev/MinGfx/docs/html/classmingfx_1_1_ray.html | 1378 ++++++++++++------------- 1 file changed, 689 insertions(+), 689 deletions(-) (limited to 'dev/MinGfx/docs/html/classmingfx_1_1_ray.html') diff --git a/dev/MinGfx/docs/html/classmingfx_1_1_ray.html b/dev/MinGfx/docs/html/classmingfx_1_1_ray.html index 0c5b500..32845ac 100644 --- a/dev/MinGfx/docs/html/classmingfx_1_1_ray.html +++ b/dev/MinGfx/docs/html/classmingfx_1_1_ray.html @@ -1,689 +1,689 @@ - - - - - - - -MinGfx Toolkit: mingfx::Ray Class Reference - - - - - - - - - - - - -
-
- - - - - - -
-
MinGfx Toolkit -  1.0 -
-
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
- -
-
mingfx::Ray Class Reference
-
-
-

Detailed Description

-

Stores the mathematical object of a ray that begins at an origin (a 3D point) and points in a direction (a unit 3D vector).

-

Rays can intersect a variety of other computer graphics objects, such as planes, triangles, spheres, 3D meshes, etc. These intersections can be tested with the Intersect...() methods. The Ray can also be transformed by a Matrix4. Example:

// Create a pick ray from the mouse position
-
void MyGraphicsApp::OnLeftMouseDown(const Point2 &pos) {
-
Point2 mouse_xy = PixelsToNormalizedDeviceCoords(pos);
-
float mouse_z = ReadZValueAtPixel(pos);
-
Point3 mouse_3d = GfxMath::ScreenToNearPlane(view_matrix, proj_matrix, mouse_xy, mouse_z);
-
Matrix4 camera_matrix = view_matrix.Inverse();
-
Point3 eye = camera_matrix.ColumnToPoint3(3);
-
-
Ray pick_ray(eye, mouse_3d - eye);
-
-
// check to see if the ray intersects a sphere
-
float t;
-
Point3 p;
-
if (pick_ray.IntersectSphere(Point3(0,0,0), 2.0, &t, &p)) {
-
std::cout << "Mouse pointing at sphere! Intersection point = " << p << std::endl;
-
}
-
}
-
static Point3 ScreenToNearPlane(const Matrix4 &viewMatrix, const Matrix4 &projMatrix, const Point2 &normalizedScreenPt)
Converts a 2D point on the filmplane represented in Normalized Device Coorindates,...
-
Ray()
Defaults to a ray at the origin and pointing in the -Z direction.
-
-

Definition at line 54 of file ray.h.

-
-

#include <ray.h>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

-Public Member Functions

 Ray ()
 Defaults to a ray at the origin and pointing in the -Z direction. More...
 
 Ray (const Point3 &origin, const Vector3 &direction)
 Creates a ray from a 3D origin and direction. More...
 
virtual ~Ray ()
 Ray destructor. More...
 
bool operator== (const Ray &other) const
 Check for "equality", taking floating point imprecision into account. More...
 
bool operator!= (const Ray &other) const
 Check for "inequality", taking floating point imprecision into account. More...
 
float Length () const
 Returns the length of the direction vector. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
bool IntersectMesh (const Mesh &mesh, float *iTime, Point3 *iPoint, int *iTriangleID) const
 Checks to see if the ray intersects a triangle mesh. More...
 
bool FastIntersectMesh (Mesh *mesh, float *iTime, Point3 *iPoint, int *iTriangleID) const
 Checks to see if the ray intersects a triangle mesh. More...
 
bool IntersectAABB (const AABB &box, float *iTime) const
 Checks to see if the ray intersects an AABB (Axis-Aligned Bounding Box). More...
 
Point3 origin () const
 Returns the origin. More...
 
Vector3 direction () const
 Returns the direction. More...
 
void set (Point3 newOrigin, Vector3 newDir)
 Sets a new origin and direction. More...
 
-

Constructor & Destructor Documentation

- -

◆ Ray() [1/2]

- -
-
- - - - - - - -
mingfx::Ray::Ray ()
-
- -

Defaults to a ray at the origin and pointing in the -Z direction.

- -
-
- -

◆ Ray() [2/2]

- -
-
- - - - - - - - - - - - - - - - - - -
mingfx::Ray::Ray (const Point3origin,
const Vector3direction 
)
-
- -

Creates a ray from a 3D origin and direction.

- -
-
- -

◆ ~Ray()

- -
-
- - - - - -
- - - - - - - -
virtual mingfx::Ray::~Ray ()
-
-virtual
-
- -

Ray destructor.

- -
-
-

Member Function Documentation

- -

◆ direction()

- -
-
- - - - - - - -
Vector3 mingfx::Ray::direction () const
-
- -

Returns the direction.

- -
-
- -

◆ FastIntersectMesh()

- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool mingfx::Ray::FastIntersectMesh (Meshmesh,
float * iTime,
Point3iPoint,
int * iTriangleID 
) const
-
- -

Checks to see if the ray intersects a triangle mesh.

-

This uses a BVH (Bounding Volume Hierarchy) to accelerate the ray-triangle intersection tests. Each mesh can optionally store a BVH. If a BVH has already been calculated for the mesh (done with Mesh::CalculateBVH()), then this function will be much faster than the brute-force IntersectMesh() function. If a BVH has not already been calculated for the mesh, the first call to FastIntersectMesh() will trigger the mesh to create a BVH (not a fast operation) but then subsequent calls to FastIntersectMesh() will be fast.

- -
-
- -

◆ IntersectAABB()

- -
-
- - - - - - - - - - - - - - - - - - -
bool mingfx::Ray::IntersectAABB (const AABBbox,
float * iTime 
) const
-
- -

Checks to see if the ray intersects an AABB (Axis-Aligned Bounding Box).

-

Typically, this is the first step of a more detailed intersection test and we don't care about the actual point of intersection, just whether it intersects or not. So, we don't bother calculating the iPoint. We get the iTime for free though, so we do return that. You can calc the iPoint if you want using:

float t;
-
if (ray.IntersectAABB(box, &t)) {
-
Point3 iPoint = ray.origin() + t*ray.direction();
-
}
-
-
-
- -

◆ IntersectMesh()

- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool mingfx::Ray::IntersectMesh (const Meshmesh,
float * iTime,
Point3iPoint,
int * iTriangleID 
) const
-
- -

Checks to see if the ray intersects a triangle mesh.

-

This is a brute-force check over each triangle in the mesh. If there was an intersection, true is returned, iTime is set to the intersection time, iPoint is set to the intersection point, and iTriangleID is set to the ID of the closest intersected triangle along the ray.

- -
-
- -

◆ IntersectPlane()

- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool mingfx::Ray::IntersectPlane (const Point3planePt,
const Vector3planeNormal,
float * iTime,
Point3iPoint 
) const
-
- -

Checks to see if the ray intersects a plane defined by a point and a normal.

-

If there was an intersection, true is returned, iTime is set to the intersection time, and iPoint is set to the intersection point. The plane is considered to be 1-sided. That is the intersection will only occur if the ray hits the plane from its front side as determined by the plane's normal.

- -
-
- -

◆ IntersectQuad()

- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool mingfx::Ray::IntersectQuad (const Point3v1,
const Point3v2,
const Point3v3,
const Point3v4,
float * iTime,
Point3iPoint 
) const
-
- -

Checks to see if the ray intersects a quad defined by the vertices v1, v2, v3, and v4.

-

The vertices must be provided in counter-clockwise order so that the normal of the triangle can be determined via the right-hand rule. The intersection will only happen if the ray hits the front side of the triangle. If there was an intersection, true is returned, iTime is set to the intersection time, and iPoint is set to the intersection point.

- -
-
- -

◆ IntersectSphere()

- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool mingfx::Ray::IntersectSphere (const Point3center,
float radius,
float * iTime,
Point3iPoint 
) const
-
- -

Checks to see if the ray intersects a sphere defined by a center point and a radius.

-

If there was an intersection, true is returned, iTime is set to the intersection time, and iPoint is set to the intersection point.

- -
-
- -

◆ IntersectTriangle()

- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool mingfx::Ray::IntersectTriangle (const Point3v1,
const Point3v2,
const Point3v3,
float * iTime,
Point3iPoint 
) const
-
- -

Checks to see if the ray intersects a triangle defined by the vertices v1, v2, and v3.

-

The vertices must be provided in counter-clockwise order so that the normal of the triangle can be determined via the right-hand rule. The intersection will only happen if the ray hits the front side of the triangle. If there was an intersection, true is returned, iTime is set to the intersection time, and iPoint is set to the intersection point.

- -
-
- -

◆ Length()

- -
-
- - - - - - - -
float mingfx::Ray::Length () const
-
- -

Returns the length of the direction vector.

- -
-
- -

◆ operator!=()

- -
-
- - - - - - - - -
bool mingfx::Ray::operator!= (const Rayother) const
-
- -

Check for "inequality", taking floating point imprecision into account.

- -
-
- -

◆ operator==()

- -
-
- - - - - - - - -
bool mingfx::Ray::operator== (const Rayother) const
-
- -

Check for "equality", taking floating point imprecision into account.

- -
-
- -

◆ origin()

- -
-
- - - - - - - -
Point3 mingfx::Ray::origin () const
-
- -

Returns the origin.

- -
-
- -

◆ set()

- -
-
- - - - - - - - - - - - - - - - - - -
void mingfx::Ray::set (Point3 newOrigin,
Vector3 newDir 
)
-
- -

Sets a new origin and direction.

- -
-
-
The documentation for this class was generated from the following file: -
- - - - - + + + + + + + +MinGfx Toolkit: mingfx::Ray Class Reference + + + + + + + + + + + + +
+
+ + + + + + +
+
MinGfx Toolkit +  1.0 +
+
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
mingfx::Ray Class Reference
+
+
+

Detailed Description

+

Stores the mathematical object of a ray that begins at an origin (a 3D point) and points in a direction (a unit 3D vector).

+

Rays can intersect a variety of other computer graphics objects, such as planes, triangles, spheres, 3D meshes, etc. These intersections can be tested with the Intersect...() methods. The Ray can also be transformed by a Matrix4. Example:

// Create a pick ray from the mouse position
+
void MyGraphicsApp::OnLeftMouseDown(const Point2 &pos) {
+
Point2 mouse_xy = PixelsToNormalizedDeviceCoords(pos);
+
float mouse_z = ReadZValueAtPixel(pos);
+
Point3 mouse_3d = GfxMath::ScreenToNearPlane(view_matrix, proj_matrix, mouse_xy, mouse_z);
+
Matrix4 camera_matrix = view_matrix.Inverse();
+
Point3 eye = camera_matrix.ColumnToPoint3(3);
+
+
Ray pick_ray(eye, mouse_3d - eye);
+
+
// check to see if the ray intersects a sphere
+
float t;
+
Point3 p;
+
if (pick_ray.IntersectSphere(Point3(0,0,0), 2.0, &t, &p)) {
+
std::cout << "Mouse pointing at sphere! Intersection point = " << p << std::endl;
+
}
+
}
+
static Point3 ScreenToNearPlane(const Matrix4 &viewMatrix, const Matrix4 &projMatrix, const Point2 &normalizedScreenPt)
Converts a 2D point on the filmplane represented in Normalized Device Coorindates,...
+
Ray()
Defaults to a ray at the origin and pointing in the -Z direction.
+
+

Definition at line 54 of file ray.h.

+
+

#include <ray.h>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Public Member Functions

 Ray ()
 Defaults to a ray at the origin and pointing in the -Z direction. More...
 
 Ray (const Point3 &origin, const Vector3 &direction)
 Creates a ray from a 3D origin and direction. More...
 
virtual ~Ray ()
 Ray destructor. More...
 
bool operator== (const Ray &other) const
 Check for "equality", taking floating point imprecision into account. More...
 
bool operator!= (const Ray &other) const
 Check for "inequality", taking floating point imprecision into account. More...
 
float Length () const
 Returns the length of the direction vector. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
bool IntersectMesh (const Mesh &mesh, float *iTime, Point3 *iPoint, int *iTriangleID) const
 Checks to see if the ray intersects a triangle mesh. More...
 
bool FastIntersectMesh (Mesh *mesh, float *iTime, Point3 *iPoint, int *iTriangleID) const
 Checks to see if the ray intersects a triangle mesh. More...
 
bool IntersectAABB (const AABB &box, float *iTime) const
 Checks to see if the ray intersects an AABB (Axis-Aligned Bounding Box). More...
 
Point3 origin () const
 Returns the origin. More...
 
Vector3 direction () const
 Returns the direction. More...
 
void set (Point3 newOrigin, Vector3 newDir)
 Sets a new origin and direction. More...
 
+

Constructor & Destructor Documentation

+ +

◆ Ray() [1/2]

+ +
+
+ + + + + + + +
mingfx::Ray::Ray ()
+
+ +

Defaults to a ray at the origin and pointing in the -Z direction.

+ +
+
+ +

◆ Ray() [2/2]

+ +
+
+ + + + + + + + + + + + + + + + + + +
mingfx::Ray::Ray (const Point3origin,
const Vector3direction 
)
+
+ +

Creates a ray from a 3D origin and direction.

+ +
+
+ +

◆ ~Ray()

+ +
+
+ + + + + +
+ + + + + + + +
virtual mingfx::Ray::~Ray ()
+
+virtual
+
+ +

Ray destructor.

+ +
+
+

Member Function Documentation

+ +

◆ direction()

+ +
+
+ + + + + + + +
Vector3 mingfx::Ray::direction () const
+
+ +

Returns the direction.

+ +
+
+ +

◆ FastIntersectMesh()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool mingfx::Ray::FastIntersectMesh (Meshmesh,
float * iTime,
Point3iPoint,
int * iTriangleID 
) const
+
+ +

Checks to see if the ray intersects a triangle mesh.

+

This uses a BVH (Bounding Volume Hierarchy) to accelerate the ray-triangle intersection tests. Each mesh can optionally store a BVH. If a BVH has already been calculated for the mesh (done with Mesh::CalculateBVH()), then this function will be much faster than the brute-force IntersectMesh() function. If a BVH has not already been calculated for the mesh, the first call to FastIntersectMesh() will trigger the mesh to create a BVH (not a fast operation) but then subsequent calls to FastIntersectMesh() will be fast.

+ +
+
+ +

◆ IntersectAABB()

+ +
+
+ + + + + + + + + + + + + + + + + + +
bool mingfx::Ray::IntersectAABB (const AABBbox,
float * iTime 
) const
+
+ +

Checks to see if the ray intersects an AABB (Axis-Aligned Bounding Box).

+

Typically, this is the first step of a more detailed intersection test and we don't care about the actual point of intersection, just whether it intersects or not. So, we don't bother calculating the iPoint. We get the iTime for free though, so we do return that. You can calc the iPoint if you want using:

float t;
+
if (ray.IntersectAABB(box, &t)) {
+
Point3 iPoint = ray.origin() + t*ray.direction();
+
}
+
+
+
+ +

◆ IntersectMesh()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool mingfx::Ray::IntersectMesh (const Meshmesh,
float * iTime,
Point3iPoint,
int * iTriangleID 
) const
+
+ +

Checks to see if the ray intersects a triangle mesh.

+

This is a brute-force check over each triangle in the mesh. If there was an intersection, true is returned, iTime is set to the intersection time, iPoint is set to the intersection point, and iTriangleID is set to the ID of the closest intersected triangle along the ray.

+ +
+
+ +

◆ IntersectPlane()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool mingfx::Ray::IntersectPlane (const Point3planePt,
const Vector3planeNormal,
float * iTime,
Point3iPoint 
) const
+
+ +

Checks to see if the ray intersects a plane defined by a point and a normal.

+

If there was an intersection, true is returned, iTime is set to the intersection time, and iPoint is set to the intersection point. The plane is considered to be 1-sided. That is the intersection will only occur if the ray hits the plane from its front side as determined by the plane's normal.

+ +
+
+ +

◆ IntersectQuad()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool mingfx::Ray::IntersectQuad (const Point3v1,
const Point3v2,
const Point3v3,
const Point3v4,
float * iTime,
Point3iPoint 
) const
+
+ +

Checks to see if the ray intersects a quad defined by the vertices v1, v2, v3, and v4.

+

The vertices must be provided in counter-clockwise order so that the normal of the triangle can be determined via the right-hand rule. The intersection will only happen if the ray hits the front side of the triangle. If there was an intersection, true is returned, iTime is set to the intersection time, and iPoint is set to the intersection point.

+ +
+
+ +

◆ IntersectSphere()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool mingfx::Ray::IntersectSphere (const Point3center,
float radius,
float * iTime,
Point3iPoint 
) const
+
+ +

Checks to see if the ray intersects a sphere defined by a center point and a radius.

+

If there was an intersection, true is returned, iTime is set to the intersection time, and iPoint is set to the intersection point.

+ +
+
+ +

◆ IntersectTriangle()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool mingfx::Ray::IntersectTriangle (const Point3v1,
const Point3v2,
const Point3v3,
float * iTime,
Point3iPoint 
) const
+
+ +

Checks to see if the ray intersects a triangle defined by the vertices v1, v2, and v3.

+

The vertices must be provided in counter-clockwise order so that the normal of the triangle can be determined via the right-hand rule. The intersection will only happen if the ray hits the front side of the triangle. If there was an intersection, true is returned, iTime is set to the intersection time, and iPoint is set to the intersection point.

+ +
+
+ +

◆ Length()

+ +
+
+ + + + + + + +
float mingfx::Ray::Length () const
+
+ +

Returns the length of the direction vector.

+ +
+
+ +

◆ operator!=()

+ +
+
+ + + + + + + + +
bool mingfx::Ray::operator!= (const Rayother) const
+
+ +

Check for "inequality", taking floating point imprecision into account.

+ +
+
+ +

◆ operator==()

+ +
+
+ + + + + + + + +
bool mingfx::Ray::operator== (const Rayother) const
+
+ +

Check for "equality", taking floating point imprecision into account.

+ +
+
+ +

◆ origin()

+ +
+
+ + + + + + + +
Point3 mingfx::Ray::origin () const
+
+ +

Returns the origin.

+ +
+
+ +

◆ set()

+ +
+
+ + + + + + + + + + + + + + + + + + +
void mingfx::Ray::set (Point3 newOrigin,
Vector3 newDir 
)
+
+ +

Sets a new origin and direction.

+ +
+
+
The documentation for this class was generated from the following file: +
+ + + + + -- cgit v1.2.3