Search in sources :

Example 1 with OrbitalElementsGroup

use of gaiasky.scenegraph.OrbitalElementsGroup 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 2 with OrbitalElementsGroup

use of gaiasky.scenegraph.OrbitalElementsGroup in project gaiasky by langurmonkey.

the class OrbitalElementsGroupRenderSystem method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    if (event.equals(Event.GPU_DISPOSE_ORBITAL_ELEMENTS)) {
        if (source instanceof OrbitalElementsGroup) {
            OrbitalElementsGroup oeg = (OrbitalElementsGroup) source;
            int offset = getOffset(oeg);
            if (offset >= 0) {
                clearMeshData(offset);
            }
            setOffset(oeg, -1);
            setInGpu(oeg, false);
        }
    }
}
Also used : OrbitalElementsGroup(gaiasky.scenegraph.OrbitalElementsGroup)

Aggregations

OrbitalElementsGroup (gaiasky.scenegraph.OrbitalElementsGroup)2 IRenderable (gaiasky.render.IRenderable)1 Orbit (gaiasky.scenegraph.Orbit)1 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)1 OrbitComponent (gaiasky.scenegraph.component.OrbitComponent)1 CatalogInfo (gaiasky.util.CatalogInfo)1 ExtShaderProgram (gaiasky.util.gdx.shader.ExtShaderProgram)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1