Terrain stuff

Started by
4 comments, last by kayX 22 years, 5 months ago
Lets say i have a complete terrain engine using ROAM. But how do i place my objects on the world? and how do i determine which object is to be rendered and which should not thanks in advance.
Advertisement
Well, I suppose all objects have a set of coordinates, which you could weigh against the player''s current coordinates, and render them when they are in your frustrum.

-----------------------------
Jappie
BabJap Productions

"There''s no such things as bugs; they''re just unintentional extra features"
----------------------------- JappieBabJap Productions"There's no such things as bugs; they're just unintentional extra features"
What if.. lets say; i have 500 objects in the world. Does this means i have to check if 500 objects? if the number of objects is a lot more than this figure, will that be slow?
Well, the more objects you have, the slower your prog is gonna be, can''t help you there. Maybe you could make some kind of sorting algo based on the position of the frustrum, ie objects closest to the player first, then you could rule out a lot of objects as soon as the coords get out of the frustrum. Dunno if it''s fast, just off the top of my head

-----------------------------
Jappie
BabJap Productions

"There''s no such things as bugs; they''re just unintentional extra features"
----------------------------- JappieBabJap Productions"There's no such things as bugs; they're just unintentional extra features"
Its much easier in fact to test spheres than actualy objects, for instance an object could be represented by a vector and a radius from that vector. The vector is the approximate geometrical center of an object and the radius would be just long enough to encompass the entire object.

Then you simply have to find the normal of each of the 6 planes of the frustrum and make sure that the object does not intersect any of them, and does not fall between them.

Finding if the object might intersect a plane is as simple as making sure that the object is farther away from the plane than the radius of the sphere in the direction of the planes normal ( the direction that the plane faces ) Since the normals of all the planes should be facing inward it shouldnt be very difficult.

I do happen to forget at this very moment how to calculate if the sphere lies within all 6 planes though.

~Vendayan
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan

If your terrain doesn''t have ''sections'' you should probably discard objects on a simple distance check first. If the distance to the object is greater than the distance to the farthest corner of your frustum - it''s not visible.

If you want to optimize further, just check the distance in
two dimensions first - if the distance is greater there, it
will be even greater in three dimensions.

--Michael

This topic is closed to new replies.

Advertisement