Search in sources :

Example 1 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class StarGroup method update.

public void update(ITimeFrameProvider time, final Vector3b parentTransform, ICamera camera, float opacity) {
    // Fade node visibility
    if (active.length > 0) {
        cPosD.set(camera.getPos());
        // Delta years
        currDeltaYears = AstroUtils.getMsSince(time.getTime(), epochJd) * Nature.MS_TO_Y;
        super.update(time, parentTransform, camera, opacity);
        // Update close stars
        for (int i = 0; i < Math.min(proximity.updating.length, pointData.size()); i++) {
            if (filter(active[i]) && isVisible(active[i])) {
                IParticleRecord closeStar = pointData.get(active[i]);
                proximity.set(i, active[i], closeStar, camera, currDeltaYears);
                camera.checkClosestParticle(proximity.updating[i]);
                // Model distance
                if (i == 0) {
                    modelDist = 172.4643429 * closeStar.radius();
                }
            }
        }
    }
}
Also used : IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 2 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class StarGroup method getAbsolutePosition.

public Vector3d getAbsolutePosition(String name, Vector3d aux) {
    if (index.containsKey(name)) {
        int idx = index.get(name);
        IParticleRecord sb = pointData.get(idx);
        fetchPosition(sb, null, aux, currDeltaYears);
        return aux;
    } else {
        return null;
    }
}
Also used : IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 3 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class StarGroup method renderStarLabel.

private void renderStarLabel(int idx, Vector3d starPosition, float thOverFactor, ExtSpriteBatch batch, ExtShaderProgram shader, FontRenderSystem sys, RenderingContext rc, ICamera camera) {
    boolean forceLabel = forceLabelStars.contains(idx);
    IParticleRecord star = pointData.get(idx);
    starPosition = fetchPosition(star, cPosD, starPosition, currDeltaYears);
    double distToCamera = starPosition.len();
    float radius = (float) getRadius(idx);
    if (forceLabel) {
        radius = Math.max(radius, 1e4f);
    }
    float viewAngle = (float) (((radius / distToCamera) / camera.getFovFactor()) * Settings.settings.scene.star.brightness * 1.5f);
    if (forceLabel || viewAngle >= thOverFactor && camera.isVisible(viewAngle, starPosition, distToCamera) && distToCamera > radius * 100) {
        textPosition(camera, starPosition, distToCamera, radius);
        shader.setUniformf("u_viewAngle", viewAngle);
        shader.setUniformf("u_viewAnglePow", 1f);
        shader.setUniformf("u_thOverFactor", thOverFactor);
        shader.setUniformf("u_thOverFactorScl", camera.getFovFactor());
        // Override object color
        shader.setUniform4fv("u_color", textColour(star.names()[0]), 0, 4);
        double textSize = FastMath.tanh(viewAngle) * distToCamera * 1e5d;
        float alpha = Math.min((float) FastMath.atan(textSize / distToCamera), 1.e-3f);
        textSize = (float) FastMath.tan(alpha) * distToCamera * 0.5f;
        render3DLabel(batch, shader, sys.fontDistanceField, camera, rc, star.names()[0], starPosition, distToCamera, textScale() * camera.getFovFactor(), textSize * camera.getFovFactor(), forceLabel);
    }
}
Also used : IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 4 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class StarGroup method updateMetadata.

/**
 * Updates the additional information array, to use for sorting.
 * In stars, we need to take into account the proper motion and the brightness.
 *
 * @param time   The current time frame provider
 * @param camera The camera
 */
