[racket] Racket/gui : How to rotate a bitmap% ?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue May 10 11:38:31 EDT 2011

I see two sets of bugs related to rotations and transformations in
`racket/draw'. I'm fixing the bugs, but to work around them meanwhile:

 * use the 'smoothed drawing mode

 * stick to `set-origin' and `set-rotate'

For example, this `draw-rotated-bitmap' function draws a bitmap rotated
around its center point:

(define (draw-rotated-bitmap dc bm theta x y)
  (let ([t (send dc get-transformation)]
        [s (send dc get-smoothing)]
        [dx (/ (send plt get-width) 2)]
        [dy (/ (send plt get-height) 2)])
    (send dc set-smoothing 'smoothed)
    (send dc set-origin (+ x dx) (+ y dy))
    (send dc set-rotation theta)
    (send dc draw-bitmap plt (- dx) (- dy))
    (send dc set-smoothing s)
    (send dc set-transformation t)))

At Tue, 10 May 2011 14:53:42 +0200, Jyu 。 wrote:
> 
> @noelWelsh : I tested your advice, but it not run.. I tested to rotate and 
> translate then : The bitmap is turn around another point..I test to translate 
> and rotate then, the result is the same. Thanks you anyway.
> @Jay : I don't know how you can rotate bitmap with gl2d library.. I must draw 
> with another thing ? 
> 
> > Date: Mon, 9 May 2011 08:21:49 -0600
> > Subject: Re: [racket] Racket/gui : How to rotate a bitmap% ?
> > From: jay.mccarthy at gmail.com
> > To: noelwelsh at gmail.com
> > CC: julien-0659 at hotmail.fr; users at racket-lang.org
> > 
> > And that's the exact same thing you do in OpenGL too. My gl2d code
> > just packages those GL commands in a nice way. I have a new experiment
> > with doing the same thing but with a functional packaging:
> > 
> > https://github.com/get-bonus/get-bonus/blob/master/exp/gl.rkt
> > 
> > Look at the contracts at the bottom. (This package, btw, can very
> > easily get very high frame rates with very naive rendering, because it
> > automatically compiles common draw sequences to the card.)
> > 
> > Jay
> > 
> > 2011/5/9 Noel Welsh <noelwelsh at gmail.com>:
> > > 2011/5/9 Jyu 。 <julien-0659 at hotmail.fr>:
> > >> I can rotate a bitmap% around the (0,0) coordinate point, but I cannot do
> > >> the same for any other point..
> > >
> > > You probably need to call translate and then rotate. There is a
> > > transformation matrix maintained by the dc% which allows for rotation,
> > > translation, and scaling. If you first translate and then rotate you
> > > should be able to rotate your bitmap around an arbitrary point. (I say
> > > "should" because I haven't tested it myself.)
> > >
> > > HTH,
> > > N.
> > >
> > > _________________________________________________
> > >  For list-related administrative tasks:
> > >  http://lists.racket-lang.org/listinfo/users
> > 
> > 
> > 
> > -- 
> > Jay McCarthy <jay at cs.byu.edu>
> > Assistant Professor / Brigham Young University
> > http://faculty.cs.byu.edu/~jay
> > 
> > "The glory of God is Intelligence" - D&C 93
>  		 	   		  
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users



Posted on the users mailing list.