# 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 / Placing system.

Message
Posted: 30th Dec 2012 04:09
Hello my Name is Nathan and i have searched every where i have found a couple of things that are kinda what i want, but they are in dbpro and i do not understand there code, because there are no comments.
I am trying to figure out some way to place & destroy blocks like you would place them in minecraft the game however is nothing like minecraft i just want to figure out a way to do it.
Posted: 30th Dec 2012 10:15
Discribe exactly how you want to do it. The common thing in placing objects is the ability to "project" a vector from screen space to object space. Google "D3DXVec3Project". There may be a GDK function for this, but I can't think of it off the top of my head.

The fastest code is the code never written.
Posted: 30th Dec 2012 11:11
I do not know if you have played minecraft, but its a game where you can build structures as well as brake them, but they use only textured cubes. when you are playing it you place down the textured blocks,but they snap together and that's the hard part.

example below

#### Attachments

Posted: 31st Dec 2012 08:26 Edited at: 31st Dec 2012 08:27
Quote: "but they snap together "
That's not hard. When you place a block, simply lock it into an integer value. If each block is 10x10x10, then cast the location values into integers and divide them by 10, then multiply by 10, then replace the object. This will lock values like this:
x=12.5
y=50.1
z=21.9
int ix=x/10;//this will result in a 1
ix*=10;//this will result in a value of 10
x=ix;//now the location is locked into 10 instead of 12.5

Do this for the other 2 variables and you are "locked" into block areas. You could also do this:
int ix=(x+5)/10;//this way if it's 15.0 or greater, it will cast into 20 instead of 10....

The fastest code is the code never written.
Posted: 31st Dec 2012 10:05
Oh wow Thank you that works, but I can only put it in the position of the camera. how could you put it where the camera is pointing, like in front of the camera.I attempted this but failed, for i do not know trigonometry relationships very well XD. Also if there is already a block in that position how would you place that block in an adjacent or above position.

again thank you allot for your help.

Here is the code for corrections i figured it could help you point out my problem better than guessing at what i wrote

Posted: 31st Dec 2012 19:12
If you want to place it at a fixed distance from the camera, then it's easy.
In your code, move your camera foreward, place the object, then move it back into its original position.

The fastest code is the code never written.
Posted: 3rd Jan 2013 01:11
OK again thank you for all of your help, but i have one more question. How could you make a marker so that you know where you are about to place the block.
Posted: 3rd Jan 2013 15:58
A marker is just another "object". Make a plane and turn wire frame on. Now you use the same idea for placing the objects on that plane and *poof* you have a marker.

The fastest code is the code never written.