|
| 1 | +package jme3test.math; |
| 2 | + |
| 3 | +import com.jme3.app.SimpleApplication; |
| 4 | +import com.jme3.material.Material; |
| 5 | +import com.jme3.math.ColorRGBA; |
| 6 | +import com.jme3.math.FastMath; |
| 7 | +import com.jme3.math.Vector2f; |
| 8 | +import com.jme3.math.Vector3f; |
| 9 | +import com.jme3.scene.Geometry; |
| 10 | +import com.jme3.scene.Mesh; |
| 11 | +import com.jme3.scene.debug.Arrow; |
| 12 | +import com.jme3.scene.debug.Grid; |
| 13 | +import com.jme3.scene.debug.WireSphere; |
| 14 | +import com.jme3.scene.shape.Sphere; |
| 15 | + |
| 16 | +/** |
| 17 | + * @author capdevon |
| 18 | + */ |
| 19 | +public class TestRandomPoints extends SimpleApplication { |
| 20 | + |
| 21 | + public static void main(String[] args) { |
| 22 | + TestRandomPoints app = new TestRandomPoints(); |
| 23 | + app.start(); |
| 24 | + } |
| 25 | + |
| 26 | + private float radius = 5; |
| 27 | + |
| 28 | + @Override |
| 29 | + public void simpleInitApp() { |
| 30 | + configureCamera(); |
| 31 | + viewPort.setBackgroundColor(ColorRGBA.DarkGray); |
| 32 | + |
| 33 | + Geometry grid = makeShape("DebugGrid", new Grid(21, 21, 2), ColorRGBA.LightGray); |
| 34 | + grid.center().move(0, 0, 0); |
| 35 | + rootNode.attachChild(grid); |
| 36 | + |
| 37 | + Geometry bsphere = makeShape("BoundingSphere", new WireSphere(radius), ColorRGBA.Red); |
| 38 | + rootNode.attachChild(bsphere); |
| 39 | + |
| 40 | + for (int i = 0; i < 100; i++) { |
| 41 | + Vector2f v = FastMath.insideUnitCircle().multLocal(radius); |
| 42 | + Arrow arrow = new Arrow(Vector3f.UNIT_Y.negate()); |
| 43 | + Geometry geo = makeShape("Arrow." + i, arrow, ColorRGBA.Green); |
| 44 | + geo.setLocalTranslation(new Vector3f(v.x, 0, v.y)); |
| 45 | + rootNode.attachChild(geo); |
| 46 | + } |
| 47 | + |
| 48 | + for (int i = 0; i < 100; i++) { |
| 49 | + Vector3f v = FastMath.insideUnitSphere().multLocal(radius); |
| 50 | + Geometry geo = makeShape("Sphere." + i, new Sphere(16, 16, 0.05f), ColorRGBA.Blue); |
| 51 | + geo.setLocalTranslation(v); |
| 52 | + rootNode.attachChild(geo); |
| 53 | + } |
| 54 | + |
| 55 | + for (int i = 0; i < 100; i++) { |
| 56 | + Vector3f v = FastMath.onUnitSphere().multLocal(radius); |
| 57 | + Geometry geo = makeShape("Sphere." + i, new Sphere(16, 16, 0.06f), ColorRGBA.Cyan); |
| 58 | + geo.setLocalTranslation(v); |
| 59 | + rootNode.attachChild(geo); |
| 60 | + } |
| 61 | + |
| 62 | + for (int i = 0; i < 100; i++) { |
| 63 | + float value = FastMath.nextRandomFloat(-5, 5); |
| 64 | + System.out.println(value); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + private void configureCamera() { |
| 69 | + flyCam.setMoveSpeed(15f); |
| 70 | + flyCam.setDragToRotate(true); |
| 71 | + |
| 72 | + cam.setLocation(Vector3f.UNIT_XYZ.mult(12)); |
| 73 | + cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); |
| 74 | + } |
| 75 | + |
| 76 | + private Geometry makeShape(String name, Mesh mesh, ColorRGBA color) { |
| 77 | + Geometry geo = new Geometry(name, mesh); |
| 78 | + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); |
| 79 | + mat.setColor("Color", color); |
| 80 | + geo.setMaterial(mat); |
| 81 | + return geo; |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments