Adding new objects to Simutrans

Discuss the free TT-like game Simutrans.
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

Oh ok cool :D

Now time for you to give me some code :wink:

How do you manage to convert from mouse x/y position to x/y on the map?
<!-- End Of Post !-->
Image
User avatar
Hajo
Route Supervisor
Route Supervisor
Posts: 420
Joined: 17 Jan 2003 09:52

Post 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.
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

I don't understand, what about different heights of land?

What do you use for Simutrans?
<!-- End Of Post !-->
Image
User avatar
Hajo
Route Supervisor
Route Supervisor
Posts: 420
Joined: 17 Jan 2003 09:52

Post 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.
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

ack

I'll work on the engine first and put up with using a console :(
<!-- End Of Post !-->
Image
User avatar
Hajo
Route Supervisor
Route Supervisor
Posts: 420
Joined: 17 Jan 2003 09:52

Post by Hajo »

BobXP wrote: I'll work on the engine first and put up with using a console :(
Good luck with your project :)
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

:D thanks

all of a sudden i am so busy!!! no time to code :(
<!-- End Of Post !-->
Image
User avatar
Hajo
Route Supervisor
Route Supervisor
Posts: 420
Joined: 17 Jan 2003 09:52

Post 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.
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

Does it work with older versions ofSimutrans?
<!-- End Of Post !-->
Image
User avatar
Hajo
Route Supervisor
Route Supervisor
Posts: 420
Joined: 17 Jan 2003 09:52

Post by Hajo »

No.
BobXP
Tycoon
Tycoon
Posts: 2720
Joined: 04 May 2003 11:00
Location: Torquay, England
Contact:

Post by BobXP »

Well I'll just wait until Simutrans 1 comes out then. :D
<!-- End Of Post !-->
Image
Post Reply

Return to “Simutrans”

Who is online

Users browsing this forum: No registered users and 0 guests