POV-Ray : Newsgroups : povray.advanced-users : Collision Detection : Collision Detection Server Time
29 Jul 2024 10:25:49 EDT (-0400)
  Collision Detection  
From: Mike
Date: 2 Aug 2002 23:40:02
Message: <web.3d4b4ff6fac903ee9d3dc080@news.povray.org>
I have been working on this for hours and have gotten close, but no cigar.

What I want is for a sphere to follow the curves of something below it as it
is animated (the ultimate goal is to have a tire [torus] roll across a
height field).  I will post the code that I got so far...

=======================================================
===== CODE TO FOLLOW ==================================
=======================================================
#version 3.5;

#include "colors.inc"

global_settings {
  assumed_gamma 1.0
}

camera {
  location  <0.0, 0.5, -4.0>
  direction 1.5*z
  right     x*image_width/image_height
  look_at   <0.0, 0.0,  0.0>
}

sky_sphere {
  pigment {
    gradient y
    color_map {
      [0.0 rgb <0.6,0.7,1.0>]
      [0.7 rgb <0.0,0.1,0.8>]
    }
  }
}

light_source {
  <0, 0, 0>            // light's position (translated below)
  color rgb <1, 1, 1>  // light's color
  translate <-30, 30, -30>
}

// ----------------------------------------
#declare Ground =
  plane { y, -1 }

#declare Wheel=
  sphere {<0,-.75,0>,.25}

#declare Rock=
  union
    {
    sphere {<-1,-1,0>,.5}
    sphere {<0,-1,0>,.7}
    sphere {<1,-1,0>,.5}
    }

#macro MoveWheel()
  #declare initLoc=-2+clock*4;

  #declare height=0;

  #declare Norm=<0,0,0>;
  #declare intersect=trace(Rock,<initLoc,height,0>, <0,-1,0>, Norm);
  #debug concat("intersect: <",vstr(3,intersect,",",4,3))
  #debug concat("> norm:<",vstr(3,Norm,",",4,3),"> "," initLoc = ")
  #debug concat(str(initLoc,3,1),"\n")

  #declare height=height+(Norm.y/2);
  translate<initLoc,height,0>
#end


#declare Rock=
  union
    {
    sphere {<-1,-1,0>,.5}
    sphere {<0,-1,0>,.7}
    sphere {<1,-1,0>,.5}
    texture{pigment{color rgb<1,0,0>}}
    }

object {Ground pigment { color rgb <0.7,0.5,0.3> }}
object {Rock pigment{color rgb<1,0,0>}}

object
  {
  Wheel
  MoveWheel()
  pigment{color rgb<0,0,1>}
  }

=======================================================
===== END CODE ========================================
=======================================================

If you animate the above code, you will see my wheel go over the first and
third spheres more or less correctly, but it definitatly goes *inside* the
middle one.  Can anyone give me any idea why this is happening.

Thanks,
Mike

PS. If there is a better way to do this, I'm VERY open to suggestions.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.