Vec2f pos = new Vec2f(); pos.setX(x); pos.setY(z); 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()); int z1 = z0 + 1; float h3 = config.getHeightmapDataBuffer().get(config.getHeightmap().getMetaData().getWidth() * z1 + x1); float percentU = pos.getX() - x0; float percentV = pos.getY() - z0;
Vec2f sunToWindowCenter = windowMidPos.sub(lightScreenSpacePos); float brightness = 1 - sunToWindowCenter.div(new Vec2f(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight())).length(); light.getScreenSpacePosition().getX() + (sunToWindowCenter.getX() * lensFlareTexture.getSpacing()) - lensFlareTexture.getOrthoTransform().getScaling().getX()/2f); lensFlareTexture.getOrthoTransform().getTranslation().setY( light.getScreenSpacePosition().getY() + (sunToWindowCenter.getY() * lensFlareTexture.getSpacing()) - lensFlareTexture.getOrthoTransform().getScaling().getY()/2f); lensFlareTexture.setOrthographicMatrix(
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; }
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(); }
public TerrainQuadtree(HashMap<NodeComponentType, NodeComponent> components){ for (int i=0; i<rootPatches; i++){ for (int j=0; j<rootPatches; j++){ addChild(new TerrainNode(components, new Vec2f(1f * i/(float)rootPatches,1f * j/(float)rootPatches), 0, new Vec2f(i,j))); } } thread = new Thread(this); }
L = Integer.valueOf(properties.getProperty("fft.L")); amplitude = Float.valueOf(properties.getProperty("fft.amplitude")); windDirection = new Vec2f(Float.valueOf(properties.getProperty("wind.x")), Float.valueOf(properties.getProperty("wind.y"))).normalize(); windSpeed = Float.valueOf(properties.getProperty("wind.speed")); capillarWavesSupression = Float.valueOf(properties.getProperty("fft.capillarwavesSuppression"));
DoubleBuffer yPos = BufferUtils.createDoubleBuffer(1); glfwGetCursorPos(BaseContext.getWindow().getId(), xPos, yPos); Vec2f screenPos = new Vec2f((float) xPos.get(),(float) yPos.get()); 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);
public TerrainQuadtree(Map<NodeComponentType, NodeComponent> components, int rootChunkCount, float horizontalScaling) { super(); Transform worldTransformFace0 = new Transform(); worldTransformFace0.setTranslation(-0.5f * horizontalScaling, 0, -0.5f * horizontalScaling); worldTransformFace0.setScaling(horizontalScaling); for (int i=0; i<rootChunkCount; i++){ for (int j=0; j<rootChunkCount; j++){ addChild(createChildChunk(components, quadtreeCache, worldTransformFace0, new Vec2f(1f * i/(float)rootChunkCount,1f * j/(float)rootChunkCount), 0, new Vec2f(i,j))); } } }
Vec2f pos = new Vec2f(); pos.setX(x); pos.setY(z); 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()); int z1 = z0 + 1; float h3 = config.getHeightmapDataBuffer().get(config.getHeightmap().getMetaData().getWidth() * z1 + x1); float percentU = pos.getX() - x0; float percentV = pos.getY() - z0;
float strength = Float.valueOf(properties.getProperty("fractal" + i + ".strength")); int random = Integer.valueOf(properties.getProperty("fractal" + i + ".random")); Vec2f direction = new Vec2f(Float.valueOf(properties.getProperty("fractal" + i + ".direction.x")), Float.valueOf(properties.getProperty("fractal" + i + ".direction.y"))); float intensity = Float.valueOf(properties.getProperty("fractal" + i + ".intensity"));
Vec2f pos = new Vec2f(); pos.setX(x); pos.setY(z); 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()); int z1 = z0 + 1; float h3 = config.getHeightmapDataBuffer().get(config.getHeightmap().getMetaData().getWidth() * z1 + x1); float percentU = pos.getX() - x0; float percentV = pos.getY() - z0;
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(); }