コード例 #1
0
ファイル: TestQ3.java プロジェクト: filinep/castlegame
 @Override
 public void simpleUpdate(float tpf) {
   Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);
   Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
   walkDirection.set(0, 0, 0);
   if (left) walkDirection.addLocal(camLeft);
   if (right) walkDirection.addLocal(camLeft.negate());
   if (up) walkDirection.addLocal(camDir);
   if (down) walkDirection.addLocal(camDir.negate());
   player.setWalkDirection(walkDirection);
   cam.setLocation(player.getPhysicsLocation());
 }
コード例 #2
0
  public void onAnalog(String name, float value, float tpf) {
    if ((Boolean) player.getUserData("alive")) {
      if (name.equals("mousePick")) {
        // shoot Bullet
        if (System.currentTimeMillis() - bulletCooldown > 83f) {
          bulletCooldown = System.currentTimeMillis();

          Vector3f aim = getAimDirection();
          Vector3f offset = new Vector3f(aim.y / 3, -aim.x / 3, 0);

          //                    init bullet 1
          Spatial bullet = getSpatial("Bullet");
          Vector3f finalOffset = aim.add(offset).mult(30);
          Vector3f trans = player.getLocalTranslation().add(finalOffset);
          bullet.setLocalTranslation(trans);
          bullet.addControl(
              new BulletControl(
                  aim, settings.getWidth(), settings.getHeight(), particleManager, grid));
          bulletNode.attachChild(bullet);

          //                    init bullet 2
          Spatial bullet2 = getSpatial("Bullet");
          finalOffset = aim.add(offset.negate()).mult(30);
          trans = player.getLocalTranslation().add(finalOffset);
          bullet2.setLocalTranslation(trans);
          bullet2.addControl(
              new BulletControl(
                  aim, settings.getWidth(), settings.getHeight(), particleManager, grid));
          bulletNode.attachChild(bullet2);

          sound.shoot();
        }
      }
    }
  }
コード例 #3
0
ファイル: AvatarControl.java プロジェクト: psyras/game-system
 @Override
 public void update(final float tpf) {
   super.update(tpf);
   final Vector3f modelForwardDir = spatial.getWorldRotation().mult(Vector3f.UNIT_Z);
   final Vector3f modelLeftDir = spatial.getWorldRotation().mult(Vector3f.UNIT_X);
   walkDirection.set(0, 0, 0);
   if (forward) {
     walkDirection.addLocal(modelForwardDir.mult(avatar.forwardSpeed(running)));
   } else if (backward) {
     walkDirection.addLocal(modelForwardDir.negate().mult(avatar.backwardSpeed(running)));
   }
   if (leftStrafe) {
     walkDirection.addLocal(modelLeftDir.mult(avatar.sideSpeed(running)));
   } else if (rightStrafe) {
     walkDirection.addLocal(modelLeftDir.negate().mult(avatar.sideSpeed(running)));
   }
   this.avatar.setLocation(convertVectorToArray(spatial.getLocalTranslation()));
 }
コード例 #4
0
 protected void computeRandomSpawnPoint(Flight flight) {
   Vector3f position =
       new Vector3f(
           randomSpawnGenerator.nextInt(7000) - 3500,
           randomSpawnGenerator.nextInt(7000) - 3500,
           randomSpawnGenerator.nextInt(7000) - 3500);
   Quaternion rotation = new Quaternion();
   rotation.lookAt(position.negate(), Vector3f.UNIT_Z);
   flight.setSpawn(new Spawn(position, rotation));
 }
コード例 #5
0
  @Override
  public void simpleUpdate(final float tpf) {
    Vector3f camDir = this.cam.getCamera().getDirection().clone().multLocal(0.6f);
    Vector3f camLeft = this.cam.getCamera().getLeft().clone().multLocal(0.4f);
    this.walkDirection.set(0, 0, 0);
    if (this.left) {
      this.walkDirection.addLocal(camLeft);
    }
    if (this.right) {
      this.walkDirection.addLocal(camLeft.negate());
    }
    if (this.up) {
      this.walkDirection.addLocal(camDir);
    }
    if (this.down) {
      this.walkDirection.addLocal(camDir.negate());
    }

    if (usePhysics) {
      this.player3.setWalkDirection(this.walkDirection);
      this.cam.updateLocation(this.player3.getPhysicsLocation());
    }
  }
