コード例 #1
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
  public void visible(boolean visible) {

    for (GameObject g : children) {
      g.visible(visible);
    }
    visibleNoChildren(visible);
  }
コード例 #2
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
  public void transform(Matrix4f mat, boolean updateLocal) {
    activate();

    Transform t = new Transform();
    t.set(mat);

    Vector3f v = new Vector3f();
    for (int i = 0; i < 3; ++i) {
      t.basis.getColumn(i, v);
      v.normalize();
      t.basis.setColumn(i, v);
    }

    body.setWorldTransform(t);

    // required for static objects:
    body.getMotionState().setWorldTransform(t);
    if (body.isInWorld() && body.isStaticOrKinematicObject()) {
      scene.world.updateSingleAabb(body);
      for (GameObject g : touchingObjects) g.activate();
    }
    //

    updateChildTransforms();

    if (parent != null && updateLocal) {
      updateLocalTransform();
    }
  }
コード例 #3
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 public void endNoChildren() {
   onEnd();
   parent(null);
   valid = false;
   if (uniqueModel != null) uniqueModel.dispose();
   scene.remove(this);
   for (GameObject g : touchingObjects) g.activate();
 }
コード例 #4
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 public ArrayListGameObject childrenRecursive() {
   ArrayListGameObject childList = new ArrayListGameObject();
   for (GameObject child : children) {
     childList.add(child);
     childList.addAll(child.childrenRecursive());
   }
   return childList;
 }
コード例 #5
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 private void updateLocalTransform() {
   localTransform = parent.transform();
   Matrix4f ms = new Matrix4f();
   ms.setIdentity();
   Vector3f ps = parent.scale();
   ms.m00 = ps.x;
   ms.m11 = ps.y;
   ms.m22 = ps.z;
   localTransform.mul(ms);
   localTransform.invert();
   localTransform.mul(transform());
 }
コード例 #6
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
  public void updateChildTransforms() {
    Matrix4f pt = transform();
    Matrix4f ct = new Matrix4f();
    Matrix4f ms = new Matrix4f();
    ms.setIdentity();
    Vector3f ps = scale();
    ms.m00 = ps.x;
    ms.m11 = ps.y;
    ms.m22 = ps.z;
    pt.mul(ms);

    for (GameObject c : children) {
      ct.mul(pt, c.localTransform);
      c.transform(ct, false);
    }
  }
コード例 #7
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
  public void parent(GameObject p, boolean compound) {
    CompoundShape compShapeOld = null;

    if (parent != null) {
      parent.children.remove(this);

      if (compound) {
        compShapeOld = parent.compoundShape();
        if (compShapeOld != null) {
          scene.world.removeRigidBody(parent.body);
          compShapeOld.removeChildShape(body.getCollisionShape());
          scene.world.addRigidBody(parent.body);
        }
      }

    } else if (p == null) {
      return;
    }

    parent = p;

    if (parent != null) {

      parent.children.add(this);

      updateLocalTransform();
      updateLocalScale();

      if (compound) {
        CompoundShape compShape = parent.compoundShape();
        if (compShape != null) {
          scene.world.removeRigidBody(body);
          compShape.addChildShape(new Transform(localTransform), body.getCollisionShape());
        }
      } else {
        dynamics(false);
      }

    } else if (currBodyType.equals("STATIC") || currBodyType.equals("SENSOR")) {
      if (compound && compShapeOld != null) scene.world.addRigidBody(body);

    } else {
      dynamics(true);
    }
  }
コード例 #8
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
  public void scale(float x, float y, float z, boolean updateLocal) {
    activate();
    // Set unit scale
    Matrix4 t = modelInstance.transform;
    Matrix4 mat_scale = new Matrix4();
    Vector3 s = new Vector3();
    t.getScale(s);
    mat_scale.scl(1 / s.x, 1 / s.y, 1 / s.z);
    t.mul(mat_scale);

    // Set target scale
    mat_scale.idt();
    mat_scale.scl(x, y, z);
    t.mul(mat_scale);

    // Relevant bullet body update
    CollisionShape cs = body.getCollisionShape();
    cs.setLocalScaling(new Vector3f(x, y, z));
    if (body.isInWorld() && body.isStaticOrKinematicObject()) scene.world.updateSingleAabb(body);

    // Child propagation
    Vector3f ps = scale();
    Matrix4f pt = transform();
    Matrix4f ct = new Matrix4f();
    Matrix4f ms = new Matrix4f();
    ms.setIdentity();
    ms.m00 = ps.x;
    ms.m11 = ps.y;
    ms.m22 = ps.z;
    pt.mul(ms);

    for (GameObject c : children) {
      c.scale(scale().mul(c.localScale), false);
      ct.mul(pt, c.localTransform);
      c.transform(ct, false);
    }

    if (parent != null && updateLocal) {
      updateLocalScale();
    }
  }
