[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Suggestions
. . -> [Subject]  Miniwindow image rotation
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Miniwindow image rotation

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  3  

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Wed 25 Aug 2010 10:37 PM (UTC)
Message
I suggest having a way to rotate an image as you draw it to another window. With this you could have (for example) a "spinner" image that you could animate by rotating it a number of degrees/radians.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Wed 25 Aug 2010 11:18 PM (UTC)
Message
I suggest you use sprites instead.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #2 on Wed 25 Aug 2010 11:33 PM (UTC)

Amended on Thu 26 Aug 2010 12:12 AM (UTC) by Twisol

Message
When the animation is the same image, just rotated, using sprites seems like overkill. =/

I'm thinking about more than just file images, though. You can use WindowImageFromWindow() to get the contents of a miniwindow as an image.

Rotation can be useful in other ways, too. If you look at OpenGL, there's a glRotatef() function that affects how later operations are drawn, effecting a rotational effect (EDIT: brought to you by the department of redundancy department). If there was a way to rotate and draw images, you could take a similar approach, drawing something on a separate, invisible canvas and applying it to the main window.

I know of no way to draw rotated rectangles, either. You could argue that a diamond can be drawn with lines, but then what do you say about using WindowCircleOp to draw a filled (textured) rectangle?

If you can rotate an image, you can rotate anything, because windows can be converted to images. Rotation is genuinely useful, and it makes many tasks easier. My only concern is how hard it might be to integrate into the current API... but lets deal with that only if we decide this is worth having.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Wed 25 Aug 2010 11:40 PM (UTC)

Amended on Thu 26 Aug 2010 12:13 AM (UTC) by Twisol

Message
I had one idea for adding this to the API. (Yes, I should practice what I preach, shush.) An image can have a rotational variable added to it, and a new function WindowImageRotate() would affect it. It would start at 0 (no rotation). When the image is later drawn with WindowImageDraw(Alpha), they would take this value into account, rotating the image before it's drawn.

The image isn't -actually- rotated when WindowImageRotate() is used, because due to the rectangular nature of images, that would either clip the image's corners or require a resizing of the canvas. It's simpler just to store a rotational value, and use that when the image is drawn.

Example:
WindowImageRotate("window", "image", 45) -- degrees, in this example
WindowDrawImage("window", "image", 0, 0, 0, 0, 1, 0, 0, 0, 0)


No other function API is affected, so it's totally backwards-compatible. If you don't use WindowImageRotate, it's just not rotated.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #4 on Thu 26 Aug 2010 05:32 AM (UTC)
Message
If something is already feasible, what is wrong with the current feasibility?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Thu 26 Aug 2010 05:35 AM (UTC)

Amended on Thu 26 Aug 2010 06:00 AM (UTC) by Twisol

Message
David Haley said:

If something is already feasible, what is wrong with the current feasibility?


Sorry David, I don't understand what you mean. Rotating images is effectively impossible right now. I thought I explained why it would be a very good thing to have in my second post, too. :S Can you elaborate?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 26 Aug 2010 06:02 AM (UTC)
Message
Twisol said:

I suggest having a way to rotate an image as you draw it to another window. With this you could have (for example) a "spinner" image that you could animate by rotating it a number of degrees/radians.


I was about to reply "absolutely not, it would be too slow", when I discovered the SetWorldTransform API. This simplifies things considerably.

See:

http://msdn.microsoft.com/en-us/library/dd145104%28VS.85%29.aspx


I had thought it would be nice to have (say) rotated text, but thought the overhead would be prohibitive. However it seems not.

Proviso - this API only works on Windows 98 upwards, however I think most people have moved on from Windows 95 by now, eh?

Twisol said:

The image isn't -actually- rotated when WindowImageRotate() is used, because due to the rectangular nature of images, that would either clip the image's corners or require a resizing of the canvas. It's simpler just to store a rotational value, and use that when the image is drawn.


I can't say I agree with this bit.

For maximum generality I am experimenting with setting up a translation matrix (see the API documentation mentioned above). This lets you set up 6 numbers, M11, M12, M21, M22, Dx and Dy.

Effectively this lets you control the translation between x and x' as a multiplication of the old x/y position with a multiplier (applied independently to x and y) followed by a displacement.

In a nutshell, this lets you scale, rotate, shear or reflect depending on the six values you supply.

http://msdn.microsoft.com/en-us/library/dd145228%28v=VS.85%29.aspx

So this gives you so much more than mere rotation, you could scale as well (or reflect).

I think for simplicity we will assume that the source image is to be completely applied to the destination (in other words, excluding sub-images), and at a given point.

You are correct that with virtually any transformation (that is, excluding mere reflection) some clipping or resizing will be required. However that is really just a case of having the room available to start with.

So, for example, if I had a long, thin image with the word "inventory" in it, and wanted to rotate it 90 degrees then the destination would need to be as deep as the source is wide, for it to fit.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #7 on Thu 26 Aug 2010 06:07 AM (UTC)
Message
So, what, we get WindowImageTransform?

...

You rule.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #8 on Thu 26 Aug 2010 06:11 AM (UTC)

Amended on Thu 26 Aug 2010 06:28 AM (UTC) by Twisol

Message
Nick Gammon said:
Twisol said:

The image isn't -actually- rotated when WindowImageRotate() is used, because due to the rectangular nature of images, that would either clip the image's corners or require a resizing of the canvas. It's simpler just to store a rotational value, and use that when the image is drawn.


I can't say I agree with this bit.

For maximum generality I am experimenting with setting up a translation matrix (see the API documentation mentioned above). This lets you set up 6 numbers, M11, M12, M21, M22, Dx and Dy.

Effectively this lets you control the translation between x and x' as a multiplication of the old x/y position with a multiplier (applied independently to x and y) followed by a displacement.

In a nutshell, this lets you scale, rotate, shear or reflect depending on the six values you supply.

http://msdn.microsoft.com/en-us/library/dd145228%28v=VS.85%29.aspx

So this gives you so much more than mere rotation, you could scale as well (or reflect).

I think for simplicity we will assume that the source image is to be completely applied to the destination (in other words, excluding sub-images), and at a given point.

You are correct that with virtually any transformation (that is, excluding mere reflection) some clipping or resizing will be required. However that is really just a case of having the room available to start with.

So, for example, if I had a long, thin image with the word "inventory" in it, and wanted to rotate it 90 degrees then the destination would need to be as deep as the source is wide, for it to fit.


([EDIT]: I think I might've misunderstood you here; if I'm way off here, can you set me straight?)

Well, I realize that nothing prevents it from working if you apply the transformation immediately. My thought was that when you apply a transformation, you would only store the transformation matrix with the image; when you draw the image, -then- the matrix would be applied. Basically, the image clipping is based on the size of the target canvas rather than that of the source canvas.

If you have to explicitly size a window so you're sure you can rotate it to any angle you want, I'd think it would be a bit of a hassle. :S And the only difference is when you apply the transformation.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #9 on Thu 26 Aug 2010 06:40 AM (UTC)
Message
I am making a separate function WindowTranslateImage that lets you copy/transform from an image into the miniwindow via a specified set of 6 transformation parameters (two multiplications and one addition per x and y).

This avoids the complexity of also trying to select subimages, or have scaling applied via the normal WindowDrawImage.

You don't have to explicitly size anything, however if the destination is not the right size, the image won't fit (same as at present, really).

For example, if you make Dx and Dy large (eg. 1000) so that the image pixels are moved off the right of the bitmap, well you won't see it. So don't do that.

I don't think there is a simple generic solution that guarantees you will see the resulting image. A lot depends on the scaling, the rotation and the displacement.

Effectively the Dx and Dy parameters will control what you are rotating around (assuming you are rotating at all). With some values it will rotate around a corner, with others, around the center, with others around some other point.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Thu 26 Aug 2010 06:43 AM (UTC)
Message
Twisol said:

Well, I realize that nothing prevents it from working if you apply the transformation immediately. My thought was that when you apply a transformation, you would only store the transformation matrix with the image; when you draw the image, -then- the matrix would be applied. Basically, the image clipping is based on the size of the target canvas rather than that of the source canvas.


Imagine you have cut out a small picture and have a large piece of paper on your desk. You can rotate the picture, and then throw it down somewhere onto the paper. The first four parameters control the rotation and the last two where it ends up, translated in the x and y direction.

If it happens to land on the paper on your desk, so it is completely on top of it, well and good. If it is off to one side it might be clipped.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #11 on Thu 26 Aug 2010 06:44 AM (UTC)

Amended on Thu 26 Aug 2010 06:49 AM (UTC) by Twisol

Message
Okay, I see. This new function actually transforms and draws at the same time? That's all that had confused me, I get it now.

Nick Gammon said:
If it happens to land on the paper on your desk, so it is completely on top of it, well and good. If it is off to one side it might be clipped.

To put it in perspective, I thought you were talking about transforming the content of the page (without moving the page). So, naturally, some content would not fall on the page. And no desk was involved. (I think that would be an extremely bad idea.)


The reason I wanted to separate the transformation from the drawing is because we already have, uh... three(?) other image-drawing functions: WindowDrawImage, WindowDrawImageAlpha, and WindowImageOp. Setting the transform separately means these three functions can still be used with transformations.

I think the term is "orthogonality".

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Thu 26 Aug 2010 07:06 AM (UTC)
Message
Twisol said:

I suggest having a way to rotate an image as you draw it to another window.


That's what I did. You rotate it as you copy it to the window.

Quote:

To put it in perspective, I thought you were talking about transforming the content of the page (without moving the page).


Well that's a bit fiddlier. If you mean transforming bits of the page then what gets left behind under the rotated bit?

And I'm not too keen on having some sort of mode that gets stored with an image (like a rotation) because then you will never really be sure if someone earlier on set up a rotation on it. Having to explicitly transform/rotate as a single operation makes it clear that you are rotating right now.

If you look at the source, right now images are just bitmaps associated with an image name. There is no meta-data stored with them.

I'm not trying to replace Photoshop here (well, not yet).

With this new function you could rotate maps (eg. so that "up" is the way you are facing), or rotate text so labels could run sideways (assuming you pre-draw the text into a temporary window).

Reflection and shearing could be used to make nice shadows, but again, let's not get too far ahead of ourselves. This isn't supposed to be a 3D client.

Having said that though, with the transformation matrix you could somewhat more easily bang images onto a window with some sort of perspective (or I think you could, this is starting to stretch my knowledge of 3D maths, and matrices).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Thu 26 Aug 2010 07:13 AM (UTC)

Amended on Thu 26 Aug 2010 07:14 AM (UTC) by Nick Gammon

Message
If you want to give your brain a work-out, read this about matrices:

http://en.wikipedia.org/wiki/Matrix_(mathematics)

A little way down (Linear transformations) it mentions how matrices can be used to shear, rotate, squeeze, scale and flip.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #14 on Thu 26 Aug 2010 07:19 AM (UTC)

Amended on Thu 26 Aug 2010 07:24 AM (UTC) by Twisol

Message
Nick Gammon said:

Quote:

To put it in perspective, I thought you were talking about transforming the content of the page (without moving the page).

And I'm not too keen on having some sort of mode that gets stored with an image (like a rotation) because then you will never really be sure if someone earlier on set up a rotation on it. Having to explicitly transform/rotate as a single operation makes it clear that you are rotating right now.

Actually, I think that's a benefit. You can compose multiple transformations together by multiplying the matrices, so theoretically you could apply a scaling operation in one part of the code, then a rotational operation elsewhere. Assuming WindowImageTransform would multiply rather than replace, that is.

OpenGL - at least, its immediate mode - uses this a lot. It's really nice.

Nick Gammon said:
If you look at the source, right now images are just bitmaps associated with an image name. There is no meta-data stored with them.

I'll admit I haven't looked at the source yet about this; mostly I wanted to see whether anything might come of the idea.

Nick Gammon said:
With this new function you could rotate maps (eg. so that "up" is the way you are facing), or rotate text so labels could run sideways (assuming you pre-draw the text into a temporary window).

Reflection and shearing could be used to make nice shadows, but again, let's not get too far ahead of ourselves. This isn't supposed to be a 3D client.

These are all acceptable 2D operations. Genuinely useful ones, too. ;)

Nick Gammon said:
Having said that though, with the transformation matrix you could somewhat more easily bang images onto a window with some sort of perspective (or I think you could, this is starting to stretch my knowledge of 3D maths, and matrices).

I'm not sure what the third dimension you're referring to is. We don't have a depth axis in miniwindows, unless it's emulated a la your exits visualization demo.

My knowledge of the graphical application of matrices is that you have the four corners of a quadrilateral, and the cells of a matrix define translations of these points to new locations, thus stretching and/or squeezing the quadrilateral. I could be way off, but that's how I understand it.


At any rate, I still think orthogonality of an API is a really good thing to shoot for. If we attach a transformation matrix to each image - initialized to the identity matrix, of course - then it can be managed separately from the current, existing functions which I'm sure you're loath to break backwards-compatibility or, and hopefully just as loath to reimplement their functionality in a set of new functions.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


15,371 views.

This is page 1, subject is 3 pages long: 1 2  3  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]