use of com.chrisali.javaflightsim.lwjgl.terrain.Terrain in project j6dof-flight-sim by chris-ali.
the class TerrainRenderer method render.
public void render(TreeSet<Terrain> terrainTree) {
for (Terrain terrain : terrainTree) {
// Render only terrain objects that are within a certain distance of ownship
if (terrain.getDistanceFromOwnship() < MasterRenderer.getDrawDistance()) {
prepareTerrain(terrain);
loadModelMatrix(terrain);
GL11.glDrawElements(GL11.GL_TRIANGLES, terrain.getModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
unbindTexturedModel();
// System.out.printf("%5.0f - %5.0f is %5.0f from ownship\n", terrain.getX(), terrain.getZ(), terrain.getDistanceFromOwnship());
}
}
// System.out.println("---------------------------------------");
// System.out.printf("Terrain tree has %d items\n", terrainTree.size());
}
use of com.chrisali.javaflightsim.lwjgl.terrain.Terrain in project j6dof-flight-sim by chris-ali.
the class Player method move.
/**
* Simple physics to move the player around the world while being tied to the ground
*
* @param terrainMap
*/
public void move(TreeMap<String, Terrain> terrainMap) {
checkInputs();
super.increaseRotation(0, currentTurnSpeed * DisplayManager.getFrameTimeSeconds(), 0);
float distance = currentSpeed * DisplayManager.getFrameTimeSeconds();
float dx = distance * (float) Math.sin(Math.toRadians(super.getRotY()));
float dz = distance * (float) Math.cos(Math.toRadians(super.getRotY()));
super.increasePosition(dx, 0, dz);
currentVerticalSpeed += GRAVITY * DisplayManager.getFrameTimeSeconds();
super.increasePosition(0, currentVerticalSpeed * DisplayManager.getFrameTimeSeconds(), 0);
Terrain terrain = Terrain.getCurrentTerrain(terrainMap, super.getPosition().x, super.getPosition().z);
float terrainHeight = terrain.getTerrainHeight(super.getPosition().x, super.getPosition().z);
if (super.getPosition().y < terrainHeight) {
currentVerticalSpeed = 0;
isAirborne = false;
super.getPosition().y = terrainHeight;
}
}
use of com.chrisali.javaflightsim.lwjgl.terrain.Terrain in project j6dof-flight-sim by chris-ali.
the class MasterRenderer method renderWholeScene.
/**
* Takes all entities and terrains, and adds them (if necessary) to entity/terrain maps, and then renders the scene with
* the given lights, camera and clipping plane
*
* @param entityCollection
* @param terrainTreeMap
* @param lights
* @param camera
* @param clippingPlane
*/
public void renderWholeScene(EntityCollections entityCollection, TreeMap<String, Terrain> terrainTreeMap, List<Light> lights, Camera camera, Vector4f clippingPlane) {
// Process miscellaneous entities from entityCollention
for (Entity entity : entityCollection.getStaticEntities()) processEntity(entity);
for (Entity entity : entityCollection.getLitEntities()) processEntity(entity);
this.terrainTree = new TreeSet<>(terrainTreeMap.values());
// Process entities tied to each terrain only if they are part of a terrain within the draw distance
for (Terrain terrain : terrainTree) {
if (terrain.getDistanceFromOwnship() < drawDistance) {
for (Entity entity : terrain.getStaticEntities()) processEntity(entity);
for (Entity entity : terrain.getLitEntities()) processEntity(entity);
}
}
render(lights, camera, clippingPlane);
}
use of com.chrisali.javaflightsim.lwjgl.terrain.Terrain in project j6dof-flight-sim by chris-ali.
the class LWJGLWorld method getTerrainHeight.
@Override
public synchronized float getTerrainHeight() {
if (terrainCollection == null)
return 0.0f;
TreeMap<String, Terrain> terrainTree = terrainCollection.getTerrainTree();
Vector3f position = ownship.getPosition();
// Terrain object ownship is currently on
Terrain currentTerrain = Terrain.getCurrentTerrain(terrainTree, position.x, position.z);
// If outside world bounds, return 0 as terrain height
return (currentTerrain == null) ? 0.0f : currentTerrain.getTerrainHeight(position.x, position.z);
}