public void updateMetadata(ITimeFrameProvider time, ICamera camera) {
    Vector3d camPos = camera.getPos().tov3d(D34.get());
    double deltaYears = AstroUtils.getMsSince(time.getTime(), epochJd) * Nature.MS_TO_Y;
    if (pointData != null) {
        int n = pointData.size();
        for (int i = 0; i < n; i++) {
            IParticleRecord d = pointData.get(i);
            // Pm
            Vector3d dx = D32.get().set(d.pmx(), d.pmy(), d.pmz()).scl(deltaYears);
            // Pos
            Vector3d x = D31.get().set(d.x(), d.y(), d.z()).add(dx);
            metadata[i] = filter(i) ? (-(((d.size() * Constants.STAR_SIZE_FACTOR) / camPos.dst(x)) / camera.getFovFactor()) * Settings.settings.scene.star.brightness) : Double.MAX_VALUE;
        }
    }
}
Also used : Vector3d(gaiasky.util.math.Vector3d) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Example 5 with IParticleRecord

use of gaiasky.scenegraph.particle.IParticleRecord in project gaiasky by langurmonkey.

the class StarGroup method render.

/**
 * Proper motion rendering
 */
@Override
public void render(LineRenderSystem renderer, ICamera camera, float alpha) {
    alpha *= GaiaSky.instance.sgr.alphas[ComponentTypes.ComponentType.VelocityVectors.ordinal()];
    float thPointTimesFovFactor = (float) Settings.settings.scene.star.threshold.point * camera.getFovFactor();
    int n = (int) getMaxProperMotionLines();
    for (int i = n - 1; i >= 0; i--) {
        IParticleRecord star = pointData.get(active[i]);
        float radius = (float) (getSize(active[i]) * Constants.STAR_SIZE_FACTOR);
        // Position
        Vector3d lPos = fetchPosition(star, cPosD, D31.get(), currDeltaYears);
        // Proper motion
        Vector3d pm = D32.get().set(star.pmx(), star.pmy(), star.pmz()).scl(currDeltaYears);
        // Rest of attributes
        float distToCamera = (float) lPos.len();
        float viewAngle = ((radius / distToCamera) / camera.getFovFactor()) * Settings.settings.scene.star.brightness;
        if (viewAngle >= thPointTimesFovFactor / Settings.settings.scene.properMotion.number && (star.pmx() != 0 || star.pmy() != 0 || star.pmz() != 0)) {
            Vector3d p1 = D31.get().set(star.x() + pm.x, star.y() + pm.y, star.z() + pm.z).sub(camera.getPos());
            Vector3d ppm = D32.get().set(star.pmx(), star.pmy(), star.pmz()).scl(Settings.settings.scene.properMotion.length);
            double p1p2len = ppm.len();
            Vector3d p2 = D33.get().set(ppm).add(p1);
            // Maximum speed in km/s, to normalize
            float maxSpeedKms = 100;
            float r, g, b;
            switch(Settings.settings.scene.properMotion.colorMode) {
                case 0:
                default:
                    // DIRECTION
                    // Normalize, each component is in [-1:1], map to [0:1] and to a color channel
                    ppm.nor();
                    r = (float) (ppm.x + 1d) / 2f;
                    g = (float) (ppm.y + 1d) / 2f;
                    b = (float) (ppm.z + 1d) / 2f;
                    break;
                case 1:
                    // LENGTH
                    ppm.set(star.pmx(), star.pmy(), star.pmz());
                    // Units/year to Km/s
                    ppm.scl(Constants.U_TO_KM / Nature.Y_TO_S);
                    double len = MathUtilsd.clamp(ppm.len(), 0d, maxSpeedKms) / maxSpeedKms;
                    ColorUtils.colormap_long_rainbow((float) (1 - len), rgba);
                    r = rgba[0];
                    g = rgba[1];
                    b = rgba[2];
                    break;
                case 2:
                    // HAS RADIAL VELOCITY - blue: stars with RV, red: stars without RV
                    if (star.radvel() != 0) {
                        r = ColorUtils.gBlue[0] + 0.2f;
                        g = ColorUtils.gBlue[1] + 0.4f;
                        b = ColorUtils.gBlue[2] + 0.4f;
                    } else {
                        r = ColorUtils.gRed[0] + 0.4f;
                        g = ColorUtils.gRed[1] + 0.2f;
                        b = ColorUtils.gRed[2] + 0.2f;
                    }
                    break;
                case 3:
                    // REDSHIFT from Sun - blue: -100 Km/s, red: 100 Km/s
                    float rav = star.radvel();
                    if (rav != 0) {
                        // rv in [0:1]
                        float rv = ((MathUtilsd.clamp(rav, -maxSpeedKms, maxSpeedKms) / maxSpeedKms) + 1) / 2;
                        ColorUtils.colormap_blue_white_red(rv, rgba);
                        r = rgba[0];
                        g = rgba[1];
                        b = rgba[2];
                    } else {
                        r = g = b = 1;
                    }
                    break;
                case 4:
                    // REDSHIFT from Camera - blue: -100 Km/s, red: 100 Km/s
                    if (ppm.len2() != 0) {
                        ppm.set(star.pmx(), star.pmy(), star.pmz());
                        // Units/year to Km/s
                        ppm.scl(Constants.U_TO_KM / Nature.Y_TO_S);
                        Vector3d camStar = D34.get().set(p1);
                        double pr = ppm.dot(camStar.nor());
                        double projection = ((MathUtilsd.clamp(pr, -(double) maxSpeedKms, maxSpeedKms) / (double) maxSpeedKms) + 1) / 2;
                        ColorUtils.colormap_blue_white_red((float) projection, rgba);
                        r = rgba[0];
                        g = rgba[1];
                        b = rgba[2];
                    } else {
                        r = g = b = 1;
                    }
                    break;
                case 5:
                    // SINGLE COLOR
                    r = ColorUtils.gBlue[0] + 0.2f;
                    g = ColorUtils.gBlue[1] + 0.4f;
                    b = ColorUtils.gBlue[2] + 0.4f;
                    break;
            }
            // Clamp
            r = MathUtilsd.clamp(r, 0, 1);
            g = MathUtilsd.clamp(g, 0, 1);
            b = MathUtilsd.clamp(b, 0, 1);
            renderer.addLine(this, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, r, g, b, alpha * this.opacity);
            if (Settings.settings.scene.properMotion.arrowHeads) {
                // Add Arrow cap
                Vector3d p3 = D32.get().set(ppm).nor().scl(p1p2len * .86).add(p1);
                p3.rotate(p2, 30);
                renderer.addLine(this, p3.x, p3.y, p3.z, p2.x, p2.y, p2.z, r, g, b, alpha * this.opacity);
                p3.rotate(p2, -60);
                renderer.addLine(this, p3.x, p3.y, p3.z, p2.x, p2.y, p2.z, r, g, b, alpha * this.opacity);
            }
        }
    }
}
Also used : Vector3d(gaiasky.util.math.Vector3d) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord)

