Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Determining mouse position relative to a matrix

Author
Message
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 23rd Sep 2003 19:05
I am trying to code a turn-based strategy game in DBPro. I had to abandon a 2D approach to it due to poor frame rates so I have decided to go quasi-3D by using a matrix and rotating the camera to mimic an isometric viewpoint.

Try as I might, I just can’t work out how to code a function that will tell me what 'tile' of the matrix I have clicked on if I click the mouse button. Basically, I need a function that will determine which tile of the matrix the mouse is hovering over so that when the player clicks the mouse button, I can execute relevant code.

Any and all help will be greatly appreciated

zzabb
23
Years of Service
User Offline
Joined: 25th Apr 2003
Location: Seattle, USA
Posted: 23rd Sep 2003 20:21
in the code snippets forum there is an awsome 3d engine that does something simular, you may want to give that a look

My advice is free -
unfortunately you get what you pay for (-:
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 23rd Sep 2003 20:35
If you mean the post by Chiwawa, I don't understand it at all. When I donwload it I get a bunch of files with strange extensions. How am I supposed to use it? Is this what you are on about?

FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 23rd Sep 2003 20:42
Also, searching for 3d mouse control isn't too helpful as it provides plenty of snippets for selecting objects in 3D space. I need to select the matrix tile itself

zzabb
23
Years of Service
User Offline
Joined: 25th Apr 2003
Location: Seattle, USA
Posted: 23rd Sep 2003 22:32
i'm so sorry i told you the wrong post )-: i got the same thing with that one, no its the
"RTS bare bone demo for DBP" by Phaelax

http://darkbasic.thegamecreators.com/?m=forum_view&t=15384&b=6

it makes a world/map similar to "age of empires" and other God view type games
he selects the matrix and moves characters around, its really cool

My advice is free -
unfortunately you get what you pay for (-:
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 23rd Sep 2003 23:25
See codebase, i posted a snippet.

c:/dos
c:/dos run
run dos run
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 24th Sep 2003 00:16 Edited at: 24th Sep 2003 00:17
No worries zzabb, thanks for the correct post That barebones code is great. The only problem is it calculates exactly where on the matrix you have clicked but I need to somehow calculate which 'tile' you have clicked on. The game I have in mind that i'm trying to make a clone of is Civilization 3. You need to know exactly which tile you have clicked on if you want to, for instance, place a city, etc. I had hoped not to fall so early (especially since I know the AI is going to be a pain in the butt to code

@David89:
Great code David except it does the same as many of the other code snippets I have stumbled across in that it can select objects but not the matrix tile

zzabb
23
Years of Service
User Offline
Joined: 25th Apr 2003
Location: Seattle, USA
Posted: 24th Sep 2003 01:33
well since all matrix tiles are at a certain x and z cordinates
couldn't you...

psuedo-
if x cordinates < tile3 x pos and x cordinates > tile1 x pos and z cordinates < tile3 z pos and z cordinates > tile1 z pos
then
do what you want with the matrix tile
endif

just a thought?

My advice is free -
unfortunately you get what you pay for (-:
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Sep 2003 01:53
if matrix tiles are say, 50x50 units, then:
x = matrix coordinates
z = matrix coordinates

tilex = x/50 + 1
tilez = z/50 + 1

that's assuming your first tile starts with the number 1 and not zero.
spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 24th Sep 2003 12:19
Try code below. It's a bit of a mess and has lots of duplicate code but is needed to optimise. Tried to post it last night but forum was down late last night!

It 'should' cope with matrix positioned anywhere and camera positioned anywhere. If matrix is always gonna positioned at 0,0,0 you can get rid of a lot of code.



If your mansion house needs haunting, just call Rentaghost!
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 24th Sep 2003 12:26 Edited at: 24th Sep 2003 12:27
@Spooky,

Thanks for the code but there's an error during compiling. It can't understand line 29 (pick screen mousex()).

In fact, it doesn't understand any of the pick commands

FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 24th Sep 2003 12:28
Oops, let me just download Upgrade 5!! Duh

FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 24th Sep 2003 13:41
@Spooky:

That code is excellent! It is exactly what I needed! With a little tinkering I was able to slot it into my code. Still got a long way to go but this is an immense help

Login to post a reply

Server time is: 2026-07-25 07:01:49
Your offset time is: 2026-07-25 07:01:49