Teen Programmers Unite  
 

 

Return to forum top

Maths for a dummy (me)

Posted by AngelOD [send private reply] at October 07, 2001, 09:37:39 PM

Okay, so this is (if I recall correctly), the first time I'm actually asking for help about anything on this site. Normally I just keep trying until I get whatever I'm trying to do, right..

However, this time I'm simply unable to figure out how to solve this problem (if you could call it that)..

Basically, I'm trying to learn about isometric graphic, and I have all the various stuff in regards to drawing correct, but the place I'm stuck is figuring out which spot the mouse is over. I've asked a couple of people I know about this, and one suggested iterating through all spots and check the values, but there must be a more efficient way. Then I found this article: http://www.geocities.com/SiliconValley/Vista/6774/IsoCalc.html

I read it 5 or 6 times before giving up and asking a friend about it, and all he could tell me was, that it was the simplest way of explaining it, and therefore, I was probably just dumb.

Anyway, can anyone help me understand this? I don't need long mathematic equations, but more of an easy to understand explanation on the calculations.. Maybe a simple, and heavily commented example (I'm familiar with C/C++, Pascal, BASIC, PHP and Java, but Pseudo would probably be the best for everyone).

Well, I guess this is it.. Hope anyone can help me understand this.

Posted by taubz [send private reply] at October 07, 2001, 10:38:16 PM

It'd be easier for me if you'd describe what you're try to do some more. You have a map and want to go from screen coordinates to map coordinates?

How are you drawing items on the map onto the screen? (That'll give you the formula, and you just have to take the inverse of it.)

- taubz

Posted by miken [send private reply] at October 09, 2001, 08:53:59 PM

When you look at your iso map, it is split into spaces by two series of straight lines, one in the x direction and the second in the y direction. What the author of the article is doing is just defining a set of equations with the same slope but different b values (of the form y = mx + b) for each series of lines. Thus, the x set (the ones running parallel with the bottom of the screen) will have one slope and the y set (the ones running diagonally up/down the screen) will have another.

So now we have to obtain the mouse coordinates and use these to determine in what space those coordiantes refer to. It's easy to find the row the mouse is in; since the lines are parallel to the x-axis (the bottom of your monitor), and because we know that the height is (usually) constant, we can make an easy calculation to find the exact row by using the knowledge of what segment of the map the monitor is currently displaying. The column, however, is a bit trickier because its lines are diagonal. This is where the equations come into play. Just find which two equations the mouse must be between to start out with. Next, armed with the x- and y-coordinate of the mouse, start plugging the mouse's y-coordinate into the y = mx + b equations for each of the lines it may be in between. This will find the upper and lower bounds that the x-coordinate can be to be in the space that is bordered by the two equations you tested it for.

A second way is to transform the screen coordinates to a flat grid beforehand using a very similar procedure.

Hope this helped some - sorry for more math :(

Posted by AngelOD [send private reply] at October 10, 2001, 04:48:35 PM

Hmm.. Well, thank you for atleast trying.. However, I will go back to read up on whatever math I've been missing out on, cuz it turns out, that I don't even have a solid grasp on the drawing of the isometrics..

So anyway, unless someone has a really good, and really easy to understand article on the subject, there probably aren't any real way of helping.. But again, thank you both for trying. :o)

Posted by Psion [send private reply] at October 10, 2001, 05:56:38 PM

Read a high school algebra book. :-)

Posted by AngelOD [send private reply] at October 11, 2001, 09:05:44 PM

Well, our educational system is different, but I know what you mean anyway, and funny enough, I *am* reading an algebra book from school.. :D

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.