Hello

Does anyone know of a reference for creating a system of vehicles moving over a 3D rendered terrain?

Thank you.

Hello

Does anyone know of a reference for creating a system of vehicles moving over a 3D rendered terrain?

Thank you.

Interesting. â€śSystem of vehiclesâ€ť as in flocking? How are they moving as a system?

Or do you want a flow field that works like a topographical map?

This is an old project, not processing, but it is one example of the concepts involved found on a keyword search â€“ flocking plus 3D terrain

https://digitalcommons.unl.edu/cgi/viewcontent.cgi?httpsredir=1&article=1127&context=csetechreports

Yes, a flocking system will do it. I am just interested in agents moving about a tridimensional landscape. They may wander or flock or whatever. A topographical field might be useful.

Thanks for the link, though I only know processing Iâ€™ll check it out.

If you are building your own, a good way to get started is to generate a 3d terrain

then have an agent move over on in a straight line â€“ that is, update its x and y, but take its z from the terrain intercept. So, given a mesh / terrain and an x,y coordinate on it, what is the height intercept?

Working this out for one agent with simple motion, THEN adding 2D flocking on the x,y behaviors of your agents, and you will have vehicles flocking on 3D terrain. In essence, the 2d flocking sketch and the 3D single agent on terrain sketch can be easily combined.

After that, you may wish to then indicate impassible terrain, or modify motion for angle of attack on a steep grade etc.

Edit: I should note that just projecting z does have a downside â€“ things move faster on the grade than the do on the flat, which may look odd for boyds heading uphillâ€“depending on what you are trying to simulate. Still, it is a simple way to start.

1 Like

Flocking

Steering behaviours

I succeeded in making a thing move through the mountains coherently, i.e, its z coordinate adapts to the particular value of where it is standing on the 2D array.

Hereâ€™s the code.

```
int cols, rows;
int scl = 20; //scale
int w = 1200; //width, adjustable
int h = 900; //height, adjustable
int atX = 0;
int atY = 0;
float [][] z;
float moveOffX = 0;
float moveOffY = 0;
void setup() {
size(1600, 1100, P3D);
frameRate(60);
cols = w / scl;
rows = h / scl;
z = new float[cols][rows];
float yoff = 0; //small float offset for smooth changes in value
for (int y = 0; y < rows; y++) {
float xoff = 0;
for (int x = 0; x < cols; x++) {
z[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100); //output of map(last numbers) controlled for height of mountains.
xoff += 0.2;//change offsets to control smoothness.
}
yoff +=0.2;
}
}
void draw() {
background(0);
stroke(255);
fill(111, 222, 55);
translate(width/2, height/2); //prepares to rotate everything relative to center of window
rotateX(radians(45));
translate(-w/2, -h/2); //offsets beginning of coordinates so that all of them appear in the screen.
//TRIANGLE_STRIP: LAND
for (int y = 0; y < rows-1; y++) {
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < cols; x++) {
vertex(x*scl, y*scl, z[x][y]);
vertex(x*scl, (y+1)*scl, z[x][y+1]);
}
endShape();
}
for (int y = 0; y < rows-1; y++) {
for (int x = 0; x < cols; x++) {
if (x == atX && y == atY) {
fill(255, 0, 0);
pushMatrix();
translate(x*scl, y*scl, z[x][y] + 9); //the addition makes the ellipse not intersect the mountains for the most part.
ellipse(0, 0, 19, 19);
popMatrix();
}
}
}
//these are the coordinates now. I can control these to control the thing's movement.
atX = int(map(mouseX, 0, width, 0, cols));
atY = int(map(mouseY, 0, height, 0, rows));
}
```

I am at odds however not knowing how to introduce an agent system over such a rugged plane. The agent system in question is irrelevant for now. I donâ€™t need to learn flocking. I just need to figure out how to put an agent-based, vector-based system over the mountainous terrain and look natural (natural enough). To begin with, the simplest agent based system could implement simple seeking behavior, in which a single Vehicle pursues a target. The target could be the red circle that you can move with the mouse in my sketch. I know how to do this on a regular window, but I need it to occur over the terrain.

2 Likes

Congrats on solving this. If you know how to do it in 2d, is it possible to extend that method to 3d, ie given that your vehicle will have 3 components x,y,z if you know where it is in the x and z location, would it be possible to calculate the angle the vehicle needs to be based on the height of the tiles below it. So that if all tiles where flat the vehicle would be completely flat in the y axis, then step through each wheel location and adjust how high they should be

1 Like

Natural how? Is the idea that you want the agent going uphill to be slower than downhill, and for the agent to choose a path to the target that optimizes their speed or their arrival time? Or just avoids grades steeper than x?

1 Like