Search in sources :

Example 1 with Vector3b

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

the class RecursiveGrid method initialize.

@Override
public void initialize() {
    transformName = Settings.settings.scene.visibility.get(ComponentType.Galactic.toString()) ? "galacticToEquatorial" : (Settings.settings.scene.visibility.get(ComponentType.Ecliptic.toString()) ? "eclipticToEquatorial" : null);
    coordinateSystem = new Matrix4();
    coordinateSystemd = new Matrix4d();
    mat4daux = new Matrix4d();
    scalingFading = new Pair<>(0d, 0d);
    updateCoordinateSystem();
    nf = NumberFormatFactory.getFormatter("0.###E0");
    cc = Settings.settings.scene.visibility.get(ComponentType.Galactic.toString()) ? ccGal : (Settings.settings.scene.visibility.get(ComponentType.Ecliptic.toString()) ? ccEcl : ccEq);
    labelcolor = cc;
    label = true;
    labelPosition = new Vector3b();
    localTransform = new Matrix4();
    p01 = new Vector3d();
    p02 = new Vector3d();
    d01 = -1;
    d02 = -1;
    a = new Vector3d();
    b = new Vector3d();
    c = new Vector3d();
    d = new Vector3d();
    // Init billboard model
    mc = new ModelComponent();
    mc.setType("twofacedbillboard");
    Map<String, Object> p = new HashMap<>();
    p.put("diameter", 1d);
    mc.setParams(p);
    mc.forceInit = true;
    mc.initialize(null);
    mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, cc[0], cc[1], cc[2], cc[3]));
    // Depth reads, no depth writes
    mc.setDepthTest(GL20.GL_LEQUAL, false);
    // Initialize annotations vectorR
    initAnnotations();
}
Also used : Matrix4d(gaiasky.util.math.Matrix4d) Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) ModelComponent(gaiasky.scenegraph.component.ModelComponent) HashMap(java.util.HashMap) ColorAttribute(gaiasky.util.gdx.shader.attribute.ColorAttribute) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 2 with Vector3b

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

the class Spacecraft method updateLocalValues.

@Override
public void updateLocalValues(ITimeFrameProvider time, ICamera camera) {
    if (yawv != 0 || pitchv != 0 || rollv != 0 || vel.len2() != 0 || render) {
        // Poll keys
        if (camera.getMode().isSpacecraft())
            pollKeys(Gdx.graphics.getDeltaTime());
        double dt = time.getDt();
        // POSITION
        pos = computePosition(dt, camera.getSecondClosestBody(), currentEnginePower, thrust, direction, force, accel, vel, pos);
        if (leveling) {
            // No velocity, we just stop Euler angle motions
            if (yawv != 0) {
                yawp = -Math.signum(yawv) * MathUtilsd.clamp(Math.abs(yawv), 0, 1);
            }
            if (pitchv != 0) {
                pitchp = -Math.signum(pitchv) * MathUtilsd.clamp(Math.abs(pitchv), 0, 1);
            }
            if (rollv != 0) {
                rollp = -Math.signum(rollv) * MathUtilsd.clamp(Math.abs(rollv), 0, 1);
            }
            if (Math.abs(yawv) < 1e-3 && Math.abs(pitchv) < 1e-3 && Math.abs(rollv) < 1e-3) {
                setYawPower(0);
                setPitchPower(0);
                setRollPower(0);
                yawv = 0;
                pitchv = 0;
                rollv = 0;
                EventManager.publish(Event.SPACECRAFT_STABILISE_CMD, this, false);
            }
        }
        double rollDiff = computeDirectionUp(dt, dirup);
        double len = direction.len();
        pitch = Math.asin(direction.y / len);
        yaw = Math.atan2(direction.z, direction.x);
        roll += rollDiff;
        pitch = Math.toDegrees(pitch);
        yaw = Math.toDegrees(yaw);
    }
    // Update float vectors
    Vector3b camPos = B31.get().set(pos).add(camera.getInversePos());
    camPos.put(posf);
    direction.put(directionf);
    up.put(upf);
}
Also used : Vector3b(gaiasky.util.math.Vector3b)

