From 1be5be38ea1b089893ca44f3a84a39c8230dd07f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 15 Apr 2015 18:59:28 +1000 Subject: [PATCH] ray: add convenience point-point constructor --- ray.cpp | 13 +++++++++++++ ray.hpp | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/ray.cpp b/ray.cpp index 23218c35..7b269735 100644 --- a/ray.cpp +++ b/ray.cpp @@ -32,6 +32,19 @@ ray::ray (util::point _origin, } +//----------------------------------------------------------------------------- +template +ray +ray::make (util::point origin, + util::point target) +{ + return { + origin, + (target - origin).normalised () + }; +} + + /////////////////////////////////////////////////////////////////////////////// /// returns the distance along the ray in a ray-plane intersection /// diff --git a/ray.hpp b/ray.hpp index ac95cabf..caca6810 100644 --- a/ray.hpp +++ b/ray.hpp @@ -32,6 +32,10 @@ namespace util { ray (point origin, vector direction); + static + ray make (point origin, + point target); + // intersection tests T intersect (plane) const; T intersect (AABB) const;