Search in sources :

Example 6 with Vector3b

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

the class StarClusterLoader method addCluster.

private void addCluster(String[] names, double ra, double rarad, double dec, double decrad, double dist, double distpc, double mualphastar, double mudelta, double radvel, double radius, int nstars, Array<StarCluster> clusters) {
    Vector3b pos = Coordinates.sphericalToCartesian(rarad, decrad, new Apfloat(dist, Constants.PREC), new Vector3b());
    Vector3d pm = AstroUtils.properMotionsToCartesian(mualphastar, mudelta, radvel, Math.toRadians(ra), Math.toRadians(dec), distpc, new Vector3d());
    Vector3d posSph = new Vector3d((float) ra, (float) dec, (float) dist);
    Vector3 pmSph = new Vector3((float) (mualphastar), (float) (mudelta), (float) radvel);
    StarCluster c = new StarCluster(names, parentName != null ? parentName : "MWSC", pos, pm, posSph, pmSph, radius, nstars);
    clusters.add(c);
}
Also used : Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) Vector3(com.badlogic.gdx.math.Vector3) StarCluster(gaiasky.scenegraph.StarCluster) Apfloat(org.apfloat.Apfloat)

Example 7 with Vector3b

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

the class Positions2DExtractor method process.

public void process() throws IOException {
    MoonAACoordinates moonCoord = new MoonAACoordinates();
    AbstractVSOP87 earthCoord = (AbstractVSOP87) VSOP87.instance.getVOSP87("Earth");
    FileWriter fw = new FileWriter(filePath);
    BufferedWriter bw = new BufferedWriter(fw);
    Calendar c = Calendar.getInstance();
    c.set(year, month - 1, day, 0, 0, 0);
    Date ini = c.getTime();
    long inims = ini.getTime();
    long dtms = MS_IN_YEAR / steps;
    Vector3b e = new Vector3b(), m = new Vector3b();
    bw.write("precomputed=True");
    bw.newLine();
    bw.newLine();
    bw.write("# nbodies");
    bw.newLine();
    bw.write("3");
    bw.newLine();
    bw.write("# number of time steps");
    bw.newLine();
    bw.write(Integer.toString(steps));
    bw.newLine();
    bw.write("# base date");
    bw.newLine();
    bw.write(ini.toString());
    bw.newLine();
    bw.write("# base date [ms since January 1, 1970, 00:00:00 GMT]");
    bw.newLine();
    bw.write(Long.toString(ini.getTime()));
    bw.newLine();
    bw.write("#t[ms] x[km] y[km] mass[kg]");
    bw.newLine();
    for (long t = inims; t < inims + MS_IN_YEAR; t += dtms) {
        Instant now = Instant.ofEpochMilli(t);
        // Sun
        bw.write(t + " 0.0 0.0 " + Mo);
        bw.newLine();
        // Earth
        earthCoord.getEclipticCartesianCoordinates(now, e);
        e.scl(Constants.U_TO_KM);
        bw.write(t + " " + e.x + " " + e.z + " " + Me);
        bw.newLine();
        // Moon
        moonCoord.getEclipticCartesianCoordinates(now, m);
        m.scl(Constants.U_TO_KM);
        m.add(e);
        bw.write(t + " " + m.x + " " + m.z + " " + Mm);
        bw.newLine();
    }
    bw.close();
}
Also used : Vector3b(gaiasky.util.math.Vector3b) AbstractVSOP87(gaiasky.util.coord.vsop87.AbstractVSOP87) FileWriter(java.io.FileWriter) Calendar(java.util.Calendar) Instant(java.time.Instant) MoonAACoordinates(gaiasky.util.coord.MoonAACoordinates) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter)

Example 8 with Vector3b

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

