Search in sources :

Example 46 with Vector3f

use of org.joml.Vector3f in project chunkstories-core by Hugobros3.

the class ParticleLight method getRenderer.

@Override
public ParticleTypeRenderer getRenderer(ParticlesRenderer particlesRenderer) {
    return new ParticleTypeRenderer(particlesRenderer) {

        @Override
        public void forEach_Rendering(RenderingInterface renderingContext, ParticleData data2) {
            ParticleLightData data = (ParticleLightData) data2;
            renderingContext.getLightsRenderer().queueLight(new Light(new Vector3f(1.0f, 181f / 255f, 79 / 255f), new Vector3f((float) data.c.x(), (float) data.c.y(), (float) data.c.z()), 15f + (float) Math.random() * 5f));
        }

        @Override
        public void destroy() {
        }
    };
}
Also used : Light(io.xol.chunkstories.api.rendering.lightning.Light) Vector3f(org.joml.Vector3f) RenderingInterface(io.xol.chunkstories.api.rendering.RenderingInterface)

Example 47 with Vector3f

use of org.joml.Vector3f in project chunkstories-core by Hugobros3.

the class SignRenderer method renderVoxels.

@Override
public void renderVoxels(RenderingInterface renderingContext, IterableIterator<ChunkCell> renderableEntitiesIterator) {
    setupRender(renderingContext);
    renderingContext.setObjectMatrix(null);
    for (// .getElementsInFrustrumOnly())
    ChunkCell context : // .getElementsInFrustrumOnly())
    renderableEntitiesIterator) {
        if (renderingContext.getCamera().getCameraPosition().distance(context.getLocation()) > 32)
            continue;
        Texture2D diffuse = renderingContext.textures().getTexture("./models/sign.png");
        diffuse.setLinearFiltering(false);
        renderingContext.bindAlbedoTexture(diffuse);
        renderingContext.bindNormalTexture(renderingContext.textures().getTexture("./textures/normalnormal.png"));
        renderingContext.currentShader().setUniform2f("worldLightIn", context.getBlocklight(), context.getSunlight());
        boolean isPost = context.getVoxel().getName().endsWith("_post");
        int facing = context.getMetaData();
        Matrix4f mutrix = new Matrix4f();
        mutrix.translate(new Vector3f(0.5f, 0.0f, 0.5f));
        Location loc = context.getLocation();
        mutrix.translate((float) loc.x, (float) loc.y, (float) loc.z);
        mutrix.rotate((float) Math.PI * 2.0f * (-facing) / 16f, new Vector3f(0, 1, 0));
        if (!isPost)
            mutrix.translate(new Vector3f(0.0f, 0.0f, -0.5f));
        renderingContext.setObjectMatrix(mutrix);
        if (!isPost)
            renderingContext.meshes().getRenderableMeshByName("./models/sign_post.obj").render(renderingContext);
        else
            renderingContext.meshes().getRenderableMeshByName("./models/sign.obj").render(renderingContext);
        VoxelComponentSignText signTextComponent = (VoxelComponentSignText) context.components().get("signData");
        if (signTextComponent == null)
            continue;
        // bake sign mesh
        if (signTextComponent.cachedText == null || !signTextComponent.cachedText.equals(signTextComponent.getSignText())) {
            // entitySign.renderData = new TextMeshObject(entitySign.signText.getSignText());
            signTextComponent.cachedText = signTextComponent.getSignText();
            signTextComponent.renderData = renderingContext.getFontRenderer().newTextMeshObject(renderingContext.getFontRenderer().defaultFont(), signTextComponent.cachedText);
        }
        // signTextComponent.setSignText("fuck");
        // System.out.println("cachedText:"+signTextComponent.getSignText());
        // Display it
        mutrix.translate(new Vector3f(0.0f, 1.15f, 0.055f));
        renderingContext.setObjectMatrix(mutrix);
        signTextComponent.renderData.render(renderingContext);
    }
}
Also used : VoxelComponentSignText(io.xol.chunkstories.core.voxel.components.VoxelComponentSignText) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) ChunkCell(io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell) Location(io.xol.chunkstories.api.Location)

Example 48 with Vector3f

use of org.joml.Vector3f in project chunkstories-core by Hugobros3.

the class FlatIconItemRenderer method renderItemInWorld.

@Override
public void renderItemInWorld(RenderingInterface renderingInterface, ItemPile pile, World world, Location location, Matrix4f handTransformation) {
    handTransformation.translate(new Vector3f(-0.05f, -0.05f, 0.05f));
    handTransformation.rotate((float) -(Math.PI / 4f), new Vector3f(0.0f, 0.0f, 1.0f));
    super.renderItemInWorld(renderingInterface, pile, world, location, handTransformation);
}
Also used : Vector3f(org.joml.Vector3f)

