Room size

Started by ld-airgrafix, Wed 19/02/2020 11:40:51

Previous topic - Next topic

eri0o

Quote from: Laura Hunt on Thu 20/02/2020 17:34:58
I'm still wondering if this couldn't be done with simple linear algebra? We need to consider that because this is isometric perspective, I already have the angle and thus the slope of the line. If the angle of our perspective is 30 degrees, then m = tan 30?

Now with just one point of the rail and knowing the slope, I can have its equation: y - a = m(x - b)

Then I would define a second line the same way, but with the reverse slope value and using the player position as my reference point. This is the line that goes from the player to the rail.

And finally, I just need to find the intersection between these two equations (there has to be a formula, right?) which would give me the point where I need to place the viewport.

I've just looked up a lot of these things real quick so I might be off in places, but I think the idea seems solid? (Of course, there would be a lot of additional calculations to acommodate the "inverted" Y axis and the fact that the viewport position is set using its top left corner rather than its center!)

I have a vague idea of using the player.x to calculate the y in the line using the line equation... Not sure of how it works.

Laura Hunt

#21
Quote from: eri0o on Thu 20/02/2020 18:40:13
I have a vague idea of using the player.x to calculate the y in the line using the line equation... Not sure of how it works.

I've been trying to give this a spin, if only as a mental exercise...

So if the slope of the rail is m = tan 30,

And thus the rail equation is y - a = m(x - b), or y = m(x-b) + a,

Then the line from the player to the rail should have an angle of 180 - 30 = 150 degrees in order to be "perpendicular" in this perspective. So n = tan 150.

And so the line from the player to the rail would be y - player.y = n(x - player.x) or y = n(x - player.x) + player.y.

Now y = y represents the intersection, so m(x-b) + a = n(x - player.x) + player.y.

We solve for x = (n*player.x + player.y + mb - a) / (m-n) and we set this as the viewport's X coordinate. Then once we have X, we set Y using any of the previous Y equations.

Might even work! I need to build a test game at some point and try it out!

SMF spam blocked by CleanTalk