Exemple #1
0
  public Trapeeze(Game game) {
    Cylinder pole = new Cylinder(10, 10, radius, height, true);
    leftPole = new Geometry("leftPole", pole);
    leftPole.rotate(90f * FastMath.DEG_TO_RAD, 0, 0);
    leftPole.setLocalTranslation(-1f, height / 2f, 0f);
    leftPole.setShadowMode(RenderQueue.ShadowMode.Cast);

    rightPole = new Geometry("rightPole", pole);
    rightPole.rotate(90f * FastMath.DEG_TO_RAD, 0, 0);
    rightPole.setLocalTranslation(1f, height / 2f, 0f);
    rightPole.setShadowMode(RenderQueue.ShadowMode.Cast);

    float betweenPoles = rightPole.getLocalTranslation().x - leftPole.getLocalTranslation().x;
    Box seat = new Box(betweenPoles, radius, radius * 4);
    swing = new Geometry("swing", seat);
    swing.rotate(90f * FastMath.DEG_TO_RAD, 0, 0);
    swing.setLocalTranslation(0f, 3, 0f);
    swing.setShadowMode(RenderQueue.ShadowMode.Cast);

    swing.move(-4.0f, 6f, 0.0f);
    leftPole.move(-4.0f, 10f, 0.0f);
    rightPole.move(-4.0f, 10f, 0.0f);

    setTrapeezeMaterial(Main.matOrange);

    collisionShape = CollisionShapeFactory.createBoxShape(leftPole);
    collisionShape = CollisionShapeFactory.createBoxShape(rightPole);
    collisionShape = CollisionShapeFactory.createBoxShape(swing);

    this.attachChild(leftPole);
    this.attachChild(swing);
  }
  // debug function that create a displayable frustrum
  protected Geometry createFrustum(Vector3f[] pts, int i) {
    WireFrustum frustum = new WireFrustum(pts);
    Geometry frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    frustumMdl.setMaterial(mat);
    switch (i) {
      case 0:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink);
        break;
      case 1:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
        break;
      case 2:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green);
        break;
      case 3:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue);
        break;
      default:
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.White);
        break;
    }

    frustumMdl.updateGeometricState();
    return frustumMdl;
  }
 /** Make a solid floor and add it to the scene. */
 public void initFloor() {
   Geometry floor_geo = new Geometry("Floor", floor);
   floor_geo.setMaterial(floor_mat);
   floor_geo.setShadowMode(ShadowMode.Receive);
   floor_geo.setLocalTranslation(0, -0.1f, 0);
   this.rootNode.attachChild(floor_geo);
   /* Make the floor physical with mass 0.0f! */
   floor_phy = new RigidBodyControl(0.0f);
   floor_geo.addControl(floor_phy);
   bulletAppState.getPhysicsSpace().add(floor_phy);
 }
Exemple #4
0
 public void addBrick(Vector3f ori) {
   Geometry reBoxg = new Geometry("brick", brick);
   reBoxg.setMaterial(mat);
   reBoxg.setLocalTranslation(ori);
   reBoxg.rotate(0f, (float) Math.toRadians(angle), 0f);
   reBoxg.addControl(new RigidBodyControl(1.5f));
   reBoxg.setShadowMode(ShadowMode.CastAndReceive);
   reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f);
   this.rootNode.attachChild(reBoxg);
   this.getPhysicsSpace().add(reBoxg);
 }
Exemple #5
0
  public void initFloor() {
    Box floorBox = new Box(Vector3f.ZERO, 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);
  }
