Search in sources :

Example 1 with TexturedModel

use of com.chrisali.javaflightsim.lwjgl.models.TexturedModel in project j6dof-flight-sim by chris-ali.

the class LWJGLWorld method loadAssets.

/**
 * Initializes and generates all assets needed to render lights, entities, particles terrain and text
 */
private void loadAssets() {
    // ==================================== Sun ===========================================================
    logger.debug("Generating sun...");
    lights = new ArrayList<>();
    lights.add(new Light(new Vector3f(20000, 40000, 20000), new Vector3f(0.95f, 0.95f, 0.95f)));
    // ================================= Entities ==========================================================
    logger.debug("Generating collections of entities...");
    entities = new EntityCollections(lights, loader);
    // ================================= Ownship ===========================================================
    logger.debug("Creating ownship...");
    TexturedModel airplane = new TexturedModel(OBJLoader.loadObjModel("airplane", OTWDirectories.ENTITIES.toString(), loader), new ModelTexture(loader.loadTexture("airplane", OTWDirectories.ENTITIES.toString())));
    ownship = new Ownship(airplane, configuration.getInitialConditions(), 1.25f);
    logger.debug("Setting up camera...");
    // Camera tied to ownship as first person view
    camera = new Camera(ownship);
    camera.setChaseView(true);
    ownship.setScale(camera.isChaseView() ? 1.25f : 0f);
    entities.addToStaticEntities(ownship);
    // ================================= Terrain ==========================================================
    logger.debug("Generating terrain...");
    terrainCollection = new TerrainCollection(10, loader, ownship);
    entities.setTerrainTree(terrainCollection.getTerrainTree());
    // =============================== Particles ==========================================================
    logger.debug("Generating clouds...");
    ParticleTexture clouds = new ParticleTexture(loader.loadTexture("clouds", OTWDirectories.PARTICLES.toString()), 4, true);
    // Generates clouds at random positions along terrain map
    Random random = new Random();
    for (int i = -1000; i < 1000; i++) new Cloud(clouds, new Vector3f(random.nextInt(800 * 10), 300, i * 10), new Vector3f(0, 0, 0), 0, 200);
    // =============================== Interface ==========================================================
    logger.debug("Generating on-screen text and panel...");
    // On-screen text
    simTexts = new SimulationTexts(new FontType(loader, "ubuntu"));
    // Instrument Panel and Gauges
    interfaceTextures = new ArrayList<>();
    panel = FileUtilities.readInstrumentPanelConfiguration(configuration.getSelectedAircraft());
    if (configuration.getSimulationOptions().contains(Options.INSTRUMENT_PANEL)) {
        interfaceTextures = panel.loadAndGetTextures(loader, configuration.getSelectedAircraft());
        camera.setPilotPosition(new Vector3f(0, 5, 0));
        camera.setPitchOffset(25);
    }
    // ==================================== Audio =========================================================
    logger.debug("Generating sound collection...");
    soundCollection = new SoundCollection(configuration);
}
Also used : Ownship(com.chrisali.javaflightsim.lwjgl.entities.Ownship) TerrainCollection(com.chrisali.javaflightsim.lwjgl.terrain.TerrainCollection) SimulationTexts(com.chrisali.javaflightsim.lwjgl.interfaces.text.SimulationTexts) TexturedModel(com.chrisali.javaflightsim.lwjgl.models.TexturedModel) ParticleTexture(com.chrisali.javaflightsim.lwjgl.particles.ParticleTexture) EntityCollections(com.chrisali.javaflightsim.lwjgl.entities.EntityCollections) FontType(com.chrisali.javaflightsim.lwjgl.interfaces.text.FontType) ModelTexture(com.chrisali.javaflightsim.lwjgl.textures.ModelTexture) SoundCollection(com.chrisali.javaflightsim.lwjgl.audio.SoundCollection) Random(java.util.Random) Light(com.chrisali.javaflightsim.lwjgl.entities.Light) Vector3f(org.lwjgl.util.vector.Vector3f) Cloud(com.chrisali.javaflightsim.lwjgl.particles.Cloud) Camera(com.chrisali.javaflightsim.lwjgl.entities.Camera)

