Cool Tip

Started by
2 comments, last by darrin 24 years, 1 month ago
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.location.z * orient->scale.z; PR_Transform (orient->rot_mat); x2 = ent->segment_orientation.location.x; z2 = ent->segment_orientation.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 </i>
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.

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
i have a rough idea but will prefer viewing the max file.

Is it possible ?

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

This topic is closed to new replies.

Advertisement