/** Given the Avatar character, create and set it's collision controller. */ private void setCollisionController(WlAvatarCharacter avatar) { // Create a spatial that represents the bounds of the avatar to use // for collision. These are hardcoded values for now. Vector3f origin = new Vector3f(0f, 0.57f, 0.0f); float radius = 0.25f; if (selectedForInput) { Spatial collisionGraph = new Sphere("AvatarCollision", origin, 10, 10, radius); collisionGraph.setModelBound(new BoundingBox()); collisionGraph.updateModelBound(); // Fetch the JME Collision system using the server manager of the Cell // to which this renderer is attached. ServerSessionManager manager = cell.getCellCache().getSession().getSessionManager(); CollisionSystem collisionSystem = ClientContextJME.getCollisionSystem(manager, "Default"); // Create a new collision controller, and set on the avatar CollisionController controller = new CollisionController(collisionGraph, (JMECollisionSystem) collisionSystem); collisionChangeRequestListener.setCollisionController(controller); AvatarController ac = (AvatarController) avatar.getContext().getController(); ac.setCollisionController(controller); if (collisionListener == null) { collisionListener = new WLCollisionListener(); } ac.addCollisionListener(collisionListener); } else { AvatarController ac = (AvatarController) avatar.getContext().getController(); ac.setCollisionController(null); ac.removeCollisionListener(collisionListener); } }
public Enemy(String id, Renderer renderer) { super(id, null); URL model = getClass().getClassLoader().getResource("fokker.jme"); Spatial ship = null; try { ship = (Spatial) BinaryImporter.getInstance().load(model.openStream()); } catch (IOException e) { e.printStackTrace(); } ship.setLocalScale(.2f); TextureState ts = renderer.createTextureState(); ts.setEnabled(true); ts.setTexture( TextureManager.loadTexture( getClass().getClassLoader().getResource("fokker.jpg"), Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear)); ship.setRenderState(ts); ship.setNormalsMode(NormalsMode.AlwaysNormalize); ship.setModelBound(new BoundingBox()); ship.updateModelBound(); // ship.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Z)); setModel(ship); Vector3f[] points = new Vector3f[6]; points[0] = new Vector3f(110, 0, 110); points[1] = new Vector3f(110, 0, 50); points[2] = new Vector3f(-20, 0, 10); points[3] = new Vector3f(20, 0, -20); points[4] = new Vector3f(-90, 0, -90); points[5] = new Vector3f(0, 0, 110); endPoint = points[5]; CatmullRomCurve curve = new CatmullRomCurve("Curve", points); curve.setSteps(512); // ship.setLocalTranslation(points[0]); // curve.setCullHint(CullHint.Always); CurveController curveController = new CurveController(curve, ship); ship.addController(curveController); curveController.setRepeatType(Controller.RT_CLAMP); curveController.setSpeed(0.05f); curveController.setAutoRotation(true); curveController.setUpVector(new Vector3f(0, 0.5f, 0)); attachChild(curve); ExplosionFactory.warmup(); }