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 / Loading Multiple arrayed objects

Author
Message
BasCelik
8
Years of Service
User Offline
Joined: 21st Jan 2012
Location: Mechanicsville, VA
Posted: 22nd Mar 2012 05:38
Scenerio: I have a dbTerrain with rolling hills and a river system running through it. I want to load instances of arrayed objects. Example: I have 3 different tree models, I randomly place 25 on the map surface after doing a height test. That part works fine, but either my loop is not changing to the next type of tree or it is possibly placing the next group of trees in the same exact position as the previous type. I do not clearly understand the the dbRandomize(int seed) to know if I even need it or I am using it correctly. Not even sure the way I am loading these objects is effective enough. Bare in mind I am a novice, but learning a lot creating this project. Not sure how to add a snippet. If it does not add it I will post it. Any help would be appreciated, I can post the entire project code if needed. I also believe this could help other novices in the future. I declared the following:

int trees[3] = {15, 16, 17};
int Tree1 = 15;
int Tree2 = 16;
int Tree3 = 17;

JTK
10
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 22nd Mar 2012 20:45
dbInstanceObject(temptree, i);

The Trees[] array doesn't have 15, 16 or 17 elements. It only has 3.

Alternatively, you can change the for..loop for i to be between 0 and 3.

for (int i=0; i<3; i++)

Either option should work fine.

Regards,

JTK
BasCelik
8
Years of Service
User Offline
Joined: 21st Jan 2012
Location: Mechanicsville, VA
Posted: 23rd Mar 2012 05:24
Thanks for the reply JTK. I made a few adjustments based on your suggestion. I did realize that this code needed changed to where it was referencing the array trees[i]and not just i.

It still did not give the result I expected. I do get 25 random trees on the terrain. So, I did a little test by changing the loop from:

to the following:

Each time I changed the loop count I did get a different type tree when I ran the program. It does appear that when I use the

it is using the last object in the array to place 25 randomly on my map. Any ideas what else I might be doing wrong? Do you need to see more code?
JTK
10
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Mar 2012 23:38
Quote: "Each time I changed the loop count I did get a different type tree when I ran the program. It does appear that when I use the
+ Code Snippet
it is using the last object in the array to place 25 randomly on my map. Any ideas what else I might be doing wrong? Do you need to see more code? "


Yeah, now that I've taken a closer look at your original code, I can see why...

I've added a new code snippet that should replace what you've posted above (with some chunks removed for brevity). Essentially, what was happening is that for every pass in the outer for..loop (between 0 and 3) you were re-using ID values 9000 through 9024. This new snippet adds additional ID values for the other 2-passes...



I hope this helps clarify things,

Regards,
JTK
BasCelik
8
Years of Service
User Offline
Joined: 21st Jan 2012
Location: Mechanicsville, VA
Posted: 24th Mar 2012 07:49
JTK...you hit it right on the head!! That was the primary issue for sure. I had to make only one change to the code and that was in the outer for loop. I still had to refernce the object that was in the trees[i]. We had it using i as the object. see snippet.


it was looking for an object 0 and not trees[0], hence: int trees[3] = {15, 16, 17}; Once I changed it to look at the elements of the tree array: tree[0] = object 15, tree[1] = object 16, tree[2] = object 17.

Works perfect and I give props to you! I was not even looking in that part for the issue. Thanks again for taking the time to look closer at my code!!! Now, can I ask your opinion on loading objects this way? Also, is there an easy way to do a terrainheight check that covers a certain diameter. Example: where my trees are placed, it's based on a one point check, so if it is on the side of a hill, part of the roots will be sticking out into thin air. So, if I could check a certian diameter and the terrianheight is the same across that diameter, I can go ahead and place the tree there, else not place it there. If you would like to help, that would be awesome, if not, I totally understand. Again, thanks for your help, it is greatly appreciated!

Login to post a reply

Server time is: 2020-02-20 09:57:40
Your offset time is: 2020-02-20 09:57:40