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 / how do you put random objects on a matrix

Author
Message
killal4
21
Years of Service
User Offline
Joined: 22nd Jan 2003
Location:
Posted: 22nd Jan 2003 23:52
I am trying to put random trees on a matrix terrain but i dont know how.please help.
indi
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 23rd Jan 2003 05:49
lets say u have 10 trees and a 5x5 matrix area.

Now one problem that I can think of that pops up straight
away is over lapping of two randomly placed trees.


25 tiles makes up 5x5 so u could say u only wanted to plot one tree per tile space to get around this, and to make it look less rigid then perform a small random offset from the center of that tile position.


so in order to manage this easy we should really create an array of the same size in 2 dimensions.

lets call it DynaTree.

now an array uses space zero as one of the psaces when counting but DB doesnt use a zero to track media objects.

We will skip the zero space for now but keep in mind its there for other arrays.


dim DynaTree(5,5)
for x = 1 to 5
for y = 1 to 5
DynaTree(x,y)=0
next x
next y

this prepaares the array with zeros so we know for sure
its clean before we plot our trees.

now lets plot 1's into the array that represent the tree
locations.

for i = 1 to 10
rndx = rnd(4)+1
rndy = rnd(4)+1
DynaTree(rndx,rndy)=1
next i


from here depending on how big your matrix is then u make another loop to position each tree but using the position of the tile in a magnification.
eg: if your matrix was 5x5 but 100 wide and across u would prolly do it x 10 and if it was 1000 then it would be x 100

once u have plotted them u could then offset them within the space of the known matrix tile size and then this would solve any overlapping problems.


Once u have plotted the trees into those tile spaces, It also allows u to have a flat tile area if your trees look silly on hills due to the trunks not having a bit of model under the center point to allow for this.

Its only one possible method to the approach also.
You will need to adapt the ebst method to your games requirements.


I hoped this helps a bit

indi
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 23rd Jan 2003 05:51
indi
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 23rd Jan 2003 06:01
and if u dont care and want to be sloppy

provided the trees where declared in the 1- 10 3d media locations

for i = 1 to 10
position object i,rnd(999)+1,0,rnd(999)+1
next i

provided your matrix is 1000 x 1000 and all in positive space.

randomize timer()
should also be up the top of these snippets for a better random result.

John H
Retired Moderator
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 23rd Jan 2003 13:46
Yea indis right. But next time- read the top of this board and post it in the Newcomers Corner, or the Darkbasic(pro) forum. This says DO NOT ASK QUESTIONS!!

RPGamer

Current - RPG: Eternal Destiny : Help Wanted!
http://www.halbrosproductions.netfirms.com
Dont ask those questions! Read the help files lazy!
indi
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 23rd Jan 2003 15:11
I tried to make it into one per say because it was an ok question to cover as a theory/snippet

Login to post a reply

Server time is: 2024-05-17 05:14:49
Your offset time is: 2024-05-17 05:14:49