Wednesday, April 18, 2012

Earth Moving III

General outline for preliminary earth moving logic (I fully intend for this to get polished later)

start with bounding rectangle (mesh coordinates) denoting excavation selection and ‘depth’ to excavate to.

Also start with bounding rectangle denoting ‘deposit’ selection (usually smaller).  No ‘depth’ necessary.

Eventually may change the ‘deposit’ area selection to a ‘circle’ once I figure out 
the math.

  • create 2d array of vertices covered in the excavation selection
  • create a 2d array of vertices covered in the deposit selection
  • loop through excavation vertices
    • find the ‘highest’ one to excavate and excavate it once.
    • find the ‘lowest’ vertice in the deposit area selection and drop it off
  • end loop

psuedo code for vertice array creation for excavation OR deposit

var ppp = map_height/plots; //note that currently map height/width are same
plots_x = floor(selection_width / ppp);
plots_y = floor(selection_height / ppp);
var vertice_array = new Array();
for(var y = 0;y<plots_y;y++){

var row = new Array();
for(var x = 0;x<plots_x;x++)
     vertice = find_vertice(left_edge+x*ppp, top_edge+y*ppp);
//find_vertice function finds vertice in mesh closest to the x/y coordinate

**UPDATE.  Yeah..silly of me...this assumes that each 'scoop' (excavation) of dirt will cover only a single vertice...and at the moment (because of performance reasons), it is actually about the future (assuming I move to another platform or otherwise solve), I'll have to have a more complex algorithm that checks the height of ALL vertices in the selected area and based on the radius of the 'scoop' decide where to dig/dump.

No comments:

Post a Comment