Search in sources :

Example 16 with Vector3b

use of gaiasky.util.math.Vector3b in project gaiasky by langurmonkey.

the class RecursiveGrid method renderDistanceLabel.

private void renderDistanceLabel(ExtSpriteBatch batch, ExtShaderProgram shader, FontRenderSystem sys, RenderingContext rc, ICamera camera, double dist, String text) {
    shader.setUniformf("u_viewAngle", 90f);
    shader.setUniformf("u_viewAnglePow", 1);
    shader.setUniformf("u_thOverFactor", 1);
    shader.setUniformf("u_thOverFactorScl", 1);
    IFocus focus = camera.getFocus();
    Vector3b v = B31.get().setZero();
    if (Settings.settings.program.recursiveGrid.origin.isFocus() && focus != null) {
        focus.getAbsolutePosition(v);
    }
    float ff = camera.getFovFactor();
    float min = 0.025f * ff;
    float max = 0.07f * ff;
    // +Z
    labelPosition.set(0d, 0d, dist);
    labelPosition.mul(coordinateSystemd);
    labelPosition.add(v).sub(camera.getPos());
    render3DLabel(batch, shader, sys.fontDistanceField, camera, rc, text, labelPosition.put(D34.get()), distToCamera, textScale(), (float) (dist * 1.5e-3d * camera.getFovFactor()), min, max, this.forceLabel);
    // -Z
    labelPosition.set(0d, 0d, -dist);
    labelPosition.mul(coordinateSystemd);
    labelPosition.add(v).sub(camera.getPos());
    render3DLabel(batch, shader, sys.fontDistanceField, camera, rc, text, labelPosition.put(D34.get()), distToCamera, textScale(), (float) (dist * 1.5e-3d * camera.getFovFactor()), min, max, this.forceLabel);
}
Also used : Vector3b(gaiasky.util.math.Vector3b)

Example 17 with Vector3b

use of gaiasky.util.math.Vector3b in project gaiasky by langurmonkey.

the class RecursiveGrid method getCFPos.

private void getCFPos(Vector3d cpos, Vector3d fpos, ICamera camera, IFocus focus) {
    Matrix4d inv = coordinateSystemd;
    Matrix4d trf = mat4daux.set(inv).inv();
    camera.getPos().put(cpos).mul(trf);
    Vector3b v3b = new Vector3b(fpos);
    focus.getPredictedPosition(v3b, GaiaSky.instance.time, camera, false).mul(trf);
    v3b.put(fpos).sub(cpos);
}
Also used : Matrix4d(gaiasky.util.math.Matrix4d) Vector3b(gaiasky.util.math.Vector3b)

Example 18 with Vector3b

use of gaiasky.util.math.Vector3b in project gaiasky by langurmonkey.

the class Spacecraft method computePosition.

