Search in sources :

Example 6 with InterfaceTexture

use of com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture in project j6dof-flight-sim by chris-ali.

the class VerticalSpeed method setGaugeValue.

@Override
public void setGaugeValue(Map<FlightDataType, Double> flightData) {
    if (flightData != null) {
        double verticalSpeed = flightData.get(FlightDataType.VERT_SPEED);
        double rotationAngle = 0.0;
        if (Math.abs(verticalSpeed) < 3000)
            rotationAngle = -(Math.PI / 3000) * verticalSpeed;
        else if (Math.abs(verticalSpeed) > 3000)
            rotationAngle = -Math.PI;
        InterfaceTexture pointer = gaugeTextures.get(POINTER);
        if (pointer != null)
            pointer.setRotation((float) Math.toDegrees(rotationAngle));
    }
}
Also used : InterfaceTexture(com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture)

Example 7 with InterfaceTexture

use of com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture in project j6dof-flight-sim by chris-ali.

the class InterfaceRenderer method render.

public void render(List<InterfaceTexture> interfaceTextures) {
    shader.start();
    GL30.glBindVertexArray(quad.getVaoID());
    GL20.glEnableVertexAttribArray(0);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    for (InterfaceTexture interfaceTexture : interfaceTextures) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, interfaceTexture.getTexture());
        Matrix4f matrix = RenderingUtilities.createTransformationMatrix(interfaceTexture.getPosition(), interfaceTexture.getRotation(), interfaceTexture.getScale());
        shader.loadTransformation(matrix);
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount());
    }
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_BLEND);
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
    shader.stop();
}
Also used : InterfaceTexture(com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture) Matrix4f(org.lwjgl.util.vector.Matrix4f)

Example 8 with InterfaceTexture

use of com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture in project j6dof-flight-sim by chris-ali.

the class AbstractGauge method loadTextures.

/**
 * After the gauge has been deserialized, call this method to load all textures in to memory
 * in the textureNames list
 *
 * @param loader
 */
public void loadTextures(Loader loader) {
    if (gaugeTextures == null || gaugeTextures.size() == 0) {
        logger.error("No texture information stored in class!");
        return;
    }
    logger.debug("Loading " + getClass().getSimpleName() + "'s associated textures...");
    for (Map.Entry<String, InterfaceTexture> entry : gaugeTextures.entrySet()) {
        Texture texture = loader.loadAndGetTexture(entry.getKey(), OTWDirectories.GAUGES.toString());
        entry.getValue().setTexture(texture.getTextureID());
    }
}
Also used : InterfaceTexture(com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) InterfaceTexture(com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture) Texture(org.newdawn.slick.opengl.Texture)

Example 9 with InterfaceTexture

use of com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture in project j6dof-flight-sim by chris-ali.

the class ArtificialHorizon method setGaugeValue.

@Override
public void setGaugeValue(Map<FlightDataType, Double> flightData) {
    if (flightData != null) {
        double pitch = flightData.get(FlightDataType.PITCH) * -1 % 180;
        double roll = flightData.get(FlightDataType.ROLL) % 360;
        // Handle upside down cases
        if (pitch > 90) {
            pitch = 180 - pitch;
            roll = (roll - 180) % 360;
        } else if (pitch < -90) {
            pitch = -180 - pitch;
            roll = (roll + 180) % 360;
        }
        InterfaceTexture horizonInner = gaugeTextures.get(HORIZON_INNER), horizonOuter = gaugeTextures.get(HORIZON_OUTER);
        // Account for horizon roll offset
        float horizonPosX = (float) ((pitch * 0.0025) * Math.sin(Math.toRadians(roll)));
        float horizonPosY = (float) ((pitch * 0.0025) * Math.cos(Math.toRadians(roll)));
        if (horizonInner != null) {
            horizonInner.setPosition(new Vector2f(position.x - horizonPosX, position.y + horizonPosY));
            horizonInner.setRotation((float) roll);
        }
        if (horizonOuter != null)
            horizonOuter.setRotation((float) roll);
    }
}
Also used : InterfaceTexture(com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture) Vector2f(org.lwjgl.util.vector.Vector2f)

Example 10 with InterfaceTexture

use of com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture in project j6dof-flight-sim by chris-ali.

the class InstrumentPanel method loadAndGetTextures.

/**
 * Loads all {@link InterfaceTexture} objects associated with each {@link AbstractGauge} in this class to be
 * rendered. Call this method after initializing this object
 *
 * @param loader
 * @return List of {@link InterfaceTexture} objects
 */
public List<InterfaceTexture> loadAndGetTextures(Loader loader, String aircraftName) {
    List<InterfaceTexture> interfaceTextures = new ArrayList<>();
    logger.debug("Initializing instrument panel...");
    InterfaceTexture panelBase = new InterfaceTexture(loader.loadTexture(SimDirectories.AIRCRAFT.toString(), getClass().getSimpleName(), aircraftName), panelPosition, 0.0f, panelScale);
    interfaceTextures.add(panelBase);
    for (AbstractGauge gauge : gauges) {
        gauge.loadTextures(loader);
        interfaceTextures.addAll(gauge.getTextures());
    }
    logger.debug("...done!");
    return interfaceTextures;
}
Also used : InterfaceTexture(com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture) ArrayList(java.util.ArrayList)

Aggregations

InterfaceTexture (com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture)10 Vector2f (org.lwjgl.util.vector.Vector2f)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Matrix4f (org.lwjgl.util.vector.Matrix4f)1 Texture (org.newdawn.slick.opengl.Texture)1