Author Topic: Drawing on a diagonal...  (Read 16535 times)

Cymon

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
  • Reviving the Type-Ins of Old
    • View Profile
    • Cymon's Games
    • Email
Drawing on a diagonal...
« on: October 07, 2008, 07:34:23 PM »
I think part of this is going to be me thinking out loud.

I want to do a ASCII game (it's too far from the official definition to be considered Roguelike in my opinion) where the room will occasionally flip around a center point. The game itself will never be played on anything other than level surfaces, so the rotations will only be a momentary visual thing, but it could stop at 90o from the original rotation. I wonder if it will even work? I mean, text boxes aren't exactly square. Maybe I should use the whole "double up" trick to keep things a little more level...

Actually, that could work since every step will have an inbetween that will need to be animated, the flip could just be the inbetween for that moment. Hmmm.

Either way, what I need is a way to walk through the data at a diagonal and draw it straight. There's got to be a nice mathematical way of doing that. I did something similar with alleytris, but that was only fo 90o angles. Does a similar technique exist for more discreet angles? I'm sure it does. AND I have to, like I said, center it at a point. This could be fun.

Does anyone here know of some good rotation around a point algorithm resources?
A new game every week. Please visit Cymon's Games!

elsairon

  • Newcomer
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Drawing on a diagonal...
« Reply #1 on: October 15, 2008, 08:11:50 PM »
Not sure how it would work

###
###
###

  #
 ##
###
 ##
  #

Flipping directly a traditional gridded map won't 'snap' properly at 45%

You might have more success with a hexagonal style map.

Cymon

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
  • Reviving the Type-Ins of Old
    • View Profile
    • Cymon's Games
    • Email
Re: Drawing on a diagonal...
« Reply #2 on: October 23, 2008, 06:14:08 PM »
Hex boards make my head hurt. Besides, this is a momentary effect that will only last an instant. However, I will be doubling my blocks so that there's more of a square effect.

To complete you example, I want it to go like this:
Code: [Select]
112233
445566
778899

  33
 2266
115599
 4488
  77

336699
225588
114477
Which requires some sort of half steps. One of the problems is that a diagonal is longer than a ordinal.

Since I posted that first post I've become an expert on rotation. Let me share what I've learned:

A rotation matrix looks like:
[
Cos DSin D
-Sin DCos D
which you then multiply with a [x,y] matrix. Fortunately we can cut the whole matrix thing and just say that:
(x,y) rotated D degrees = (x*cos D - y*sin D, x*sin D + y*cos D)
So basically change D for the degree of rotation and you have a rotated x,y around a center point (0,0). Complications with shifting aside there is a simplification we can make because we're dealing with a 450 rotation and cos 45o = sin 45o = 0.707. So our rotation above becomes:
(x*0.707 - y*0.707, x*0.707 + y*0.707)
(0.707*(x - y), 0.707*(x + y))
Similarly for a 90o rotation we get sin(90)=1, cos(90)=0 so we can simplify our rotation matrix:
(x*0 - y*1, x*1 + y*0)
(-y, x)
Which is pretty simple.

But it's that 45o transformation that we should be buggered about. What does that look like when you do a rotation? With rounding we get:
Code: [Select]
112233
445566
778899

223366
115599
447788
What thu? I guess that works, it's not what I expect tho. What happens when we go bigger than a 3x3 block? How will it look? Will we get overlaps?

And here's another caveat. In reality what I want to use an inverse operation so I don't have to worry about clipping.

I know I can do this, but it's going to be a pain in the neck.
A new game every week. Please visit Cymon's Games!

Cymon

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
  • Reviving the Type-Ins of Old
    • View Profile
    • Cymon's Games
    • Email
Re: Drawing on a diagonal...
« Reply #3 on: March 05, 2009, 07:28:53 PM »
I made a prototype that does rotation. If you download the source it's fun to play with steps that are smaller than 45o, but be warned you may never find zero again.

http://cymonsgames.retroremakes.com/forum/index.php/topic,7.msg14.html#msg14
A new game every week. Please visit Cymon's Games!