Example 3 with Vector3b

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

the class Star method addHit.

public void addHit(int screenX, int screenY, int w, int h, int minPixDist, NaturalCamera camera, Array<IFocus> hits) {
    if (checkHitCondition()) {
        Vector3 pos = F31.get();
        Vector3b aux = B31.get();
        Vector3b posD = getAbsolutePosition(aux).add(camera.getInversePos());
        pos.set(posD.valuesf());
        if (camera.direction.dot(posD) > 0) {
            // The object is in front of us
            double angle = computeViewAngle(camera.getFovFactor()) * Settings.settings.scene.star.brightness * 1e3f;
            PerspectiveCamera perspectiveCamera;
            if (Settings.settings.program.modeStereo.active) {
                if (screenX < Gdx.graphics.getWidth() / 2f) {
                    perspectiveCamera = camera.getCameraStereoLeft();
                } else {
                    perspectiveCamera = camera.getCameraStereoRight();
                }
                perspectiveCamera.update();
            } else {
                perspectiveCamera = camera.camera;
            }
            angle = (float) Math.toDegrees(angle * camera.getFovFactor()) * (40f / perspectiveCamera.fieldOfView);
            double pixelSize = Math.max(minPixDist, ((angle * perspectiveCamera.viewportHeight) / perspectiveCamera.fieldOfView) / 2);
            perspectiveCamera.project(pos);
            pos.y = perspectiveCamera.viewportHeight - pos.y;
            if (Settings.settings.program.modeStereo.active) {
                pos.x /= 2;
            }
            // Check click distance
            if (checkClickDistance(screenX, screenY, pos, camera, perspectiveCamera, pixelSize)) {
                // Hit
                hits.add(this);
            }
        }
    }
}
Also used : Vector3b(gaiasky.util.math.Vector3b) Vector3(com.badlogic.gdx.math.Vector3) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera)

Example 4 with Vector3b

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

the class LocationLogManager method addRecord.

/**
 * Adds a new record with the given object, camera and time
 */
public void addRecord(final IFocus object, final ICamera camera, final ITimeFrameProvider time) {
    if (object != null) {
        final Instant entryTime = Instant.now();
        final Instant simulationTime = time.getTime();
        final String name = object.getClosestName();
        // Check if the new record is already in the 10 most recent items
        boolean found = false;
        int stop = Math.max(0, locations.size() - 10);
        for (int i = locations.size() - 1; i >= stop; i--) {
            if (locations.get(i).name.equalsIgnoreCase(name)) {
                found = true;
                break;
            }
        }
        if (!found) {
            // Create record
            final LocationRecord record = new LocationRecord();
            record.name = name;
            record.entryTime = entryTime;
            record.simulationTime = simulationTime;
            record.position = new Vector3b().set(camera.getPos());
            record.direction = new Vector3d().set(camera.getDirection());
            record.up = new Vector3d().set(camera.getUp());
            if (locations.size() == MAX_SIZE) {
                locations.pollFirst();
            }
            locations.add(record);
            EventManager.publish(Event.NEW_LOCATION_RECORD, this, locations);
            logger.debug(I18n.txt("gui.locationlog.newrecord", record.toStringFull()));
        }
    }
}
Also used : Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) Instant(java.time.Instant)

Example 5 with Vector3b

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

the class AbstractVSOP87 method getEquatorialCartesianCoordinates.

@Override
public Vector3b getEquatorialCartesianCoordinates(Instant date, Vector3b out) {
    Vector3b v = getEclipticSphericalCoordinates(date, out);
    if (v == null)
        return null;
    Coordinates.sphericalToCartesian(out, out);
    out.mul(Coordinates.eclToEq());
    return out;
}
Also used : Vector3b(gaiasky.util.math.Vector3b)

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