Page 2 of 2
Posted: 01 Sep 2003 15:43
by BobXP
Oh ok cool
Now time for you to give me some code
How do you manage to convert from mouse x/y position to x/y on the map?
Posted: 01 Sep 2003 16:05
by Hajo
BobXP wrote:When
b) I find a way to convert x/y of the mouse coordinates to x/y of the piece of terrain pointed to.
This of course depends on your used display projection. In isometric display it's fairly easy. For perspectivic (word ?) 3D view it's a bit more complicated.
--
Isometric:
I call map coordinates i and j
I call screen coordinates x and y
Assuming map location i,j is drawn at
x = i - j
y = i + j
Then mouse pointing to (x,y) means map location
i = (x+y)/2
j = (y-x)/2
I hope I made no mistake. It's been a few years since I left school. You can scale y by 0.5 to get the usual 2:1 tiling. There are several options for isometric projection. You might use another one in your program -> be careful with the signs of the variables.
--
There is a brute force method that's slow but will work always: during drawing, for each drawn pixel store a reference to the drawn object. Then you can look up the reference array with the x/y mouse coordinates and you get the object.
Of course you don't want to do this if there are more efficient solutions.
Posted: 01 Sep 2003 16:09
by BobXP
I don't understand, what about different heights of land?
What do you use for Simutrans?
Posted: 01 Sep 2003 16:23
by Hajo
BobXP wrote:I don't understand, what about different heights of land?
What do you use for Simutrans?
Heights are tricky. They introduces ambiguity if the slopes exceed a certain amount. So far I found no 'real' solution, although for slopes below that limit the projection must be invertable. Maybe someone with better math knowledge can work it out?
For Simutrans I currenlty use an approximation, making use of the fact that height and y-Axis are parallel:
0) Assume height = 0
1) From mouse position calculate map tile for assumed height.
2) Calculate screen position of that map tile.
3) The y difference between mouse and screen position is the error introduced because the height was (most likely) wrong
4) assume new height = height + error
5) if error is not 0 go to step 1
This usually finds the correct tile in two or three loops. It isn't perfect but it seems good enough.
Posted: 01 Sep 2003 16:38
by BobXP
ack
I'll work on the engine first and put up with using a console

Posted: 05 Sep 2003 13:44
by Hajo
BobXP wrote:
I'll work on the engine first and put up with using a console

Good luck with your project

Posted: 05 Sep 2003 17:34
by BobXP

thanks
all of a sudden i am so busy!!! no time to code

Posted: 15 Oct 2003 09:49
by Hajo
A new version of MakeObj is now available:
http://www.simugraph.com/forum/viewtopi ... =12&t_id=2
Since Simutrans 0.82.12 factories can produce several goods. Each good has it's own production rate. MakeObj 0.1.3 allows to create PAK files for factories that produce multiple goods at different rates.
Posted: 15 Oct 2003 18:45
by BobXP
Does it work with older versions ofSimutrans?
Posted: 16 Oct 2003 07:04
by Hajo
No.
Posted: 16 Oct 2003 17:41
by BobXP
Well I'll just wait until Simutrans 1 comes out then.
