Search in sources :

Example 1 with MutableAABB

use of co.paralleluniverse.spacebase.MutableAABB in project spaceships-demo by puniverse.

the class GLPort method getCurrentPort.

private MutableAABB getCurrentPort(final long ct) {
    if (portMaxXAnimation == 0 & portMaxYAnimation == 0)
        return port;
    MutableAABB currentPort = MutableAABB.create(2);
    final double width = port.max(X) - port.min(X);
    final double height = port.max(Y) - port.min(Y);
    final double ratio = height / width;
    double animation = Math.min(1.0, (double) (ct - portAnimationStartTime) / ANIMATION_DURATION);
    currentPort.min(X, port.min(X) + animation * portMinXAnimation);
    currentPort.min(Y, port.min(Y) + animation * portMinYAnimation);
    currentPort.max(X, port.max(X) + animation * portMaxXAnimation);
    currentPort.max(Y, port.max(Y) + animation * portMaxYAnimation);
    return currentPort;
}
Also used : MutableAABB(co.paralleluniverse.spacebase.MutableAABB)

Example 2 with MutableAABB

use of co.paralleluniverse.spacebase.MutableAABB in project spaceships-demo by puniverse.

the class Spaceship method getAABB.

private static AABB getAABB(Record<SpaceshipState> state) {
    final MutableAABB aabb = AABB.create(2);
    getAABB(state, aabb);
    return aabb;
}
Also used : MutableAABB(co.paralleluniverse.spacebase.MutableAABB)

Example 3 with MutableAABB

use of co.paralleluniverse.spacebase.MutableAABB in project spaceships-demo by puniverse.

the class GLPort method display.

@Override
public void display(GLAutoDrawable drawable) {
    try {
        final GL3 gl = drawable.getGL().getGL3();
        shaderState.bind(gl);
        vao.bind(gl);
        int spaceshipLoc = gl.glGetUniformLocation(shaderProgram.program(), "spaceshipTex");
        gl.glUniform1i(spaceshipLoc, 0);
        gl.glActiveTexture(GL.GL_TEXTURE0);
        gl.glBindTexture(GL.GL_TEXTURE_2D, spaceshipTex.getTextureObject(gl));
        int explosionLoc = gl.glGetUniformLocation(shaderProgram.program(), "explosionTex");
        gl.glUniform1i(explosionLoc, 1);
        gl.glActiveTexture(GL.GL_TEXTURE0 + 1);
        gl.glBindTexture(GL.GL_TEXTURE_2D, explosionTex.getTextureObject(gl));
        vertices.clear();
        colors.clear();
        final FloatBuffer verticesb = (FloatBuffer) vertices.getBuffer();
        final FloatBuffer colorsb = (FloatBuffer) colors.getBuffer();
        long now = global.now();
        long clock = System.currentTimeMillis();
        fixPort(clock, true);
        MutableAABB currentPort = getCurrentPort(clock);
        portToMvMatrix(currentPort);
        double margins = WIDTH_MARGINS;
        final int n;
        if (clock - lastQueryTime > SB_QUERY_RATE) {
            n = query(now, SpatialQueries.contained(AABB.create(currentPort.min(X) - margins, currentPort.max(X) + margins, currentPort.min(Y) - margins, currentPort.max(Y) + margins)));
            lastQueryTime = clock;
        } else {
            n = indexGen.get();
            lastDispTime = clock;
        }
        int countInPort = 0;
        for (Record<SpaceshipState> s : ships.slice(0, n)) {
            long extrapolationTime = global.extrapolate ? Math.min(now, s.get($lastMoved) + MAX_EXTRAPOLATION_DURATION) : s.get($lastMoved);
            Spaceship.getCurrentLocation(s, extrapolationTime, verticesb);
            if (// 0.01 - start blow animation, 1.0 - end of animation
            s.get($blowTime) > 0)
                colorsb.put(Math.min(1.0f, (now - s.get($blowTime)) / EXPLOSION_DURATION));
            else
                // ship isn't blowing up
                colorsb.put(0);
            colorsb.put((float) Spaceship.getCurrentHeading(s, extrapolationTime));
            // put the shotLength (0 for ship that's not firing)
            colorsb.put(now - s.get($timeFired) < SHOOT_DURATION ? (float) s.get($shotLength) : 0f);
            if (portContains(s.get($x), s.get($y)))
                countInPort++;
        }
        setTitle((glxNode >= 0 ? "Node " + glxNode + ": " : "") + countInPort + " Spaceships " + (int) (port.max(X) - port.min(X)) + "x" + (int) (port.max(Y) - port.min(Y)));
        vertices.flip();
        colors.flip();
        int numElems = verticesb.limit() / 2;
        vertices.write(gl, 0, numElems);
        colors.write(gl, 0, numElems);
        shaderState.setUniform(gl, "in_Matrix", 4, 4, pmv.glGetMvMatrixf());
        gl.glClear(GL3.GL_COLOR_BUFFER_BIT);
        gl.glDrawArrays(GL3.GL_POINTS, 0, numElems);
        vao.unbind(gl);
        shaderState.unbind(gl);
    } catch (Throwable t) {
        System.err.println("XXXXXX");
        t.printStackTrace();
        throw t;
    }
}
Also used : FloatBuffer(java.nio.FloatBuffer) MutableAABB(co.paralleluniverse.spacebase.MutableAABB) SpaceshipState(co.paralleluniverse.spaceships.SpaceshipState) GL3(javax.media.opengl.GL3) DebugGL3(javax.media.opengl.DebugGL3)

Example 4 with MutableAABB

use of co.paralleluniverse.spacebase.MutableAABB in project spaceships-demo by puniverse.

the class RandSpatial method randomAABB.

public AABB randomAABB(AABB bounds) {
    MutableAABB aabb = AABB.create(bounds.dims());
    for (int i = 0; i < bounds.dims(); i++) {
        double a = randRange(bounds.min(i), bounds.max(i));
        double b = randRange(bounds.min(i), bounds.max(i));
        aabb.min(i, (float) min(a, b));
        aabb.max(i, (float) max(a, b));
    }
    return floatify(aabb);
}
Also used : MutableAABB(co.paralleluniverse.spacebase.MutableAABB)

Example 5 with MutableAABB

use of co.paralleluniverse.spacebase.MutableAABB in project spaceships-demo by puniverse.

the class RandSpatial method randomAABB.

public AABB randomAABB(AABB bounds, double expSize, double variance) {
    MutableAABB aabb = AABB.create(bounds.dims());
    for (int i = 0; i < bounds.dims(); i++) {
        double tmp = getRandom().nextGaussian();
        double size = (tmp * tmp) * variance + expSize;
        if (expSize > 0 && size == 0)
            size = 0.01;
        double a = randRange(bounds.min(i), bounds.max(i) - size);
        aabb.min(i, (float) a);
        aabb.max(i, (float) (a + size));
    }
    return floatify(aabb);
}
Also used : MutableAABB(co.paralleluniverse.spacebase.MutableAABB)

Aggregations

MutableAABB (co.paralleluniverse.spacebase.MutableAABB)5 SpaceshipState (co.paralleluniverse.spaceships.SpaceshipState)1 FloatBuffer (java.nio.FloatBuffer)1 DebugGL3 (javax.media.opengl.DebugGL3)1 GL3 (javax.media.opengl.GL3)1