Exemple #6
0
  @Override
  public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(0.7804813f, 1.7502685f, -2.1556435f));
    cam.setRotation(new Quaternion(0.1961598f, -0.7213164f, 0.2266092f, 0.6243975f));
    cam.setFrustumFar(10);

    Material mat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m");
    rootNode.setShadowMode(ShadowMode.Off);
    Box floor = new Box(Vector3f.ZERO, 3, 0.1f, 3);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setLocalTranslation(0, -0.2f, 0);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);

    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalScale(2f);
    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(teapot);
    //        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    //        lightMdl.setMaterial(mat);
    //        // disable shadowing for light representation
    //        lightMdl.setShadowMode(ShadowMode.Off);
    //        rootNode.attachChild(lightMdl);

    bsr = new BasicShadowRenderer(assetManager, 512);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    viewPort.addProcessor(bsr);

    frustum = new WireFrustum(bsr.getPoints());
    frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
    frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
    rootNode.attachChild(frustumMdl);
  }
  public void simpleInitApp() {
    renderManager.setAlphaToCoverage(true);
    cam.setLocation(new Vector3f(0.14914267f, 0.58147097f, 4.7686534f));
    cam.setRotation(new Quaternion(-0.0044764364f, 0.9767943f, 0.21314798f, 0.020512417f));

    //        cam.setLocation(new Vector3f(2.0606942f, 3.20342f, 6.7860126f));
    //        cam.setRotation(new Quaternion(-0.017481906f, 0.98241085f, -0.12393151f,
    // -0.13857932f));

    viewPort.setBackgroundColor(ColorRGBA.DarkGray);

    Quad q = new Quad(20, 20);
    q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(5));
    Geometry geom = new Geometry("floor", q);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    geom.setMaterial(mat);

    geom.rotate(-FastMath.HALF_PI, 0, 0);
    geom.center();
    geom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(geom);

    // create the geometry and attach it
    Spatial teaGeom = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
    teaGeom.setQueueBucket(Bucket.Transparent);
    teaGeom.setShadowMode(ShadowMode.Cast);
    makeToonish(teaGeom);

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(al);

    DirectionalLight dl1 = new DirectionalLight();
    dl1.setDirection(new Vector3f(1, -1, 1).normalizeLocal());
    dl1.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    rootNode.addLight(dl1);

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f));
    rootNode.addLight(dl);

    rootNode.attachChild(teaGeom);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    CartoonEdgeFilter toon = new CartoonEdgeFilter();
    toon.setEdgeWidth(0.5f);
    toon.setEdgeIntensity(1.0f);
    toon.setNormalThreshold(0.8f);
    fpp.addFilter(toon);
    viewPort.addProcessor(fpp);
  }
Exemple #8
0
  @Override
  public void simpleInitApp() {
    // sun
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
    dl.setColor(ColorRGBA.Orange);
    rootNode.addLight(dl);
    // ambient light
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
    rootNode.addLight(al);

    // floor
    Material textureMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    textureMat.setTexture("ColorMap", assetManager.loadTexture("myAssets/Textures/woodFloor.jpg"));
    Box floor = new Box(Vector3f.ZERO, 20.0f, 0.01f, 20.0f);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(textureMat);
    rootNode.attachChild(floorGeom);

    // object
    Spatial tree = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
    tree.setQueueBucket(Bucket.Transparent);
    rootNode.attachChild(tree);

    // projector
    PApplet applet = new ColorBarsPApplet();
    PAppletProjectorNode projectorNode =
        new PAppletProjectorNode("projector0", assetManager, applet, 200, 200, true);
    rootNode.attachChild(projectorNode);
    rootNode.attachChild(
        projectorNode
            .getFrustmMdel()); // if you don't want to see frustum, please don't attach it to
    // rootNode.
    // projector should be added to TextureProjectorRenderer, and TextureProjectorRenderer should be
    // added to ViewPort.
    TextureProjectorRenderer ptr = new TextureProjectorRenderer(assetManager);
    ptr.getTextureProjectors().add(projectorNode.getProjector());
    viewPort.addProcessor(ptr);

    // projector is a kind of Shadow, and following processes are necessary for Shadow Rendering.
    floorGeom.setShadowMode(ShadowMode.Receive);
    tree.setShadowMode(ShadowMode.CastAndReceive); // tree makes and receives shadow

    projectorNode.setLocalTranslation(new Vector3f(0, 10, 0)); // move the projector,
    projectorNode.lookAt(
        new Vector3f(0, 0, 0), Vector3f.UNIT_X); // and make it to look at where you want.

    // cam
    cam.setLocation(Vector3f.UNIT_XYZ.mult(10.0f)); // camera moves to 10, 10, 10
    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); // and looks at 0,0,0.
  }
 /** This method creates one individual physical brick. */
 public void makeBrick(Vector3f loc) {
   /** Create a brick geometry and attach to scene graph. */
   Geometry brick_geo = new Geometry("brick", box);
   brick_geo.setMaterial(wall_mat);
   rootNode.attachChild(brick_geo);
   /** Position the brick geometry and activate shadows */
   brick_geo.setLocalTranslation(loc);
   brick_geo.setShadowMode(ShadowMode.CastAndReceive);
   /** Make brick physical with a mass > 0.0f. */
   brick_phy = new RigidBodyControl(2f);
   /** Add physical brick to physics space. */
   brick_geo.addControl(brick_phy);
   bulletAppState.getPhysicsSpace().add(brick_phy);
 }
