public void setUniform(String uniformName, Vec2f value) { glUniform2f(uniforms.get(uniformName), value.getX(), value.getY()); } public void setUniform(String uniformName, Vec3f value)
public boolean onClick() { DoubleBuffer xPos = BufferUtils.createDoubleBuffer(1); DoubleBuffer yPos = BufferUtils.createDoubleBuffer(1); glfwGetCursorPos(BaseContext.getWindow().getId(), xPos, yPos); Vec2f mousePos = new Vec2f((float) xPos.get(),(float) yPos.get()); if(pos[0].getX() < mousePos.getX() && pos[1].getX() < mousePos.getX() && pos[2].getX() > mousePos.getX() && pos[3].getX() > mousePos.getX() && pos[0].getY() < BaseContext.getWindow().getHeight() - mousePos.getY() && pos[3].getY() < BaseContext.getWindow().getHeight() - mousePos.getY() && pos[1].getY() > BaseContext.getWindow().getHeight() - mousePos.getY() && pos[2].getY() > BaseContext.getWindow().getHeight() - mousePos.getY()) { return true; } else return false; }
public void update(String newText){ if (outputText.equals(newText)){ return; } super.update(newText); ByteBuffer ubo = memAlloc(Float.BYTES * panel.getVertices().length * 4); for (int i=0; i<panel.getVertices().length; i++){ ubo.putFloat(panel.getVertices()[i].getUVCoord().getX()); ubo.putFloat(panel.getVertices()[i].getUVCoord().getY()); ubo.putFloat(0); ubo.putFloat(0); } ubo.flip(); buffer.mapMemory(ubo); } }
public QuadtreeChunk(Map<NodeComponentType, NodeComponent> components, QuadtreeCache quadtreeCache, Transform worldTransform, Vec2f location, int lod, Vec2f index){ addComponent(NodeComponentType.CONFIGURATION, components.get(NodeComponentType.CONFIGURATION)); terrainProperties = getComponent(NodeComponentType.CONFIGURATION); this.quadtreeCache = quadtreeCache; this.isleaf = true; this.index = index; this.lod = lod; this.location = location; this.gap = 1f/(terrainProperties.getRootChunkCount() * (float)(Math.pow(2, lod))); Vec3f localScaling = new Vec3f(gap,0,gap); Vec3f localTranslation = new Vec3f(location.getX(),0,location.getY()); getLocalTransform().setScaling(localScaling); getLocalTransform().setTranslation(localTranslation); setWorldTransform(worldTransform); computeWorldPos(); }
pos = pos.add(config.getHorizontalScaling()/2f); pos = pos.div(config.getHorizontalScaling()); Vec2f floor = new Vec2f((int) Math.floor(pos.getX()), (int) Math.floor(pos.getY())); pos = pos.sub(floor); pos = pos.mul(config.getHeightmap().getMetaData().getWidth()); int x0 = (int) Math.floor(pos.getX()); int x1 = x0 + 1; int z0 = (int) Math.floor(pos.getY()); float h3 = config.getHeightmapDataBuffer().get(config.getHeightmap().getMetaData().getWidth() * z1 + x1); float percentU = pos.getX() - x0; float percentV = pos.getY() - z0;
pos = pos.add(config.getScaleXZ()/2f); pos = pos.div(config.getScaleXZ()); Vec2f floor = new Vec2f((int) Math.floor(pos.getX()), (int) Math.floor(pos.getY())); pos = pos.sub(floor); pos = pos.mul(config.getHeightmap().getMetaData().getWidth()); int x0 = (int) Math.floor(pos.getX()); int x1 = x0 + 1; int z0 = (int) Math.floor(pos.getY()); float h3 = config.getHeightmapDataBuffer().get(config.getHeightmap().getMetaData().getWidth() * z1 + x1); float percentU = pos.getX() - x0; float percentV = pos.getY() - z0;
pos = pos.add(config.getScaleXZ()/2f); pos = pos.div(config.getScaleXZ()); Vec2f floor = new Vec2f((int) Math.floor(pos.getX()), (int) Math.floor(pos.getY())); pos = pos.sub(floor); pos = pos.mul(config.getHeightmap().getMetaData().getWidth()); int x0 = (int) Math.floor(pos.getX()); int x1 = x0 + 1; int z0 = (int) Math.floor(pos.getY()); float h3 = config.getHeightmapDataBuffer().get(config.getHeightmap().getMetaData().getWidth() * z1 + x1); float percentU = pos.getX() - x0; float percentV = pos.getY() - z0;
protected void computeWorldPos(){ Vec2f chunkCenter = location.add(gap/2f); Vec4f worldPosition = getWorldTransform().getWorldMatrixRTS().mul( new Vec4f(chunkCenter.getX(),0,chunkCenter.getY(),1)); worldPosition = worldPosition.normalize(); worldPosition = worldPosition.mul(terrainProperties.getHorizontalScaling()); // TODO displacment // Vec3f displacement = TerrainHelper.getTerrainHeight(terrainProperties, loc.getX(), loc.getY()); // System.out.println(worldPosition); worldPos = worldPosition.xyz(); }
float depth = depthmapBuffer.get((int) (BaseContext.getWindow().getWidth() * screenPos.getY() + screenPos.getX())); Vec2f w = new Vec2f(screenPos.getX()/BaseContext.getWindow().getWidth(), screenPos.getY()/BaseContext.getWindow().getHeight()); Vec3f ndc = new Vec3f(w.getX() * 2 - 1, w.getY() * 2 - 1, depth); float cw = BaseContext.getCamera().getProjectionMatrix().get(3,2) / (ndc.getZ() - BaseContext.getCamera().getProjectionMatrix().get(2,2)); Vec3f clip = ndc.mul(cw);
pushConstants.putFloat(amplitude); pushConstants.putFloat(windSpeed); pushConstants.putFloat(windDirection.getX()); pushConstants.putFloat(windDirection.getY()); pushConstants.putFloat(capillarSuppressFactor);
Vec3f localTranslation = new Vec3f(location.getX(),0,location.getY());
ubo.putFloat(panel.getVertices()[i].getUVCoord().getX()); ubo.putFloat(panel.getVertices()[i].getUVCoord().getY()); ubo.putFloat(0);
pushConstants.putFloat(waterConfiguration.getWindDirection().getX()); pushConstants.putFloat(waterConfiguration.getWindDirection().getY()); pushConstants.putFloat(waterConfiguration.getTessellationSlope());