Search in sources :

Example 1 with ParticleTexture

use of com.chrisali.javaflightsim.lwjgl.particles.ParticleTexture 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 ParticleTexture

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

the class ParticleRenderer method render.

public void render(Map<ParticleTexture, List<Particle>> particles, Camera camera) {
    Matrix4f viewMatrix = RenderingUtilities.createViewMatrix(camera);
    prepare();
    shader.loadSkyColor(MasterRenderer.getSkyColor().x, MasterRenderer.getSkyColor().y, MasterRenderer.getSkyColor().z);
    shader.loadFog(MasterRenderer.getFogDensity(), MasterRenderer.getFogGradient());
    for (ParticleTexture texture : particles.keySet()) {
        bindTexture(texture);
        List<Particle> particleList = particles.get(texture);
        pointer = 0;
        float[] vboData = new float[particleList.size() * INSTANCE_DATA_LENGTH];
        for (Particle particle : particles.get(texture)) {
            // Subtracts out the camera roll to prevent clouds/particles rolling with the camera
            updateModelViewMatrix(particle.getPosition(), particle.getRotation() - camera.getRoll(), particle.getScale(), viewMatrix, vboData);
            updateTextureCoordinateInfo(particle, vboData);
        }
        loader.updateVBO(vbo, vboData, buffer);
        GL31.glDrawArraysInstanced(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount(), particleList.size());
    }
    finishRendering();
}
Also used : Particle(com.chrisali.javaflightsim.lwjgl.particles.Particle) Matrix4f(org.lwjgl.util.vector.Matrix4f) ParticleTexture(com.chrisali.javaflightsim.lwjgl.particles.ParticleTexture)

Aggregations

ParticleTexture (com.chrisali.javaflightsim.lwjgl.particles.ParticleTexture)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 TexturedModel (com.chrisali.javaflightsim.lwjgl.models.TexturedModel)1 Cloud (com.chrisali.javaflightsim.lwjgl.particles.Cloud)1 Particle (com.chrisali.javaflightsim.lwjgl.particles.Particle)1 TerrainCollection (com.chrisali.javaflightsim.lwjgl.terrain.TerrainCollection)1 ModelTexture (com.chrisali.javaflightsim.lwjgl.textures.ModelTexture)1 Random (java.util.Random)1 Matrix4f (org.lwjgl.util.vector.Matrix4f)1 Vector3f (org.lwjgl.util.vector.Vector3f)1