Search in sources :

Example 11 with Vector3b

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

the class CelestialBody method addHit.

public void addHit(Vector3d p0, Vector3d p1, NaturalCamera camera, Array<IFocus> hits) {
    if (checkHitCondition()) {
        Vector3b aux = B31.get();
        Vector3b posb = getAbsolutePosition(aux).add(camera.getInversePos());
        if (camera.direction.dot(posb) > 0) {
            // The star is in front of us
            // Diminish the size of the star
            // when we are close by
            double dist = posb.lend();
            double distToLine = Intersectord.distanceLinePoint(p0, p1, posb.put(D31.get()));
            double value = distToLine / dist;
            if (value < 0.01) {
                hits.add(this);
            }
        }
    }
}
Also used : Vector3b(gaiasky.util.math.Vector3b)

Example 12 with Vector3b

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

the class Constellation method render.

/**
 * Line rendering.
 */
@Override
public void render(LineRenderSystem renderer, ICamera camera, float alpha) {
    alpha *= this.alpha * opacity;
    Vector3d p1 = D31.get();
    Vector3d p2 = D32.get();
    Vector3b campos = camera.getPos();
    for (IPosition[] pair : lines) {
        if (pair != null) {
            getPosition(pair[0], campos, p1);
            getPosition(pair[1], campos, p2);
            renderer.addLine(this, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, cc[0], cc[1], cc[2], alpha);
        }
    }
}
Also used : IPosition(gaiasky.util.tree.IPosition) Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d)

Example 13 with Vector3b

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

the class NaturalCamera method initialize.

