Search in sources :

Example 21 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class PhotonMappingDemo method createSceneVao.

/**
 * Creates a VAO for the scene.
 */
private void createSceneVao() {
    int vao = glGenVertexArrays();
    /* Create vertex data */
    int vbo = glGenBuffers();
    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    ByteBuffer bb = BufferUtils.createByteBuffer(4 * (3 + 3) * 6 * 6);
    FloatBuffer fv = bb.asFloatBuffer();
    DemoUtils.triangulateUnitBox(fv);
    glBufferData(GL_ARRAY_BUFFER, bb, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, false, 4 * (3 + 3), 0L);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 3, GL_FLOAT, false, 4 * (3 + 3), 4 * 3);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    /* Create per instance data (position and size of box) */
    int ivbo = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, ivbo);
    bb = BufferUtils.createByteBuffer(4 * (3 + 3) * boxes.length);
    fv = bb.asFloatBuffer();
    for (int i = 0; i < boxes.length; i += 2) {
        Vector3f min = boxes[i];
        Vector3f max = boxes[i + 1];
        fv.put((max.x + min.x) / 2.0f).put((max.y + min.y) / 2.0f).put((max.z + min.z) / 2.0f);
        fv.put((max.x - min.x) / 2.0f).put((max.y - min.y) / 2.0f).put((max.z - min.z) / 2.0f);
    }
    glBufferData(GL_ARRAY_BUFFER, bb, GL_STATIC_DRAW);
    glEnableVertexAttribArray(2);
    glVertexAttribPointer(2, 3, GL_FLOAT, false, 4 * (3 + 3), 0L);
    glVertexAttribDivisor(2, 1);
    glEnableVertexAttribArray(3);
    glVertexAttribPointer(3, 3, GL_FLOAT, false, 4 * (3 + 3), 4 * 3);
    glVertexAttribDivisor(3, 1);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);
    this.vaoScene = vao;
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 22 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class PhotonMappingDemo method createSceneSSBO.

/**
 * Create a Shader Storage Buffer Object which will hold our boxes to be
 * read by our Compute Shader.
 */
