Esempio n. 1
0
    @Override
    public void onTouchEvent(MotionEvent e) {
      float x = e.getX();
      float y = e.getY();
      switch (e.getAction()) {
        case MotionEvent.ACTION_UP:
          x = x * .001f;
          y = y * .001f;
          for (int i = 0; i < _scene.numChildren(); i++) {
            Object3d obj = _scene.getChildAt(i);

            if (obj == _up || obj == _down || obj == _east || obj == _west) continue;

            // TODO: make pressure equal to distance from touch

            obj.velocity().z = -(e.getPressure() * 100);
            obj.velocity().z = -(e.getPressure() * 100);
          }
          break;
        case MotionEvent.ACTION_MOVE:
          float dx = x - mPreviousX;
          float dy = y - mPreviousY;
          for (int i = 0; i < _scene.numChildren(); i++) {
            Object3d obj = _scene.getChildAt(i);

            if (obj == _up || obj == _down || obj == _east || obj == _west) continue;

            obj.rotation().x += dx * Object3d.TOUCH_SCALE_FACTOR;
            obj.rotation().y += dy * Object3d.TOUCH_SCALE_FACTOR;
          }
          break;
      }
      mPreviousX = x;
      mPreviousY = y;
    }
Esempio n. 2
0
    // Handles all ball-ball collisions
    void handleBallBallCollisions() {

      for (int i = 0; i < _scene.numChildren(); i++)
        for (int j = 0; j < _scene.numChildren(); j++) {

          if (i == j) continue;

          Object3d b1 = _scene.getChildAt(i);
          Object3d b2 = _scene.getChildAt(j);

          // if (b1 == _room || b2 == _room)
          // continue;

          if (testBallBallCollision(b1, b2)) {
            // Make the balls reflect off of each other

            Number3d displacement = Number3d.subtract(b1.position(), b2.position());
            displacement.normalize();
            float objDot = Number3d.dot(b1.velocity(), displacement);
            displacement.multiply(objDot);
            displacement.multiply(2f);
            b1.velocity().subtract(displacement);

            displacement = Number3d.subtract(b1.position(), b2.position());
            displacement.normalize();
            objDot = Number3d.dot(b2.velocity(), displacement);
            displacement.multiply(objDot);
            displacement.multiply(2f);
            b2.velocity().subtract(displacement);
          }
        }
    }
Esempio n. 3
0
    public void onDrawFrame(GL10 gl) {

      double time = System.currentTimeMillis();
      double elapsed = time - _lastDraw;
      _lastDraw = time;

      if (elapsed > 1000) elapsed = 60;

      elapsed = elapsed / 1000;

      float pitch = _sensor.getPitch();
      float roll = _sensor.getRoll();

      for (int i = 0; i < _scene.numChildren(); i++) {
        Object3d obj = _scene.getChildAt(i);
        if (obj != _down && obj != _up && obj != _east && obj != _west) {
          updateObject(obj, elapsed, _sensor.getAccelerometer(), roll, pitch);
        }
      }

      _renderer.onDrawFrame(gl);
    }