Example 2 with TexturedModel

use of com.chrisali.javaflightsim.lwjgl.models.TexturedModel in project j6dof-flight-sim by chris-ali.

the class MasterRenderer method processEntity.

private void processEntity(Entity entity) {
    TexturedModel entityModel = entity.getModel();
    List<Entity> batch = entityMap.get(entityModel);
    if (batch != null) {
        batch.add(entity);
    } else {
        List<Entity> newBatch = new ArrayList<>();
        newBatch.add(entity);
        entityMap.put(entityModel, newBatch);
    }
}
Also used : Entity(com.chrisali.javaflightsim.lwjgl.entities.Entity) TexturedModel(com.chrisali.javaflightsim.lwjgl.models.TexturedModel) ArrayList(java.util.ArrayList)

Example 3 with TexturedModel

use of com.chrisali.javaflightsim.lwjgl.models.TexturedModel in project j6dof-flight-sim by chris-ali.

the class EntityCollections method createLitEntity.

/**
 * <p>Creates a single lit entity based on the X and Z coordinates specified; the Y coordinate is the height of the terrain
 * at the given X and Z coordinates; </p>
 *<p>lightPosOffset refers to the position offset
 * from the entity's position that the light is centered at (e.g. a lamp post whose light is far above the post's position);
 * attenuation is the brightness of the light </p>
 *
 * @param entityName
 * @param xPos
 * @param zPos
 * @param yRot
 * @param scale
 * @param color
 * @param attenuation
 * @param lightPosOffset
 */
public void createLitEntity(String entityName, float xPos, float zPos, float yRot, float scale, Vector3f color, Vector3f attenuation, Vector3f lightPosOffset) {
    TexturedModel litEntity = new TexturedModel(OBJLoader.loadObjModel(entityName, OTWDirectories.ENTITIES.toString(), loader), new ModelTexture(loader.loadTexture(entityName, OTWDirectories.ENTITIES.toString())));
    float yPos = Terrain.getCurrentTerrain(terrainTree, xPos, zPos).getTerrainHeight(xPos, zPos);
    Vector3f position = new Vector3f(xPos, yPos, zPos);
    logger.debug("Generating a(n)" + entityName + " at: (" + xPos + ", " + yPos + ", " + zPos + ")...");
    miscLitEntities.add(new Entity(litEntity, position, 0, yRot, 0, scale));
    Light light = new Light(Vector3f.add(position, lightPosOffset, position), color, attenuation);
    lights.add(light);
}
Also used : TexturedModel(com.chrisali.javaflightsim.lwjgl.models.TexturedModel) Vector3f(org.lwjgl.util.vector.Vector3f) ModelTexture(com.chrisali.javaflightsim.lwjgl.textures.ModelTexture)

Example 4 with TexturedModel

use of com.chrisali.javaflightsim.lwjgl.models.TexturedModel in project j6dof-flight-sim by chris-ali.

the class EntityCollections method initializeEntities.

/**
 * Initializes all {@link TexturedModel} objects for in methods, which create entities
 */
