Search in sources :

Example 1 with OrbitComponent

use of gaiasky.scenegraph.component.OrbitComponent in project gaiasky by langurmonkey.

the class OrbitalParametersProvider method load.

@Override
public void load(String file, OrbitDataLoaderParameter parameter, boolean newMethod) {
    if (newMethod) {
        OrbitComponent params = parameter.orbitalParamaters;
        Vector3d out = new Vector3d();
        try {
            // in days
            double period = params.period;
            // in days
            double epoch = params.epoch;
            data = new PointCloudData();
            data.period = period;
            // Step time in days, a full period over number of samples starting at epoch
            double t_step = period / (parameter.numSamples - 1.0);
            double t = 0.0;
            for (int n = 0; n < parameter.numSamples; n++) {
                params.loadDataPoint(out, t);
                if (n == parameter.numSamples - 1) {
                    // Close orbit
                    double sx = data.getX(0);
                    double sy = data.getY(0);
                    double sz = data.getZ(0);
                    data.x.add(sx);
                    data.y.add(sy);
                    data.z.add(sz);
                } else {
                    // Add point
                    data.x.add(out.x);
                    data.y.add(out.y);
                    data.z.add(out.z);
                }
                data.time.add(AstroUtils.julianDateToInstant(epoch + t));
                t += t_step;
            }
            EventManager.publish(Event.ORBIT_DATA_LOADED, this, data, parameter.name);
        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    } else {
        loadOld(file, parameter);
    }
}
Also used : OrbitComponent(gaiasky.scenegraph.component.OrbitComponent) PointCloudData(gaiasky.data.util.PointCloudData) Vector3d(gaiasky.util.math.Vector3d)

Example 2 with OrbitComponent

use of gaiasky.scenegraph.component.OrbitComponent in project gaiasky by langurmonkey.

the class OrbitalParametersProvider method loadOld.

public void loadOld(String file, OrbitDataLoaderParameter parameter) {
    OrbitComponent params = parameter.orbitalParamaters;
    try {
        // Parameters of the ellipse
        double a = params.semimajoraxis;
        double f = params.e * params.semimajoraxis;
        double b = Math.sqrt(Math.pow(a, 2) - Math.pow(f, 2));
        int nSamples = Math.min(Math.max(50, (int) (a * 0.01)), 100);
        double step = 360d / nSamples;
        Vector3d[] samples = new Vector3d[nSamples + 1];
        int i = 0;
        for (double angledeg = 0; angledeg < 360; angledeg += step) {
            double angleRad = Math.toRadians(angledeg);
            Vector3d point = new Vector3d(b * Math.sin(angleRad), 0d, a * Math.cos(angleRad));
            samples[i] = point;
            i++;
        }
        // Last, to close the orbit.
        samples[i] = samples[0].cpy();
        Matrix4d transform = new Matrix4d();
        transform.scl(Constants.KM_TO_U);
        data = new PointCloudData();
        for (Vector3d point : samples) {
            point.mul(transform);
            data.x.add(point.x);
            data.y.add(point.y);
            data.z.add(point.z);
            data.time.add(Instant.now());
        }
        EventManager.publish(Event.ORBIT_DATA_LOADED, this, data, parameter.name);
    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }
}
Also used : Matrix4d(gaiasky.util.math.Matrix4d) OrbitComponent(gaiasky.scenegraph.component.OrbitComponent) PointCloudData(gaiasky.data.util.PointCloudData) Vector3d(gaiasky.util.math.Vector3d)

Example 3 with OrbitComponent

use of gaiasky.scenegraph.component.OrbitComponent in project gaiasky by langurmonkey.

the class OrbitalElementsGroupRenderSystem method renderStud.

@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
    for (IRenderable renderable : renderables) {
        OrbitalElementsGroup oeg = (OrbitalElementsGroup) renderable;
        if (!inGpu(oeg)) {
            int n = oeg.children.size;
            int offset = addMeshData(n * 4, n * 6);
            setOffset(oeg, offset);
            curr = meshes.get(offset);
            ensureTempVertsSize(n * 4 * curr.vertexSize);
            ensureTempIndicesSize(n * 6);
            AtomicInteger numVerticesAdded = new AtomicInteger(0);
            AtomicInteger numParticlesAdded = new AtomicInteger(0);
            CatalogInfo ci = oeg.getCatalogInfo();
            Array<SceneGraphNode> children = oeg.children;
            children.forEach(child -> {
                Orbit orbit = (Orbit) child;
                OrbitComponent oc = orbit.oc;
                // 4 vertices per particle
                for (int vert = 0; vert < 4; vert++) {
                    // Vertex POSITION
                    tempVerts[curr.vertexIdx + posOffset] = vertPos[vert].getFirst();
                    tempVerts[curr.vertexIdx + posOffset + 1] = vertPos[vert].getSecond();
                    // UV coordinates
                    tempVerts[curr.vertexIdx + uvOffset] = vertUV[vert].getFirst();
                    tempVerts[curr.vertexIdx + uvOffset + 1] = vertUV[vert].getSecond();
                    // COLOR
                    float[] c = oeg.isHighlighted() && ci != null ? ci.getHlColor() : orbit.pointColor;
                    tempVerts[curr.vertexIdx + curr.colorOffset] = Color.toFloatBits(c[0], c[1], c[2], c[3]);
                    // ORBIT ELEMENTS 01
                    tempVerts[curr.vertexIdx + elems01Offset] = (float) Math.sqrt(oc.mu / Math.pow(oc.semimajoraxis * 1000d, 3d));
                    tempVerts[curr.vertexIdx + elems01Offset + 1] = (float) oc.epoch;
                    // In metres
                    tempVerts[curr.vertexIdx + elems01Offset + 2] = (float) (oc.semimajoraxis * 1000d);
                    tempVerts[curr.vertexIdx + elems01Offset + 3] = (float) oc.e;
                    // ORBIT ELEMENTS 02
                    tempVerts[curr.vertexIdx + elems02Offset] = (float) (oc.i * MathUtilsd.degRad);
                    tempVerts[curr.vertexIdx + elems02Offset + 1] = (float) (oc.ascendingnode * MathUtilsd.degRad);
                    tempVerts[curr.vertexIdx + elems02Offset + 2] = (float) (oc.argofpericenter * MathUtilsd.degRad);
                    tempVerts[curr.vertexIdx + elems02Offset + 3] = (float) (oc.meananomaly * MathUtilsd.degRad);
                    // SIZE
                    tempVerts[curr.vertexIdx + sizeOffset] = orbit.pointSize * (oeg.isHighlighted() && ci != null ? ci.hlSizeFactor : 1);
                    curr.vertexIdx += curr.vertexSize;
                    curr.numVertices++;
                    numVerticesAdded.incrementAndGet();
                }
                // Indices
                quadIndices(curr);
                numParticlesAdded.incrementAndGet();
                setInGpu(orbit, true);
            });
            int count = numVerticesAdded.get() * curr.vertexSize;
            setCount(oeg, count);
            curr.mesh.setVertices(tempVerts, 0, count);
            curr.mesh.setIndices(tempIndices, 0, numParticlesAdded.get() * 6);
            setInGpu(oeg, true);
        }
        curr = meshes.get(getOffset(renderable));
        if (curr != null) {
            ExtShaderProgram shaderProgram = getShaderProgram();
            shaderProgram.begin();
            shaderProgram.setUniformMatrix("u_projView", camera.getCamera().combined);
            shaderProgram.setUniformf("u_camPos", camera.getPos().put(aux1));
            shaderProgram.setUniformf("u_alpha", alphas[renderable.getComponentType().getFirstOrdinal()] * renderable.getOpacity());
            shaderProgram.setUniformf("u_falloff", 2.5f);
            shaderProgram.setUniformf("u_sizeFactor", Settings.settings.scene.star.pointSize * 0.08f * oeg.getPointscaling());
            shaderProgram.setUniformf("u_sizeLimits", (float) (particleSizeLimits[0]), (float) (particleSizeLimits[1]));
            // VR scale
            shaderProgram.setUniformf("u_vrScale", (float) Constants.DISTANCE_SCALE_FACTOR);
            // Emulate double, for compatibility
            double curRt = AstroUtils.getJulianDate(GaiaSky.instance.time.getTime());
            float curRt1 = (float) curRt;
            float curRt2 = (float) (curRt - (double) curRt1);
            shaderProgram.setUniformf("u_t", curRt1, curRt2);
            shaderProgram.setUniformMatrix("u_eclToEq", maux.setToRotation(0, 1, 0, -90).mul(Coordinates.equatorialToEclipticF()));
            // Relativistic effects
            addEffectsUniforms(shaderProgram, camera);
            try {
                curr.mesh.render(shaderProgram, GL20.GL_TRIANGLES);
            } catch (IllegalArgumentException e) {
                logger.error(e, "Render exception");
            }
            shaderProgram.end();
        }
    }
}
Also used : OrbitalElementsGroup(gaiasky.scenegraph.OrbitalElementsGroup) IRenderable(gaiasky.render.IRenderable) Orbit(gaiasky.scenegraph.Orbit) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ExtShaderProgram(gaiasky.util.gdx.shader.ExtShaderProgram) OrbitComponent(gaiasky.scenegraph.component.OrbitComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CatalogInfo(gaiasky.util.CatalogInfo)

Example 4 with OrbitComponent

use of gaiasky.scenegraph.component.OrbitComponent in project gaiasky by langurmonkey.

the class OrbitalElementsParticlesRenderSystem method renderStud.

@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
    int n = renderables.size;
    if (n > 0 && renderables.get(0).getOpacity() > 0) {
        Orbit first = (Orbit) renderables.get(0);
        if (forceAdd || !inGpu(first)) {
            forceAdd = false;
            curr = meshes.get(addMeshData(n * 4, n * 6));
            ensureTempVertsSize(n * 4 * curr.vertexSize);
            ensureTempIndicesSize(n * 6);
            AtomicInteger numVerticesAdded = new AtomicInteger(0);
            AtomicInteger numParticlesAdded = new AtomicInteger(0);
            renderables.forEach(renderable -> {
                Orbit orbitElems = (Orbit) renderable;
                if (!inGpu(orbitElems)) {
                    OrbitComponent oc = orbitElems.oc;
                    // 4 vertices per particle
                    for (int vert = 0; vert < 4; vert++) {
                        // Vertex POSITION
                        tempVerts[curr.vertexIdx + posOffset] = vertPos[vert].getFirst();
                        tempVerts[curr.vertexIdx + posOffset + 1] = vertPos[vert].getSecond();
                        // UV coordinates
                        tempVerts[curr.vertexIdx + uvOffset] = vertUV[vert].getFirst();
                        tempVerts[curr.vertexIdx + uvOffset + 1] = vertUV[vert].getSecond();
                        // COLOR
                        tempVerts[curr.vertexIdx + curr.colorOffset] = Color.toFloatBits(orbitElems.pointColor[0], orbitElems.pointColor[1], orbitElems.pointColor[2], orbitElems.pointColor[3]);
                        // ORBIT ELEMENTS 01
                        tempVerts[curr.vertexIdx + elems01Offset] = (float) Math.sqrt(oc.mu / Math.pow(oc.semimajoraxis * 1000d, 3d));
                        tempVerts[curr.vertexIdx + elems01Offset + 1] = (float) oc.epoch;
                        // In metres
                        tempVerts[curr.vertexIdx + elems01Offset + 2] = (float) (oc.semimajoraxis * 1000d);
                        tempVerts[curr.vertexIdx + elems01Offset + 3] = (float) oc.e;
                        // ORBIT ELEMENTS 02
                        tempVerts[curr.vertexIdx + elems02Offset] = (float) (oc.i * MathUtilsd.degRad);
                        tempVerts[curr.vertexIdx + elems02Offset + 1] = (float) (oc.ascendingnode * MathUtilsd.degRad);
                        tempVerts[curr.vertexIdx + elems02Offset + 2] = (float) (oc.argofpericenter * MathUtilsd.degRad);
                        tempVerts[curr.vertexIdx + elems02Offset + 3] = (float) (oc.meananomaly * MathUtilsd.degRad);
                        // SIZE
                        tempVerts[curr.vertexIdx + sizeOffset] = orbitElems.pointSize;
                        curr.vertexIdx += curr.vertexSize;
                        curr.numVertices++;
                        numVerticesAdded.incrementAndGet();
                    }
                    // Indices
                    quadIndices(curr);
                    numParticlesAdded.incrementAndGet();
                    setInGpu(orbitElems, true);
                }
            });
            int count = numVerticesAdded.get() * curr.vertexSize;
            curr.mesh.setVertices(tempVerts, 0, count);
            curr.mesh.setIndices(tempIndices, 0, numParticlesAdded.get() * 6);
        }
        if (curr != null) {
            ExtShaderProgram shaderProgram = getShaderProgram();
            shaderProgram.begin();
            shaderProgram.setUniformMatrix("u_projView", camera.getCamera().combined);
            shaderProgram.setUniformf("u_camPos", camera.getPos().put(aux1));
            shaderProgram.setUniformf("u_alpha", alphas[first.ct.getFirstOrdinal()] * first.getOpacity());
            shaderProgram.setUniformf("u_falloff", 2.5f);
            shaderProgram.setUniformf("u_sizeFactor", Settings.settings.scene.star.pointSize * 0.08f);
            shaderProgram.setUniformf("u_sizeLimits", (float) (particleSizeLimits[0]), (float) (particleSizeLimits[1]));
            // VR scale
            shaderProgram.setUniformf("u_vrScale", (float) Constants.DISTANCE_SCALE_FACTOR);
            // Emulate double, for compatibility
            double curRt = AstroUtils.getJulianDate(GaiaSky.instance.time.getTime());
            float curRt1 = (float) curRt;
            float curRt2 = (float) (curRt - (double) curRt1);
            shaderProgram.setUniformf("u_t", curRt1, curRt2);
            shaderProgram.setUniformMatrix("u_eclToEq", maux.setToRotation(0, 1, 0, -90).mul(Coordinates.equatorialToEclipticF()));
            // Relativistic effects
            addEffectsUniforms(shaderProgram, camera);
            try {
                curr.mesh.render(shaderProgram, GL20.GL_TRIANGLES);
            } catch (IllegalArgumentException e) {
                logger.error(e, "Render exception");
            }
            shaderProgram.end();
        }
    }
}
Also used : OrbitComponent(gaiasky.scenegraph.component.OrbitComponent) Orbit(gaiasky.scenegraph.Orbit) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExtShaderProgram(gaiasky.util.gdx.shader.ExtShaderProgram)

Aggregations

OrbitComponent (gaiasky.scenegraph.component.OrbitComponent)4 PointCloudData (gaiasky.data.util.PointCloudData)2 Orbit (gaiasky.scenegraph.Orbit)2 ExtShaderProgram (gaiasky.util.gdx.shader.ExtShaderProgram)2 Vector3d (gaiasky.util.math.Vector3d)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IRenderable (gaiasky.render.IRenderable)1 OrbitalElementsGroup (gaiasky.scenegraph.OrbitalElementsGroup)1 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)1 CatalogInfo (gaiasky.util.CatalogInfo)1 Matrix4d (gaiasky.util.math.Matrix4d)1