123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|660|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Monkey -> Monkey Transforms

Mon, 07 Oct 2013, 08:19
spinal
ARGH!!!!!!!!! monkey transform function makes no sense to me at all!!!!!!!!!!!!!!!!!

-=-=-
Check out my excellent homepage!
Mon, 07 Oct 2013, 08:19
shroom_monk
While I've never used Monkey, a search on the function pulled up this: www.monkeycoder.co.nz/Community/posts.php?topic=1098

Basically, it applies a linear transformation matrix to something, then translates it too (since translations are not linear transformations).

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Mon, 07 Oct 2013, 09:40
Jayenkai
> Reveal 🔎

-=-=-
''Load, Next List!''
Mon, 07 Oct 2013, 10:10
spinal
Jay, you're a little nuts. Thats why we all like you

|edit| Shroom, i'll need better teaching than that

-=-=-
Check out my excellent homepage!
Mon, 07 Oct 2013, 11:05
shroom_monk
(Apologies for logging in and out of Socoder many times over the last hour - I didn't see your edit until I had another look in here! D: )

Okay, so I can't seem to find any Monkey documentation, so there are a few bits you'll have to experiment on yourself - namely, I'm not sure what drawing stuff this function will be applied to. Given the forum link I posted above, I assume images?

So, the function takes 6 values:


The first 4 of these form a 2x2 matrix. The second two given a translation vector. This is something else you'll need to experiment with - I assume that it applies the matrix, then the translation, but I could be wrong. The order it does them it will have an effect on the result.

The 2x2 matrix will be probably be oriented:

(but again, something to check! The alternative is that the iy and jx terms are swapped)

When you use this function, any drawing stuff it is applied to will first be premultiplied by this matrix. This performs whatever linear transformation is encoded by the matrix you have given it. Once it has done this, it will translate (move) your drawing by (tx, ty).

Examples of common linear transformations are in my article, as well as some PMC examples. This Monkey function looks similar to the one provided by PMC, so maybe take a look at the code for my demos to see how they can be applied.

Hopefully that's more helpful, but if I'm still not explaining very well, I'll try to clear things up.

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Mon, 07 Oct 2013, 11:15
spinal
I don't think that it's your explaining that's the problem, more the fact that in the past 15 years, the most maths I have done is count to 100 on an almost daily basis for the last year or so. As a result everything I once learned about this sort of thing has been replaced with day-to-day useless crap.


I managed to translate my images (in a map) using the following-


So now the screen (rendered from 0,0) appears centered at the player location. What I don't understand is why (-PlayerX*2)+screenwidth is needed to offset the map by PlayerX,PlayerY.
The other thing I don't understand is, well, everything

-=-=-
Check out my excellent homepage!
Mon, 07 Oct 2013, 11:21
shroom_monk
That's an odd one. A translation of (-PlayerX + screenwidth/2, -PlayerY + screenheight/2) should put (PlayerX, PlayerY) in the centre of the screen, since the sum of those two vectors is always equal to (screenwidth/2, screenheight/2).

Assuming it's not a bug in your code, it could be some quirk of how Monkey has this implemented. What happens if you use

?
In theory that should do the same as not having the line there at all.

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Mon, 07 Oct 2013, 13:31
spinal
Transform(1,0,0,1,0,0) indeed renders the screen as if no transformation has been performed.


-- dammit, jays framework --
I wasn't taking into account the fact that I was doing everything at a different resolution to what was being rendered.

2 options, 1 - wrap the transform function to account for the crazy that is jays framework, or 2, set the virtual resolution to the same as the actual resolution.
I'll go for the second option for now.

-=-=-
Check out my excellent homepage!
Mon, 07 Oct 2013, 13:39
shroom_monk
That would explain it. How does Jay's framework fiddle the resolutions, then? Does it use the Transform function, or is there something else? (again, I have no Monkey experience, so I'm not sure how it is set up)

Anyway, will you be wanting to do any linear transformations with this, or are you only needing to do translations?

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Mon, 07 Oct 2013, 13:46
Jayenkai
Nah, my framework just rescales everything as it's drawing it. To be honest, it's probably a lot quicker doing everything with a single transform, but for my purposes, I was getting more than enough per-frame, do stuck with that...

It'd be interesting to see any results, doing it the other way..

-=-=-
''Load, Next List!''
Mon, 07 Oct 2013, 14:03
spinal
my plan was (not sure how possible it is) to do a mode 7 effect ( snes mariokart).
it seems to be getting trickier by the day.

-=-=-
Check out my excellent homepage!
Mon, 07 Oct 2013, 14:32
shroom_monk
Wikipedia gives the transformations used to perform Mode 7 on the SNES, but they are a bit more complicated than what the Transform command alone is meant for. However, there is probably a way of doing it - I'll have a think about it and get back to you.

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Mon, 07 Oct 2013, 14:50
shroom_monk
Okay, bearing in mind that everything I know about Mode 7 I learnt just now, what I'm about to say might be a little shaky. At some point I'll have a fiddle with this in PMC to be more sure of this (got a few other things I need to get done in the meantime though). So you have been warned: I make no guarantees about how well this will work, nor about how correct any of what I'm about to say is!

The previously linked Wikipedia article gives the formula for how to get the coordinates on your background image for any given location on the screen. The variables are:
  • a, b, c, d - the elements of the linear transformation being used (not yet sure what you'd want to set this to)
  • x, y - the coordinate on the screen that you want to get the colour of so you can draw it
  • x0, y0 - the position of the origin (I presume in the world?)
  • x', y' - the coordinates on your background image map that you want to draw at (x, y); i.e. the colour of (x', y') on the image you already have is what you want to draw on-screen at (x, y)

Now, the matrix multiplication given on Wikipedia multiplies out to the following:


It turns out we can make this very useful to ourselves with just a simple rearrangement! If we subtract the vector for the position of the origin (x0, y0) from our equations, we get:

...and this can be represented by a matrix multiplication (using my faux-matrix notation from my articles):


Given this, I think we can now achieve a Mode 7 effect by:
1) Translating the screen by (-x0, -y0)
2) Applying some linear transformation matrix (rotation, shear, whatever) to the screen
3) Translating the screen by (x0, y0)

Now I've typed it, it seems somewhat like what I would've suggested without looking it up as a first thing to try. Anyway, I suspect the matrix you want will be some form of rotation and shear matrix, but until I've experimented myself, I can't say for sure.

So long as Monkey lets you 'stack' the Transform command (i.e. applying it multiple times applies all of them in order rather than simply overwriting the last one), this should be possible. Have a play about with it (try some of the linear transformation matrices in my examples), and see what happens. I'll post more here when I've had a chance (probably won't be today) to try it myself.

Hope that helps!

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Mon, 07 Oct 2013, 15:28
shroom_monk
I got curious and had a little play about with this anyway. I'm starting to think that linear transformations might not be the way to go after all.

On a more positive note, there is an alternative way to do it, but this will probably run super slowly unless you're rendering something really low-resolution: gamedev.stackexchange.com/questions/24957/doing-an-snes-mode-7-affine-transform-effect-in-pygame

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!