|
MCORE_INLINE | Ray () |
|
MCORE_INLINE | Ray (const AZ::Vector3 &org, const AZ::Vector3 &endPoint) |
|
MCORE_INLINE | Ray (const AZ::Vector3 &org, const AZ::Vector3 &endPoint, const AZ::Vector3 &dir) |
|
MCORE_INLINE void | Set (const AZ::Vector3 &org, const AZ::Vector3 &endPoint) |
|
MCORE_INLINE void | SetOrigin (const AZ::Vector3 &org) |
|
MCORE_INLINE void | SetDest (const AZ::Vector3 &dest) |
|
MCORE_INLINE const AZ::Vector3 & | GetOrigin () const |
|
MCORE_INLINE const AZ::Vector3 & | GetDest () const |
|
MCORE_INLINE const AZ::Vector3 & | GetDirection () const |
|
bool | Intersects (const BoundingSphere &s, AZ::Vector3 *intersectA=nullptr, AZ::Vector3 *intersectB=nullptr) const |
|
bool | Intersects (const PlaneEq &p, AZ::Vector3 *intersect=nullptr) const |
|
bool | Intersects (const AZ::Vector3 &p1, const AZ::Vector3 &p2, const AZ::Vector3 &p3, AZ::Vector3 *intersect=nullptr, float *baryU=nullptr, float *baryV=nullptr) const |
|
MCORE_INLINE float | Length () const |
|
The Ray template/class. A ray is normally an infinite line, starting at a given point (the origin) and heading into a given direction. However, this template does not represent an infinite line, but a finite line, since that will be a lot more useful. This means we have an origin, which is the starting point and a destination, which is the end point. This automatically gives us a direction vector too. So basically we now have a finite ray, which is just a 3D line. We can use rays mainly to perform intersection tests. This class provides you with methods to calculate interection information between the ray and bounding spheres, axis aligned bounding boxes, triangles and planes. More intersection tests might be added in a later stage. Or they have already been added, but this documentation should be updated :) Example fields where rays are (often) used are: collision and hit detection, raytracing images, global illumination, lightmap generation, pathtracing, real-time volumetric effects, lensflares, etc.
bool MCore::Ray::Intersects |
( |
const AZ::Vector3 & |
p1, |
|
|
const AZ::Vector3 & |
p2, |
|
|
const AZ::Vector3 & |
p3, |
|
|
AZ::Vector3 * |
intersect = nullptr , |
|
|
float * |
baryU = nullptr , |
|
|
float * |
baryV = nullptr |
|
) |
| const |
Perform a ray/triangle intersection test.
- Parameters
-
p1 | The first point of the triangle. |
p2 | The second point of the triangle. |
p3 | The third point of the triangle. |
intersect | If not nullptr, the intersection point will be stored in here, in case of an intersection. |
baryU | If not nullptr, the 'u' barycentric coordinate will be stored in here. |
baryV | If not nullptr, the 'v' barycentric coordinate will be stored in here. |
- Returns
- Returns true in case of an intersection, otherwise false. If there is no intersection, 'intersect', 'baryU' and 'baryV' will not be modified. You can calculate the uv or normal or whatsoever at the intersection point by using the baryU and baryV values.
The calculation goes like:
valueAtIntersectionPoint = (1-u-v)*A + u*B + v*C;
Where u and v are the values written in baryU and baryV and A, B and C are the three 'attributes' on the 3 points of the triangle. For example the three vertex normals or uv coordinates or colors. Where A is the attribute linked with 'p1', B the attribute linked with 'p2' and C the attribute linked with 'p3'.
To make it easy for you, we created a function caled BarycentricInterpolate() which takes the required parameters and returns the attribute value at the given barycentric coordinates for you. The usage would now be:
valueAtIntersectionPoint = BarycentricInterpolate<Vector3>(u, v, A, B, C);
Where A, B and C could be the vertex normals of the triangle for example. You can easily also calculate the intersection point yourself by using the u and v, by doing this:
intersectionPoint = BarycentricInterpolate<Vector3>(u, v, p1, p2, p3);
- See also
- BarycentricInterpolate