Hi,
As a very first try I used an intersection function I found in the web and put a class Intersection around that offers a getHOT() function. You can find it here : http://www.world-of-mystery.de/download/Intersection.java
It’s not optimized yet, e.g. it should check which mesh is out of question and skip the triangles. It only works with triples of coordinates forming a triangle.
To use it I have something like the following in the code:
private Intersection terrain;
terrain = new Intersection();
aseReader = new AseReader(new BufferedReader(new FileReader("simple.ASE")),aseFile,false);
aseFile.parse(aseReader);
aseModel = aseFile.getModel();
for (Node ch : (ArrayList<Node>)aseModel.getChildren())
{
if (ch instanceof Shape3D && ch.getName().startsWith("Plane"))
{
System.out.println("found: "+ch.getName()+" is "+ch.getClass());
Shape3D sh = (Shape3D)ch;
Geometry g = sh.getGeometry();
System.out.println(" with "+g.getClass());
if (!(g instanceof GeometryArray))
continue;
GeometryArray ga = (GeometryArray)g;
Point3f[] vertices = new Point3f[ga.getValidVertexCount()];
for (int i = 0; i < vertices.length; i++)
vertices[i] = new Point3f();
ga.getCoordinates(0,vertices);
terrain.addTriMesh(vertices, ch.getName());
}
}
private Point3f skyVector;
private Vector3f earthVector;
skyVector = new Point3f(0,0,1);
earthVector = new Vector3f(skyVector);
earthVector.negate();
float hot = terrain.getHOT(new Vector3f(playerPosition), earthVector);
if (Math.abs(hot) < 30 && (hot > eyeHeight || hot < eyeHeight))
playerPosition.z -= hot - eyeHeight;
(These are snippets from different places in the code, not a complete function.)
This way it follows the terrain quite well. Checks for heights that a character cannot climb and depth too big to jump down can be done in the function that steers the character.