private void createSceneSSBO() {
    this.ssbo = glGenBuffers();
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
    ByteBuffer ssboData = BufferUtils.createByteBuffer(4 * (4 + 4) * boxes.length / 2);
    FloatBuffer fv = ssboData.asFloatBuffer();
    for (int i = 0; i < boxes.length; i += 2) {
        Vector3f min = boxes[i];
        Vector3f max = boxes[i + 1];
        /*
			 * NOTE: We need to write vec4 here, because SSBOs have specific
			 * alignment requirements for struct members (vec3 is always treated
			 * as vec4 in memory!)
			 * 
			 * See:
			 * "https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html"
			 */
        fv.put(min.x).put(min.y).put(min.z).put(0.0f);
        fv.put(max.x).put(max.y).put(max.z).put(0.0f);
    }
    glBufferData(GL_SHADER_STORAGE_BUFFER, ssboData, GL_STATIC_DRAW);
    glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 23 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class DemoSsbo method createSceneSSBO.

/**
 * Create a Shader Storage Buffer Object which will hold our boxes to be
 * read by our Compute Shader.
 */
private void createSceneSSBO() {
    this.ssbo = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, ssbo);
    ByteBuffer ssboData = BufferUtils.createByteBuffer(4 * (4 + 4) * boxes.length / 2);
    FloatBuffer fv = ssboData.asFloatBuffer();
    for (int i = 0; i < boxes.length; i += 2) {
        Vector3f min = boxes[i];
        Vector3f max = boxes[i + 1];
        /*
			 * NOTE: We need to write vec4 here, because SSBOs have specific
			 * alignment requirements for struct members (vec3 is always treated
			 * as vec4 in memory!)
			 * 
			 * See:
			 * "https://www.safaribooksonline.com/library/view/opengl-programming-guide/9780132748445/app09lev1sec3.html"
			 */
        fv.put(min.x).put(min.y).put(min.z).put(0.0f);
        fv.put(max.x).put(max.y).put(max.z).put(0.0f);
    }
    glBufferData(GL_ARRAY_BUFFER, ssboData, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 24 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class SpaceGame method drawHudShip.

private void drawHudShip() {
    glUseProgram(0);
    Ship enemyShip = ships[shootingShip];
    if (enemyShip == null)
        return;
    Vector3f targetOrigin = tmp2;
    targetOrigin.set((float) (enemyShip.x - cam.position.x), (float) (enemyShip.y - cam.position.y), (float) (enemyShip.z - cam.position.z));
    tmp3.set(tmp2);
    viewMatrix.transformPosition(targetOrigin);
    boolean backward = targetOrigin.z > 0.0f;
    if (backward)
        return;
    projMatrix.transformProject(targetOrigin);
    if (targetOrigin.x < -1.0f)
        targetOrigin.x = -1.0f;
    if (targetOrigin.x > 1.0f)
        targetOrigin.x = 1.0f;
    if (targetOrigin.y < -1.0f)
        targetOrigin.y = -1.0f;
    if (targetOrigin.y > 1.0f)
        targetOrigin.y = 1.0f;
    float crosshairSize = 0.03f;
    float xs = crosshairSize * height / width;
    float ys = crosshairSize;
    crosshairVertices.clear();
    crosshairVertices.put(targetOrigin.x - xs).put(targetOrigin.y - ys);
    crosshairVertices.put(targetOrigin.x + xs).put(targetOrigin.y - ys);
    crosshairVertices.put(targetOrigin.x + xs).put(targetOrigin.y + ys);
    crosshairVertices.put(targetOrigin.x - xs).put(targetOrigin.y + ys);
    crosshairVertices.flip();
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glVertexPointer(2, GL_FLOAT, 0, crosshairVertices);
    glDrawArrays(GL_QUADS, 0, 4);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    // Draw distance text of enemy
    int quads = stb_easy_font_print(0, 0, Integer.toString((int) (tmp3.length())), null, charBuffer);
    glVertexPointer(2, GL_FLOAT, 16, charBuffer);
    glPushMatrix();
    // Scroll
    glTranslatef(targetOrigin.x, targetOrigin.y - crosshairSize * 1.1f, 0f);
    float aspect = (float) width / height;
    glScalef(1.0f / 500.0f, -1.0f / 500.0f * aspect, 0.0f);
    glDrawArrays(GL_QUADS, 0, quads * 4);
    glPopMatrix();
}
Also used : Vector3f(org.joml.Vector3f) STBEasyFont.stb_easy_font_print(org.lwjgl.stb.STBEasyFont.stb_easy_font_print)

Example 25 with Vector3f

use of org.joml.Vector3f in project lwjgl3-demos by LWJGL.

the class Cubes method frame.

@Override
protected void frame(float time, float frameTime) {
    bgfx_dbg_text_printf(0, 1, 0x4f, "bgfx/examples/01-cubes");
    bgfx_dbg_text_printf(0, 2, 0x6f, "Description: Rendering simple static mesh.");
    bgfx_dbg_text_printf(0, 3, 0x0f, String.format("Frame: %7.3f[ms]", frameTime));
    BGFXDemoUtil.lookAt(new Vector3f(0.0f, 0.0f, 0.0f), new Vector3f(0.0f, 0.0f, -35.0f), view);
    BGFXDemoUtil.perspective(60.0f, getWindowWidth(), getWindowHeight(), 0.1f, 100.0f, proj);
    view.get(viewBuf);
    proj.get(projBuf);
    bgfx_set_view_transform(0, viewBuf, projBuf);
    long encoder = bgfx_begin();
    for (int yy = 0; yy < 11; ++yy) {
        for (int xx = 0; xx < 11; ++xx) {
            model.identity().translate(-15.0f + xx * 3.0f, -15.0f + yy * 3.0f, 0.0f).rotateAffineXYZ(time + xx * 0.21f, time + yy * 0.37f, 0.0f);
            model.get(modelBuf);
            bgfx_encoder_set_transform(encoder, modelBuf);
            bgfx_encoder_set_vertex_buffer(encoder, 0, vbh, 0, 8);
            bgfx_encoder_set_index_buffer(encoder, ibh, 0, 36);
            bgfx_encoder_set_state(encoder, BGFX_STATE_DEFAULT, 0);
            bgfx_encoder_submit(encoder, 0, program, 0, false);
        }
    }
    bgfx_end(encoder);
}
Also used : Vector3f(org.joml.Vector3f)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8