Aggregations

IParticleRecord (gaiasky.scenegraph.particle.IParticleRecord)48 Vector3d (gaiasky.util.math.Vector3d)10 StarGroup (gaiasky.scenegraph.StarGroup)8 ArrayList (java.util.ArrayList)6 Array (com.badlogic.gdx.utils.Array)5 Vector3 (com.badlogic.gdx.math.Vector3)4 ParticleGroup (gaiasky.scenegraph.ParticleGroup)4 OctreeNode (gaiasky.util.tree.OctreeNode)4 FileHandle (com.badlogic.gdx.files.FileHandle)3 ParticleRecord (gaiasky.scenegraph.particle.ParticleRecord)3 Coordinates (gaiasky.util.coord.Coordinates)3 Matrix4 (com.badlogic.gdx.math.Matrix4)2 LongMap (com.badlogic.gdx.utils.LongMap)2 Method (com.badlogic.gdx.utils.reflect.Method)2 ReflectionException (com.badlogic.gdx.utils.reflect.ReflectionException)2 IStarGroupDataProvider (gaiasky.data.group.IStarGroupDataProvider)2 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)2 ICamera (gaiasky.scenegraph.camera.ICamera)2 AbstractOctreeWrapper (gaiasky.scenegraph.octreewrapper.AbstractOctreeWrapper)2 BillboardDataset (gaiasky.scenegraph.particle.BillboardDataset)2