Button vs. Message box scripts; P.S. Invert matrices?

Jim Hurley jhurley at infostations.com
Sun Mar 30 02:29:01 EST 2003


>on Fri Mar 28 09:55:01 2003
>Jim Hurley wrote:
>
>>I ran the following single line in the msg box:
>  >revrotatepoly graphic "MyPoly", 90
>>and sure enough, the graphic "MyPoly" rotated 90
>>degrees.
>>But the button handler:
>>On mouseUp
>>revrotatepoly graphic "MyPoly", 90
>>end mouseUp
>>return an error: "Chunk source is not a container."
>>Why is it that the msg box can find the graphic
>>but the button cannot?
>
>My guess is that this function is using the
>selectedobject as argument, so probably if
>you script first "select graphic number X"
>it would work. I don't have RunRev installed
>in this machine to test now.
>
>>P.S. I don't suppose anyone has a routine to
>>invert matrices?
>
>Actually, I do. If you can wait until tomorrow,
>I can clean it a bit and upload to some place.
>
>Using matrices for scaling, rotating and skewing
>polygonal graphics is extraordinarly exact.
>
>You can transform the graphics as many times as
>you wish and always can retrace your steps to
>get the original graphic.
>
>The key for the exactitude of all these operations
>is to hold the exact values returned by these
>operations in a custom property of the graphic.
>I've called this property the "exactPoints"
>and is get BEFORE every operation and set AFTER the
>operations are done. Of course, if the exactPoints
>of a graphics is empty then is necesary to use
>the points, but only one time, because all operations
>create and set this custom property in the graphic.
>
>Serious graphic users will love to use matrices
>for rotating, skewing and scaling polygon graphics.
>
>Alejandro
>
=====

Alejandro,

Selecting the graphic first doesn't help, but thanks for the 
suggestion. I can't believe someone hasn't discovered this problem 
with revRotatePoly. It is so bazaar.  It works in the msg box but not 
in a button, card or stack. Usually it is the other  way around.

But I did find the following routine in the archives for rotating 
lines and polygons. It is very nice. It rotates the object about an 
*arbitrary* point, not just the  object's loc. The author is Derek 
Huby.

It doesn't use the explicit matrix  formalism to rotate vectors but 
the mathematics is equivalent.

I get the feeling, since you mention it with reference to rotation in 
a plane, that your matrix inversion routine might be for two 
dimensions only, but I'll be delighted to be wrong.  Unfortunately I 
need to invert a 4x4. But I understand. Matrix inversion in general 
is a major computational challenge.

But  here is Derek's very nice rotations program. It presumes you 
have  constructed a graphic named: "CoR" which serves as the axis of 
rotation.

Let me know if you find the problem with revRotatePoly.

Regards,

Jim

on rotateshape shapename, angle
   -- this will rotate gc shapename through 'angle' degrees anticlockwise

   -- check the graphic exists
   if there is not a graphic shapename
   then
     exit rotateshape
   end if

   --"CoR" (centre of rotation) is a small cicular 'grabbable' gc 
marking the centre
   put item 1 of the loc of graphic "CoR" into XCentre
   put item 2 of the loc of graphic "CoR" into YCentre

   --"origPts" is a custom property containing the original point list.
   --You can't just rotate from the 'current' point list; rounding errors
will 'degrade' the shape.

   if the origPts of graphic shapename = empty
   then
     set the origPts of graphic shapename to the points of graphic shapename
   end if

   --"rotAngle" is a custom property that tells you how far the shape is
--currently rotated

   if the rotAngle of graphic shapename = empty
   then
     set the rotAngle of graphic shapename to 0
   end if

   put empty into newPointList
   put the origPts of graphic shapename into pointList

   -- Build new list of coords relative to CoR as origin
   repeat for each line k in pointlist
     put (item 1 of k)- Xcentre & "," & (item 2 of k)- Ycentre & return after
newPointList
   end repeat


   set the rotangle of graphic shapename to (the rotangle of graphic
shapename + angle) mod 360


   put sin(the rotangle of graphic shapename * pi/180) into S
   put cos(the rotangle of graphic shapename * pi/180) into C

   put empty into rotptlist

   --Now do the actual rotation
   repeat for each line k in newPointlist
     put round(c*(item 1 of k)+ s*(item 2 of k) + xCentre) after rotptlist
     put "," after rotptlist
     put round(c*(item 2 of k) - s*(item 1 of k)+ Ycentre)after rotptlist
     put return after rotPtList
   end repeat

   set the points of graphic shapename to rotPtlist

end rotateshape

**



More information about the use-livecode mailing list