public void initialize(ShaderProgram spriteShader, ShaderProgram shapeShader) {
    if (vr) {
        camera = new PerspectiveCamera(Settings.settings.scene.camera.fov, Settings.settings.graphics.backBufferResolution[0], Settings.settings.graphics.backBufferResolution[1]);
    } else {
        camera = new PerspectiveCamera(Settings.settings.scene.camera.fov, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    }
    camera.near = (float) CAM_NEAR;
    camera.far = (float) CAM_FAR;
    fovBackup = Settings.settings.scene.camera.fov;
    // init cameras vector
    cameras = new PerspectiveCamera[] { camera, camLeft, camRight };
    fovFactor = camera.fieldOfView / 40f;
    up = new Vector3d(1, 0, 0);
    direction = new Vector3d(0, 1, 0);
    focusDirection = new Vector3b();
    desired = new Vector3b();
    pitch = new Vector3d(0.0f, 0.0f, -3.0291599E-6f);
    yaw = new Vector3d(0.0f, 0.0f, -7.9807205E-6f);
    roll = new Vector3d(0.0f, 0.0f, -1.4423944E-4f);
    horizontal = new Vector3d();
    vertical = new Vector3d();
    friction = new Vector3b();
    lastVel = new Vector3d();
    focusPos = new Vector3b();
    freeTargetPos = new Vector3b();
    freeTargetOn = false;
    DIST_A = 0.1 * Constants.PC_TO_U;
    DIST_B = 5.0 * Constants.KPC_TO_U;
    DIST_C = 5000.0 * Constants.MPC_TO_U;
    aux1 = new Vector3d();
    aux2 = new Vector3d();
    aux5 = new Vector3d();
    auxf1 = new Vector3();
    aux2f2 = new Vector2();
    aux1b = new Vector3b();
    aux2b = new Vector3b();
    aux3b = new Vector3b();
    aux4b = new Vector3b();
    aux5b = new Vector3b();
    dx = new Vector3b();
    nextFocusPosition = new Vector3b();
    nextClosestPosition = new Vector3b();
    // Mouse and keyboard listeners
    naturalMouseKbdListener = new NaturalMouseKbdListener(this);
    gameMouseKbdListener = new GameMouseKbdListener(this);
    currentMouseKbdListener = null;
    // Controller listeners
    controllerListener = new NaturalControllerListener(this, Settings.settings.controls.gamepad.mappingsFile);
    ControllerConnectionListener controllerConnectionListener = new ControllerConnectionListener();
    Controllers.addListener(controllerConnectionListener);
    if (vr)
        openVRListener = new OpenVRListener(this);
    // Shape renderer (pointer guide lines)
    shapeRenderer = new ShapeRenderer(10, shapeShader);
    shapeRenderer.getProjectionMatrix().setToOrtho2D(0, 0, camera.viewportWidth, camera.viewportHeight);
    // Init sprite batch for crosshair
    spriteBatch = new SpriteBatch(50, spriteShader);
    // Focus crosshair
    Texture crosshairFocus = new Texture(Gdx.files.internal("img/crosshair-focus.png"));
    crosshairFocus.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    spriteFocus = new Sprite(crosshairFocus);
    // Closest crosshair
    Texture crosshairClosest = new Texture(Gdx.files.internal("img/crosshair-closest.png"));
    crosshairClosest.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    spriteClosest = new Sprite(crosshairClosest);
    // Home crosshair
    Texture crosshairHome = new Texture(Gdx.files.internal("img/crosshair-home.png"));
    crosshairHome.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    spriteHome = new Sprite(crosshairHome);
    // Arrow crosshair
    crosshairArrow = new Texture(Gdx.files.internal("img/crosshair-arrow.png"));
    crosshairArrow.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    // Velocity vector crosshair
    Texture velocityCrosshair = new Texture(Gdx.files.internal("img/ai-vel.png"));
    velocityCrosshair.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    // Anti-velocity vector crosshair
    Texture antiVelocityCrosshair = new Texture(Gdx.files.internal("img/ai-antivel.png"));
    antiVelocityCrosshair.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    // Grav wave crosshair
    gravWaveCrosshair = new Texture(Gdx.files.internal("img/gravwave-pointer.png"));
    gravWaveCrosshair.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    // Speed HUD
    Texture sHUD = new Texture(Gdx.files.internal("img/hud-corners.png"));
    sHUD.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    hudWidth = sHUD.getWidth();
    hudHeight = sHUD.getHeight();
    hudScales = new double[] { HUD_SCALE_MIN, HUD_SCALE_MIN + (HUD_SCALE_MAX - HUD_SCALE_MIN) / 3d, HUD_SCALE_MIN + (HUD_SCALE_MAX - HUD_SCALE_MIN) * 2d / 3d };
    Sprite[] hudSprites = new Sprite[hudScales.length];
    hudColors = new Color[] { Color.WHITE, Color.GREEN, Color.GOLD, Color.LIME, Color.PINK, Color.ORANGE, Color.CORAL, Color.CYAN, Color.FIREBRICK, Color.FOREST };
    for (int i = 0; i < hudScales.length; i++) {
        hudSprites[i] = new Sprite(sHUD);
        hudSprites[i].setOriginCenter();
    }
    // FOCUS_MODE is changed from GUI
    EventManager.instance.subscribe(this, Event.FOCUS_CHANGE_CMD, Event.FOV_CHANGED_CMD, Event.ORIENTATION_LOCK_CMD, Event.CAMERA_POS_CMD, Event.CAMERA_DIR_CMD, Event.CAMERA_UP_CMD, Event.CAMERA_PROJECTION_CMD, Event.CAMERA_FWD, Event.CAMERA_ROTATE, Event.CAMERA_PAN, Event.CAMERA_ROLL, Event.CAMERA_TURN, Event.CAMERA_STOP, Event.CAMERA_CENTER, Event.GO_TO_OBJECT_CMD, Event.CUBEMAP_CMD, Event.FREE_MODE_COORD_CMD, Event.CATALOG_VISIBLE, Event.CATALOG_REMOVE, Event.FOCUS_NOT_AVAILABLE, Event.TOGGLE_VISIBILITY_CMD, Event.CAMERA_CENTER_FOCUS_CMD, Event.CONTROLLER_CONNECTED_INFO, Event.CONTROLLER_DISCONNECTED_INFO, Event.NEW_DISTANCE_SCALE_FACTOR, Event.CAMERA_TRACKING_OBJECT_CMD);
}
Also used : Sprite(gaiasky.util.gdx.g2d.Sprite) Vector3(com.badlogic.gdx.math.Vector3) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) Vector2(com.badlogic.gdx.math.Vector2)

Example 14 with Vector3b

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

the class NaturalCamera method drawCrosshairDecal.

private void drawCrosshairDecal(SpriteBatch batch, IFocus chFocus, Sprite sprite, float r, float g, float b, float a) {
    sprite.setColor(r, g, b, a);
    Vector3b p = chFocus.getClosestAbsolutePos(aux1b).add(posinv);
    Vector3d pos = aux5;
    p.put(pos);
    DecalUtils.drawSprite(sprite, batch, (float) pos.x, (float) pos.y, (float) pos.z, 0.0008d, 1f, this, true, 0.04f, 0.04f);
}
Also used : Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d)