コード例 #9
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 public void bodyType(String s) {
   int flags = body.getCollisionFlags();
   if (body.isInWorld()) scene.world.removeRigidBody(body);
   if (s.equals("NO_COLLISION")) {
     for (GameObject g : touchingObjects) g.activate();
     flags &= ~CollisionFlags.KINEMATIC_OBJECT;
   } else {
     if (s.equals("STATIC")) {
       flags |= CollisionFlags.KINEMATIC_OBJECT;
     } else if (s.equals("SENSOR")) {
       flags |= CollisionFlags.KINEMATIC_OBJECT;
       flags |= CollisionFlags.NO_CONTACT_RESPONSE;
     } else {
       // NO_COLLISION -> DYNAMIC or RIGID_BODY hack
       if (currBodyType.equals("NO_COLLISION")) {
         body.clearForces();
         body.setLinearVelocity(new Vector3f());
       }
       // kinematic initialization hack
       if (mass() == Float.POSITIVE_INFINITY) {
         mass(1); // Blender default
         flags &= ~CollisionFlags.KINEMATIC_OBJECT;
         body.setCollisionFlags(flags);
       }
       flags &= ~CollisionFlags.KINEMATIC_OBJECT;
       if (s.equals("DYNAMIC")) {
         body.setAngularVelocity(new Vector3f());
         body.setAngularFactor(0);
       } else if (s.equals("RIGID_BODY")) {
         body.setAngularFactor(1);
       } else {
         throw new RuntimeException(s + " is no valid bodyType name.");
       }
     }
     scene.world.addRigidBody(body);
     activate();
   }
   body.setCollisionFlags(flags);
   currBodyType = s;
 }
コード例 #10
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 public void color(float r, float g, float b, float a) {
   colorNoChildren(r, g, b, a);
   for (GameObject child : children) child.color(r, g, b, a);
 }
コード例 #11
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 private void updateLocalScale() {
   localScale = scale().div(parent.scale());
 }
コード例 #12
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 public void end() {
   for (GameObject g : new ArrayList<GameObject>(children)) {
     g.end();
   }
   endNoChildren();
 }
コード例 #13
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 public void ghost(boolean ghost) {
   for (GameObject g : children) {
     g.ghost(ghost);
   }
   ghostNoChildren(ghost);
 }
コード例 #14
0
ファイル: GameObject.java プロジェクト: msoftware/bdx
 public boolean hit(String name) {
   for (GameObject g : touchingObjects) {
     if (g.name().equals(name) && !touchingObjectsLast.contains(g)) return true;
   }
   return false;
 }
コード例 #15
0
ファイル: Bdx.java プロジェクト: colepram/bdx
  public static void main() {
    profiler.start("__graphics");
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    profiler.stop("__graphics");

    // -------- Update Input --------
    time += TICK_TIME;
    ++GdxProcessor.currentTick;
    fingers.clear();
    for (Finger f : allocatedFingers) {
      if (f.down() || f.up()) fingers.add(f);
    }
    // ------------------------------

    for (Component c : components) {
      if (c.state != null) c.state.main();
    }

    profiler.stop("__input");

    for (Scene scene : (ArrayListScenes) scenes.clone()) {
      scene.update();

      profiler.start("__render");

      // ------- Render Scene --------

      if (scene.filters.size() > 0) {
        frameBuffer.begin();
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      }

      Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
      modelBatch.begin(scene.camera.data);
      for (GameObject g : scene.objects) {
        if (g.visible() && g.insideFrustum()) {
          modelBatch.render(g.modelInstance, scene.environment);
        }
      }
      modelBatch.end();

      if (scene.filters.size() > 0) {

        frameBuffer.end();

        scene.lastFrameBuffer.getColorBufferTexture().bind(1);
        Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);

        for (ShaderProgram filter : scene.filters) {

          filter.begin();
          filter.setUniformf("time", Bdx.time);
          filter.setUniformi("lastFrame", 1);
          filter.setUniformf("screenWidth", Bdx.display.size().x);
          filter.setUniformf("screenHeight", Bdx.display.size().y);
          filter.end();

          tempBuffer.clear();

          int width = (int) (Gdx.graphics.getWidth() * filter.renderScale.x);
          int height = (int) (Gdx.graphics.getHeight() * filter.renderScale.y);

          if (tempBuffer.getWidth() != width || tempBuffer.getHeight() != height)
            tempBuffer = new RenderBuffer(spriteBatch, width, height);

          frameBuffer.drawTo(tempBuffer, filter);

          if (!filter.overlay) frameBuffer.clear();

          tempBuffer.drawTo(frameBuffer);
        }

        frameBuffer.drawTo(null); //  Draw to screen
        scene.lastFrameBuffer.clear();
        frameBuffer.drawTo(scene.lastFrameBuffer);
      }

      // ------- Render physics debug view --------

      Bullet.DebugDrawer debugDrawer = (Bullet.DebugDrawer) scene.world.getDebugDrawer();
      debugDrawer.drawWorld(scene.world, scene.camera.data);

      profiler.stop("__render");
    }
    mouse.wheelMove = 0;

    profiler.updateVariables();
    if (profiler.visible()) {
      profiler.updateVisible();

      // ------- Render profiler scene --------

      Scene profilerScene = profiler.scene;
      profilerScene.update();
      Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);
      modelBatch.begin(profilerScene.camera.data);
      for (GameObject g : profilerScene.objects) {
        if (g.visible()) {
          modelBatch.render(g.modelInstance, profilerScene.environment);
        }
      }
      modelBatch.end();
    }
    if (profiler.gl.isEnabled()) {
      profiler.gl.updateFields();
    }
  }