I’m trying to ‘automatically’ place objects on the scene ‘floor’ using either a Ray or collideWith(), but nothing is reporting the correct distance between the two Spatials in order to translate my new Geometry correctly.
I believe the correct was is to create either a plane, or a quad, as the floor and then collideWith() the new Geometry to get the Y distance to translate by? (I’ve tried a Ray as well but this doesn’t produce any results).
The added complication is that my entire scene is rotated to align with a localised coordinate system, therefore the floor and simple geometries like Box() are rotated as; Front: (0.79030997, -0.029681953, -0.6119788), Up: (-0.61155105, 0.02296824, -0.79087156)
I would like this method to work for both 2D flat ‘Floors’, but shortly I’m also going to implement a HeightMap terrain as well, therefore the distance between new objects and the ground will vary, hence the need for something ‘automatic’.
Can anyone tell me why neither of these work?
[java]
CollisionResults results = new CollisionResults();
featureRoot.collideWith(floor2D.getWorldBound(), results);
if (results.size() > 0) {
// how to react when a collision was detected
CollisionResult closest = results.getClosestCollision();
System.out.println("What was hit? " + closest.getGeometry().getName() );
System.out.println("Distance? " + closest.getDistance() );
}
floor2D.collideWith(featureRoot, results);
if (results.size() > 0) {
// how to react when a collision was detected
CollisionResult closest = results.getClosestCollision();
System.out.println("What was hit? " + closest.getGeometry().getName() );
System.out.println("Distance? " + closest.getDistance() );
}
[/java]
Floor creation code;
[java]
Vector3f[] vertices = toVector3fArray( geomToProcess.getCoordinates() );
Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(0,0);
texCoord[1] = new Vector2f(1,0);
texCoord[2] = new Vector2f(0,1);
texCoord[3] = new Vector2f(1,1);
short [] indexes = { 2,0,1, 1,3,2 };
float[] normals = new float[]{
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1};
Mesh mesh = new Mesh();
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
mesh.setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(indexes));
mesh. setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
mesh.updateBound();
[/java]
Many thanks…