Search in sources :

Example 6 with ICamera

use of gaiasky.scenegraph.camera.ICamera in project gaiasky by langurmonkey.

the class Spacecraft method render.

/**
 * Default model rendering. *
 */
public void render(IntModelBatch modelBatch, float alpha, double t, boolean shadowEnv) {
    ICamera cam = GaiaSky.instance.getICamera();
    if (mc.isModelInitialised()) {
        // Good, render
        if (shadowEnv)
            prepareShadowEnvironment();
        mc.setTransparency(alpha * fadeOpacity);
        if (cam.getMode().isSpacecraft())
            // In SPACECRAFT_MODE mode, we are not affected by relativistic aberration or Doppler shift
            mc.updateRelativisticEffects(cam, 0);
        else
            mc.updateRelativisticEffects(cam);
        mc.updateVelocityBufferUniforms(cam);
        modelBatch.render(mc.instance, mc.env);
    } else {
        // Keep loading
        mc.load(localTransform);
    }
}
Also used : ICamera(gaiasky.scenegraph.camera.ICamera)

Example 7 with ICamera

use of gaiasky.scenegraph.camera.ICamera in project gaiasky by langurmonkey.

the class StarGroup method getCandidateViewAngleApparent.

@Override
public double getCandidateViewAngleApparent() {
    if (candidateFocusIndex >= 0) {
        IParticleRecord candidate = pointData.get(candidateFocusIndex);
        Vector3d aux = candidate.pos(D31.get());
        ICamera camera = GaiaSky.instance.getICamera();
        double va = (float) ((candidate.radius() / aux.sub(camera.getPos()).len()) / camera.getFovFactor());
        return va * Settings.settings.scene.star.brightness;
    } else {
        return -1;
    }
}
Also used : Vector3d(gaiasky.util.math.Vector3d) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) ICamera(gaiasky.scenegraph.camera.ICamera)

Example 8 with ICamera

use of gaiasky.scenegraph.camera.ICamera in project gaiasky by langurmonkey.

the class DecalUtils method drawSprite.

/**
 * Draws the given sprite using the given font in the given 3D position using
 * the 3D coordinate space. If faceCamera is true, the sprite is rendered
 * always facing the camera. It assumes that {@link ExtSpriteBatch#begin()} has
 * been called. This enables 3D techniques such as z-buffering to be applied
 * to the text textures.
 *
 * @param sprite           The sprite.
 * @param batch          The sprite batch to use.
 * @param x              The x coordinate.
 * @param y              The y coordinate.
 * @param z              The z coordinate.
 * @param size           The scale of the sprite.
 * @param rotationCenter Angles to rotate around center.
 * @param cam         The camera.
 * @param faceCamera     Whether to apply bill-boarding.
 * @param minSizeDegrees Minimum visual size of the text in degrees. Zero or negative to disable.
 * @param maxSizeDegrees Maximum visual size of the text in degrees. Zero or negative to disable.
 */
public static void drawSprite(Sprite sprite, SpriteBatch batch, float x, float y, float z, double size, float rotationCenter, ICamera cam, boolean faceCamera, float minSizeDegrees, float maxSizeDegrees) {
    sprite.setPosition(0, 0);
    sprite.setCenter(0, 0);
    // Store batch matrices
    aux1.set(batch.getTransformMatrix());
    aux2.set(batch.getProjectionMatrix());
    Camera camera = cam.getCamera();
    Quaternion rotation = getBillboardRotation(faceCamera ? camera.direction : tmp3.set(x, y, z).nor(), camera.up);
    if (minSizeDegrees > 0 || maxSizeDegrees > 0) {
        double dist = camera.position.dst(tmp3.set(x, y, z));
        double minsize = minSizeDegrees > 0 ? Math.tan(Math.toRadians(minSizeDegrees)) * dist : 0d;
        double maxsize = maxSizeDegrees > 0 ? Math.tan(Math.toRadians(maxSizeDegrees)) * dist : 1e20d;
        size = MathUtils.clamp(size, (float) minsize, (float) maxsize);
    }
    float sizeF = (float) size;
    batch.getTransformMatrix().set(camera.combined).translate(x, y, z).rotate(rotation).rotate(0, 1, 0, 180).rotate(0, 0, 1, rotationCenter).scale(sizeF, sizeF, sizeF);
    // Force matrices to be set to shader
    batch.setProjectionMatrix(idt);
    sprite.draw(batch);
    // Restore batch matrices
    batch.setTransformMatrix(aux1);
    batch.setProjectionMatrix(aux2);
}
Also used : Quaternion(com.badlogic.gdx.math.Quaternion) ICamera(gaiasky.scenegraph.camera.ICamera) Camera(com.badlogic.gdx.graphics.Camera)

