From 11022618b327b52353cb03b56b44718681f745ab Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 3 Sep 2013 20:07:59 +1000 Subject: [PATCH] Add ray types --- src/cgmath/lib.rs | 2 ++ src/cgmath/ray.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/cgmath/ray.rs diff --git a/src/cgmath/lib.rs b/src/cgmath/lib.rs index c683f21..eace56f 100644 --- a/src/cgmath/lib.rs +++ b/src/cgmath/lib.rs @@ -28,6 +28,8 @@ pub mod point; pub mod quaternion; pub mod vector; +pub mod ray; + pub mod projection; pub mod util { diff --git a/src/cgmath/ray.rs b/src/cgmath/ray.rs new file mode 100644 index 0000000..ec6c06a --- /dev/null +++ b/src/cgmath/ray.rs @@ -0,0 +1,45 @@ +// Copyright 2013 The CGMath Developers. For a full listing of the authors, +// refer to the AUTHORS file at the top-level directionectory of this distribution. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use point::{Point2, Point3}; +use vector::{Vec2, Vec3}; + +#[deriving(Clone, Eq)] +pub struct Ray2 { + origin: Point2, + direction: Vec2, +} + +impl Ray2 { + /// Creates a new ray from a position coordinate and a direction vector + #[inline] + pub fn new(origin: Point2, direction: Vec2) -> Ray2 { + Ray2 { origin: origin, direction: direction } + } +} + +#[deriving(Clone, Eq)] +pub struct Ray3 { + origin: Point3, + direction: Vec3, +} + +impl Ray3 { + /// Creates a new ray from a position coordinate and a direction vector + #[inline] + pub fn new(origin: Point3, direction: Vec3) -> Ray3 { + Ray3 { origin: origin, direction: direction } + } +}