static Vector2f[] toVector2(double[] data) { Vector2f[] vectors = new Vector2f[data.length / 2]; for (int i = 0; i < vectors.length; i++) { float x = (float) data[i * 2]; float y = (float) data[i * 2 + 1]; vectors[i] = new Vector2f(x, y); } return vectors; }
/** * <code>mult</code> multiplies this vector by a scalar. The resultant * vector is returned. * * @param scalar * the value to multiply this vector by. * @return the new vector. */ public Vector2f mult(float scalar) { return new Vector2f(x * scalar, y * scalar); }
/** * <code>divide</code> divides the values of this vector by a scalar and * returns the result. The values of this vector remain untouched. * * @param scalar * the value to divide this vectors attributes by. * @return the result <code>Vector</code>. */ public Vector2f divide(float scalar) { return new Vector2f(x / scalar, y / scalar); }
/** * <code>negate</code> returns the negative of this vector. All values are * negated and set to a new vector. * * @return the negated vector. */ public Vector2f negate() { return new Vector2f(-x, -y); }
/** * <code>subtract</code> subtracts the given x,y values from those of this * vector creating a new vector object. * * @param valX * value to subtract from x * @param valY * value to subtract from y * @return this */ public Vector2f subtract(float valX, float valY) { return new Vector2f(x - valX, y - valY); }
private Vector2f axis(float input) { // See above comments about reusing vectors return new Vector2f(input, input); }
private boolean isInRadius(float x, float y, float radius) { Vector2f point = new Vector2f(x, y); // return true if the distance is less than equal to the radius return point.length() <= radius; }
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; }
@Override public boolean init() { logger.config("Initialize OpenVR input."); for (int i = 0; i < VR.k_unMaxTrackedDeviceCount; i++) { rotStore[i] = new Quaternion(); posStore[i] = new Vector3f(); cStates[i] = VRControllerState.create(); lastCallAxis[i] = new Vector2f(); logger.config(" Input " + (i + 1) + "/" + VR.k_unMaxTrackedDeviceCount + " binded."); } return true; }
private Vector2f cv(OVRVector2f in) { // TODO do we want to reuse vectors rather than making new ones? // TODO OpenVRInput does this, but it will probably cause some bugs. return new Vector2f(in.x(), in.y()); }
private static Vector2f randomVector() { return new Vector2f(FastMath.nextRandomFloat(), FastMath.nextRandomFloat()); }
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); touch.setPointerId(pointerId);//TODO: pointer ID touch.setTime(time); touch.setPressure(1.0f); //touch.setPressure(event.getPressure(pointerIndex)); //TODO: preassure lastPositions.put(pointerId, new Vector2f(jmeX, jmeY)); processEvent(touch); }
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; }
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); } }
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); }
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); }
@Override public void write(JmeExporter e) throws IOException { super.write(e); OutputCapsule c = e.getCapsule(this); c.write(size, "size", 0); c.write(totalSize, "totalSize", 0); c.write(stepScale, "stepScale", null); c.write(offset, "offset", new Vector2f(0,0)); c.write(offsetAmount, "offsetAmount", 0); c.write(quadrant, "quadrant", 0); //c.write(lodCalculatorFactory, "lodCalculatorFactory", null); //c.write(lodCalculator, "lodCalculator", null); }
public void initFloor() { Box floorBox = new Box(10f, 0.1f, 5f); floorBox.scaleTextureCoordinates(new Vector2f(3, 6)); Geometry floor = new Geometry("floor", floorBox); floor.setMaterial(mat3); floor.setShadowMode(ShadowMode.Receive); floor.setLocalTranslation(0, 0, 0); floor.addControl(new RigidBodyControl(0)); this.rootNode.attachChild(floor); this.getPhysicsSpace().add(floor); }
public void initFloor() { Box floorBox = new Box(10f, 0.1f, 5f); floorBox.scaleTextureCoordinates(new Vector2f(3, 6)); Geometry floor = new Geometry("floor", floorBox); floor.setMaterial(mat3); floor.setShadowMode(ShadowMode.Receive); floor.setLocalTranslation(0, 0, 0); floor.addControl(new RigidBodyControl(0)); this.rootNode.attachChild(floor); this.getPhysicsSpace().add(floor); }
public void initFloor() { Box floorBox = new Box(10f, 0.1f, 5f); floorBox.scaleTextureCoordinates(new Vector2f(3, 6)); Geometry floor = new Geometry("floor", floorBox); floor.setMaterial(mat3); floor.setShadowMode(ShadowMode.Receive); floor.setLocalTranslation(0, -0.1f, 0); floor.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(10f, 0.1f, 5f)), 0)); this.rootNode.attachChild(floor); this.getPhysicsSpace().add(floor); }