[plt-scheme] some more frtime questions

From: Dave Griffiths (dave at pawfal.org)
Date: Mon Feb 11 17:46:39 EST 2008

Hi Greg,

I didn't realise you could do that - it works a treat.

Thanks! You saved me a lot of work ;)

dave

On Mon, 2008-02-11 at 11:48 -0500, Gregory Cooper wrote:
> Hi Dave,
> 
> You can call the C++ code, but you'll have to make sure not to pass it
> any behaviors (or vectors of behaviors).  The easiest way to ensure
> this is probably to 'lift' all of your vector operations:
> 
> (require (lifted (lib "maths.ss" "fluxus-0.14") vmul vadd vsub ...))
> 
> If you do this, you'll also need to lift the constructor and accessors
> for your vectors.  Since 'vector' and 'vector-ref' are already bound
> in FrTime, the easiest thing might be to use different names, e.g.:
> 
> (define (vec3 x y z)
>   (lift #f vector x y z))
> 
> (define (vec3-x v)
>   (lift #t vector-ref v 0))
> 
> etc.
> 
> Cheers,
> Greg
> 
> On 2/11/08, Dave Griffiths <dave at pawfal.org> wrote:
> > 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):
> > http://www.pawfal.org/Software/fluxus/docs/0.13/en/maths.html
> >
> > 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
> > working.
> >
> > (require (lib "frisbee.ss" "fluxus-0.14"))
> >
> > (define player-pos
> >   (vector (integral
> >               (hold
> >                (map-e
> >                 (lambda (key)
> >                   (case key
> >                     ((#\a) -0.01)
> >                     ((#\d) 0.01)))
> >                 keyboard) 0))
> >
> >           (+ (integral
> >               (hold
> >                (map-e
> >                 (lambda (key)
> >                   (case key
> >                     ((#\s) -0.01)
> >                     ((#\w) 0.01)))
> >                 keyboard) 0)) 5)
> >           0))
> >
> > (define npc-pos (vector 0 0 0))
> >
> > (define (sq x) (* x x))
> >
> > (define (dist a b)
> >     (sqrt
> >      (+ (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))))))
> >
> > (scene
> >  (list
> >   (cube
> >    #:translate player-pos)
> >   (sphere
> >    #:translate npc-pos
> >    #:colour (hold
> >              (map-e
> >               (lambda (_)
> >                 (snapshot/apply
> >                  (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.