コード例 #6
0
ファイル: TestPhysics.java プロジェクト: ChristiaanV/Cubes
 @Override
 public void simpleUpdate(float lastTimePerFrame) {
   float playerMoveSpeed = ((cubesSettings.getBlockSize() * 6.5f) * lastTimePerFrame);
   Vector3f camDir = cam.getDirection().mult(playerMoveSpeed);
   Vector3f camLeft = cam.getLeft().mult(playerMoveSpeed);
   walkDirection.set(0, 0, 0);
   if (arrowKeys[0]) {
     walkDirection.addLocal(camDir);
   }
   if (arrowKeys[1]) {
     walkDirection.addLocal(camLeft.negate());
   }
   if (arrowKeys[2]) {
     walkDirection.addLocal(camDir.negate());
   }
   if (arrowKeys[3]) {
     walkDirection.addLocal(camLeft);
   }
   walkDirection.setY(0);
   walkDirection.normalize();
   walkDirection.multLocal(lastTimePerFrame * 10);
   playerControl.setWalkDirection(walkDirection);
   cam.setLocation(playerControl.getPhysicsLocation());
 }
コード例 #7
0
ファイル: FloatToFixed.java プロジェクト: jingchan/jh_rogue
  private static Transform convertPositions(FloatBuffer input, BoundingBox bbox, Buffer output) {
    if (output.capacity() < input.capacity())
      throw new RuntimeException("Output must be at least as large as input!");

    Vector3f offset = bbox.getCenter().negate();
    Vector3f size = new Vector3f(bbox.getXExtent(), bbox.getYExtent(), bbox.getZExtent());
    size.multLocal(2);

    ShortBuffer sb = null;
    ByteBuffer bb = null;
    float dataTypeSize;
    float dataTypeOffset;
    if (output instanceof ShortBuffer) {
      sb = (ShortBuffer) output;
      dataTypeOffset = shortOff;
      dataTypeSize = shortSize;
    } else {
      bb = (ByteBuffer) output;
      dataTypeOffset = byteOff;
      dataTypeSize = byteSize;
    }
    Vector3f scale = new Vector3f();
    scale.set(dataTypeSize, dataTypeSize, dataTypeSize).divideLocal(size);

    Vector3f invScale = new Vector3f();
    invScale.set(size).divideLocal(dataTypeSize);

    offset.multLocal(scale);
    offset.addLocal(dataTypeOffset, dataTypeOffset, dataTypeOffset);

    // offset = (-modelOffset * shortSize)/modelSize + shortOff
    // scale = shortSize / modelSize

    input.clear();
    output.clear();
    Vector3f temp = new Vector3f();
    int vertexCount = input.capacity() / 3;
    for (int i = 0; i < vertexCount; i++) {
      BufferUtils.populateFromBuffer(temp, input, i);

      // offset and scale vector into -32768 ... 32767
      // or into -128 ... 127 if using bytes
      temp.multLocal(scale);
      temp.addLocal(offset);

      // quantize and store
      if (sb != null) {
        short v1 = (short) temp.getX();
        short v2 = (short) temp.getY();
        short v3 = (short) temp.getZ();
        sb.put(v1).put(v2).put(v3);
      } else {
        byte v1 = (byte) temp.getX();
        byte v2 = (byte) temp.getY();
        byte v3 = (byte) temp.getZ();
        bb.put(v1).put(v2).put(v3);
      }
    }

    Transform transform = new Transform();
    transform.setTranslation(offset.negate().multLocal(invScale));
    transform.setScale(invScale);
    return transform;
  }