Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Plane.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011, The Cinder Project, All rights reserved.
3  This code is intended for use with the Cinder C++ library: http://libcinder.org
4 
5  Portions of this code (C) Paul Houx
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
9  the following conditions are met:
10 
11  * Redistributions of source code must retain the above copyright notice, this list of conditions and
12  the following disclaimer.
13  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
14  the following disclaimer in the documentation and/or other materials provided with the distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
17  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
19  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23  POSSIBILITY OF SUCH DAMAGE.
24 */
25 
26 #pragma once
27 
28 #include "cinder/Vector.h"
29 #include <iostream>
30 
31 namespace cinder {
32 
33 template<typename T>
34 class Plane
35 {
36  public:
37  Plane() {}
38  Plane( const Vec3<T> &v1, const Vec3<T> &v2, const Vec3<T> &v3 );
39  Plane( const Vec3<T> &point, const Vec3<T> &normal );
40  Plane( T a, T b, T c, T d );
41 
43  void set( const Vec3<T> &v1, const Vec3<T> &v2, const Vec3<T> &v3 );
45  void set( const Vec3<T> &point, const Vec3<T> &normal );
47  void set( T a, T b, T c, T d );
48 
49  Vec3<T> getPoint() const { return mNormal * mDistance; };
50  const Vec3<T>& getNormal() const { return mNormal; };
51  T getDistance() const { return mDistance; }
52  T distance( const Vec3<T> &p ) const { return (mNormal.dot(p) - mDistance); };
53 
54  Vec3<T> reflectPoint( const Vec3<T> &p ) const { return mNormal * distance( p ) * -2 + p; }
55  Vec3<T> reflectVector( const Vec3<T> &v ) const { return mNormal * mNormal.dot(v) * 2 - v; }
56 
59 };
60 
63 
64 template<typename T>
65 std::ostream& operator<<( std::ostream &o, const Plane<T> &p )
66 {
67  return o << "(" << p.mNormal << ", " << p.mDistance << ")";
68 }
69 
70 
71 class PlaneExc : public std::exception {
72  public:
73  virtual const char* what() const throw() { return "Invalid parameters specified"; }
74 };
75 
76 } // namespace cinder
Plane< float > Planef
Definition: Plane.h:61
void set(const Vec3< T > &v1, const Vec3< T > &v2, const Vec3< T > &v3)
Defines a plane using 3 points.
Definition: Plane.cpp:49
T distance(const Vec3< T > &p) const
Definition: Plane.h:52
T getDistance() const
Definition: Plane.h:51
Vec3< T > mNormal
Definition: Plane.h:57
void normal(float x, float y, float z)
Sets the current normal.
Definition: dx.cpp:848
GLfloat GLfloat v1
Definition: GLee.h:2445
T mDistance
Definition: Plane.h:58
const Vec3< T > & getNormal() const
Definition: Plane.h:50
Plane()
Definition: Plane.h:37
Definition: Vector.h:65
Vec3< T > getPoint() const
Definition: Plane.h:49
Definition: Plane.h:34
GLfloat GLfloat GLfloat v2
Definition: GLee.h:2451
Vec3< T > reflectVector(const Vec3< T > &v) const
Definition: Plane.h:55
const GLdouble * v
Definition: GLee.h:1384
GLboolean GLboolean GLboolean b
Definition: GLee.h:2964
GLfloat GLfloat p
Definition: GLee.h:8473
const GLubyte * c
Definition: GLee.h:8491
Plane< double > Planed
Definition: Plane.h:62
GLboolean GLboolean GLboolean GLboolean a
Definition: GLee.h:2964
Vec3< T > reflectPoint(const Vec3< T > &p) const
Definition: Plane.h:54
Definition: Plane.h:71
virtual const char * what() const
Definition: Plane.h:73
GLfloat GLfloat GLfloat GLfloat v3
Definition: GLee.h:2457