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.

Newcomers DBPro Corner / Clicking an area of a Matrix to move it up/down

Author
Message
Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 9th Sep 2007 13:34 Edited at: 9th Sep 2007 13:35
Hey everyone,

I'm working on a small terrain/pathfinding demo, but I want to be able to raise/lower
points on the matrix when you left-click to raise, and right-click to lower.

I read through the Matrix tutorial by TDK, and that gave me some good ideas to try, such as this:



But nothing appeared to raise.

So, how would you make it raise the point of ground that the mouse is on, while pressing
the left mouse button?

Thanks for all help, it's appreciated.


[center]
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 9th Sep 2007 15:23
why have you got 4 lines doing the same thing?

and I think you need to use the update matrix command afterwards

http://jamesmason01.googlepages.com/index.htm
Penfold
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: RED postbox houses of parliment
Posted: 9th Sep 2007 17:20
Quote: "I think you need to use the update matrix command afterwards"


Yup that was what I was thinking. then obviously sync if you have sync on.

Sounds like you want to make a populus style land raise lower effect. much the same as many level editors?

'Ooh 'eck chief'...'crumbs'
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 9th Sep 2007 18:17
This doesn't exactly what you're after but it may give some ideas

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Sep 2007 02:05 Edited at: 10th Sep 2007 02:06
Don't forget that after altering any part of a matrix, nothing will happen until you use:

Update Matrix MatrixNumber

[Edit] Oops - didn't see that demons breath had already suggested this.

TDK_Man

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 11th Sep 2007 16:59
Nope, still no difference. Current code:




[center]
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 11th Sep 2007 21:07
You can't do it like that!

The current mouse X position is nothing to do with the current mousewheel position.

What you need to do is have a hidden object move around at the mouse pointer so you have the X/Z position of the matrix.

When the LMB is pressed, grab the matrix X and Z position and it's current height with Get Matrix Height (not Get Ground Height).

Drop into a repeat until loop and check MouseMoveY() - adding whatever it is to the height of the matrix at the stored X and Z positions.

If you are struggling, just shout and I'll knock together an example for you (if the above example by Scorpyo doesn't do what you are after).

TDK_Man

Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 11th Sep 2007 21:08
Well it works here: Just keep the mouse values within the matrix tile numbers.
Not sure why you use mousex() instead of mousemovex() etc. since the former(s) return too high values when away from the very top left of the screen.


Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 13th Sep 2007 13:11
Tried your explanation TDK, thanks for it by the way. Anyway, I came up with the following code, but it has obvious problems:



Firstly, mtx and mty are equal to the matrix position not the tile position. How do I check for the tile position, the help documentation didn't have any commands for tile checking.

Also, when trying to compile, it can't understand the command GET MATRIX HEIGHT, but it's not because i'm not using an integer, because I tried by replacing the mtx and mty with 10, just to check.

Anyway, thanks for the help so far.


[href=www.verongames.com/gamestudioa7.html][/href]
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th Sep 2007 22:44
I was over tired when I wrote the last post and re-reading it I'm confused myself!

Here's a snippet showing the way I would do it:



It needs some work, but should point you in the right direction.

Move the cube around with the mouse and use the left mouse button to alter the height by holding it down and moving the mouse forwards and backwards to alter the height.

TDK_Man

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 14th Sep 2007 10:56 Edited at: 14th Sep 2007 11:53
Ok, I broke down the code you gave above, which was very helpful, and attempted to put it into a basic RTS engine. The full code is below:



But, whenever I compile the code above, it runs fine, until I try to raise or lower the terrain, which gives me the error:

Runtime Error 7017 - Matrix coordinates illegal at line 523

I'm fairly sure the error is to do with the size of the matrix at lines 23-26. How would I fix this?

I've got another question, however, and it's sort of related to matrices, but regarding the viewpoint of them.

What i've benn trying to do is make it so if the mouse wheel is scrolled up, then the view height, or angle increases, making the view more top-down, and if the mouse wheel is scrolled down, the angle is decreased, bringing the camera closer to the ground, or even level to the ground.

Thanks for all your help so far.


TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Sep 2007 19:11 Edited at: 14th Sep 2007 19:14
I don't have your A* lib so I can't run it. But looking through your code, it might be more helpful to explain what my snippet does.

Also, although not directly connected to your problem, you are using float variables in many places they are not necessary.

When using matrices, the height value is the only thing that should be float. So, variables like Squaresize# should be an integer. In the same way, with the line:

MatrixTilesAcross = mapX * squareSize#

MatrixTilesAcross can only store an integer, so using a float in the calculation will still only end up as an integer.

So, my snippet lets you state the integer size of each matrix tile and the number of tiles across and down. The unit size of the matrix is then calculated using these variables.

This is far better than setting the size of the matrix first. For example:

Make Matrix 1,5000,5000,70,70

will result in a tile size of 71.4285. Integers are better, so setting the tilesize first and multiplying this with the number of tiles across and down to set the matrix width and height is much better - you always end up with integer values.

In the snippet, you can only raise the 4 corner points on the matrix tiles, so when you move the pointer around, it takes the X and Z position of the cube and divides it by the tilesize.

This gives you the integer tile number the cube is on (by losing the decimal places) and stores them in TileX and TileZ.

Multiplying these by the tilesize will position the cube correctly on an intersection.

Set Matrix Height in the Repeat..Until loop uses TileX and TileZ when raising or lowering the point, so my guess is that in your program these are not being calculated correctly.

You can double-check this by replacing the variables with numbers seeing as you already know the number of tiles across and down and the size of the tiles.

As for the camera angle, you can rotate it using the cube as the axis point - or as a 'cheap' alternative (which looks very similar), use MouseMoveZ() to alter the height of the camera, re-pointing the camera at the cube as it moves.

Here's the 'cheap' version:



TDK_Man

Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 16th Sep 2007 11:05
Thanks for taking the time to type that all out, it's really helpful.

I've been playing around with the code, and implemented it into my work, and the mouse wheel doesn't work at all, but the raising of terrain does, you just can't see the terrain. The current code:



Thanks.


Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 20th Sep 2007 10:45
Sorry to bump it, but I pretty much needed to.


Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 27th Sep 2007 05:36
Wow, this thread has been dead for a while now, is anybody able to help with the post just above?


Veron
18
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 9th Oct 2007 06:38
I took yet another look over at TDK's code, tried to implement it into mine, but no no avail.

I looked at Scorpyo's code, which doesn't work unless the mouse in being pressed once it's inside the top left-hand tile, because of this code:



But without that code, you get the error when you try to click "Matrix Co-ordinates illegal at line 52."

Any help on getting Scorpyo's to work within any tile on the matrix?


Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 10th Oct 2007 01:43 Edited at: 10th Oct 2007 01:44
Dude,
The best I have come up with is this:

Login to post a reply

Server time is: 2024-11-25 12:21:59
Your offset time is: 2024-11-25 12:21:59