//------------------------------------------------------------------------------ // Author: Gero Mueller // Copyright: (c) 2006 Gero Mueller // License: MIT License //------------------------------------------------------------------------------ #ifndef BLUECORE_RAY_H #define BLUECORE_RAY_H #include "Scalar.h" #include "Vector.h" namespace BlueCore { template class RayTemplate { Vector3Template point, direction; public: /** * normalize the vector to length 1 */ inline RayTemplate() { } /** * constructor from point and direction */ template inline RayTemplate( const Vector3Template &point, const Vector3Template &direction ) { this->point = point; this->direction = direction.normalized(); } /** * set the point */ template inline void setPoint( const Vector3Template &point ) { this->point = point; } /** * set the direction */ template inline void setDirection( const Vector3Template &direction ) { this->direction = direction.normalized(); } /** * get point */ inline const Vector3Template &getPoint() const { return point; } /** * get direction */ inline const Vector3Template &getDirection() const { return direction; } /** * checks if a point lies on the ray */ template inline bool contains( const Vector3Template &a ) { return (a - point).parallel( direction ); } /** * calculate the distance between a point and the ray */ template inline T distance( const Vector3Template &a ) const { T t = direction.dot( a - point ); Vector3Template b = at(t) - a; return b.length(); } /** * gets the position at distance t */ template inline Vector3Template at( const T a ) const { return Vector3Template( point + direction * a ); } }; typedef RayTemplate RayFloat; typedef RayTemplate RayDouble; typedef RayTemplate Ray; } #endif