the class CamRecorder method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    switch(event) {
        case RECORD_CAMERA_CMD:
            // Start recording
            RecorderState m;
            if (data[0] != null) {
                if ((Boolean) data[0]) {
                    m = RecorderState.RECORDING;
                } else {
                    m = RecorderState.IDLE;
                }
            } else {
                m = (mode == RecorderState.RECORDING) ? RecorderState.IDLE : RecorderState.RECORDING;
            }
            if (m == RecorderState.RECORDING) {
                String filename;
                if (data.length > 1 && data[1] != null && !((String) data[1]).isBlank()) {
                    filename = (String) data[1];
                } else {
                    filename = df.format(new Date());
                }
                // We start recording, prepare buffer!
                if (mode == RecorderState.RECORDING) {
                    logger.info(I18n.txt("error.camerarecord.already"));
                    return;
                }
                // Annotate by date
                f = SysUtils.getDefaultCameraDir().resolve(filename + ".gsc");
                if (Files.exists(f)) {
                    try {
                        Files.delete(f);
                    } catch (IOException e) {
                        logger.error(e);
                    }
                }
                try {
                    Files.createFile(f);
                    os = new BufferedWriter(new FileWriter(f.toFile()));
                    // Print header
                    os.append("#time_ms").append(sep).append("pos_x").append(sep).append("pos_y").append(sep).append("pos_z").append(sep);
                    os.append("dir_x").append(sep).append("dir_y").append(sep).append("dir_z").append(sep);
                    os.append("up_x").append(sep).append("up_y").append(sep).append("up_z").append(sep);
                    os.append("\n");
                } catch (IOException e) {
                    logger.error(e);
                    return;
                }
                logger.info(I18n.txt("notif.camerarecord.start"));
                startMs = System.currentTimeMillis();
                time = 0;
                mode = RecorderState.RECORDING;
            } else if (m == RecorderState.IDLE) {
                // Flush and close
                if (mode == RecorderState.IDLE) {
                    // No recording to cancel
                    return;
                }
                try {
                    os.close();
                } catch (IOException e) {
                    logger.error(e);
                }
                os = null;
                long elapsed = System.currentTimeMillis() - startMs;
                startMs = 0;
                float secs = elapsed / 1000f;
                logger.info(I18n.txt("notif.camerarecord.done", f.toAbsolutePath(), secs));
                EventManager.publish(Event.POST_POPUP_NOTIFICATION, this, I18n.txt("notif.camerarecord.done", f.toAbsolutePath(), secs));
                f = null;
                mode = RecorderState.IDLE;
            }
            break;
        case PLAY_CAMERA_CMD:
            // Start playing
            if (is != null) {
                logger.warn("Hey, we are already playing another movie!");
            }
            if (mode != RecorderState.IDLE) {
                throw new RuntimeException("The recorder is busy! The current mode is " + mode);
            }
            Object f = data[0];
            Path file;
            if (f instanceof String) {
                file = Paths.get((String) f);
            } else {
                file = (Path) f;
            }
            try {
                is = new BufferedReader(new InputStreamReader(Files.newInputStream(file)));
                logger.info(I18n.txt("notif.cameraplay.start", file));
                EventManager.publish(Event.POST_POPUP_NOTIFICATION, this, I18n.txt("notif.cameraplay.start", file));
                mode = RecorderState.PLAYING;
                // Issue message informing playing has started
                EventManager.publish(Event.CAMERA_PLAY_INFO, this, true);
                // Enable frame output if option is on
                if (Settings.settings.camrecorder.auto) {
                    // Stop frame output if it is on!
                    EventManager.publish(Event.FRAME_OUTPUT_CMD, this, true);
                }
            } catch (Exception e) {
                logger.error(e);
            }
            break;
        case UPDATE_CAM_RECORDER:
            // Update with current position
            ITimeFrameProvider dt = (ITimeFrameProvider) data[0];
            Vector3b pos = (Vector3b) data[1];
            Vector3d dir = (Vector3d) data[2];
            Vector3d up = (Vector3d) data[3];
            update(dt, pos, dir, up);
            break;
        case STOP_CAMERA_PLAY:
            // Stop playing
            mode = RecorderState.IDLE;
            // Stop camera
            EventManager.publish(Event.CAMERA_STOP, this);
            // Post notification
            logger.info(I18n.txt("notif.cameraplay.done"));
            EventManager.publish(Event.POST_POPUP_NOTIFICATION, this, I18n.txt("notif.cameraplay.done"));
            // Issue message informing playing has stopped
            EventManager.publish(Event.CAMERA_PLAY_INFO, this, false);
            // Stop frame output if it is on!
            EventManager.publish(Event.FRAME_OUTPUT_CMD, this, false);
            break;
        default:
            break;
    }
}
Also used : Path(java.nio.file.Path) Date(java.util.Date) Vector3b(gaiasky.util.math.Vector3b) Vector3d(gaiasky.util.math.Vector3d) ITimeFrameProvider(gaiasky.util.time.ITimeFrameProvider)

Example 9 with Vector3b

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

the class NBGLoader method loadData.

