Java Code Examples for com.jme3.bullet.control.RigidBodyControl#setCollisionGroup()

The following examples show how to use com.jme3.bullet.control.RigidBodyControl#setCollisionGroup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestIssue1283.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Add a projectile to the scene and physics space. Its initial position and
 * velocity are determined by the camera the and mouse pointer.
 */
private void launchProjectile() {
    Vector2f screenXY = inputManager.getCursorPosition();
    float nearZ = 0f;
    Vector3f nearLocation = cam.getWorldCoordinates(screenXY, nearZ);
    float farZ = 1f;
    Vector3f farLocation = cam.getWorldCoordinates(screenXY, farZ);
    Vector3f direction = farLocation.subtract(nearLocation);
    direction.normalizeLocal();

    Geometry geometry = new Geometry("projectile", projectileMesh);
    rootNode.attachChild(geometry);
    geometry.setLocalTranslation(nearLocation);
    geometry.setMaterial(projectileMaterial);

    float mass = 1f;
    RigidBodyControl physicsControl = new RigidBodyControl(mass);
    geometry.addControl(physicsControl);

    physicsControl.setCcdMotionThreshold(0.01f);
    physicsControl.setCcdSweptSphereRadius(projectileRadius);
    physicsControl.setCollisionGroup(
            PhysicsCollisionObject.COLLISION_GROUP_02);
    physicsControl.setCollideWithGroups(
            PhysicsCollisionObject.COLLISION_GROUP_02);
    physicsControl.setRestitution(0.8f);

    float projectileSpeed = 250f; // physics-space units per second
    Vector3f initialVelocity = direction.mult(projectileSpeed);
    physicsControl.setLinearVelocity(initialVelocity);

    physicsSpace.add(physicsControl);
}
 
Example 2
Source File: TestHoveringTank.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void makeMissile() {
    Vector3f pos = spaceCraft.getWorldTranslation().clone();
    Quaternion rot = spaceCraft.getWorldRotation();
    Vector3f dir = rot.getRotationColumn(2);

    Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
    missile.scale(0.5f);
    missile.rotate(0, FastMath.PI, 0);
    missile.updateGeometricState();

    BoundingBox box = (BoundingBox) missile.getWorldBound();
    final Vector3f extent = box.getExtent(null);

    BoxCollisionShape boxShape = new BoxCollisionShape(extent);

    missile.setName("Missile");
    missile.rotate(rot);
    missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
    missile.setLocalRotation(hoverControl.getPhysicsRotation());
    missile.setShadowMode(ShadowMode.Cast);
    RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
    control.setLinearVelocity(dir.mult(100));
    control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
    missile.addControl(control);


    rootNode.attachChild(missile);
    getPhysicsSpace().add(missile);
}
 
Example 3
Source File: TestHoveringTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void makeMissile() {
    Vector3f pos = spaceCraft.getWorldTranslation().clone();
    Quaternion rot = spaceCraft.getWorldRotation();
    Vector3f dir = rot.getRotationColumn(2);

    Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
    missile.scale(0.5f);
    missile.rotate(0, FastMath.PI, 0);
    missile.updateGeometricState();

    BoundingBox box = (BoundingBox) missile.getWorldBound();
    final Vector3f extent = box.getExtent(null);

    BoxCollisionShape boxShape = new BoxCollisionShape(extent);

    missile.setName("Missile");
    missile.rotate(rot);
    missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
    missile.setLocalRotation(hoverControl.getPhysicsRotation());
    missile.setShadowMode(ShadowMode.Cast);
    RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
    control.setLinearVelocity(dir.mult(100));
    control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
    missile.addControl(control);


    rootNode.attachChild(missile);
    getPhysicsSpace().add(missile);
}