Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Ray.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Cinder Project: http://libcinder.org
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Vector.h"
26 
27 namespace cinder {
28 
29 class Ray {
30  public:
31  Ray() {}
32  Ray( const Vec3f &aOrigin, const Vec3f &aDirection ) : mOrigin( aOrigin ) { setDirection( aDirection ); }
33 
34  void setOrigin( const Vec3f &aOrigin ) { mOrigin = aOrigin; }
35  const Vec3f& getOrigin() const { return mOrigin; }
36 
37  void setDirection( const Vec3f &aDirection ) {
38  mDirection = aDirection;
39  mInvDirection = Vec3f( 1.0f / mDirection.x, 1.0f / mDirection.y, 1.0f / mDirection.z );
40  mSignX = ( mDirection.x < 0.0f ) ? 1 : 0;
41  mSignY = ( mDirection.y < 0.0f ) ? 1 : 0;
42  mSignZ = ( mDirection.z < 0.0f ) ? 1 : 0;
43  }
44  const Vec3f& getDirection() const { return mDirection; }
45  const Vec3f& getInverseDirection() const { return mInvDirection; }
46 
47  char getSignX() const { return mSignX; }
48  char getSignY() const { return mSignY; }
49  char getSignZ() const { return mSignZ; }
50 
51  Vec3f calcPosition( float t ) const { return mOrigin + mDirection * t; }
52 
53  bool calcTriangleIntersection( const Vec3f &vert0, const Vec3f &vert1, const Vec3f &vert2, float *result ) const;
54  bool calcPlaneIntersection( const Vec3f &origin, const Vec3f &normal, float *result ) const;
55 
56  protected:
59  // these are helpful to certain ray intersection algorithms
62 };
63 
64 } // namespace cinder
Ray(const Vec3f &aOrigin, const Vec3f &aDirection)
Definition: Ray.h:32
Vec3f calcPosition(float t) const
Definition: Ray.h:51
char mSignY
Definition: Ray.h:60
char mSignX
Definition: Ray.h:60
T z
Definition: Vector.h:321
T x
Definition: Vector.h:321
Definition: Ray.h:29
const Vec3f & getOrigin() const
Definition: Ray.h:35
T y
Definition: Vector.h:321
Vec3f mDirection
Definition: Ray.h:58
void normal(float x, float y, float z)
Sets the current normal.
Definition: dx.cpp:848
char getSignX() const
Definition: Ray.h:47
void setDirection(const Vec3f &aDirection)
Definition: Ray.h:37
Vec3< float > Vec3f
Definition: Vector.h:1317
Vec3f mOrigin
Definition: Ray.h:57
const Vec3f & getInverseDirection() const
Definition: Ray.h:45
bool calcTriangleIntersection(const Vec3f &vert0, const Vec3f &vert1, const Vec3f &vert2, float *result) const
Definition: Ray.cpp:28
void setOrigin(const Vec3f &aOrigin)
Definition: Ray.h:34
char mSignZ
Definition: Ray.h:60
bool calcPlaneIntersection(const Vec3f &origin, const Vec3f &normal, float *result) const
Definition: Ray.cpp:78
Vec3f mInvDirection
Definition: Ray.h:61
Ray()
Definition: Ray.h:31
GLdouble GLdouble t
Definition: GLee.h:1426
const Vec3f & getDirection() const
Definition: Ray.h:44
char getSignY() const
Definition: Ray.h:48
GLclampf f
Definition: GLee.h:15307
char getSignZ() const
Definition: Ray.h:49