Search in sources :

Example 1 with Orbit

use of gaiasky.scenegraph.Orbit 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 Orbit

use of gaiasky.scenegraph.Orbit 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)

Example 3 with Orbit

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

the class VertGPURenderSystem method renderStud.

@Override
public void renderStud(Array<IRenderable> renderables, ICamera camera, double t) {
    if (isLine()) {
        // Enable GL_LINE_SMOOTH
        Gdx.gl20.glEnable(GL11.GL_LINE_SMOOTH);
        Gdx.gl.glHint(GL20.GL_NICEST, GL11.GL_LINE_SMOOTH_HINT);
        // Enable GL_LINE_WIDTH
        Gdx.gl20.glEnable(GL20.GL_LINE_WIDTH);
    }
    this.camera = camera;
    renderables.forEach(r -> {
        T renderable = (T) r;
        /*
             * ADD LINES
             */
        if (!inGpu(renderable)) {
            // Remove previous line data if present
            if (getOffset(renderable) >= 0) {
                clearMeshData(getOffset(renderable));
                setOffset(renderable, -1);
            }
            // Actually add data
            PointCloudData od = renderable.getPointCloud();
            int nPoints = od.getNumPoints();
            // Initialize or fetch mesh data
            if (getOffset(renderable) < 0) {
                setOffset(renderable, addMeshData(nPoints));
            } else {
                curr = meshes.get(getOffset(renderable));
                // Check we still have capacity, otherwise, reinitialize.
                if (curr.numVertices != od.getNumPoints()) {
                    curr.clear();
                    curr.mesh.dispose();
                    meshes.set(getOffset(renderable), null);
                    setOffset(renderable, addMeshData(nPoints));
                }
            }
            // Coord maps time
            long t0 = od.getDate(0).getEpochSecond();
            long t1 = od.getDate(od.getNumPoints() - 1).getEpochSecond();
            long t01 = t1 - t0;
            // Ensure vertices capacity
            ensureTempVertsSize((nPoints + 2) * curr.vertexSize);
            curr.vertices = tempVerts;
            float[] cc = renderable.getColor();
            for (int point_i = 0; point_i < nPoints; point_i++) {
                coord((float) ((double) (od.getDate(point_i).getEpochSecond() - t0) / (double) t01));
                color(cc[0], cc[1], cc[2], 1.0);
                vertex((float) od.getX(point_i), (float) od.getY(point_i), (float) od.getZ(point_i));
            }
            // Close loop
            if (renderable.isClosedLoop()) {
                coord(1f);
                color(cc[0], cc[1], cc[2], 1.0);
                vertex((float) od.getX(0), (float) od.getY(0), (float) od.getZ(0));
            }
            int count = nPoints * curr.vertexSize;
            setCount(renderable, count);
            curr.mesh.setVertices(curr.vertices, 0, count);
            curr.vertices = null;
            setInGpu(renderable, true);
        }
        curr = meshes.get(getOffset(renderable));
        /*
             * RENDER
             */
        ExtShaderProgram shaderProgram = getShaderProgram();
        shaderProgram.begin();
        // Regular
        if (isLine())
            Gdx.gl.glLineWidth(renderable.getPrimitiveSize() * Settings.settings.scene.lineWidth);
        if (isPoint())
            shaderProgram.setUniformf("u_pointSize", renderable.getPrimitiveSize());
        shaderProgram.setUniformMatrix("u_worldTransform", renderable.getLocalTransform());
        shaderProgram.setUniformMatrix("u_projView", camera.getCamera().combined);
        shaderProgram.setUniformf("u_alpha", (float) (renderable.getAlpha()) * getAlpha(renderable));
        shaderProgram.setUniformf("u_coordPos", renderable instanceof Orbit ? (float) ((Orbit) renderable).coord : 1f);
        shaderProgram.setUniformf("u_period", renderable instanceof Orbit && ((Orbit) renderable).oc != null ? (float) ((Orbit) renderable).oc.period : 0f);
        if (renderable.getParent() != null) {
            Vector3d urp = renderable.getParent().getUnrotatedPos();
            if (urp != null)
                shaderProgram.setUniformf("u_parentPos", (float) urp.x, (float) urp.y, (float) urp.z);
            else
                shaderProgram.setUniformf("u_parentPos", 0, 0, 0);
        }
        // Rel, grav, z-buffer
        addEffectsUniforms(shaderProgram, camera);
        curr.mesh.render(shaderProgram, renderable.getGlPrimitive());
        shaderProgram.end();
    });
}
Also used : PointCloudData(gaiasky.data.util.PointCloudData) Orbit(gaiasky.scenegraph.Orbit) Vector3d(gaiasky.util.math.Vector3d) ExtShaderProgram(gaiasky.util.gdx.shader.ExtShaderProgram)

Aggregations

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