Example 49 with Vector3f

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

the class Std430Writer method writeField.

private static <T> void writeField(Field f, T obj, DynamicByteBuffer bb) throws IllegalArgumentException, IllegalAccessException {
    Class<?> t = f.getType();
    if (t == int.class)
        bb.putInt(f.getInt(obj));
    else if (t == float.class)
        bb.putFloat(f.getFloat(obj));
    else if (t == Vector3f.class) {
        Vector3f v = (Vector3f) f.get(obj);
        bb.putFloat(v.x).putFloat(v.y).putFloat(v.z);
    } else if (t.isArray()) {
        Object arr = f.get(obj);
        int len = Array.getLength(arr);
        Class<?> ct = t.getComponentType();
        for (int i = 0; i < len; i++) {
            if (ct == int.class)
                bb.putInt(Array.getInt(arr, i));
            else
                throw new UnsupportedOperationException("NYI");
        }
    } else
        throw new UnsupportedOperationException("NYI");
}
Also used : Vector3f(org.joml.Vector3f)

Example 50 with Vector3f

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

the class KDTreeForTutorial7 method findSplitPlane.

private float findSplitPlane(Node node) {
    if (node == null) {
        return Float.POSITIVE_INFINITY;
    }
    Box bb = node.boundingBox;
    int nPrims = node.triangles.size();
    Vector3f costvector = new Vector3f(bb.max).sub(bb.min);
    int ax = costvector.maxComponent();
    float box_width = costvector.get(ax);
    if (box_width <= EPSILON) {
        node.splitAxis = -1;
        return Float.POSITIVE_INFINITY;
    }
    float inv_box_width = 1.0f / box_width;
    if (box_width <= EPSILON) {
        throw new IllegalStateException("!!! KDTree.findSplitPlane: box to small");
    }
    List<IntervalBoundary> intervals = new ArrayList<IntervalBoundary>(nPrims * 2);
    for (int i = 0; i < nPrims; i++) {
        Box b = node.triangles.get(i).getBounds();
        if (!bb.intersectsWithBox(b)) {
            throw new IllegalStateException("!!! KDTree.findSplitPlane: no intersection of boxes");
        }
        intervals.add(new IntervalBoundary(0, b.min.get(ax)));
        intervals.add(new IntervalBoundary(1, b.max.get(ax)));
    }
    Collections.sort(intervals, new Comparator<IntervalBoundary>() {

        public int compare(IntervalBoundary sib1, IntervalBoundary sib2) {
            return sib1.compareTo(sib2);
        }
    });
    int done_intervals = 0;
    int open_intervals = 0;
    float alpha;
    int minid = 0;
    float mincost = Float.MAX_VALUE;
    for (int i = 0; i < intervals.size(); i++) {
        if (intervals.get(i).type == 1) {
            open_intervals--;
            done_intervals++;
        }
        alpha = (intervals.get(i).pos - bb.min.get(ax)) * inv_box_width;
        float cost = mSahTrvCosts + mSahIntCosts * ((done_intervals + open_intervals) * alpha + (nPrims - done_intervals) * (1.0f - alpha));
        if (cost < mincost) {
            minid = i;
            mincost = cost;
        }
        if (intervals.get(i).type == 0) {
            open_intervals++;
        }
    }
    float splitPlane = intervals.get(minid).pos;
    if (splitPlane == bb.min.get(ax) || splitPlane == bb.max.get(ax)) {
        node.splitAxis = -1;
        return Float.POSITIVE_INFINITY;
    }
    node.splitAxis = ax;
    return intervals.get(minid).pos;
}
Also used : Vector3f(org.joml.Vector3f) ArrayList(java.util.ArrayList)

Aggregations

Vector3f (org.joml.Vector3f)60 ByteBuffer (java.nio.ByteBuffer)14 FloatBuffer (java.nio.FloatBuffer)12 Matrix4f (org.joml.Matrix4f)10 Vector3d (org.joml.Vector3d)7 Vector4f (org.joml.Vector4f)7 ArrayList (java.util.ArrayList)6 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)5 Location (io.xol.chunkstories.api.Location)4 Light (io.xol.chunkstories.api.rendering.lightning.Light)4 RenderingInterface (io.xol.chunkstories.api.rendering.RenderingInterface)3 Shader (io.xol.chunkstories.api.rendering.shader.Shader)3 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)2 Voxel (io.xol.chunkstories.api.voxel.Voxel)2 CellData (io.xol.chunkstories.api.world.cell.CellData)2 DummyCell (io.xol.chunkstories.api.world.cell.DummyCell)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2