private void initializeEntities() {
    // Create models
    // Static
    planatusForest = new TexturedModel(OBJLoader.loadObjModel("grassModel", OTWDirectories.ENTITIES.toString(), loader), new ModelTexture(loader.loadTexture("platanusforest", OTWDirectories.ENTITIES.toString())));
    pineForest = new TexturedModel(OBJLoader.loadObjModel("grassModel", OTWDirectories.ENTITIES.toString(), loader), new ModelTexture(loader.loadTexture("pineforest", OTWDirectories.ENTITIES.toString())));
    oakForest = new TexturedModel(OBJLoader.loadObjModel("grassModel", OTWDirectories.ENTITIES.toString(), loader), new ModelTexture(loader.loadTexture("oakforest", OTWDirectories.ENTITIES.toString())));
    // Lit
    lamp = new TexturedModel(OBJLoader.loadObjModel("lamp", OTWDirectories.ENTITIES.toString(), loader), new ModelTexture(loader.loadTexture("lamp", OTWDirectories.ENTITIES.toString())));
    // Model settings
    // Static
    planatusForest.getTexture().setHasTransparency(true);
    planatusForest.getTexture().setUseFakeLighting(true);
    pineForest.getTexture().setHasTransparency(true);
    pineForest.getTexture().setUseFakeLighting(true);
    oakForest.getTexture().setHasTransparency(true);
    oakForest.getTexture().setUseFakeLighting(true);
    // Lit
    lamp.getTexture().setUseFakeLighting(true);
}
Also used : TexturedModel(com.chrisali.javaflightsim.lwjgl.models.TexturedModel) ModelTexture(com.chrisali.javaflightsim.lwjgl.textures.ModelTexture)

Example 5 with TexturedModel

use of com.chrisali.javaflightsim.lwjgl.models.TexturedModel in project j6dof-flight-sim by chris-ali.

the class EntityCollections method createLitEntity.

/**
 * <p>Creates a single static entity based on the player's position</p>
 * <p>lightPosOffset refers to the position offset
 * from the entity's position that the light is centered at (e.g. a lamp post whose light is far above the post's position);
 * attenuation is the brightness of the light </p>
 *
 * @param entityName
 * @param player
 * @param scale
 * @param color
 * @param attenuation
 * @param lightPosOffset
 */
public void createLitEntity(String entityName, Player player, float scale, Vector3f color, Vector3f attenuation, Vector3f lightPosOffset) {
    logger.debug("Generating a(n)" + entityName + " at the ownship's postion: (" + player.getPosition().x + ", " + player.getPosition().y + ", " + player.getPosition().z + ")...");
    TexturedModel litEntity = new TexturedModel(OBJLoader.loadObjModel(entityName, OTWDirectories.ENTITIES.toString(), loader), new ModelTexture(loader.loadTexture(entityName, OTWDirectories.ENTITIES.toString())));
    Vector3f position = player.getPosition();
    miscLitEntities.add(new Entity(litEntity, position, player.getRotX(), player.getRotY(), player.getRotZ(), scale));
    Light light = new Light(Vector3f.add(position, lightPosOffset, position), color, attenuation);
    lights.add(light);
}
Also used : TexturedModel(com.chrisali.javaflightsim.lwjgl.models.TexturedModel) Vector3f(org.lwjgl.util.vector.Vector3f) ModelTexture(com.chrisali.javaflightsim.lwjgl.textures.ModelTexture)

Aggregations

TexturedModel (com.chrisali.javaflightsim.lwjgl.models.TexturedModel)9 ModelTexture (com.chrisali.javaflightsim.lwjgl.textures.ModelTexture)7 Vector3f (org.lwjgl.util.vector.Vector3f)4 Entity (com.chrisali.javaflightsim.lwjgl.entities.Entity)2 SoundCollection (com.chrisali.javaflightsim.lwjgl.audio.SoundCollection)1 Camera (com.chrisali.javaflightsim.lwjgl.entities.Camera)1 EntityCollections (com.chrisali.javaflightsim.lwjgl.entities.EntityCollections)1 Light (com.chrisali.javaflightsim.lwjgl.entities.Light)1 Ownship (com.chrisali.javaflightsim.lwjgl.entities.Ownship)1 FontType (com.chrisali.javaflightsim.lwjgl.interfaces.text.FontType)1 SimulationTexts (com.chrisali.javaflightsim.lwjgl.interfaces.text.SimulationTexts)1 Cloud (com.chrisali.javaflightsim.lwjgl.particles.Cloud)1 ParticleTexture (com.chrisali.javaflightsim.lwjgl.particles.ParticleTexture)1 TerrainCollection (com.chrisali.javaflightsim.lwjgl.terrain.TerrainCollection)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1