use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TestTexture3DLoading method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
flyCam.setEnabled(false);
Quad q = new Quad(10, 10);
Geometry geom = new Geometry("Quad", q);
Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
TextureKey key = new TextureKey("Textures/3D/flame.dds");
key.setGenerateMips(true);
key.setTextureTypeHint(Texture.Type.ThreeDimensional);
Texture t = assetManager.loadTexture(key);
//4 * 4
int rows = 4;
q.scaleTextureCoordinates(new Vector2f(rows, rows));
//The image only have 8 pictures and we have 16 thumbs, the data will be interpolated by the GPU
material.setFloat("InvDepth", 1f / 16f);
material.setInt("Rows", rows);
material.setTexture("Texture", t);
geom.setMaterial(material);
rootNode.attachChild(geom);
cam.setLocation(new Vector3f(4.7444625f, 5.160054f, 13.1939f));
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestModifyHeight method getWorldIntersection.
private Vector3f getWorldIntersection() {
Vector3f origin = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.0f);
Vector3f direction = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.3f);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
int numCollisions = terrain.collideWith(ray, results);
if (numCollisions > 0) {
CollisionResult hit = results.getClosestCollision();
return hit.getContactPoint();
}
return null;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestModifyHeight method simpleUpdate.
@Override
public void simpleUpdate(float tpf) {
Vector3f intersection = getWorldIntersection();
updateHintText(intersection);
if (raiseTerrain) {
if (intersection != null) {
adjustHeight(intersection, 64, tpf * 60);
}
} else if (lowerTerrain) {
if (intersection != null) {
adjustHeight(intersection, 64, -tpf * 60);
}
}
if (terrain != null && intersection != null) {
float h = terrain.getHeight(new Vector2f(intersection.x, intersection.z));
Vector3f tl = terrain.getWorldTranslation();
marker.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
markerNormal.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
Vector3f normal = terrain.getNormal(new Vector2f(intersection.x, intersection.z));
((Arrow) markerNormal.getMesh()).setArrowExtent(normal);
}
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestModifyHeight method calculateHeight.
private float calculateHeight(float radius, float heightFactor, float x, float z) {
// find percentage for each 'unit' in radius
Vector2f point = new Vector2f(x, z);
float val = point.length() / radius;
val = 1 - val;
if (val <= 0) {
val = 0;
}
return heightFactor * val;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class IosTouchHandler method actionDown.
public void actionDown(int pointerId, long time, float x, float y) {
logger.log(Level.FINE, "Inject input pointer: {0}, time: {1}, x: {2}, y: {3}", new Object[] { pointerId, time, x, y });
float jmeX = iosInput.getJmeX(x);
float jmeY = iosInput.invertY(iosInput.getJmeY(y));
TouchEvent touch = iosInput.getFreeTouchEvent();
touch.set(TouchEvent.Type.DOWN, jmeX, jmeY, 0, 0);
//TODO: pointer ID
touch.setPointerId(pointerId);
touch.setTime(time);
touch.setPressure(1.0f);
//touch.setPressure(event.getPressure(pointerIndex)); //TODO: preassure
lastPositions.put(pointerId, new Vector2f(jmeX, jmeY));
processEvent(touch);
}
Aggregations