public Vector3b computePosition(double dt, IFocus closest, double currentEnginePower, Vector3d thrust, Vector3d direction, Vector3d force, Vector3d accel, Vector3d vel, Vector3b posb) {
    currentEnginePower = Math.signum(currentEnginePower);
    // Compute force from thrust
    thrust.set(direction).scl(thrustMagnitude * thrustFactor[thrustFactorIndex] * currentEnginePower);
    force.set(thrust);
    // Scale force if relativistic effects are on
    if (Settings.settings.runtime.relativisticAberration) {
        double speed = vel.len();
        double scale = (relativisticSpeedCap - speed) / relativisticSpeedCap;
        force.scl(scale);
    }
    double friction = (drag * 2e16) * dt;
    force.add(D31.get().set(vel).scl(-friction));
    if (stopping) {
        double speed = vel.len();
        if (speed != 0) {
            currentEnginePower = -1;
            thrust.set(vel).nor().scl(thrustMagnitude * thrustFactor[thrustFactorIndex] * currentEnginePower);
            force.set(thrust);
        }
        Vector3d nextVel = D33.get().set(force).scl(1d / mass).scl(Constants.M_TO_U).scl(dt).add(vel);
        if (vel.angle(nextVel) > 90) {
            setCurrentEnginePower(0);
            force.scl(0);
            vel.scl(0);
            EventManager.publish(Event.SPACECRAFT_STOP_CMD, this, false);
        }
    }
    // Compute new acceleration in m/s^2
    accel.set(force).scl(1d / mass);
    // Integrate other quantities
    // convert metres to internal units so we have the velocity in u/s
    Vector3d acc = D31.get().set(accel).scl(Constants.M_TO_U);
    if (Settings.settings.spacecraft.velocityDirection) {
        double velocityLength = vel.len();
        vel.set(direction).nor().scl(velocityLength);
    }
    vel.add(acc.scl(dt));
    Vector3b velocity = B32.get().set(vel);
    Vector3b newPosition = B33.get().set(posb).add(velocity.scl(dt));
    Vector3b pos = posb.put(B34.get());
    // Check collision!
    if (closest != null && closest != this && !this.copy) {
        double twoRadii = closest.getRadius() + this.getRadius();
        // d1 is the new distance to the centre of the object
        if (!vel.isZero() && Intersectord.distanceSegmentPoint(pos.put(D31.get()), newPosition.put(D32.get()), closest.getPos().put(D33.get())) < twoRadii) {
            logger.info("Crashed against " + closest.getName() + "!");
            Array<Vector3d> intersections = Intersectord.intersectRaySphere(pos.put(D31.get()), newPosition.put(D32.get()), closest.getPos().put(D31.get()), twoRadii);
            // Teleport outside
            if (intersections.size >= 1) {
                posb.set(intersections.get(0));
            }
            stopAllMovement();
        } else if (posb.dstd(closest.getPos()) < twoRadii) {
            posb.set(B31.get().set(posb).sub(closest.getPos()).nor().scl(posb.dst(closest.getPos(), B32.get())));
        } else {
            posb.set(newPosition);
        }
    } else {
        posb.set(newPosition);
    }
    return posb;
}
Also used : Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d)

Example 19 with Vector3b

use of gaiasky.util.math.Vector3b in project gaiasky by langurmonkey.

the class AtmosphereComponent method updateAtmosphericScatteringParams.

/**
 * Updates the atmospheric scattering shader parameters
 *
 * @param mat    The material to update.
 * @param alpha  The opacity value.
 * @param ground Whether it is the ground shader or the atmosphere.
 * @param planet The planet itself, holder of this atmosphere
 */
