[1378] | 1 | #ifndef NX_FOUNDATION_NXRAY
|
---|
| 2 | #define NX_FOUNDATION_NXRAY
|
---|
| 3 | /*----------------------------------------------------------------------------*\
|
---|
| 4 | |
|
---|
| 5 | | Public Interface to NovodeX Technology
|
---|
| 6 | |
|
---|
| 7 | | www.novodex.com
|
---|
| 8 | |
|
---|
| 9 | \*----------------------------------------------------------------------------*/
|
---|
| 10 | /** \addtogroup foundation
|
---|
| 11 | @{
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 | #include "Nx.h"
|
---|
| 15 | #include "NxVec3.h"
|
---|
| 16 |
|
---|
| 17 | class NxRay;
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | \brief Represents an infinite ray as an origin and direction.
|
---|
| 21 |
|
---|
| 22 | The direction should be normalized.
|
---|
| 23 | */
|
---|
| 24 | class NxRay
|
---|
| 25 | {
|
---|
| 26 | public:
|
---|
| 27 | /**
|
---|
| 28 | Constructor
|
---|
| 29 | */
|
---|
| 30 | NX_INLINE NxRay()
|
---|
| 31 | {
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | Constructor
|
---|
| 36 | */
|
---|
| 37 | NX_INLINE NxRay(const NxVec3& _orig, const NxVec3& _dir) : orig(_orig), dir(_dir)
|
---|
| 38 | {
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | Destructor
|
---|
| 43 | */
|
---|
| 44 | NX_INLINE ~NxRay()
|
---|
| 45 | {
|
---|
| 46 | }
|
---|
| 47 | #ifdef FOUNDATION_EXPORTS
|
---|
| 48 |
|
---|
| 49 | NX_INLINE NxF32 distanceSquared(const NxVec3& point, NxF32* t=NULL) const
|
---|
| 50 | {
|
---|
| 51 | return NxComputeDistanceSquared(*this, point, t);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | NX_INLINE NxF32 distance(const NxVec3& point, NxF32* t=NULL) const
|
---|
| 55 | {
|
---|
| 56 | return sqrtf(distanceSquared(point, t));
|
---|
| 57 | }
|
---|
| 58 | #endif
|
---|
| 59 |
|
---|
| 60 | NxVec3 orig; //!< Ray origin
|
---|
| 61 | NxVec3 dir; //!< Normalized direction
|
---|
| 62 | };
|
---|
| 63 |
|
---|
| 64 | NX_INLINE void ComputeReflexionVector(NxVec3& reflected, const NxVec3& incoming_dir, const NxVec3& outward_normal)
|
---|
| 65 | {
|
---|
| 66 | reflected = incoming_dir - outward_normal * 2.0f * incoming_dir.dot(outward_normal);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | NX_INLINE void ComputeReflexionVector(NxVec3& reflected, const NxVec3& source, const NxVec3& impact, const NxVec3& normal)
|
---|
| 70 | {
|
---|
| 71 | NxVec3 V = impact - source;
|
---|
| 72 | reflected = V - normal * 2.0f * V.dot(normal);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | NX_INLINE void ComputeNormalCompo(NxVec3& normal_compo, const NxVec3& outward_dir, const NxVec3& outward_normal)
|
---|
| 76 | {
|
---|
| 77 | normal_compo = outward_normal * outward_dir.dot(outward_normal);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | NX_INLINE void ComputeTangentCompo(NxVec3& outward_dir, const NxVec3& outward_normal)
|
---|
| 81 | {
|
---|
| 82 | outward_dir -= outward_normal * outward_dir.dot(outward_normal);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | NX_INLINE void DecomposeVector(NxVec3& normal_compo, NxVec3& tangent_compo, const NxVec3& outward_dir, const NxVec3& outward_normal)
|
---|
| 86 | {
|
---|
| 87 | normal_compo = outward_normal * outward_dir.dot(outward_normal);
|
---|
| 88 | tangent_compo = outward_dir - normal_compo;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /** @} */
|
---|
| 92 | #endif
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | //AGCOPYRIGHTBEGIN
|
---|
| 96 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 97 | // Copyright © 2005 AGEIA Technologies.
|
---|
| 98 | // All rights reserved. www.ageia.com
|
---|
| 99 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 100 | //AGCOPYRIGHTEND
|
---|
| 101 |
|
---|