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 / square and round placement -> need help -> math

Author
Message
nruser
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 16th Feb 2012 21:52
I am half way to finishing my level editor, and i want to add two options witch are square and round placement brush, i need help with this because i am not good with math.

The idea was to use square placement brush to place multiple objects at the same time that will be placed inside of the square same thing is for round variant.

This is 3d editor, so how can i make a square and find its dimensions and place correct number inside it?
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 17th Feb 2012 01:52 Edited at: 17th Feb 2012 03:18
maybe something along the lines of a flat cube tied to your mouse position for reference. upon mouseclick get object width and depth, and then use those for an X Y for loop grid.

heres some pseudocode for my methode


or you could change it to random placement which would be easier. I'm doing the same sort of thing at the moment with my editor for easily placing forest.

im not good with circles, but i imagine a similar approach with the radius and curcumferance using circle maths would do the trick, but its over my head.

maybe think of printing a circle on a dot matrix using the previously demonstrated x y technique, but increasing ymax by one for half the passes and decreasing it by one for the remainder. this would give you a circle, however it is clumsy, and i feel there is a better way with sine and pi.


edit: that circle idea would make a diamond, nevermind:/edit

hope that helps

Sometimes I like to use words out of contents
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 17th Feb 2012 10:18 Edited at: 17th Feb 2012 11:40
For the cricle you could use something such as:

pseudo


Or something similar. You would probably want to play with the variable and do some testing before you drop the objects to make sure they don't overlap.

nruser
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 17th Feb 2012 17:43
thanks now i have an idea on how to make this work for circle placement, but there is small problem, what i wanted was to select option and then when i move the mouse i could see circle with some radius to it and inside it number of objects that will be placed on the map, how can i draw circle in 3d? d3d plugin can draw circle only in 2d.
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 17th Feb 2012 18:07
Here is a link to a 3d circle function using the d3d plugin.

nruser
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 17th Feb 2012 18:28
ok thanks this will help me very much along the way
nruser
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 17th Feb 2012 19:10
there is a problem making 3d circle point downwards, when vector changes y# value there is no circle
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 17th Feb 2012 20:02
another option would be to place the circular coordinates into a 1 dimensional array

i.e.



run a for-next loop. Find the valid positions (in this case there are 13 'valid' positions) and then store them sequentially into an array, so it looks like 1;1;1;1;1;1;1;1;1;1;1;1;1. Then simply pick a random coordinate within the array from 1-13

This method is not quite as precise as you'll need to use a tile mapping method, and it comes out as a sequence of square's positioned in the vague shape of a circle. And it takes a bit of extra work as you'll need to merge 2 or 3 dimensions into 1, and then expand it back to 2d/3d afterwards

On the plus side though, this would allow you to pick valid positions for ANY shape, not just circular. You could for instance use an elipse, triangle or donut. Even throw obstacles inside those shapes to block certain parts of it, those coordinates would be excluded from the array and ensure your unit's are positioned correctly. Additionally if you recheck the valid coordinates after each unit is placed, you will ensure that none of them are placed on top of each other
nruser
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 17th Feb 2012 21:35
@Millenium7
that method could probably be used in some way for square placement,
but for circular placement, are there any other way of doing this? thing with vectors cant be used because you cant see a circle when it is pointing downward
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 17th Feb 2012 23:30
i use a sphere with xyz scale eg 100,1,100
its close enough to a flat circle

Sometimes I like to use words out of contents
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 18th Feb 2012 05:03 Edited at: 18th Feb 2012 05:03
Quote: "that method could probably be used in some way for square placement,
but for circular placement, are there any other way of doing this? thing with vectors cant be used because you cant see a circle when it is pointing downward "


it can be used for placement of any shape, you only have to define the resolution of the scan. The highest the resolution the more precise but the longer it takes. From reading your post you are looking to place objects within a spherical area?, well for the visual effect of a 'circle' use a transparent cylinder. For the actual unit placement data that's where my part comes in, it'll find valid positions
nruser
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 18th Feb 2012 18:27
@Millenium7

ok that was very helpful thanks very much

Login to post a reply

Server time is: 2026-07-09 13:52:15
Your offset time is: 2026-07-09 13:52:15