Exemple #10
0
 public void onAction(String binding, boolean value, float tpf) {
   if (binding.equals("shoot") && !value) {
     Geometry bulletg = new Geometry("bullet", bullet);
     bulletg.setMaterial(mat);
     bulletg.setName("bullet");
     bulletg.setLocalTranslation(cam.getLocation());
     bulletg.setShadowMode(ShadowMode.CastAndReceive);
     bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
     bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f);
     bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
     rootNode.attachChild(bulletg);
     getPhysicsSpace().add(bulletg);
   } else if (binding.equals("shoot2") && !value) {
     Geometry bulletg = new Geometry("bullet", bullet);
     bulletg.setMaterial(mat2);
     bulletg.setName("bullet");
     bulletg.setLocalTranslation(cam.getLocation());
     bulletg.setShadowMode(ShadowMode.CastAndReceive);
     bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
     bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
     rootNode.attachChild(bulletg);
     getPhysicsSpace().add(bulletg);
   }
 }
Exemple #11
0
 public void onAction(String name, boolean keyPressed, float tpf) {
   if (name.equals("shoot") && !keyPressed) {
     Geometry bulletg = new Geometry("bullet", bullet);
     bulletg.setMaterial(mat2);
     bulletg.setShadowMode(ShadowMode.CastAndReceive);
     bulletg.setLocalTranslation(getCam().getLocation());
     RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
     //                RigidBodyControl bulletNode = new
     // RigidBodyControl(bulletCollisionShape, 1);
     bulletNode.setLinearVelocity(getCam().getDirection().mult(25));
     bulletg.addControl(bulletNode);
     rootNode.attachChild(bulletg);
     getPhysicsSpace().add(bulletNode);
   }
 }
 /**
  * This method creates one individual physical cannon ball. By defaul, the ball is accelerated and
  * flies from the camera position in the camera direction.
  */
 public void makeCannonBall() {
   /** Create a cannon ball geometry and attach to scene graph. */
   Geometry ball_geo = new Geometry("cannon ball", sphere);
   ball_geo.setMaterial(stone_mat);
   rootNode.attachChild(ball_geo);
   /** Position the cannon ball and activate shadows */
   ball_geo.setLocalTranslation(cam.getLocation());
   ball_geo.setShadowMode(ShadowMode.CastAndReceive);
   /** Make the ball physcial with a mass > 0.0f */
   ball_phy = new RigidBodyControl(1f);
   /** Add physical ball to physics space. */
   ball_geo.addControl(ball_phy);
   bulletAppState.getPhysicsSpace().add(ball_phy);
   /** Accelerate the physcial ball to shoot it. */
   ball_phy.setLinearVelocity(cam.getDirection().mult(25));
 }
Exemple #13
0
  public void generateMesh() {
    if (!primitives.isEmpty()) {
      // Save local rotation
      Quaternion q1 = getParent().getLocalRotation().clone();
      Quaternion q2 = getParent().getParent().getLocalRotation().clone();
      // Align to Zero rotation.
      getParent().setLocalRotation(Quaternion.IDENTITY);
      getParent().getParent().setLocalRotation(Quaternion.IDENTITY);
      setLocalRotation(Quaternion.IDENTITY);

      // Discard previous mesh then reload it
      if (meshGeometry != null) {
        detachChild(meshGeometry);
      }

      // Build the hull again.
      Mesh mesh = buildPreviewMesh();

      // Re-attach the hull
      meshGeometry = new Geometry("OurMesh", mesh);
      // meshGeometry.setMaterial(Primitive.showNormalsWireframeMaterial);
      // meshGeometry.setMaterial(Primitive.showNormalsMaterial);
      meshGeometry.setMaterial(Primitive.simpleLightMaterial);
      // meshGeometry.setMaterial(Primitive.simpleLightWireframeMaterial);

      attachChild(meshGeometry);
      meshGeometry.setShadowMode(ShadowMode.CastAndReceive);

      // Restore rotation
      getParent().setLocalRotation(q1);
      getParent().getParent().setLocalRotation(q2);

      // Hide all frames.
      for (Primitive a : primitives) {
        a.setCullHint(CullHint.Always);
      }
    }
  }