Package net.cis.client.game.common.model.co

Source Code of net.cis.client.game.common.model.co.ControlledPlayer

package net.cis.client.game.common.model.co;

import net.cis.client.game.common.ctrl.IGameApplication;
import net.cis.client.game.common.model.ShipState;
import net.cis.client.game.common.util.GlobalObjectStore;
import net.cis.common.model.spaceobject.SpaceObject;

import com.jme3.asset.AssetManager;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.light.PointLight;
import com.jme3.scene.Spatial;

public class ControlledPlayer extends AbstractControlledObject<SpaceObject, Spatial> {

  private RigidBodyControl rbc;

  public ControlledPlayer(SpaceObject dataObject) {
    super(dataObject);
  }

  @Override
  public void internalLoadSceneObject() {
    sceneObject = GlobalObjectStore.<AssetManager>getObject(AssetManager.class).loadModel("ship/glider/Hull.mesh.xml");
    sceneObject.addLight(new PointLight());
    sceneObject.setName("PlayerShip");

    // TODO: ship: Gr��e laden
    CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1f, 2f);
    rbc = new RigidBodyControl(capsuleShape, 1f);
    rbc.setSleepingThresholds(0.01f, 0.01f);

    rbc.setSpatial(getSceneObject());
    sceneObject.addControl(rbc);

    // TODO: ship: Masse laden
    rbc.setMass(1.0f);

    ShipState shipState = new ShipState();
    rbc.setUserObject(shipState);
  }

  public RigidBodyControl getRigidBodyControl() {
    return rbc;
  }

  @Override
  protected boolean internalAddToScene(IGameApplication simpleApp) {
    sceneNode.attachChild(sceneObject);
    BulletAppState bulletAppState = simpleApp.getStateManager().getState(BulletAppState.class);
    bulletAppState.getPhysicsSpace().add(rbc);
   
    return true;
  };

  @Override
  protected boolean internalRemoveFromScene(IGameApplication simpleApp) {
    BulletAppState bulletAppState = simpleApp.getStateManager().getState(BulletAppState.class);
    bulletAppState.getPhysicsSpace().remove(rbc);
   
    return sceneObject.removeFromParent();
  }

}
TOP

Related Classes of net.cis.client.game.common.model.co.ControlledPlayer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.