Example 15 with Vector3b

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

the class NaturalCamera method camUpdate.

private void camUpdate(double dt, ITimeFrameProvider time) {
    currentMouseKbdListener.update();
    controllerListener.update();
    if (Settings.settings.runtime.openVr)
        openVRListener.update();
    // Next focus and closest positions
    computeNextPositions(time);
    // The whole update thread must lock the value of direction and up
    distance = pos.lend();
    CameraMode m = (parent.current == this ? parent.mode : lastMode);
    double realTransUnits = m.isGame() ? speedScaling(1e-5) : speedScaling();
    double translateUnits = Math.max(10d * Constants.M_TO_U, realTransUnits);
    switch(m) {
        case FOCUS_MODE:
            if (focus != null && !focus.isCoordinatesTimeOverflow()) {
                final double appMagCamera, appMagEarth;
                synchronized (updateLock) {
                    focusBak = focus;
                    this.focus.getAbsolutePosition(aux4b);
                    // Hack, fix this by understanding underlying problem
                    if (!aux4b.hasNaN()) {
                        focusPos.set(aux4b);
                    }
                    dx.set(0, 0, 0);
                    if (Settings.settings.scene.camera.focusLock.position) {
                        // Get focus dx
                        dx.set(nextFocusPosition).sub(focusPos);
                        // PLANETS and MOONS
                        if (Settings.settings.scene.camera.focusLock.orientation && time.getHdiff() > 0 && focus.getOrientation() != null) {
                            RotationComponent rc = focus.getRotationComponent();
                            if (rc != null) {
                                // Rotation component present - planets, etc
                                double angleBak = rc.angle;
                                double angle = previousOrientationAngle != 0 ? (angleBak - previousOrientationAngle) : 0;
                                // aux5 <- focus (future) position
                                focus.getAbsolutePosition(aux5b);
                                // aux3 <- focus to camera vector
                                aux3b.set(pos).sub(aux5b);
                                // aux2 <- spin axis
                                aux2.set(0, 1, 0).mul(focus.getOrientation());
                                // rotate aux3 around focus spin axis
                                aux3b.rotate(aux2, angle);
                                // aux3 <- camera pos after rotating
                                aux3b.add(aux5b);
                                // pos <- aux3
                                pos.set(aux3b);
                                direction.rotate(aux2, angle);
                                up.rotate(aux2, angle);
                                previousOrientationAngle = angleBak;
                            } else if (focus.getOrientationQuaternion() != null) {
                                Matrix4d ori = focus.getOrientation();
                                // aux5 <- focus (future) position
                                focus.getAbsolutePosition(aux5b);
                                // aux3 <- focus->camera vector
                                aux3b.set(pos).sub(aux5b);
                                // aux3 <- orientation difference from last frame = aux * O * O'^-1
                                aux3b.mul(ori).mul(previousOrientation);
                                // aux3 <- camera pos after rotating
                                aux3b.add(aux5b);
                                // pos <- aux3
                                pos.set(aux3b);
                                direction.mul(ori).mul(previousOrientation);
                                up.mul(ori).mul(previousOrientation);
                                // Set ori to this frame's inv(ori)
                                previousOrientation.set(ori).inv();
                            }
                        }
                        // Add dx to camera position
                        pos.add(dx);
                    }
                    // aux4b <- foucs.abspos + dx
                    this.focus.getAbsolutePosition(aux4b).add(dx);
                    if (!Settings.settings.runtime.openVr) {
                        if (!diverted) {
                            directionToTarget(dt, aux4b, Settings.settings.scene.camera.turn / (Settings.settings.scene.camera.cinematic ? 1e3f : 1e2f));
                        } else {
                            updateRotationFree(dt, Settings.settings.scene.camera.turn);
                        }
                        updateRoll(dt, Settings.settings.scene.camera.turn);
                    }
                    updatePosition(dt, translateUnits, realTransUnits);
                    updateRotation(dt, aux4b);
                    // Update focus direction
                    focusDirection.set(aux4b).sub(pos).nor();
                    focus = focusBak;
                    double dist = aux4b.dstd(pos);
                    if (dist < focus.getRadius()) {
                        // aux2 <- focus-cam with a length of radius
                        aux2b.set(pos).sub(aux4b).nor().scl(focus.getRadius());
                        // Correct camera position
                        pos.set(aux4b).add(aux2b);
                    }
                    // Track
                    if (!Settings.settings.runtime.openVr && this.trackingObject != null && this.trackingName != null) {
                        // Track the tracking object
                        this.trackingObject.getAbsolutePosition(trackingName, aux5b);
                        directionToTrackingObject(aux5b);
                    }
                    // Apparent magnitude from camera
                    appMagCamera = computeFocusApparentMagnitudeCamera();
                    // Apparent magnitude from Earth (planets, etc)
                    appMagEarth = computeFocusApparentMagnitudeEarth();
                }
                EventManager.publish(Event.FOCUS_INFO_UPDATED, this, focus.getDistToCamera() - focus.getRadius(), focus.getViewAngle(), focus.getAlpha(), focus.getDelta(), focus.getAbsolutePosition(aux2b).lend() - focus.getRadius(), appMagCamera, appMagEarth);
            } else {
                EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FREE_MODE);
            }
            break;
        case GAME_MODE:
            synchronized (updateLock) {
                if (gravity && (closestBody != null) && closestBody instanceof Planet && !currentMouseKbdListener.isKeyPressed(Input.Keys.SPACE)) {
                    // Add gravity to force, pulling to the closest body
                    final Vector3b camObj = closestBody.getAbsolutePosition(aux1b).sub(pos);
                    final double dist = camObj.lend();
                    // Gravity acts only at twice the radius, in planets
                    if (dist < closestBody.getRadius() * 2d) {
                        force.add(camObj.nor().scl(0.002d));
                        fullStop = false;
                    } else {
                        fullStop = true;
                    }
                } else {
                    fullStop = true;
                }
            }
        case FREE_MODE:
            synchronized (updateLock) {
                updatePosition(dt, translateUnits, Settings.settings.scene.camera.targetMode ? realTransUnits : 1);
                if (!Settings.settings.runtime.openVr) {
                    // If target is present, update direction
                    if (freeTargetOn) {
                        directionToTarget(dt, freeTargetPos, Settings.settings.scene.camera.turn / (Settings.settings.scene.camera.cinematic ? 1e3d : 1e2d));
                        if (facingFocus) {
                            freeTargetOn = false;
                        }
                    }
                    // Update direction with pitch, yaw, roll
                    updateRotationFree(dt, Settings.settings.scene.camera.turn);
                    updateRoll(dt, Settings.settings.scene.camera.turn);
                }
                updateLateral(dt, translateUnits);
            }
            break;
        case GAIA_SCENE_MODE:
            if (entity1 == null || entity2 == null) {
                entity1 = (CelestialBody) GaiaSky.instance.sceneGraph.getNode("Gaia");
                entity2 = (CelestialBody) GaiaSky.instance.sceneGraph.getNode("Earth");
                entity3 = (CelestialBody) GaiaSky.instance.sceneGraph.getNode("Mars");
            }
            SceneGraphNode focusCopy = entity1.getLineCopy();
            focusCopy.getRoot().translation.set(0, 0, 0);
            focusCopy.getRoot().update(time, null, this);
            focusCopy.translation.put(this.pos);
            this.pos.add(0, 0, entity1.getRadius() * 5.0);
            this.posinv.set(this.pos).scl(-1);
            this.direction.set(0, 0, -1);
            this.up.set(0, 1, 0);
            closestBody = entity1;
            // Return to pool
            SceneGraphNode ape = focusCopy;
            do {
                ape.returnToPool();
                ape = ape.parent;
            } while (ape != null);
            break;
        default:
            break;
    }
    // Update camera recorder
    EventManager.publish(Event.UPDATE_CAM_RECORDER, this, time, pos, direction, up);
    // Update actual camera
    lastFwdTime += dt;
    lastMode = m;
    posDistanceCheck();
    if (pos.hasNaN()) {
        pos.set(posBak);
    } else {
        posBak.set(pos);
    }
    updatePerspectiveCamera();
}
Also used : Matrix4d(gaiasky.util.math.Matrix4d) Vector3b(gaiasky.util.math.Vector3b) CameraMode(gaiasky.scenegraph.camera.CameraManager.CameraMode) RotationComponent(gaiasky.scenegraph.component.RotationComponent)

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