Search in sources :

Example 1 with Cone

use of com.ardor3d.scenegraph.shape.Cone in project energy3d by concord-consortium.

the class Tree method init.

@Override
protected void init() {
    super.init();
    switch(treeType) {
        case COTTONWOOD:
            treeWidth = 80;
            treeHeight = 100;
            break;
        case LINDEN:
            treeWidth = 90;
            treeHeight = 120;
            break;
        case OAK:
            treeWidth = 70;
            treeHeight = 80;
            break;
        case ELM:
            treeWidth = 60;
            treeHeight = 75;
            break;
        case MAPLE:
            treeWidth = 30;
            treeHeight = 60;
            break;
        case PINE:
            treeWidth = 30;
            treeHeight = 80;
            break;
        default:
            treeWidth = 30;
            treeHeight = 40;
    }
    mesh = new Quad("Tree Quad", treeWidth, treeHeight);
    mesh.setModelBound(new BoundingBox());
    mesh.updateModelBound();
    mesh.setRotation(new Matrix3().fromAngles(Math.PI / 2, 0, 0));
    mesh.setTranslation(0, 0, treeHeight / 2.0);
    mesh.getSceneHints().setPickingHint(PickingHint.Pickable, false);
    final BlendState bs = new BlendState();
    bs.setEnabled(true);
    bs.setBlendEnabled(false);
    bs.setTestEnabled(true);
    bs.setTestFunction(TestFunction.GreaterThan);
    bs.setReference(0.7f);
    mesh.setRenderState(bs);
    mesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    billboard = new BillboardNode("Billboard");
    billboard.setAlignment(BillboardAlignment.AxialZ);
    billboard.attachChild(mesh);
    root.attachChild(billboard);
    switch(treeType) {
        case PINE:
            // axis samples, radial samples, radius, height, closed
            crown = new Cone("Tree Crown", 2, 6, 18, 20, false);
            break;
        default:
            // z samples, radial samples, radius
            crown = new Sphere("Tree Crown", 4, 8, 14);
    }
    crown.setModelBound(new BoundingSphere());
    crown.updateModelBound();
    final Cylinder trunk = new Cylinder("Tree Trunk", 10, 10, 1, 20);
    trunk.setModelBound(new BoundingBox());
    trunk.updateModelBound();
    switch(treeType) {
        case COTTONWOOD:
            crown.setScale(3, 3, 3.5);
            crown.setTranslation(0, 0, 55);
            trunk.setScale(8, 8, 2);
            trunk.setTranslation(0, 0, 20);
            break;
        case LINDEN:
            crown.setScale(3.5, 3.5, 4);
            crown.setTranslation(0, 0, 65);
            trunk.setScale(5, 5, 2);
            trunk.setTranslation(0, 0, 20);
            break;
        case OAK:
            crown.setScale(2.5, 2.5, 3);
            crown.setTranslation(0, 0, 45);
            trunk.setScale(5, 5, 2);
            trunk.setTranslation(0, 0, 20);
            break;
        case ELM:
            crown.setScale(2, 2, 2.5);
            crown.setTranslation(0, 0, 40);
            trunk.setScale(2, 2, 2);
            trunk.setTranslation(0, 0, 20);
            break;
        case MAPLE:
            crown.setScale(1, 1, 2.1);
            crown.setTranslation(0, 0, 32);
            trunk.setTranslation(0, 0, 10);
            break;
        case PINE:
            crown.setScale(1, 1, -4.0);
            crown.setTranslation(0, 0, 45);
            trunk.setTranslation(0, 0, 10);
            break;
        default:
            crown.setScale(1, 1, 1.2);
            crown.setTranslation(0, 0, 24);
            trunk.setTranslation(0, 0, 10);
            break;
    }
    collisionRoot = new Node("Tree Collision Root");
    collisionRoot.attachChild(crown);
    collisionRoot.attachChild(trunk);
    if (points.size() > 0) {
        collisionRoot.setTranslation(getAbsPoint(0));
    }
    collisionRoot.updateWorldTransform(true);
    collisionRoot.updateWorldBound(true);
    collisionRoot.getSceneHints().setCullHint(showPolygons ? CullHint.Never : CullHint.Always);
    root.attachChild(collisionRoot);
    crown.setUserData(new UserData(this));
    trunk.setUserData(new UserData(this));
    updateTextureAndColor();
}
Also used : Sphere(com.ardor3d.scenegraph.shape.Sphere) BoundingSphere(com.ardor3d.bounding.BoundingSphere) Quad(com.ardor3d.scenegraph.shape.Quad) Cylinder(com.ardor3d.scenegraph.shape.Cylinder) Cone(com.ardor3d.scenegraph.shape.Cone) BoundingSphere(com.ardor3d.bounding.BoundingSphere) BoundingBox(com.ardor3d.bounding.BoundingBox) Node(com.ardor3d.scenegraph.Node) BillboardNode(com.ardor3d.scenegraph.extension.BillboardNode) BillboardNode(com.ardor3d.scenegraph.extension.BillboardNode) BlendState(com.ardor3d.renderer.state.BlendState) Matrix3(com.ardor3d.math.Matrix3)

Aggregations

BoundingBox (com.ardor3d.bounding.BoundingBox)1 BoundingSphere (com.ardor3d.bounding.BoundingSphere)1 Matrix3 (com.ardor3d.math.Matrix3)1 BlendState (com.ardor3d.renderer.state.BlendState)1 Node (com.ardor3d.scenegraph.Node)1 BillboardNode (com.ardor3d.scenegraph.extension.BillboardNode)1 Cone (com.ardor3d.scenegraph.shape.Cone)1 Cylinder (com.ardor3d.scenegraph.shape.Cylinder)1 Quad (com.ardor3d.scenegraph.shape.Quad)1 Sphere (com.ardor3d.scenegraph.shape.Sphere)1