[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby-gnome2 question

Joe Van Dyk

2/18/2005 6:45:00 PM

I have a GnomeCanvas Group that I'm trying to rotate (in 2D).

I know which direction the "top" of the group should be pointing.

My initial attempt was
affine = Art::Affine.new([Math.cos(180), -Math.sin(180), 0,
Math.sin(180), Math.cos(180), 0])
@group.affine_absolute(affine)

That was to rotate the object 180 degrees, but it didn't work too
well. I'm pretty new to all this matrix transformation / graphical
stuff. Could someone tell me if I'm on the right track?

Thanks,
Joe Van Dyk


5 Answers

Joe Van Dyk

2/18/2005 7:12:00 PM

0

On Fri, 18 Feb 2005 10:44:29 -0800, Joe Van Dyk <joevandyk@gmail.com> wrote:
> I have a GnomeCanvas Group that I'm trying to rotate (in 2D).
>
> I know which direction the "top" of the group should be pointing.
>
> My initial attempt was
> affine = Art::Affine.new([Math.cos(180), -Math.sin(180), 0,
> Math.sin(180), Math.cos(180), 0])
> @group.affine_absolute(affine)
>
> That was to rotate the object 180 degrees, but it didn't work too
> well. I'm pretty new to all this matrix transformation / graphical
> stuff. Could someone tell me if I'm on the right track?
>

Nevermind, I got it. Reading through the C LibArt documentation, the
affine matrix needs to be in (x1, y1, x2, y2, x3, y3) format, not (x1,
x2, x3, y1, y2, y3) as I assume.


Joe Van Dyk

2/18/2005 9:46:00 PM

0

On Fri, 18 Feb 2005 11:11:25 -0800, Joe Van Dyk <joevandyk@gmail.com> wrote:
> On Fri, 18 Feb 2005 10:44:29 -0800, Joe Van Dyk <joevandyk@gmail.com> wrote:
> > I have a GnomeCanvas Group that I'm trying to rotate (in 2D).
> >
> > I know which direction the "top" of the group should be pointing.
> >
> > My initial attempt was
> > affine = Art::Affine.new([Math.cos(180), -Math.sin(180), 0,
> > Math.sin(180), Math.cos(180), 0])
> > @group.affine_absolute(affine)
> >
> > That was to rotate the object 180 degrees, but it didn't work too
> > well. I'm pretty new to all this matrix transformation / graphical
> > stuff. Could someone tell me if I'm on the right track?
> >
>
> Nevermind, I got it. Reading through the C LibArt documentation, the
> affine matrix needs to be in (x1, y1, x2, y2, x3, y3) format, not (x1,
> x2, x3, y1, y2, y3) as I assume.

Well, I thought I had it.

I have an Gnome::CanvasItem that's, say, at position (100, 100). When
I attempt to use a rotation affine translation, it rotates and moves
the object to some other place.

All I want to do is be able to rotate the item by a certain amount of
degrees in 2D space and have it stay at the same x/y coordinate.

Any ideas?


Martin DeMello

2/19/2005 10:21:00 PM

0

Joe Van Dyk <joevandyk@gmail.com> wrote:
>
> All I want to do is be able to rotate the item by a certain amount of
> degrees in 2D space and have it stay at the same x/y coordinate.
>
> Any ideas?

Not familiar with the gnome api, but in general you need to translate
the object so that the rotation point is on the origin, apply the
rotation matrix, and then translate it back.

martin

Joe Van Dyk

2/21/2005 6:07:00 PM

0

On Sun, 20 Feb 2005 07:24:43 +0900, Martin DeMello
<martindemello@yahoo.com> wrote:
> Joe Van Dyk <joevandyk@gmail.com> wrote:
> >
> > All I want to do is be able to rotate the item by a certain amount of
> > degrees in 2D space and have it stay at the same x/y coordinate.
> >
> > Any ideas?
>
> Not familiar with the gnome api, but in general you need to translate
> the object so that the rotation point is on the origin, apply the
> rotation matrix, and then translate it back.
>
> martin

Ah.... the origin of the object?


Martin DeMello

2/23/2005 7:12:00 PM

0

Joe Van Dyk <joevandyk@gmail.com> wrote:
> On Sun, 20 Feb 2005 07:24:43 +0900, Martin DeMello
> >
> > Not familiar with the gnome api, but in general you need to translate
> > the object so that the rotation point is on the origin, apply the
> > rotation matrix, and then translate it back.
>
> Ah.... the origin of the object?

No, the origin of your coordinate system. For instance, let your object
be at (100,100) and say you want to rotate it around the point
(100,100). Then the first thing you need to do is translate the rotation
point to 0,0, which means translating the object by -100, -100. Then
rotate, then translate back. So the operation is

final = T(100,100) R(theta) T(-100, -100) original

since matrix multiplication goes from right to left. Or, in function
form

T1 = art_affine_translate(-100, -100)
T2 = art_affine_translate(100, 100)
R = art_affine_rotate(theta)

final = T2*(R*(T1*original))

http://www.cs.wpi.edu/~emmanuel/courses/cs4731/slides/lec...
looks like a nice reference.

martin