PixelLightAPI  .
Intersect.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Intersect.h                                    *
00003  *      Intersection tools
00004  *
00005  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00006  *
00007  *  This file is part of PixelLight.
00008  *
00009  *  PixelLight is free software: you can redistribute it and/or modify
00010  *  it under the terms of the GNU Lesser General Public License as published by
00011  *  the Free Software Foundation, either version 3 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  PixelLight is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017  *  GNU Lesser General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU Lesser General Public License
00020  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00021 \*********************************************************/
00022 
00023 
00024 #ifndef __PLMATH_INTERSECT_H__
00025 #define __PLMATH_INTERSECT_H__
00026 #pragma once
00027 
00028 
00029 //[-------------------------------------------------------]
00030 //[ Includes                                              ]
00031 //[-------------------------------------------------------]
00032 #include "PLMath/PLMath.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Forward declarations                                  ]
00037 //[-------------------------------------------------------]
00038 namespace PLCore {
00039     template <class AType> class Array;
00040 }
00041 namespace PLMath {
00042     class Ray;
00043     class Line;
00044     class Plane;
00045     class Sphere;
00046     class Vector3;
00047     class Vector4;
00048     class PlaneSet;
00049     class BoundingBox;
00050     class AABoundingBox;
00051 }
00052 
00053 
00054 //[-------------------------------------------------------]
00055 //[ Namespace                                             ]
00056 //[-------------------------------------------------------]
00057 namespace PLMath {
00058 
00059 
00060 //[-------------------------------------------------------]
00061 //[ Classes                                               ]
00062 //[-------------------------------------------------------]
00063 /**
00064 *  @brief
00065 *    Static class with some useful intersection tools
00066 */
00067 class Intersect {
00068 
00069 
00070     //[-------------------------------------------------------]
00071     //[ Public functions                                      ]
00072     //[-------------------------------------------------------]
00073     public:
00074         //[-------------------------------------------------------]
00075         //[ Sphere                                                ]
00076         //[-------------------------------------------------------]
00077         /**
00078         *  @brief
00079         *    Check whether there's a sphere/point intersection
00080         *
00081         *  @param[in] cSphere
00082         *    Sphere to check
00083         *  @param[in] cPoint
00084         *    Point to check
00085         *
00086         *  @return
00087         *    'true' if there's a sphere/axis aligned box intersection, else 'false'
00088         */
00089         static PLMATH_API bool SpherePoint(const Sphere &cSphere, const Vector3 &cPoint);
00090         static PLMATH_API bool SpherePoint(const Sphere &cSphere, const Vector4 &cPoint);
00091 
00092         /**
00093         *  @brief
00094         *    Check whether there's a sphere/ray intersection
00095         *
00096         *  @param[in] cSphere
00097         *    Sphere to check
00098         *  @param[in] vRayOrigin
00099         *    Ray origin
00100         *  @param[in] vRayDirection
00101         *    Ray direction vector
00102         *
00103         *  @return
00104         *    Distance to intersection point, -1.0 it there was no intersection
00105         */
00106         static PLMATH_API float SphereRay(const Sphere &cSphere, const Vector3 &vRayOrigin, const Vector3 &vRayDirection);
00107 
00108         /**
00109         *  @brief
00110         *    Check whether there's a sphere/ray intersection
00111         *
00112         *  @param[in]  cSphere
00113         *    Sphere to check
00114         *  @param[in]  vRayOrigin
00115         *    Ray origin
00116         *  @param[in]  vRayDirection
00117         *    Ray direction vector
00118         *  @param[out] pvIntersect
00119         *    If not a null pointer, will receive the intersection point (if there's one)
00120         *
00121         *  @return
00122         *    'true' if there's a sphere/ray intersection, else 'false'
00123         */
00124         static PLMATH_API bool SphereRay(const Sphere &cSphere, const Vector3 &vRayOrigin, const Vector3 &vRayDirection, Vector3 *pvIntersect = nullptr);
00125 
00126         /**
00127         *  @brief
00128         *    Check whether there's a sphere/ray intersection
00129         *
00130         *  @param[in]  cSphere
00131         *    Sphere to check
00132         *  @param[in]  vRayOrigin
00133         *    Ray origin
00134         *  @param[in]  vRayDirection
00135         *    Ray direction vector
00136         *  @param[in]  fDistance
00137         *    Ray 'length'
00138         *  @param[out] pvIntersect
00139         *    If not a null pointer, will receive the intersection point (if there's one)
00140         *
00141         *  @return
00142         *    'true' if there's a sphere/ray intersection, else 'false'
00143         */
00144         static PLMATH_API bool SphereRay(const Sphere &cSphere, const Vector3 &vRayOrigin, const Vector3 &vRayDirection, float fDistance, Vector3 *pvIntersect = nullptr);
00145 
00146         /**
00147         *  @brief
00148         *    Check whether there's a sphere/ray intersection
00149         *
00150         *  @param[in]  cSphere
00151         *    Sphere to check
00152         *  @param[in]  vRayOrigin
00153         *    Ray origin
00154         *  @param[in]  vRayDirection
00155         *    Ray direction vector
00156         *  @param[out] pvIntersect
00157         *    If not a null pointer, will receive the intersection point (if there's one)
00158         *
00159         *  @return
00160         *    'true' if there's a sphere/ray intersection, else 'false'
00161         */
00162         static PLMATH_API bool SphereRayInFront(const Sphere &cSphere, const Vector3 &vRayOrigin, const Vector3 &vRayDirection, Vector3 *pvIntersect = nullptr);
00163 
00164         /**
00165         *  @brief
00166         *    Check whether there's a sphere/line intersection
00167         *
00168         *  @param[in] cSphere
00169         *    Sphere to check
00170         *  @param[in] vStart
00171         *    Line start point
00172         *  @param[in] vEnd
00173         *    Line end point
00174         *
00175         *  @return
00176         *    'true' if there's a sphere/line intersection, else 'false'
00177         */
00178         static PLMATH_API bool SphereLine(const Sphere &cSphere, const Vector3 &vStart, const Vector3 &vEnd);
00179 
00180         /**
00181         *  @brief
00182         *    Check whether there's a sphere/sphere intersection
00183         *
00184         *  @param[in] cSphere
00185         *    Sphere to check
00186         *  @param[in] vPos
00187         *    Second sphere position
00188         *  @param[in] fRadius
00189         *    Second sphere radius
00190         *
00191         *  @return
00192         *    'true' if there's a sphere/sphere intersection, else 'false'
00193         */
00194         static PLMATH_API bool SphereSphere(const Sphere &cSphere, const Vector3 &vPos, float fRadius);
00195 
00196         /**
00197         *  @brief
00198         *    Check whether there's a sphere/sphere intersection
00199         *
00200         *  @param[in] cSphere
00201         *    Sphere to check
00202         *  @param[in] cSphere2
00203         *    Second sphere to check
00204         *
00205         *  @return
00206         *    'true' if there's a sphere/sphere intersection, else 'false'
00207         */
00208         static PLMATH_API bool SphereSphere(const Sphere &cSphere, const Sphere &cSphere2);
00209 
00210         /**
00211         *  @brief
00212         *    Check whether a sphere intersects with this sphere while moving
00213         *
00214         *  @param[in] cSphere
00215         *    Sphere to check
00216         *  @param[in] cSphere2
00217         *    Second sphere to test
00218         *  @param[in] vMove1
00219         *    Movement vector of this sphere
00220         *  @param[in] vMove2
00221         *    Movement vector of the other sphere box
00222         *
00223         *  @return
00224         *    'true' if there's an intersection, else 'false'
00225         */
00226         static PLMATH_API bool SphereSphere(const Sphere &cSphere, const Sphere &cSphere2, const Vector3 &vMove1, const Vector3 &vMove2);
00227 
00228         /**
00229         *  @brief
00230         *    Check whether there's a sphere/axis aligned box intersection
00231         *
00232         *  @param[in] vSpherePos
00233         *    Position of the sphere to check
00234         *  @param[in] fSphereRadius
00235         *    Radius of the sphere to check
00236         *  @param[in] cAABox
00237         *    Axis aligned box to check
00238         *
00239         *  @return
00240         *    'true' if there's a sphere/axis aligned box intersection, else 'false'
00241         */
00242         static PLMATH_API bool SphereAABox(const Vector3 &vSpherePos, float fSphereRadius, const AABoundingBox &cAABox);
00243 
00244         /**
00245         *  @brief
00246         *    Check whether there's a sphere/axis aligned box intersection
00247         *
00248         *  @param[in] cSphere
00249         *    Sphere to check
00250         *  @param[in] cAABox
00251         *    Axis aligned box to check
00252         *
00253         *  @return
00254         *    'true' if there's a sphere/axis aligned box intersection, else 'false'
00255         */
00256         static PLMATH_API bool SphereAABox(const Sphere &cSphere, const AABoundingBox &cAABox);
00257 
00258         /**
00259         *  @brief
00260         *    Check whether there's a sphere/box intersection
00261         *
00262         *  @param[in] vSpherePos
00263         *    Position of the sphere to check
00264         *  @param[in] fSphereRadius
00265         *    Radius of the sphere to check
00266         *  @param[in] cBox
00267         *    Box to check
00268         *
00269         *  @return
00270         *    'true' if there's a sphere/box intersection, else 'false'
00271         */
00272         static PLMATH_API bool SphereBox(const Vector3 &vSpherePos, float fSphereRadius, const BoundingBox &cBox);
00273 
00274         /**
00275         *  @brief
00276         *    Check whether there's a sphere/box intersection
00277         *
00278         *  @param[in] cSphere
00279         *    Sphere to check
00280         *  @param[in] cBox
00281         *    Box to check
00282         *
00283         *  @return
00284         *    'true' if there's a sphere/box intersection, else 'false'
00285         */
00286         static PLMATH_API bool SphereBox(const Sphere &cSphere, const BoundingBox &cBox);
00287 
00288         //[-------------------------------------------------------]
00289         //[ Axis aligned box                                      ]
00290         //[-------------------------------------------------------]
00291         /**
00292         *  @brief
00293         *    Check whether a point is inside the axis aligned box
00294         *
00295         *  @param[in] vAABoxMin
00296         *    Axis aligned box minimum position
00297         *  @param[in] vAABoxMax
00298         *    Axis aligned box box maximum position
00299         *  @param[in] vPos
00300         *    Point to test
00301         *
00302         *  @return
00303         *    'true' if the given point is inside the axis aligned box, else 'false'
00304         */
00305         static PLMATH_API bool AABoxPoint(const Vector3 &vAABoxMin, const Vector3 &vAABoxMax, const Vector3 &vPos);
00306 
00307         /**
00308         *  @brief
00309         *    Check whether there's a axis aligned box/line intersection
00310         *
00311         *  @param[in]  vAABoxMin
00312         *    Axis aligned box minimum position
00313         *  @param[in]  vAABoxMax
00314         *    Axis aligned box box maximum position
00315         *  @param[in]  vStart
00316         *    Line start point
00317         *  @param[in]  vEnd
00318         *    Line end point
00319         *  @param[out] pfIntersection
00320         *    Receives the intersection distance if not null, <0 if there's no intersection or when the start point is inside the axis aligned box or when the distance is just negative
00321         *
00322         *  @return
00323         *    'true' if there's a axis aligned box/line intersection, else 'false'
00324         */
00325         static PLMATH_API bool AABoxLine(const Vector3 &vAABoxMin, const Vector3 &vAABoxMax, const Vector3 &vStart, const Vector3 &vEnd, float *pfIntersection = nullptr);
00326 
00327         /**
00328         *  @brief
00329         *    Check whether there's a axis aligned box/line intersection
00330         *
00331         *  @param[in]  vAABoxMin
00332         *    Axis aligned box minimum position
00333         *  @param[in]  vAABoxMax
00334         *    Axis aligned box box maximum position
00335         *  @param[in]  cLine
00336         *    Line to check
00337         *  @param[out] pfIntersection
00338         *    Receives the intersection distance if not null, <0 if there's no intersection or when the start point is inside the axis aligned box or when the distance is just negative
00339         *
00340         *  @return
00341         *    'true' if there's a axis aligned box/line intersection, else 'false'
00342         */
00343         static PLMATH_API bool AABoxLine(const Vector3 &vAABoxMin, const Vector3 &vAABoxMax, const Line &cLine, float *pfIntersection = nullptr);
00344 
00345         /**
00346         *  @brief
00347         *    Check whether there's a axis aligned box/sphere intersection
00348         *
00349         *  @param[in] vAABoxMin
00350         *    Axis aligned box minimum position
00351         *  @param[in] vAABoxMax
00352         *    Axis aligned box box maximum position
00353         *  @param[in] vSpherePos
00354         *    Position of the sphere to check
00355         *  @param[in] fSphereRadius
00356         *    Radius of the sphere to check
00357         *
00358         *  @return
00359         *    'true' if there's a sphere/axis aligned box intersection, else 'false'
00360         */
00361         static PLMATH_API bool AABoxSphere(const Vector3 &vAABoxMin, const Vector3 &vAABoxMax, const Vector3 &vSpherePos, float fSphereRadius);
00362 
00363         /**
00364         *  @brief
00365         *    Check whether there's a axis aligned box/axis aligned box intersection
00366         *
00367         *  @param[in] vAABoxMin1
00368         *    Axis aligned box minimum position 1
00369         *  @param[in] vAABoxMax1
00370         *    Axis aligned box box maximum position 1
00371         *  @param[in] vAABoxMin2
00372         *    Axis aligned box minimum position 2
00373         *  @param[in] vAABoxMax2
00374         *    Axis aligned box box maximum position 2
00375         *
00376         *  @return
00377         *    'true' if there's a axis aligned box/axis aligned box intersection, else 'false'
00378         */
00379         static PLMATH_API bool AABoxAABox(const Vector3 &vAABoxMin1, const Vector3 &vAABoxMax1, const Vector3 &vAABoxMin2, const Vector3 &vAABoxMax2);
00380 
00381         /**
00382         *  @brief
00383         *    Check whether there's a axis aligned box/axis aligned box intersection
00384         *
00385         *  @param[in] cBox1
00386         *    Axis aligned box 1
00387         *  @param[in] cBox2
00388         *    Axis aligned box 2
00389         *
00390         *  @return
00391         *    'true' if there's a axis aligned box/axis aligned box intersection, else 'false'
00392         */
00393         static PLMATH_API bool AABoxAABox(const AABoundingBox &cBox1, const AABoundingBox &cBox2);
00394 
00395         //[-------------------------------------------------------]
00396         //[ Box                                                   ]
00397         //[-------------------------------------------------------]
00398         /**
00399         *  @brief
00400         *    Check whether a point is inside the box
00401         *
00402         *  @param[in] cBox
00403         *    Box to check
00404         *  @param[in] vPos
00405         *    Point to test
00406         *
00407         *  @return
00408         *    'true' if the given point is inside the box, else 'false'
00409         */
00410         static PLMATH_API bool BoxPoint(const BoundingBox &cBox, const Vector3 &vPos);
00411 
00412         /**
00413         *  @brief
00414         *    Check whether a line intersects with the box
00415         *
00416         *  @param[in] cBox
00417         *    Box to check
00418         *  @param[in] vA
00419         *    Line start position
00420         *  @param[in] vB
00421         *    Line end position
00422         *
00423         *  @return
00424         *    'true' if the given line intersects with the box, else 'false'
00425         */
00426         static PLMATH_API bool BoxLine(const BoundingBox &cBox, const Vector3 &vA, const Vector3 &vB);
00427 
00428         /**
00429         *  @brief
00430         *    Check whether another box intersects with this box
00431         *
00432         *  @param[in] cBox1
00433         *    First box to check
00434         *  @param[in] cBox2
00435         *    Second box to test
00436         *
00437         *  @return
00438         *    'true' if the given box intersects with this box, else 'false'
00439         */
00440         static PLMATH_API bool BoxBox(const BoundingBox &cBox1, const BoundingBox &cBox2);
00441 
00442         /**
00443         *  @brief
00444         *    Check whether another box intersects with this box while moving
00445         *
00446         *  @param[in] cBox1
00447         *    First box to check
00448         *  @param[in] cBox2
00449         *    Second box to test
00450         *  @param[in] vMove1
00451         *    Movement vector of first box
00452         *  @param[in] vMove2
00453         *    Movement vector of second box
00454         *
00455         *  @return
00456         *    'true' if the given box intersects with this box while moving, else 'false'
00457         */
00458         static PLMATH_API bool BoxBox(const BoundingBox &cBox1, const BoundingBox &cBox2, const Vector3 &vMove1, const Vector3 &vMove2);
00459 
00460         /**
00461         *  @brief
00462         *    Check whether the box is in the plane set or not
00463         *
00464         *  @param[in] cBox
00465         *    Box to check
00466         *  @param[in] cPlaneSet
00467         *    Plane set to check
00468         *
00469         *  @return
00470         *    'true' if the box is in the plane set, else 'false'
00471         */
00472         static PLMATH_API bool BoxPlaneSet(const BoundingBox &cBox, const PlaneSet &cPlaneSet);
00473 
00474         //[-------------------------------------------------------]
00475         //[ Plane                                                 ]
00476         //[-------------------------------------------------------]
00477         /**
00478         *  @brief
00479         *    Checks if there's a plane/ray intersection
00480         *
00481         *  @param[in] cPlane
00482         *    Plane to check
00483         *  @param[in] vRayDirection
00484         *    Ray direction (must be normalized)
00485         *
00486         *  @return
00487         *    'true' if the ray intersects the plane, else 'false' (ray is parallel to plane)
00488         */
00489         static PLMATH_API bool IsPlaneRay(const Plane &cPlane, const Vector3 &vRayDirection);
00490 
00491         /**
00492         *  @brief
00493         *    Returns the plane/ray intersection point
00494         *
00495         *  @param[in] cPlane
00496         *    Plane to check
00497         *  @param[in] vRayOrigin
00498         *    Ray origin position
00499         *  @param[in] vRayDirection
00500         *    Ray direction (must be normalized)
00501         *  @param[out] vIntersectionPointPos
00502         *    Will receive the position of the intersection point, do only use the result when this method returned 'true'
00503         *
00504         *  @return
00505         *    'true' if the ray intersects the plane, else 'false'
00506         *
00507         *  @note
00508         *    - By definition, a ray has an infinite length, in both directions
00509         *    - "PlaneRayPositive()" only returns "true" for intersection with positive distance to plane
00510         *    - "PlaneRayNegative()" only returns "true" for intersection with negative distance to plane
00511         */
00512         static PLMATH_API bool PlaneRay(const Plane &cPlane, const Vector3 &vRayOrigin, const Vector3 &vRayDirection, Vector3 &vIntersectionPointPos);
00513         static PLMATH_API bool PlaneRayPositive(const Plane &cPlane, const Vector3 &vRayOrigin, const Vector3 &vRayDirection, Vector3 &vIntersectionPointPos);
00514         static PLMATH_API bool PlaneRayNegative(const Plane &cPlane, const Vector3 &vRayOrigin, const Vector3 &vRayDirection, Vector3 &vIntersectionPointPos);
00515 
00516         /**
00517         *  @brief
00518         *    Checks if there's a plane/line intersection
00519         *
00520         *  @param[in]  cPlane
00521         *    Plane to check
00522         *  @param[in]  vStartPos
00523         *    Line start position
00524         *  @param[in]  vEndPos
00525         *    Line end direction
00526         *  @param[out] pvPos
00527         *    If not a null pointer this will receive the intersection point (if there is any :)
00528         *
00529         *  @return
00530         *    Factor between 0-1 if there was an intersection, -1.0f if no intersection
00531         */
00532         static PLMATH_API float PlaneLine(const Plane &cPlane, const Vector3 &vStartPos, const Vector3 &vEndPos, Vector3 *pvPos = nullptr);
00533 
00534         /**
00535         *  @brief
00536         *    Checks if there's a plane/plane intersection
00537         *
00538         *  @param[in] cPlane
00539         *    Plane to check
00540         *  @param[in] cPlane2
00541         *    Plane2 to test with
00542         *
00543         *  @return
00544         *    'true' if the plane intersects the plane, else 'false'
00545         */
00546         static PLMATH_API bool PlanePlane(const Plane &cPlane, const Plane &cPlane2);
00547 
00548         /**
00549         *  @brief
00550         *    Checks if there's a plane/plane intersection and calculates the intersection ray
00551         *
00552         *  @param[in]  cPlane
00553         *    Plane to check
00554         *  @param[in]  cPlane2
00555         *    Second plane
00556         *  @param[out] cRay
00557         *    Receives the intersection ray/line
00558         *
00559         *  @return
00560         *    'true' if theres a plane intersection, else 'false'
00561         */
00562         static PLMATH_API bool PlanePlane(const Plane &cPlane, const Plane &cPlane2, Ray &cRay);
00563 
00564         /**
00565         *  @brief
00566         *    Checks if there's an intersection between the three planes and returns the
00567         *    intersection point
00568         *
00569         *  @param[in]  cP1
00570         *    Plane to check
00571         *  @param[in]  cP2
00572         *    Plane to intersect with
00573         *  @param[in]  cP3
00574         *    Plane to intersect with
00575         *  @param[out] vRes
00576         *    Receives the intersection point
00577         *
00578         *  @return
00579         *    'true' if there's an intersection between the three planes, else 'false'
00580         */
00581         static PLMATH_API bool PlanePlanePlane(const Plane &cP1, const Plane &cP2, const Plane &cP3, Vector3 &vRes);
00582 
00583         //[-------------------------------------------------------]
00584         //[ Plane set                                             ]
00585         //[-------------------------------------------------------]
00586         /**
00587         *  @brief
00588         *    Test whether a point is in the plane set
00589         *
00590         *  @param[in] cPlaneSet
00591         *    Plane set to check
00592         *  @param[in] vPoint
00593         *    Position of the point
00594         *
00595         *  @return
00596         *    'true' if the point is in plane set, else 'false'
00597         */
00598         static PLMATH_API bool PlaneSetPoint(const PlaneSet &cPlaneSet, const Vector3 &vPoint);
00599 
00600         /**
00601         *  @brief
00602         *    Test whether a point is in the plane set
00603         *
00604         *  @param[in] cPlaneSet
00605         *    Plane set to check
00606         *  @param[in] vPoint
00607         *    Position of the point
00608         *
00609         *  @return
00610         *    'true' if the point is in plane set, else 'false'
00611         */
00612         static PLMATH_API bool PlaneSetPoint(const PlaneSet &cPlaneSet, const Vector4 &vPoint);
00613 
00614         /**
00615         *  @brief
00616         *    Test whether the given points are in the plane set
00617         *
00618         *  @param[in] cPlaneSet
00619         *    Plane set to check
00620         *  @param[in] lstPoints
00621         *    Array of all points to test
00622         *
00623         *  @return
00624         *    'true' if the points are in plane set, else 'false'
00625         */
00626         static PLMATH_API bool PlaneSetPoints(const PlaneSet &cPlaneSet, const PLCore::Array<Vector3> &lstPoints);
00627 
00628         /**
00629         *  @brief
00630         *    Test whether the given points are in the plane set
00631         *
00632         *  @param[in] cPlaneSet
00633         *    Plane set to check
00634         *  @param[in] lstPoints
00635         *    Array of all points to test
00636         *
00637         *  @return
00638         *    'true' if the points are in plane set, else 'false'
00639         */
00640         static PLMATH_API bool PlaneSetPoints(const PlaneSet &cPlaneSet, const PLCore::Array<Vector4> &lstPoints);
00641 
00642         /**
00643         *  @brief
00644         *    Test whether a sphere is in the plane set
00645         *
00646         *  @param[in] cPlaneSet
00647         *    Plane set to check
00648         *  @param[in] vSphereOrigin
00649         *    Middle of the sphere
00650         *  @param[in] fSphereRadius
00651         *    Sphere radius
00652         *
00653         *  @return
00654         *    'true' if the sphere is in plane set, else 'false'
00655         */
00656         static PLMATH_API bool PlaneSetSphere(const PlaneSet &cPlaneSet, const Vector3 &vSphereOrigin, float fSphereRadius);
00657 
00658         /**
00659         *  @brief
00660         *    Test whether a triangle is in the plane set
00661         *
00662         *  @param[in] cPlaneSet
00663         *    Plane set to check
00664         *  @param[in] vV1
00665         *    First triangle point
00666         *  @param[in] vV2
00667         *    Second triangle point
00668         *  @param[in] vV3
00669         *    Third triangle point
00670         *
00671         *  @return
00672         *    'true' if the triangle is in plane set, else 'false'
00673         */
00674         static PLMATH_API bool PlaneSetTriangle(const PlaneSet &cPlaneSet, const Vector3 &vV1, const Vector3 &vV2, const Vector3 &vV3);
00675 
00676         /**
00677         *  @brief
00678         *    Tests whether an axis aligned box is within the plane set or not
00679         *
00680         *  @param[in] cPlaneSet
00681         *    Plane set to check
00682         *  @param[in]  vMin
00683         *    Minimum position
00684         *  @param[in]  vMax
00685         *    Maximum position
00686         *  @param[out] pnOutClipMask
00687         *    If not a null pointer, this clip mask will receive the intersection state of a
00688         *    maximum number of 32 planes if the box intersects the plane set. If this mask is
00689         *    0, there was no plane intersection at all. (= complete inside/outside the plane set)
00690         *
00691         *  @return
00692         *    'true' if the axis aligned box is within plane set, else 'false'
00693         */
00694         static PLMATH_API bool PlaneSetAABox(const PlaneSet &cPlaneSet, const Vector3 &vMin, const Vector3 &vMax, PLCore::uint32 *pnOutClipMask = nullptr);
00695 
00696         //[-------------------------------------------------------]
00697         //[ Triangle                                              ]
00698         //[-------------------------------------------------------]
00699         /**
00700         *  @brief
00701         *    Checks if there's a triangle/ray intersection
00702         *
00703         *  @param[in]  vV1
00704         *    First triangle point
00705         *  @param[in]  vV2
00706         *    Second triangle point
00707         *  @param[in]  vV3
00708         *    Third triangle point
00709         *  @param[in]  vN
00710         *    Triangle plane normal
00711         *  @param[in]  vRayOrigin
00712         *    Ray origin
00713         *  @param[in]  vRayDirection
00714         *    Ray direction vector
00715         *  @param[out] vIntersectionPointPos
00716         *    Will receive the position of the intersection point, do only use the result when this method returned 'true'
00717         *
00718         *  @return
00719         *    'true' if the ray intersects the triangle, else 'false'
00720         *
00721         *  @note
00722         *    - By definition, a ray has an infinite length, in both directions
00723         *    - "TriangleRayPositive()" only returns "true" for intersection with positive distance to triangle plane
00724         *    - "TriangleRayNegative()" only returns "true" for intersection with negative distance to triangle plane
00725         */
00726         static PLMATH_API bool TriangleRay(const Vector3 &vV1, const Vector3 &vV2,
00727                                            const Vector3 &vV3, const Vector3 &vN,
00728                                            const Vector3 &vRayOrigin, const Vector3 &vRayDirection,
00729                                            Vector3 &vIntersectionPointPos);
00730         static PLMATH_API bool TriangleRayPositive(const Vector3 &vV1, const Vector3 &vV2,
00731                                                    const Vector3 &vV3, const Vector3 &vN,
00732                                                    const Vector3 &vRayOrigin, const Vector3 &vRayDirection,
00733                                                    Vector3 &vIntersectionPointPos);
00734         static PLMATH_API bool TriangleRayNegative(const Vector3 &vV1, const Vector3 &vV2,
00735                                                    const Vector3 &vV3, const Vector3 &vN,
00736                                                    const Vector3 &vRayOrigin, const Vector3 &vRayDirection,
00737                                                    Vector3 &vIntersectionPointPos);
00738 
00739         /**
00740         *  @brief
00741         *    Checks if there's a triangle/ray intersection
00742         *
00743         *  @param[in]  vV1
00744         *    First triangle point
00745         *  @param[in]  vV2
00746         *    Second triangle point
00747         *  @param[in]  vV3
00748         *    Third triangle point
00749         *  @param[in]  vN
00750         *    Triangle plane normal
00751         *  @param[in]  cRay
00752         *    Ray to check
00753         *  @param[out] vIntersectionPointPos
00754         *    Will receive the position of the intersection point, do only use the result when this method returned 'true'
00755         *
00756         *  @return
00757         *    'true' if the ray intersects the triangle, else 'false'
00758         *
00759         *  @note
00760         *    - By definition, a ray has an infinite length, in both directions
00761         *    - "TriangleRayPositive()" only returns "true" for intersection with positive distance to triangle plane
00762         *    - "TriangleRayNegative()" only returns "true" for intersection with negative distance to triangle plane
00763         */
00764         static PLMATH_API bool TriangleRay(const Vector3 &vV1, const Vector3 &vV2,
00765                                            const Vector3 &vV3, const Vector3 &vN,
00766                                            const Ray &cRay, Vector3 &vIntersectionPointPos);
00767         static PLMATH_API bool TriangleRayPositive(const Vector3 &vV1, const Vector3 &vV2,
00768                                                    const Vector3 &vV3, const Vector3 &vN,
00769                                                    const Ray &cRay, Vector3 &vIntersectionPointPos);
00770         static PLMATH_API bool TriangleRayNegative(const Vector3 &vV1, const Vector3 &vV2,
00771                                                    const Vector3 &vV3, const Vector3 &vN,
00772                                                    const Ray &cRay, Vector3 &vIntersectionPointPos);
00773 
00774 
00775 };
00776 
00777 
00778 //[-------------------------------------------------------]
00779 //[ Namespace                                             ]
00780 //[-------------------------------------------------------]
00781 } // PLMath
00782 
00783 
00784 #endif // __PLMATH_INTERSECT_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:56
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported