[plt-scheme] some more frtime questions

From: Dave Griffiths (dave at pawfal.org)
Date: Sat Feb 16 12:13:15 EST 2008

Hi Greg, me again ;)

Bit of a sticky problem, with I'm sure a simple answer I'm not seeing -
predictably, I want to be able to delete objects when they collide with
other objects.

This code gives me a moving line of cubes, one appearing every second.
When the player moves inside the collision sphere they get removed by
the filter:

(define objects
  (collect-b 
   (metro 1) '() 
   (lambda (e lst)
     (cons 
      (object 
       #:shape 'cube
       #:colour (vec3 1 0 0)
       #:translate (vsub (vec3-integral (vec3 0 0.002 0)) (vec3 0 3 0)))
      (filter 
       (lambda (ob)
         (> (vdist (value-now (object-struct-translate (value-now ob))) 
                   (value-now player-pos)) 2))
       lst)))))

('metro' makes an event source which fires every second btw)

The problem is that my cubes only get checked for collision when a new
one is created, once a second. I can't figure out how to get at and
filter this list from another place - or is there a way of filtering a
behaviour? I can also do something like this:

(define objects
  (collect-b 
   (metro 1) '() 
   (lambda (e lst)
     (let ((pos (vsub (vec3-integral (vec3 0 0.002 0)) (vec3 0 3 0))))
       (cons 
        (if (> (vdist pos player-pos) 2)
            (object 
             #:shape 'cube
             #:colour (vec3 1 0 0)
             #:translate pos))
        lst)))))

Which feels more on the right track, but of course, they pop back into
existence when they move out of the collision volume... Is there some
way of 'locking' them off when they have collided?

As usual, for the full context, my code is here:
http://www.pawfal.org/flotsam/frisbee/
The script in question is:
http://www.pawfal.org/flotsam/frisbee/examples/delete.scm 

Many thanks.

dave

http://www.pawfal.org/dave



Posted on the users mailing list.