source: projectionDesigner/trunk/projdesigner/include/gmtl/Ray.h @ 372

Last change on this file since 372 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 3.5 KB
RevLine 
[4]1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          Ray.h,v
10 * Date modified: 2003/02/23 07:16:49
11 * Version:       1.2
12 * -----------------------------------------------------------------
13 *
14 *********************************************************** ggt-head end */
15/*************************************************************** ggt-cpr beg
16*
17* GGT: The Generic Graphics Toolkit
18* Copyright (C) 2001,2002 Allen Bierbaum
19*
20* This library is free software; you can redistribute it and/or
21* modify it under the terms of the GNU Lesser General Public
22* License as published by the Free Software Foundation; either
23* version 2.1 of the License, or (at your option) any later version.
24*
25* This library is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28* Lesser General Public License for more details.
29*
30* You should have received a copy of the GNU Lesser General Public
31* License along with this library; if not, write to the Free Software
32* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33*
34 ************************************************************ ggt-cpr end */
35#ifndef _GMTL_RAY_H_
36#define _GMTL_RAY_H_
37
38#include <gmtl/Point.h>
39#include <gmtl/Vec.h>
40#include <gmtl/VecOps.h>
41
42namespace gmtl {
43
44/**
45 * Describes a ray. This is represented by a point origin O and a
46 * normalized vector direction. Any point on the ray can be described as
47 *
48 * P(s) = O + Vs
49 *
50 * where 0 <= s <= 1
51 *
52 * @param DATA_TYPE     the internal type used for the point and vector
53 */
54template< class DATA_TYPE >
55class Ray
56{
57public:
58   /**
59    * Constructs a ray at the origin with a zero vector.
60    */
61   Ray()
62   {}
63
64   /**
65    * Constructs a ray with the given origin and vector.
66    *
67    * @param origin     the point at which the ray starts
68    * @param dir        the vector describing the direction and length of the
69    *                   ray starting at origin
70    */
71   Ray( const Point<DATA_TYPE, 3>& origin, const Vec<DATA_TYPE, 3>& dir )
72      : mOrigin( origin ), mDir( dir )
73   {}
74
75   
76
77   /**
78    * Constructs an exact duplicate of the given ray.
79    *
80    * @param lineseg    the ray to copy
81    */
82   Ray( const Ray& lineseg )
83   {
84      mOrigin = lineseg.mOrigin;
85      mDir = lineseg.mDir;
86   }
87
88   /**
89    * Gets the origin of the ray.
90    *
91    * @return  the point at the beginning of the line
92    */
93   const Point<DATA_TYPE, 3>& getOrigin() const
94   {
95      return mOrigin;
96   }
97
98   /**
99    * Sets the origin point for this ray.
100    *
101    * @param origin     the point at which the ray starts
102    */
103   void setOrigin( const Point<DATA_TYPE, 3>& origin )
104   {
105      mOrigin = origin;
106   }
107
108   /**
109    * Gets the vector describing the direction and length of the ray.
110    *
111    * @return  the ray's vector
112    */
113   const Vec<DATA_TYPE, 3>& getDir() const
114   {
115      return mDir;
116   }
117
118   /**
119    * Sets the vector describing the direction and length of the ray.
120    *
121    * @param dir     the ray's vector
122    */
123   void setDir( const Vec<DATA_TYPE, 3>& dir )
124   {
125      mDir = dir;
126   }
127
128public:
129   /**
130    * The origin of the ray.
131    */
132   Point<DATA_TYPE, 3> mOrigin;
133
134   /**
135    * The vector along which the ray lies.
136    */
137   Vec<DATA_TYPE, 3> mDir;
138};
139
140
141// --- helper types --- //
142typedef Ray<float>  Rayf;
143typedef Ray<double> Rayd;
144}
145
146#endif
Note: See TracBrowser for help on using the repository browser.