Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #52 from notlion/ray-plane

Add calcPlaneIntersection() to Ray
  • Loading branch information...
commit 46a071be02da6b3e6fc2b79e7dc74a03b28b0812 2 parents 0bf7908 + 9f065c7
Andrew Bell authored

Showing 2 changed files with 13 additions and 1 deletion. Show diff stats Hide diff stats

  1. +1 0  include/cinder/Ray.h
  2. +12 1 src/cinder/Ray.cpp
1  include/cinder/Ray.h
@@ -51,6 +51,7 @@ class Ray {
51 51 Vec3f calcPosition( float t ) const { return mOrigin + mDirection * t; }
52 52
53 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;
54 55
55 56 protected:
56 57 Vec3f mOrigin;
13 src/cinder/Ray.cpp
@@ -24,7 +24,7 @@
24 24
25 25 namespace cinder {
26 26
27   - // algorithm from "Fast, Minimum Storage Ray-Triangle Intersection"
  27 +// algorithm from "Fast, Minimum Storage Ray-Triangle Intersection"
28 28 bool Ray::calcTriangleIntersection( const Vec3f &vert0, const Vec3f &vert1, const Vec3f &vert2, float *result ) const
29 29 {
30 30 Vec3f edge1, edge2, tvec, pvec, qvec;
@@ -75,4 +75,15 @@ bool Ray::calcTriangleIntersection( const Vec3f &vert0, const Vec3f &vert1, cons
75 75 #endif
76 76 }
77 77
  78 +bool Ray::calcPlaneIntersection( const Vec3f &planeOrigin, const Vec3f &planeNormal, float *result ) const
  79 +{
  80 + float denom = planeNormal.dot(getDirection());
  81 +
  82 + if(denom != 0.0f){
  83 + *result = planeNormal.dot(planeOrigin - getOrigin()) / denom;
  84 + return true;
  85 + }
  86 + return false;
  87 +}
  88 +
78 89 } // namespace cinder

0 comments on commit 46a071b

Please sign in to comment.
Something went wrong with that request. Please try again.