Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

darrin

Cool Tip

This topic is 6823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, Heres a code snip that I use all the time, and find very useful. This takes an Entity with lots of segments and shifts the segments around their pivot point down to the terrain ground level. (Actually if the object is placed 10 units above ground level, all segments shift to 10 units above ground level) I have used this in the past for lots of things, ie Create a Clump of 10 or so trees, as one object with 10 segments. Each segments pivot is based at the foot of the tree. Now run the entity through this once during setup and it repositions each segment down to ground level. (place large groups of trees on hills with ease) Currently using it in my flight simulator to position houses/buildings on hills. I have created a 2x2 city block, with about 20 buildings as one object and just duplicate this one object around the terrain. Benefits, A lot easier than placing 10 trees individually. Faster, as PR only needs to check the BBox of one object to determine if off screen, rather than 10 ////////////////////////////////////////////////////// // move each segment in an entitys pivot to the ground ////////////////////////////////////////////////////// void SegmentsToGround(PR_ENTITY *ent) { int i; PR_REAL x,y,z; PR_REAL x2,y2,z2; PR_ORIENTATION *orient; x = ent->orientation.location.x; z = ent->orientation.location.z; y = GAME_GetTerrainHeight (x, z); //replace with your height checking routine orient=&ent->orientation; for (i = 0; i < ent->shape->num_segments; i++) { tvector[0] = ent->segment_orientation.location.x * orient->scale.x; tvector[1] = 0; tvector[2] = ent->segment_orientation[i].location.z * orient->scale.z; PR_Transform (orient->rot_mat); x2 = ent->segment_orientation[i].location.x; z2 = ent->segment_orientation[i].location.z; y2 = (GAME_GetTerrainHeight (x+tvector[0], z+tvector[2])-y); PR_PositionSegment(ent, i, x2,y2,z2); } } Hope it is of use to someone. Cheers Darrin

Share this post


Link to post
Share on other sites
Advertisement
I cannot really grasp the full concept.

Do you happen to have a model file to show how you store the objects ?

A .pro or .3ds will be good.

Share this post


Link to post
Share on other sites
Hi Iram,
The trick is to create an Object in 3DSMax, each seperate segment within your max file will fit to the ground.
What you do is position each segments pivot point at the position you want to be on the ground. (ie shift the pivot for a tree to the base of the trunk)
Then shift each segment up so that its pivot is at 0 in the y axis.

This object should now do the trick.
If this doesn''t explain it enough, respond to this and I will send a max file & pro file of some boxes to illustrate it.

Cheers
Darrin

Share this post


Link to post
Share on other sites
i have a rough idea but will prefer viewing the max file.

Is it possible ?

you can send it to: starstar@cyberway.com.sg

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!