Example 9 with ICamera

use of gaiasky.scenegraph.camera.ICamera in project gaiasky by langurmonkey.

the class DecalUtils method drawFont3D.

/**
 * Draws the given text using the given font in the given 3D position using
 * the 3D coordinate space. If faceCamera is true, the text is rendered
 * always facing the camera. It assumes that {@link ExtSpriteBatch#begin()} has
 * been called. This enables 3D techniques such as z-buffering to be applied
 * to the text textures.
 *
 * @param font           The font.
 * @param batch          The sprite batch to use.
 * @param text           The text to write.
 * @param x              The x coordinate.
 * @param y              The y coordinate.
 * @param z              The z coordinate.
 * @param size           The scale of the font.
 * @param rotationCenter Angles to rotate around center.
 * @param cam         The camera.
 * @param faceCamera     Whether to apply bill-boarding.
 * @param minSizeDegrees Minimum visual size of the text in degrees. Zero or negative to disable.
 * @param maxSizeDegrees Maximum visual size of the text in degrees. Zero or negative to disable.
 */
public static void drawFont3D(BitmapFont font, ExtSpriteBatch batch, String text, float x, float y, float z, double size, float rotationCenter, ICamera cam, boolean faceCamera, float minSizeDegrees, float maxSizeDegrees) {
    // Store batch matrices
    aux1.set(batch.getTransformMatrix());
    aux2.set(batch.getProjectionMatrix());
    Camera camera = cam.getCamera();
    Quaternion rotation = getBillboardRotation(faceCamera ? camera.direction : tmp3.set(x, y, z).nor(), camera.up);
    if (minSizeDegrees > 0 || maxSizeDegrees > 0) {
        double dist = camera.position.dst(tmp3.set(x, y, z));
        double minsize = minSizeDegrees > 0 ? Math.tan(Math.toRadians(minSizeDegrees)) * dist : 0d;
        double maxsize = maxSizeDegrees > 0 ? Math.tan(Math.toRadians(maxSizeDegrees)) * dist : 1e20d;
        size = MathUtils.clamp(size, (float) minsize, (float) maxsize);
    }
    float sizeF = (float) size;
    batch.getTransformMatrix().set(camera.combined).translate(x, y, z).rotate(rotation).rotate(0, 1, 0, 180).rotate(0, 0, 1, rotationCenter).scale(sizeF, sizeF, sizeF);
    // Force matrices to be set to shader
    batch.setProjectionMatrix(idt);
    font.draw(batch, text, 0, 0);
    // Restore batch matrices
    batch.setTransformMatrix(aux1);
    batch.setProjectionMatrix(aux2);
}
Also used : Quaternion(com.badlogic.gdx.math.Quaternion) ICamera(gaiasky.scenegraph.camera.ICamera) Camera(com.badlogic.gdx.graphics.Camera)

Aggregations

ICamera (gaiasky.scenegraph.camera.ICamera)9 Camera (com.badlogic.gdx.graphics.Camera)2 Quaternion (com.badlogic.gdx.math.Quaternion)2 IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)2 Vector3d (gaiasky.util.math.Vector3d)1