how can I do terrain looping like what "Need for speed" does?
It repeats the terrain for every lap in the car race.
I think it matches the end and front of the heights Map to be the same.
So when It come to the end, It load the same heights map again from the beginning.
Is it right? any examples / code on implementing this?
Why not just make a circle? :s
there by hitting the start when coming to the end⦠plane logic reallyā¦
Used in real life to I think you have misunderstood how NFS does itā¦
As Usul has said, need for speed courses are just circles to begin with. There is no magic.
And the terrain there is modeled prabably in a similar technique as TerrainPage⦠Or Maybe some sort of BSP modeled in an external software (because of the textures applied)
As the topic concerns racing games and I am a newbie here, I couldnāt resist asking the question:
What do you consider the neatest way of implementing various terrain types in jme? (I mean sth like asphalt road, dirt road, meadow etc.). Is there any ādefaultā way to couple that with textures? (i.e. access the info about the particular texture used at given spot)
Any suggestions would be deeply appreciated.
I donāt think anyone will answer in this 3 year old thread but for jME3 you could separate the collision shapes for the track by material, that is export the different parts (grass, road etc) as separate geometry, then create a collision shape for each. By checking which object you get returned by a rayCast from the car downwards you set the friction etc. values on the VehicleControl wheels.
I havenāt figured the forum mechanics out yet (whether the topics can resurface etc.) and I try to scavenge some pieces of knowledge every here and there. Thank you for help
Probably an easier way would be somehow to query the ground type given x,y.
@Sploreg: Do you think this kind of feature can be added? To get alphamap value and thus ground type for any point on the terrain same way getHeight(x,y) works.
It is reasonable to query the texture under a given x/z point. If you are using the default TerrainLighting material there are 3 alpha map images resulting in 12 different types of ground. It isnāt built right into the terrain API because I want to keep the material and the terrain separate, so you have to do a little work:
[java]
Image alpha1 = terrain.getMaterial().getParam(āAlphaMapā).getImage();
Image alpha2 = terrain.getMaterial().getParam(āAlphaMap_1ā).getImage();
Image alpha3 = terrain.getMaterial().getParam(āAlphaMap_2ā).getImage();
// calculate image coordinate:
Vector2f uv = new Vector2f(worldLoc.x,-worldLoc.z);
float scale = ((Node)terrain).getLocalScale().x;
uv.subtractLocal(((Node)terrain).getWorldTranslation().xscale, ((Node)terrain).getWorldTranslation().zscale); // center it on 0,0
float scaledSize = terrain.getTerrainSize()*scale;
uv.addLocal(scaledSize/2, scaledSize/2); // shift the bottom left corner up to 0,0
uv.divideLocal(scaledSize); // get the location as a percentage
uv.multLocal(alpha1.getWidth(), alpha1.getheight());
// do this for alpha1, 2, and 3
ByteBuffer buf = alpha1.getData(0);
int position = (uv.y * alpha1.getWidth() + uv.x) * 4;
buf.position( position );
return new ColorRGBA(byte2float(buf.get()), byte2float(buf.get()), byte2float(buf.get()), byte2float(buf.get()));
private float byte2float(byte b){
return ((float)(b & 0xFF)) / 255f;
}
[/java]
This code was taken from PaintTerrainToolAction.java as part of the SDKās terrain editor.