Advertisement
Guest User

Untitled

a guest
May 20th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1.  
  2. Vec3f Sphere3D::GetFarthestVert( const Vec3f& normalized_dir, const Vec3f& origin, const float radius ) {
  3.     Vec3f add( normalized_dir * radius );
  4.     add += origin;
  5.     return add;
  6. }
  7.  
  8. Vec3f Capsule3D::GetFarthestVert( const Vec3f& normalized_dir ) const {
  9.     const Vec3f a( Sphere3D::GetFarthestVert( normalized_dir, origin, radius ) );
  10.     const Vec3f b( Sphere3D::GetFarthestVert( normalized_dir, GetEnd(), radius ) );
  11.  
  12.     if ( a.Dot( normalized_dir ) > b.Dot( normalized_dir ) )
  13.         return a;
  14.     return b;
  15. }
  16.  
  17. Vec3f Cylinder3D::GetFarthestVert( const Vec3f& normalized_dir ) const {
  18.     const Vec3f spherePoint( Sphere3D::GetFarthestVert( normalized_dir, GetEnd(), radius ) );
  19.  
  20.     if ( origin.Dot( normalized_dir ) > spherePoint.Dot( normalized_dir ) )
  21.         return origin;
  22.  
  23.     // ** if the distance of the point is farther than the end of the cylinder, it exists on the sphere and we need to move it
  24.     const float dist = Plane3f::DistanceToPoint( spherePoint, normal, origin );
  25.     if ( dist > length )
  26.         return spherePoint - normal * (dist - length);
  27.  
  28.     return spherePoint;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement