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 Discussion / Populating 3D world with objects

Author
Message
No Time To Code
16
Years of Service
User Offline
Joined: 22nd Dec 2008
Location:
Posted: 7th Apr 2009 03:10
When placing objects on the matrix, does each have to have it's own object number and collision setup? Let's say I have a model of a tree and I want to use the same model to make a forest of 300 trees. Can I just define one tree object, make a collision box and place at 300 locations or do I have to do a FOR...NEXT loop and create 300 objects and define each ones collision box?

I thought that MAKE STATIC OBJECT had something to do with this but if so, I'm not sure how to use it.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 7th Apr 2009 03:25
im aware this is DBC board but if by some chance u have pro, u can use clone object to copy the object 299 times and i beleive that will also copy the collision box

There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Apr 2009 03:28
You can approach this in different ways depending on what you need to happen. If the trees are low poly (very few polygons) you could actually make the forest one object by linking all of the trees as limbs and then making one object out of the forest and setting that object to polygon collision. This is an apporach I've used for interiors and mazes with pretty good results.

I've never had good luck or results using static objects so I advise against them.

If you don't want to make the forest into 1 object, then you should create an object collision box around each one individually. MAKE OBJECT COLLISION BOX <obj>,etc. And since trees are stationary, you can set the rotation flag to 0:
MAKE OBJECT COLLISION BOX Object Number,x1,y1,z1,x2,y2,z2,flag

Don't confuse that with SET OBJECT COLLISION TO BOXES. This command will destroy your game speed if used with a lot of objects.

Also, if you are using multiple objects, then you can hide them when they aren't in the camera view to help speed up processing:

Assuming the trees are object numbers 100 to 399:


If you use MAKE OBJECT COLLISION BOX Object Number,x1,y1,z1,x2,y2,z2,flag , then the only collision that will be detected is with other objects that have a collision box around them created using the same command.

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 7th Apr 2009 03:37
problem with ur 1 object plan is that to my knowledge u cant make multiple collision boxes for one object, but im not sure

There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Apr 2009 03:41
The one object idea (linking all of the trees as limbs and then making that limbed object into one solid mesh) wouldn't use a collision box. It would be set to polygon collision.

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 7th Apr 2009 03:43
doesnt that make a frame rate drop tho?

There are only 10 kinds of people in the world, those who understand binary and those who dont
No Time To Code
16
Years of Service
User Offline
Joined: 22nd Dec 2008
Location:
Posted: 7th Apr 2009 03:46
Quote: "im aware this is DBC board but if by some chance u have pro, u can use clone object to copy the object 299 times and i beleive that will also copy the collision box
"

Thanks but I only have DBC right now.

Quote: "Also, if you are using multiple objects, then you can hide them when they aren't in the camera view to help speed up processing:"

You answered that question before I even asked (I meant to include that in my first post) I assume that loop would be for pretty much every object in the 3D world (tress, rocks, buildings, etc)?

Quote: "If you use MAKE OBJECT COLLISION BOX Object Number,x1,y1,z1,x2,y2,z2,flag , then the only collision that will be detected is with other objects that have a collision box around them created using the same command.
"


Latch, do you mean that if the trees collision is set up as you describe but my player character's (PC) collision is set up with SET OBJECT COLLISION TO POLYGONS, it would not detect collision between the PC and a tree? Also, I don't know if I'm going to use Sparky's DLL but would it work with trees set up this way?

Thanks.
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Apr 2009 04:12
Quote: "doesnt that make a frame rate drop tho?"

It's a tricky balance. If you had 6 cubes set to box collision versus 1 36 sided object set to polygon collision, the 36 sided object is going to behave more quickly. The reason is each individual object is indexed and checked and rendered which takes more time than 1 object of an equivalent polygon count. Now, if you had 6 spheres set to box collision vs 6 spheres set to polygon collision, the six spheres with box collision will behave better than the 6 spheres with polygon collision because there will be way more collision checks for each face of the 6 spheres (on top of indexing). Finding the balance can be tricky, but in my experience, setting large single areas to polygon collision (like a terrain or forest or building) performs better than setting many small parts to individual box collision.

Quote: "I assume that loop would be for pretty much every object in the 3D world (tress, rocks, buildings, etc)?"

You'd have to kinda feel it out. If the loop is too big, you'll be wasting a lot of time checking everything that may or may not need checking. If you can come up with a method of grouping objects with a single check, maybe by zones that the camera is in or isn't in, or by landscape areas blocking views, you can reduce what the loop checks for and just hide or show groups of objects at once...

Quote: "Latch, do you mean that if the trees collision is set up as you describe but my player character's (PC) collision is set up with SET OBJECT COLLISION TO POLYGONS, it would not detect collision between the PC and a tree?"

That's right. The DBC collision methods that work together are:
SET OBJECT COLLISION TO BOXES, SET OBJECT COLLISION TO SPHERES, and SET OBJECT COLLISION TO POLYGONS.

The other two methods that work together are
MAKE OBJECT COLLISION BOX, MAKE STATIC OBJECT COLLISION BOX

I think it has to do with the available commands for possible sliding collision detection that these last two methods offer. That doesn't mean you can't do sliding collision with the other methods.

Quote: "Also, I don't know if I'm going to use Sparky's DLL but would it work with trees set up this way?"

If you were going to use sparky's, I'd make the forest 1 object then set the collision in sparky's to polygons for the forest. Although, you can group objects in Sparky's which means you could have individual boxes around each tree. I haven't tried that yet so I can't speak on it, but I have made entire buildings and sewer ways set to polygon collision in Sparky's and it works quite well. The only speed lag comes from how many polys in the models DBC can handle before slowing down - but again, you can handle that with zones and what is loaded and not loaded at any given time. Sparky's behaves differently than DBC collision.

It casts a ray from one point to another point (that you specify). If an object set up for collision is in the path of the ray, then collision will be flagged. From there you can return the point of the collision, the normal, and/or the bounce vector (where the ray would end up if reflected from the point of contact).

Enjoy your day.
No Time To Code
16
Years of Service
User Offline
Joined: 22nd Dec 2008
Location:
Posted: 7th Apr 2009 05:04
Thanks very much Latch, you've been a great help!
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 7th Apr 2009 05:28
o, i c how u r, only aknowledge the GOOD advice, jerk

There are only 10 kinds of people in the world, those who understand binary and those who dont
No Time To Code
16
Years of Service
User Offline
Joined: 22nd Dec 2008
Location:
Posted: 7th Apr 2009 06:13
Quote: "Thanks but I only have DBC right now."


Perhaps you didn't see that I did thank you for your advice.
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 7th Apr 2009 07:34
You could always assemble the whole thing in an external 3d modeller. That way you don't have to load and position 300+ trees and other static objects in the code.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
No Time To Code
16
Years of Service
User Offline
Joined: 22nd Dec 2008
Location:
Posted: 8th Apr 2009 02:29
Quote: "You could always assemble the whole thing in an external 3d modeller. That way you don't have to load and position 300+ trees and other static objects in the code."


If I went that route I'm wondering how collision would work if I wanted the character to walk through the forest? If it's just one model (object) I would think collision would not let a character enter. Would the tree trunks be limbs, each with their own collision so you could maneuver between them?
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 8th Apr 2009 03:19
Use these commands

SET OBJECT COLLISION ON
SET OBJECT COLLISION TO SPHERES/BOXES/POLYGONS

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
No Time To Code
16
Years of Service
User Offline
Joined: 22nd Dec 2008
Location:
Posted: 8th Apr 2009 03:38
Quote: "If you were going to use sparky's, I'd make the forest 1 object then set the collision in sparky's to polygons for the forest. "


OK, I see that's also what Latch was saying above. Thanks BN2!
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Apr 2009 05:08 Edited at: 8th Apr 2009 05:23
@No Time To Code
Quote: "You could always assemble the whole thing in an external 3d modeller"

Sometimes I forget the obvious!
It's the same principal as adding all the trees as limbs and then creating 1 object. The advantage of using the modeling program, of course, is that in a 3d modeling program, you can place things where and how you want with relative ease and save it all as one object. By setting collision to polygons on the one object, the collision will only occur when those individual faces intersect with another object set for collision or a ray (if you are using Sparky's DLL).

Last year, someone was trying to figure out a way to have hundreds of zombies attack a player and also have hundreds of trees/houses and such while still maintaining playability and still have collision detection. I wrote them up an example of a way to accomplish that which is right along the sames lines as what we've been discussing here.

In the example that follows, there are 300 trees (green boxes), 200 zombies (cones), 1 matrix, and 1 player (sphere). The trees are all made into one object and the collision is set to polygons for that. Now, with so many zombies, having all 200 set up for collision detection can be a real resource eater. So I figured, If I have to have a loop where I need to move each zombie, I can use a single invisible "feeler" to detect collision for each zombie as it's turn comes up in the loop.

This allows me to cut down on the number of collision boxes and collision checks and helps to improve performance. That means instead of 200 collision checks for each movement of a single zombie (200x200) I have 1 collision check for each zombie that moves. Combining this with hiding those zombies that aren't within the camera view, performance improves again. And since all of the trees are 1 object, they don't have to be individually leafed through in the index chain as DB checks to see what needs to be rendered; and as one object, the collision check for polygons is faster than individual box or a sphere collision check if each tree was an individual object.

Anyway, here is that example. Take a careful look through the code and try to see what I did. The program asks you to input a sync rate at the beginning. This was for testing purposes. I wanted to see what the highest rate was I could enter that would be maintained. On my machine, the fastest that this runs is at about 132 FPS. But a sync rate of 60 or even 40 is quite reasonable.

Use the mouse to steer. Use the up and down keys to move the red sphere. The white cones (zombies) will try to swarm you. They will try and avoid trees. If you hit a tree, you will stop, so you'll have to manuever around them.



Enjoy your day.
No Time To Code
16
Years of Service
User Offline
Joined: 22nd Dec 2008
Location:
Posted: 8th Apr 2009 07:49
Cool! Thanks Latch, I'll check it out tomorrow.

Login to post a reply

Server time is: 2025-08-08 20:42:29
Your offset time is: 2025-08-08 20:42:29