[plt-scheme] some more frtime questions

From: Dave Griffiths (dave at pawfal.org)
Date: Mon Feb 11 01:47:31 EST 2008

Hi Greg,

>> I've made some more progress with FrTime/Fluxus - I'm working on some
>> smaller examples to play with collision detection, and it's going well
>> so far, using the pong example to learn from.
> Sounds good.  :-)  Note that the pong demo does collision-detection in
> a pretty naive way, so you'll probably want to find something more
> clever before long.
>> I'd just like to confirm that I'll need to write a 3D version of posn -
>> as I can't seem to use scheme vectors as behaviours. Is this because
>> FrTime supports structs but not vectors as behaviours?
> That's strange.  FrTime *should* let you use vectors without any
> trouble.  Could you send me an example of what you're trying to do and
> how it doesn't work?

silly me, fixed this - I just wasn't calling value-now on the vector, just
the elements.

>> Also, if I want to use fully supported 3D vectors this way, I'm assuming
>> I won't be able to use the vector maths in fluxus - which is part of a
>> binary extension.
> I don't understand what this means.  Does fluxus define a custom 3d
> vector struct and a bunch of operations for it?  If so, there ought to
> be a way to reuse all that code; it may just require a little extra
> work on the Scheme and/or FrTime side(s).  That I'd be glad to help
> with.

fluxus uses ordinary scheme vectors, but defines a bunch of procedures to
operate on them (implemented in C++ for speed):

in the following example (which randomly changes the colour of a sphere
when a cube is collided with it) I've had to make my own 'dist' procedure
(distance between vectors taken as points) to do the collision calculation
- if I swap 'dist' for the equivalent in fluxus - 'vdist', it stops

(require (lib "frisbee.ss" "fluxus-0.14"))

(define player-pos
  (vector (integral
                (lambda (key)
                  (case key
                    ((#\a) -0.01)
                    ((#\d) 0.01)))
                keyboard) 0))

          (+ (integral
                (lambda (key)
                  (case key
                    ((#\s) -0.01)
                    ((#\w) 0.01)))
                keyboard) 0)) 5)

(define npc-pos (vector 0 0 0))

(define (sq x) (* x x))

(define (dist a b)
     (+ (sq (- (vector-ref a 0) (vector-ref b 0)))
        (sq (- (vector-ref a 1) (vector-ref b 1)))
        (sq (- (vector-ref a 2) (vector-ref b 2))))))

   #:translate player-pos)
   #:translate npc-pos
   #:colour (hold
              (lambda (_)
                 (lambda (a b)
                   (vector (rndflt) (rndflt) (rndflt)))
                 player-pos npc-pos))
              (when-e (< (dist player-pos npc-pos) 2)))
             (vector 1 1 1))

Posted on the users mailing list.