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 / Implementing Code

Author
Message
Master Sam
16
Years of Service
User Offline
Joined: 15th Jan 2008
Location: Cyberspace
Posted: 24th Aug 2010 09:06 Edited at: 25th Aug 2010 06:01
Hi, iv been trying to implement some code i found in a rts tutorial by Phaelax with no success.The tutorial was not in GDK but i think iv accurately translated it.
Heres the translated code. All the variables have been defined at the start of my program:

And the original straight from the tutorial:

The math and stuff is beyond me - I was expecting movex, movey and move z to return the 3d location of the mouse so i could for instance get a building (or cube) to follow the mouse around on the matrix I have. But when i try to use it like that the building/cube is nowhere in sight.

So am i using it wrong? Am i wrong in what i think it does?

Here's my code:


Thanks
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 26th Aug 2010 12:19 Edited at: 26th Aug 2010 12:40
It would take a very long time and quite some mathematical knowledge to work through that code to understand what it's trying to do and why it doesn't work. However, in Dark GDK there are other ways to achieve what you want to do.

If your terrain were a normal object and not a matrix, I would suggest using dbPickObject which is the easiest method. Unfortunately, it doesn't seem to work with a matrix. (EDIT: I think it works if you use terrain instead of matrix, but I've read somewhere on the forum that it might be slow with a large terrain.)

The other way is to use dbPickScreen. That requires some additional maths to make it work, but it is much shorter than your function.

Have a look at this thread:

http://forum.thegamecreators.com/?m=forum_view&t=152343&b=22

This contains examples for both methods and some extra discussion. (I do recommend reading the other thread as well which is quoted there.) Since in your program, the view is top-down, the example given there will not work without changes. I'm still not saying that I even fully understand that code but I managed to adapt the example for you, basically exchanging Z coordinates for Y and it seems to work. Here is the code. When you click somewhere on the screen, it places a blue cube at the same position as the mouse cursor. The Y coordinate (height) is just disregarded because in top-down view, you don't see height anyway. If you later want to include height as well, you may want to have a look at the dbGetTerrainGroundHeight function.

Master Sam
16
Years of Service
User Offline
Joined: 15th Jan 2008
Location: Cyberspace
Posted: 31st Aug 2010 05:12
And it code works! I had found dbPickObject but yeh that only works for objects...didn't realize there was dbPickScreen.

Thanks alot

Oh just one other thing - Is using a matrix the best way to go? Would it be better to use an object or terrain? In the tutorial I was following it didn't mention terrain, but comparing an object to a matrix it said a matrix would be easier to deal with later on.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 4th Sep 2010 10:01
Sorry for the late answer. I don't know yet that much about different types of terrain implementation as to give an educated comparison of pros and cons, but I think it all depends on the needs of your game. If a tiled terrain is all you need, then a matrix fits the bill. It is easy to handle and you can assign different textures to each tile, even change tile textures during the game.

However, if you need more fine control over height using a height-map, or you need multi-texturing or want to set up the terrain for collision detection in a physics engine, then you probably have to look for another solution, maybe even use a plugin or external editor/modeller application.

Login to post a reply

Server time is: 2024-11-19 18:44:32
Your offset time is: 2024-11-19 18:44:32