use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TestPostFilters method setupFloor.
public void setupFloor() {
Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
Box floor = new Box(50, 1f, 50);
TangentBinormalGenerator.generate(floor);
floor.scaleTextureCoordinates(new Vector2f(5, 5));
Geometry floorGeom = new Geometry("Floor", floor);
floorGeom.setMaterial(mat);
floorGeom.setShadowMode(ShadowMode.Receive);
rootNode.attachChild(floorGeom);
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TerrainGridAlphaMapTest method updateMarkerElevations.
private void updateMarkerElevations() {
for (Spatial s : markers.getChildren()) {
float h = terrain.getHeight(new Vector2f(s.getLocalTranslation().x, s.getLocalTranslation().z));
s.setLocalTranslation(s.getLocalTranslation().x, h + 1, s.getLocalTranslation().z);
}
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestModifyHeight method adjustHeight.
private void adjustHeight(Vector3f loc, float radius, float height) {
// offset it by radius because in the loop we iterate through 2 radii
int radiusStepsX = (int) (radius / terrain.getLocalScale().x);
int radiusStepsZ = (int) (radius / terrain.getLocalScale().z);
float xStepAmount = terrain.getLocalScale().x;
float zStepAmount = terrain.getLocalScale().z;
long start = System.currentTimeMillis();
List<Vector2f> locs = new ArrayList<Vector2f>();
List<Float> heights = new ArrayList<Float>();
for (int z = -radiusStepsZ; z < radiusStepsZ; z++) {
for (int x = -radiusStepsX; x < radiusStepsX; x++) {
float locX = loc.x + (x * xStepAmount);
float locZ = loc.z + (z * zStepAmount);
if (isInRadius(locX - loc.x, locZ - loc.z, radius)) {
// see if it is in the radius of the tool
float h = calculateHeight(radius, height, locX - loc.x, locZ - loc.z);
locs.add(new Vector2f(locX, locZ));
heights.add(h);
}
}
}
terrain.adjustHeight(locs, heights);
//System.out.println("Modified "+locs.size()+" points, took: " + (System.currentTimeMillis() - start)+" ms");
terrain.updateModelBound();
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TestSceneWater method simpleInitApp.
public void simpleInitApp() {
this.flyCam.setMoveSpeed(10);
Node mainScene = new Node();
cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));
// load sky
mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
File file = new File("wildhouse.zip");
if (file.exists()) {
useHttp = false;
}
// load the level from zip or http zip
if (useHttp) {
assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
} else {
assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
}
Spatial scene = assetManager.loadModel("main.scene");
DirectionalLight sun = new DirectionalLight();
Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
sun.setDirection(lightDir);
sun.setColor(ColorRGBA.White.clone().multLocal(2));
scene.addLight(sun);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
//add lightPos Geometry
Sphere lite = new Sphere(8, 8, 3.0f);
Geometry lightSphere = new Geometry("lightsphere", lite);
lightSphere.setMaterial(mat);
Vector3f lightPos = lightDir.multLocal(-400);
lightSphere.setLocalTranslation(lightPos);
rootNode.attachChild(lightSphere);
SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager);
waterProcessor.setReflectionScene(mainScene);
waterProcessor.setDebug(false);
waterProcessor.setLightPosition(lightPos);
waterProcessor.setRefractionClippingOffset(1.0f);
//setting the water plane
Vector3f waterLocation = new Vector3f(0, -20, 0);
waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y)));
WaterUI waterUi = new WaterUI(inputManager, waterProcessor);
waterProcessor.setWaterColor(ColorRGBA.Brown);
waterProcessor.setDebug(true);
//lower render size for higher performance
// waterProcessor.setRenderSize(128,128);
//raise depth to see through water
// waterProcessor.setWaterDepth(20);
//lower the distortion scale if the waves appear too strong
// waterProcessor.setDistortionScale(0.1f);
//lower the speed of the waves if they are too fast
// waterProcessor.setWaveSpeed(0.01f);
Quad quad = new Quad(400, 400);
//the texture coordinates define the general size of the waves
quad.scaleTextureCoordinates(new Vector2f(6f, 6f));
Geometry water = new Geometry("water", quad);
water.setShadowMode(ShadowMode.Receive);
water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
water.setMaterial(waterProcessor.getMaterial());
water.setLocalTranslation(-200, -20, 250);
rootNode.attachChild(water);
viewPort.addProcessor(waterProcessor);
mainScene.attachChild(scene);
rootNode.attachChild(mainScene);
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class IosTouchHandler method actionMove.
public void actionMove(int pointerId, long time, float x, float y) {
float jmeX = iosInput.getJmeX(x);
float jmeY = iosInput.invertY(iosInput.getJmeY(y));
Vector2f lastPos = lastPositions.get(pointerId);
if (lastPos == null) {
lastPos = new Vector2f(jmeX, jmeY);
lastPositions.put(pointerId, lastPos);
}
float dX = jmeX - lastPos.x;
float dY = jmeY - lastPos.y;
if (dX != 0 || dY != 0) {
TouchEvent touch = iosInput.getFreeTouchEvent();
touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY);
touch.setPointerId(pointerId);
touch.setTime(time);
touch.setPressure(1.0f);
//touch.setPressure(event.getPressure(p));
lastPos.set(jmeX, jmeY);
processEvent(touch);
}
}
Aggregations