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.

Dark GDK / RTS in Dark gdk

Author
Message
MRPdeveloper
13
Years of Service
User Offline
Joined: 28th Sep 2010
Location: Australia
Posted: 28th Sep 2010 09:33
Hello ive been working on a RTS styled game i have been looking around on the forums bout found little information on Dark gdk RTS i had a look at Dark basic profesional and found some content i did try convert the code to Dark gdk but kept coming up with errors and problems

I have seen the command dbPickObject() for dark gdk but havent found the actual real purpose and how to make it work

Please if anyone can help with a point in the right direction or a explanation of how to make a RTS in dark gdk would be greatly appreciated:

If there is questions about what type of RTS hope this answers some questions

I pretty much need to drag the mouse which creates a box from point A to Point B and all Units inside that box will be selected then to be able to Right click a position on the Matrix and make those Units move to that position i right clicked

Thank you for Reading
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 28th Sep 2010 23:00
It doesn't sound like you need dbPickObject anyway. Using that you can click a spot on the screen and determine which object I'd you've clicked on.

I assume you're capturing the mouse position at the top/left and then again at the bottom/right to identify the rectangle of the screen? Use those coords to test each object of importance (that is player characters - no need to check trees, rocks etc.) to see if they are contained in the rectangle you've selected.

I'm not sure if there's an "easy" way to do this... Perhaps dbPickScreen()?

Hope this helps,

JTK
Abraxas77
13
Years of Service
User Offline
Joined: 26th Aug 2010
Location:
Posted: 29th Sep 2010 08:25
I would first create a function that detects and stores the screen-space position of every mouse click (at least for the mouse button that will trigger the multiple selection process). You then need to detect when the mouse is being dragged. So, each consecutive frame after the mouse button is clicked check whether the position has changed (you will probably want to allow a few pixels tolerance here). If the position has changed more than your defined tolerance, begin drawing a box to the screen. This only purpose of this box is to provide feedback to the user so they know they have initiated the multiple select process and see where they are selecting (a more elegant, but also more involved, technique would be to project the box onto your terrain ... this is possible and not even too terribly difficult, but I can suggest methods for this later if wish). Continue drawing the box from the initial screen-space mouse click point to the current location of the mouse until the mouse button is released.

Now the tricky part ... and here I'm not fully certain of to accomplish this with DarkGDK functions ... but I can at least give you the principle behind the technique.

What you need to select objects within a specified area are two points on the XZ plane. Where the first point is corresponds to the point on the XZ plane at the intersection of your terrain and line (or ray) originating from the 3D world-space representation of 2D screen-space representation of where the user first clicked the mouse button. The part I'm not certain about is the return data from dbPickScreen(). My assumption (given the funtion documentation) is that it casts a ray from the view point into the scene which passes through the near plane at the 3D representation of the mouse pointer. If so, this is exactly what we want. All you need to do is add its return values to your camera position to the the world-space point.

The rest is simple from there. Iterate all your objects and test them for the following:
1) dbObjectInScreen(); // if no, continue to next object
2) Get the objects position and test whether it is within the range of the two points gathered in the previous paragraph. If so, select them; otherwise, continue to the next object.


I hope that all makes sense to you, good luck.
~Andrew~
Abraxas77
13
Years of Service
User Offline
Joined: 26th Aug 2010
Location:
Posted: 30th Sep 2010 06:48
Ack, I should have revised my last post before posting it. Even I can hardly make sense of what I was trying to say there. So, I'll give it another go:

1) To select objects in a range you need two points on the XZ plane which define the minimum and maximum values of the selection region.

2) The two points must somehow be transformed from 2D screen-space (mouse coordinates) to corresponding 3D points on the XZ plane in world-space. Picking.

3) Picking is the process of casting a ray from the viewpoint (camera position) through the projection of the mouse coordinates onto the view frustum's near plane. The first object that intersects this ray (line) is "picked".
* Some picking implementations allow you to provide parameters which allow you to specify a type(s) of objects that will or will not qualify to returned by the picking function. I don't see such options with dbPickScreen().
* This also leads me to wonder if the terrain will qualify valid intersections or whether it is strictly limited to intersections with objects (from dbLoadObject, dbMakeObject, etc.). It will be much easier for you if dbPickScreen() will indeed pick a point on the terrain.

4) The minimum and maximum points for your range will, of course, be "picked" from the mouse-down and mouse-up coordinates respectively. Note that, in picking these points there are, at least, a couple cases you will need to handle with care:
* Case 1: The cases where the ray from either screen pick does not intersect with the terrain. You may, perhaps, establish default min & max points.
* Case 2: The case where either pick intersects with an object instead of the terrain. You may simply treat this case the same as if the point had been on the terrain, but this may result in a less intuitive system.

5) Once you have the 2 points from dbPickScreen() you will need to add them to the camera's position to get the world-space points. After that, it just a simple matter of bounds-checking all the selectable objects in the screen. Make sure you include objects whose positions are equal to the bounds; otherwise, objects that fall under the second case (above) will not be included.

-----------------

To draw the selection box projected onto the terrain:

Basically, what you are going to do here is collect a sample of points along the boundary of the selection region; translate them onto the terrain (set their y values to the terrain height); transform them into screen-space; and finally, connect all the points with dbLine().
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 30th Sep 2010 11:06 Edited at: 30th Sep 2010 14:07
The purpose and usage of dbPickObject is explained in the help. This function tells you which object is under the mouse when you click and you can even limit the search to a range of object ID numbers, so other objects are disregarded during the raycasting. Now, if you limit the search to only your terrain object, then this can help you a lot, because afterwards from the pick vector data you can get the coordinates where the terrain was clicked. For example, if you have a terrain object and a box object, then this code will move a box to where you clicked on the terrain:



I tested this with the terrain demo application of Dark GDK. Note that dbPickObject does not work with a matrix, only with terrains and objects, and in the thread which I quote below, it is also said that this command is "too slow for RTS". You need to test if it's fast enough for you or not.

As far as I see the problem, you can go two ways in solving it. The first way is to somehow convert the mouse-click (2D) coordinates into game world (3D) coordinates and compare them with the game world coordinates of your objects, to see which of them fall inside your rectangle. That's where dbPickObject can help, or you can use dbPickScreen as well but the usage of that is very tricky. You have to guess the distance, normalize the vectors, etc. There is a good explanation about that in this thread:

http://forum.thegamecreators.com/?m=forum_view&t=129031&b=10

The other way would be to use only screen coordinates. You can use the dbObjectScreenX and dbObjectScreenY functions to discover the screen coordinates of your objects and you can compare them to the mouse rectangle coordinates. This may be a little easier. You can also use the dbObjectInScreen function to determine if a unit is within the visible screen or not and compare only those which are visible.

There is also an RTS tutorial for Dark Basic Professional here:

http://zimnox.com/dbcc/?page=tutorials

Although it's a different programming language but the concepts should be easy to undestand and convert.

I've never tried to write an RTS so the only help I can give is to point to these threads which may be useful to you.

Login to post a reply

Server time is: 2024-07-02 08:28:11
Your offset time is: 2024-07-02 08:28:11