ent_nextvertex(ENTITY*, VECTOR* pos );

A7.62 Liefert die Nummer eines Terrain-Vertices neben einer gegebenen Position zurück. Läßt sich zum Umformen von Teilen von Terrain verwenden.

Parameter:

ENTITY* - Terrain-Entity-Pointer.
pos
- XYZ-Position zum Bestimmen der Vertexnummer. Es sind nur die x- und y-Koordinaten relevant.

Rückgabewerte:

Vertexnummer oder 0 wenn die Funktion fehlschlägt.

Geschwindigkeit:

Schnell

Bemerkungen:

Beispiel:

// use a dynamic array to mark already-occupied places
char* terrain_places = NULL;

// place an entity at a random position on terrain
function ent_place(ENTITY* ent,ENTITY* terrain)
{
  if (!ent || !terrain) return; 
	var num,ground_z;
// generate terrain_places char array with the same size as the terrain vertices number
	if (terrain_places == NULL)
	   terrain_places = (char*)sys_malloc(ent_status(terrain,1)*sizeof(char)); 

   var i = 0;
   while (i++ < 10) // make 10 attempts to place it 
   {
// calculate random position on terrain      
      ent.x = terrain.min_x + random(terrain.max_x-terrain.min_x);
      ent.y = terrain.min_y + random(terrain.max_y-terrain.min_y);

// get the vertex number at that place
      num = ent_nextvertex(terrain,ent.x);
      if (!terrain_places[num-1]) // when place not already occupied 
        break; 
   }
   
   terrain_places[num-1] = 1; // mark place as occupied
   ent_getvertex(terrain,hit,num);
   ent.z = hit.z - ent.scale_z*ent.min_z - 2; // plant entity on terrain ground
}

function main()
{
   level_load("terrain.hmp");
   var i;
   for (i=0; i<500; i++)
      ent_place(ent_create("tree2.mdl",NULL,NULL),level_ent);
   
   sys_free(terrain_places); // not really necessary - is automatically freed at exit
} 

Siehe auch:

ent_next, ent_status, ent_getvertex

► Aktuelle Version Online