public void updateAtmosphericScatteringParams(Material mat, float alpha, boolean ground, Planet planet, Vector3d vrOffset) {
    Vector3b transform = planet.translation;
    RotationComponent rc = planet.rc;
    SceneGraphNode sol = planet.parent;
    transform.put(aux3);
    if (vrOffset != null) {
        aux1.set(vrOffset).scl(1 / Constants.M_TO_U);
        aux3.sub(aux1);
    }
    // Distance to planet
    float camHeight = (float) (aux3.len());
    float m_ESun = m_eSun;
    float camHeightGr = camHeight - m_fInnerRadius;
    float atmFactor = (m_fAtmosphereHeight - camHeightGr) / m_fAtmosphereHeight;
    if (!ground && camHeightGr < m_fAtmosphereHeight) {
        // Camera inside atmosphere
        m_ESun += atmFactor * 100f;
    }
    // These are here to get the desired effect inside the atmosphere
    if (mat.has(AtmosphereAttribute.KrESun))
        ((AtmosphereAttribute) mat.get(AtmosphereAttribute.KrESun)).value = m_Kr * m_ESun;
    else
        mat.set(new AtmosphereAttribute(AtmosphereAttribute.KrESun, m_Kr * m_ESun));
    if (mat.has(AtmosphereAttribute.KmESun))
        ((AtmosphereAttribute) mat.get(AtmosphereAttribute.KmESun)).value = m_Km * m_ESun;
    else
        mat.set(new AtmosphereAttribute(AtmosphereAttribute.KmESun, m_Km * m_ESun));
    // Camera height
    if (mat.has(AtmosphereAttribute.CameraHeight))
        ((AtmosphereAttribute) mat.get(AtmosphereAttribute.CameraHeight)).value = camHeight;
    else
        mat.set(new AtmosphereAttribute(AtmosphereAttribute.CameraHeight, camHeight));
    // Planet position
    if (ground) {
        // Camera position must be corrected using the rotation angle of the planet
        aux3.mul(Coordinates.getTransformD(planet.inverseRefPlaneTransform)).rotate(rc.ascendingNode, 0, 1, 0).rotate(-rc.inclination - rc.axialTilt, 0, 0, 1).rotate(-rc.angle, 0, 1, 0);
    }
    ((Vector3Attribute) mat.get(Vector3Attribute.PlanetPos)).value.set(aux3.put(aux));
    // CameraPos = -PlanetPos
    aux3.scl(-1f);
    ((Vector3Attribute) mat.get(Vector3Attribute.CameraPos)).value.set(aux3.put(aux));
    // Light position respect the earth: LightPos = SunPos - EarthPos
    aux3.add(sol.translation).nor();
    if (ground) {
        // Camera position must be corrected using the rotation angle of the planet
        aux3.mul(Coordinates.getTransformD(planet.inverseRefPlaneTransform)).rotate(rc.ascendingNode, 0, 1, 0).rotate(-rc.inclination - rc.axialTilt, 0, 0, 1).rotate(-rc.angle, 0, 1, 0);
    }
    ((Vector3Attribute) mat.get(Vector3Attribute.LightPos)).value.set(aux3.put(aux));
    // Alpha value
    ((AtmosphereAttribute) mat.get(AtmosphereAttribute.Alpha)).value = alpha;
}
Also used : Vector3b(gaiasky.util.math.Vector3b) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) AtmosphereAttribute(gaiasky.util.gdx.shader.attribute.AtmosphereAttribute)

Example 20 with Vector3b

use of gaiasky.util.math.Vector3b in project gaiasky by langurmonkey.

the class VelocityBufferComponent method updateVelocityBufferMaterial.

public void updateVelocityBufferMaterial(Material material, ICamera cam) {
    if (material.get(Matrix4Attribute.PrevProjView) == null) {
        setUpVelocityBufferMaterial(material);
    }
    // Previous projection view matrix
    ((Matrix4Attribute) material.get(Matrix4Attribute.PrevProjView)).value.set(cam.getPreviousProjView());
    // Camera position difference
    Vector3 dCamPos = ((Vector3Attribute) material.get(Vector3Attribute.DCamPos)).value;
    Vector3b dp = cam.getPreviousPos();
    Vector3b p = cam.getPos();
    dCamPos.set(dp.x.subtract(p.x).floatValue(), dp.y.subtract(p.y).floatValue(), dp.z.subtract(p.z).floatValue());
}
Also used : Vector3Attribute(gaiasky.util.gdx.shader.attribute.Vector3Attribute) Vector3b(gaiasky.util.math.Vector3b) Vector3(com.badlogic.gdx.math.Vector3)

Aggregations

Vector3b (gaiasky.util.math.Vector3b)21 Vector3d (gaiasky.util.math.Vector3d)8 Vector3 (com.badlogic.gdx.math.Vector3)5 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 Matrix4d (gaiasky.util.math.Matrix4d)3 Instant (java.time.Instant)2 Date (java.util.Date)2 Apfloat (org.apfloat.Apfloat)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Texture (com.badlogic.gdx.graphics.Texture)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 Matrix4 (com.badlogic.gdx.math.Matrix4)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Array (com.badlogic.gdx.utils.Array)1 BillboardGalaxy (gaiasky.scenegraph.BillboardGalaxy)1 CelestialBody (gaiasky.scenegraph.CelestialBody)1 NBGalaxy (gaiasky.scenegraph.NBGalaxy)1 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)1 StarCluster (gaiasky.scenegraph.StarCluster)1