示例#1
0
 void addStaticServerElement(ServerElement elem) {
   RigidBody rb =
       createBody(
           0f, elem.getPosition(), getCollisionShape(elem.getSize()), 0f, elem.getOriantation());
   staticBodies.add(rb);
   // staticServerElements.add(elem);
   elementToRigidBody.put(elem, rb);
   rigidBodyToServerElement.put(rb, elem);
   dynamicsWorld.addRigidBody(rb);
 }
示例#2
0
  void updateServerElements() {
    for (RigidBody rb : rigidBodies) {
      ServerElement element = rigidBodyToServerElement.get(rb);
      if (rb != null && rb.getMotionState() != null) {
        rb.getMotionState().getWorldTransform(tmpTrans);
        element.setTransform(tmpTrans);
      }
      if (!rb.isActive()) {
        rb.activate();
      }
      // log.debug(" "+element.getPosition());
    }

    for (Integer id : serverGameArea.getGameState().getDynamicElements().keySet()) {
      ServerElement elem = serverGameArea.getGameState().getDynamicElements().get(id);
      elem.getCollidees().clear();
    }

    Integer nbManifold = dynamicsWorld.getDispatcher().getNumManifolds();
    for (Integer i = 0; i < nbManifold; i++) {
      PersistentManifold pm = dynamicsWorld.getDispatcher().getManifoldByIndexInternal(i);
      RigidBody rb0 = (RigidBody) pm.getBody0();
      RigidBody rb1 = (RigidBody) pm.getBody1();

      ServerElement elem0 = rigidBodyToServerElement.get(rb0);
      ServerElement elem1 = rigidBodyToServerElement.get(rb1);

      if ((elem0 instanceof ServerBullet) || (elem1 instanceof ServerBullet)) {
        log.info("coll " + elem0 + " " + elem1);
      }

      elem0.addCollidee(elem1);
      elem1.addCollidee(elem0);
    }
  }
示例#3
0
  private void updateRigidBodys() {
    for (RigidBody rb : rigidBodies) {
      ServerElement element = rigidBodyToServerElement.get(rb);
      if (rb != null && rb.getMotionState() != null) {
        if (element.isUpdatedByUser()) {

          /*rb.getMotionState().getWorldTransform(tmpTrans);
          tmpTrans.origin.x=element.getTransform().origin.x;
          tmpTrans.origin.y=element.getTransform().origin.y;
          tmpTrans.origin.z=element.getTransform().origin.z;
          */
          rb.getMotionState().setWorldTransform(element.getTransform());
          rb.setMotionState(rb.getMotionState());
          element.resetUpdatedByUser();
        }
      }
    }
  }
示例#4
0
  public void addDynamicServerElement(ServerElement elem, Float initialVelocity) {
    RigidBody rb =
        createBody(
            elem.getMass(),
            elem.getPosition(),
            getCollisionShape(elem.getSize()),
            initialVelocity,
            elem.getOriantation());
    dynamicsWorld.addRigidBody(rb);

    rigidBodyToServerElement.put(rb, elem);
    elementToRigidBody.put(elem, rb);
    rigidBodies.add(rb);
    // dynamicServerElements.put(elem.getId(),elem);
    if (elem instanceof ServerPlayer) {
      ServerPlayer p = (ServerPlayer) elem;
      players.add(p);
      rb.setAngularFactor(0.3f);
    }

    if (elem instanceof ServerBullet) {
      rb.setGravity(new Vector3f(0, -0.2f, 0));
    }
  }