@Override
public Array<CelestialBody> loadData() {
    Array<CelestialBody> galaxies = new Array<>(false, 900);
    long baseId = 8500000;
    long offset = 0;
    if (active)
        for (String file : files) {
            FileHandle f = Settings.settings.data.dataFileHandle(file);
            InputStream data = f.read();
            BufferedReader br = new BufferedReader(new InputStreamReader(data));
            try {
                String line;
                int linenum = 0;
                while ((line = br.readLine()) != null) {
                    if (linenum > 0) {
                        // Add galaxy
                        String[] tokens = line.split(",");
                        String name = tokens[0];
                        String altname = tokens[1];
                        double ra = Parser.parseDouble(tokens[2]);
                        double dec = Parser.parseDouble(tokens[3]);
                        double distMpc = Parser.parseDouble(tokens[4]);
                        double distPc = distMpc * 1e6d;
                        double kmag = Parser.parseDouble(tokens[5]);
                        double bmag = Parser.parseDouble(tokens[6]);
                        double a26 = Parser.parseDouble(tokens[7]);
                        double ba = Parser.parseDouble(tokens[8]);
                        int hrv = Parser.parseInt(tokens[9]);
                        int i = Parser.parseInt(tokens[10]);
                        int tt = Parser.parseInt(tokens[11]);
                        String Mcl = tokens[12];
                        String img = tokens[13];
                        double sizepc = Parser.parseDouble(tokens[14]);
                        CelestialBody g;
                        if (img == null || img.isEmpty()) {
                            // Regular shaded light point
                            Apfloat dist = new Apfloat(distMpc * Constants.MPC_TO_U, Constants.PREC);
                            Vector3b pos = Coordinates.sphericalToCartesian(Math.toRadians(ra), Math.toRadians(dec), dist, new Vector3b());
                            float colorbv = 0;
                            float absmag = (float) (kmag - 2.5 * Math.log10(Math.pow(distPc / 10d, 2d)));
                            NBGalaxy gal = new NBGalaxy(pos, (float) kmag, absmag, colorbv, altname.isBlank() ? new String[] { name } : new String[] { name, altname }, (float) ra, (float) dec, (float) bmag, (float) a26, (float) ba, hrv, i, tt, Mcl, baseId + offset);
                            gal.setParent("NBG");
                            g = gal;
                        } else {
                            // Billboard
                            BillboardGalaxy gal = new BillboardGalaxy(new String[] { name, altname }, ra, dec, distPc, sizepc, "data/tex/extragal/" + img);
                            // Fade in parsecs from sun
                            gal.setFade(new double[] { distPc * 0.3, distPc * 0.6 });
                            g = gal;
                        }
                        galaxies.add(g);
                        offset++;
                    }
                    linenum++;
                }
            } catch (IOException e) {
                logger.error(e);
            } finally {
                try {
                    br.close();
                } catch (IOException e) {
                    logger.error(e);
                }
            }
        }
    logger.info(I18n.txt("notif.catalog.init", galaxies.size));
    return galaxies;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileHandle(com.badlogic.gdx.files.FileHandle) InputStream(java.io.InputStream) IOException(java.io.IOException) NBGalaxy(gaiasky.scenegraph.NBGalaxy) Apfloat(org.apfloat.Apfloat) Array(com.badlogic.gdx.utils.Array) Vector3b(gaiasky.util.math.Vector3b) BillboardGalaxy(gaiasky.scenegraph.BillboardGalaxy) CelestialBody(gaiasky.scenegraph.CelestialBody) BufferedReader(java.io.BufferedReader)

Example 10 with Vector3b

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

the class CelestialBody 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());
            PerspectiveCamera pCamera;
            if (Settings.settings.program.modeStereo.active) {
                if (screenX < Gdx.graphics.getWidth() / 2f) {
                    pCamera = camera.getCameraStereoLeft();
                } else {
                    pCamera = camera.getCameraStereoRight();
                }
                pCamera.update();
            } else {
                pCamera = camera.camera;
            }
            angle = (float) Math.toDegrees(angle * camera.getFovFactor()) * (40f / pCamera.fieldOfView);
            double pixelSize = Math.max(minPixDist, ((angle * pCamera.viewportHeight) / pCamera.fieldOfView) / 2);
            pCamera.project(pos);
            pos.y = pCamera.viewportHeight - pos.y;
            if (Settings.settings.program.modeStereo.active) {
                pos.x /= 2;
            }
            // Check click distance
            if (checkClickDistance(screenX, screenY, pos, camera, pCamera, pixelSize)) {
                // Hit
                hits.add(this);
            }
        }
    }
}
Also used : Vector3b(gaiasky.util.math.Vector3b) Vector3(com.badlogic.gdx.math.Vector3) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera)

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