Example #1
0
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, 500, 500);
    g2d.setColor(Color.red);
    g2d.drawString(Double.toString(fpsCounter.fps()), 50, 50);
    // g2d.fillRect(0, 0, 50, 50);

    Rectangle2D.Double testRect = new Rectangle2D.Double(200, 170, 100, 100);
    Ellipse2D.Double testEllipse = new Ellipse2D.Double(200, 0, 50, 50);

    Shape testShape = testRect;
    // g2d.fill(testShape);
    switch (testShape.getClass().getCanonicalName()) {
      case "java.awt.geom.Rectangle2D.Double":
        Rectangle2D.Double newRect = (Rectangle2D.Double) testShape;

        g2d.fill(newRect);
        // System.out.println(testShape.getBounds().x + testShape.getBounds().y);
        break;
      case "java.awt.geom.Ellipse2D.Double":
        Ellipse2D.Double newEllipse = (Ellipse2D.Double) testShape;
        g2d.fill(newEllipse);
        break;
    }

    // System.out.println(testShape.getClass().getCanonicalName());

  }
Example #2
0
  @Override
  public void run() {
    while (true) {
      repaint();
      fpsCounter.interrupt();
      try {

        geoLoop.sleep(1);
      } catch (InterruptedException e) {
      }
    }
  }
Example #3
0
 public Board() {
   geoLoop = new Thread(this);
   fpsCounter = new FPSCounter();
   fpsCounter.start();
 }
Example #4
0
 public void render() {
   fps.frame();
   space.render(this);
   fps.endFrame();
 }
Example #5
0
 public void update(float delta) {
   fps.update();
   space.step(delta);
   fps.endUpdate();
 }
Example #6
0
  @Override
  public void onStep() {
    FPSCounter.tick();

    boolean isButtonDown = mIsButtonDown;
    boolean isSingleTapped = mIsSingleTapped;
    mIsButtonDown = false;
    mIsSingleTapped = false;

    if (isButtonDown) mGVRContext.getMainScene().getMainCameraRig().resetYaw();

    // ---------------------------------------thumbnail motion
    boolean MoveActive = false;
    if (Math.abs(
            ThumbnailTargetPosition[ThumbnailTargetIndex[0]][0] - ThumbnailCurrentPosition[0][0])
        < 0.2f) MoveActive = true;

    if (SelectionActive && MoveActive) {
      if (ThumbnailCurrentPosition[ThumbnailSelected][0] < -0.5f) {
        for (int i = 0; i < THUMBNAIL_NUM; i++) {
          ThumbnailTargetIndex[i]++;
          if (ThumbnailTargetIndex[i] >= THUMBNAIL_NUM)
            ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] - THUMBNAIL_NUM;
          if (ThumbnailTargetIndex[i] < 0)
            ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] + THUMBNAIL_NUM;
        }
      } else if (ThumbnailCurrentPosition[ThumbnailSelected][0] > 0.5f) {
        for (int i = 0; i < THUMBNAIL_NUM; i++) {
          ThumbnailTargetIndex[i]--;
          if (ThumbnailTargetIndex[i] >= THUMBNAIL_NUM)
            ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] - THUMBNAIL_NUM;
          if (ThumbnailTargetIndex[i] < 0)
            ThumbnailTargetIndex[i] = ThumbnailTargetIndex[i] + THUMBNAIL_NUM;
        }
      }
    }

    for (int i = 0; i < THUMBNAIL_NUM; i++) {
      float speed = 0.08f;
      for (int j = 0; j < 3; j++)
        ThumbnailCurrentPosition[i][j] +=
            speed
                * (ThumbnailTargetPosition[ThumbnailTargetIndex[i]][j]
                    - ThumbnailCurrentPosition[i][j]);
      ThumbnailObject[i]
          .getTransform()
          .setPosition(
              ThumbnailCurrentPosition[i][0],
              ThumbnailCurrentPosition[i][1],
              ThumbnailCurrentPosition[i][2]);
    }

    // if(
    // Math.abs(ThumbnailTargetPosition[ThumbnailTargetIndex[0]][0]-ThumbnailCurrentPosition[0][0])
    // > 0.02f )
    // {
    // if( THUMBNAIL_ROT > 180.0f )
    // THUMBNAIL_ROT += 0.05f*( 360.0f - THUMBNAIL_ROT );
    // else
    // THUMBNAIL_ROT += 0.05f*( 0.0f - THUMBNAIL_ROT );
    // }
    // else
    // {
    // THUMBNAIL_ROT += -1.0f;
    // if( THUMBNAIL_ROT > 360.0f ) THUMBNAIL_ROT = THUMBNAIL_ROT - 360.0f;
    // }
    THUMBNAIL_ROT = -1.0f;
    for (int i = 0; i < THUMBNAIL_NUM; i++)
      ThumbnailRotation[i].getTransform().rotateByAxis(THUMBNAIL_ROT, 0.0f, 1.0f, 0.0f);

    // ---------------------------------------object motion

    OBJECT_ROT = -1.0f;
    for (int i = 0; i < THUMBNAIL_NUM; i++)
      Objects[i].getTransform().rotateByAxis(OBJECT_ROT, 0.0f, 1.0f, 0.0f);

    float[] light = new float[4];
    light[0] = 6.0f;
    light[1] = 10.0f;
    light[2] = 10.0f;
    light[3] = 1.0f;

    float[] eye = new float[4];
    eye[0] = 0.0f;
    eye[1] = 0.0f;
    eye[2] = 3.0f * EYE_TO_OBJECT;
    eye[3] = 1.0f;

    float[] matT = ThumbnailRotation[0].getTransform().getModelMatrix();
    float[] matO = Objects[ThumbnailSelected].getTransform().getModelMatrix();

    // ---------------------------- watch, jar

    float x = matO[0] * light[0] + matO[1] * light[1] + matO[2] * light[2] + matO[3] * light[3];
    float y = matO[4] * light[0] + matO[5] * light[1] + matO[6] * light[2] + matO[7] * light[3];
    float z = matO[8] * light[0] + matO[9] * light[1] + matO[10] * light[2] + matO[11] * light[3];

    float mag = (float) Math.sqrt(x * x + y * y + z * z);

    mMetalMaterial.setVec3(MetalOnlyShader.LIGHT_KEY, x / mag, y / mag, z / mag);
    mDiffuseMaterial.setVec3(DiffuseShader.LIGHT_KEY, x / mag, y / mag, z / mag);
    mGlassMaterial.setVec3(GlassShader.LIGHT_KEY, x / mag, y / mag, z / mag);
    mPhongMaterial.setVec3(PhongShader.LIGHT_KEY, x / mag, y / mag, z / mag);

    x = matO[0] * eye[0] + matO[1] * eye[1] + matO[2] * eye[2] + matO[3] * eye[3];
    y = matO[4] * eye[0] + matO[5] * eye[1] + matO[6] * eye[2] + matO[7] * eye[3];
    z = matO[8] * eye[0] + matO[9] * eye[1] + matO[10] * eye[2] + matO[11] * eye[3];

    mag = (float) Math.sqrt(x * x + y * y + z * z);

    mMetalMaterial.setVec3(MetalOnlyShader.EYE_KEY, x / mag, y / mag, z / mag);
    mDiffuseMaterial.setVec3(DiffuseShader.EYE_KEY, x / mag, y / mag, z / mag);
    mGlassMaterial.setVec3(GlassShader.EYE_KEY, x / mag, y / mag, z / mag);
    mPhongMaterial.setVec3(PhongShader.EYE_KEY, x / mag, y / mag, z / mag);

    // ---------------------------- robot

    mRobotHeadMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mRobotHeadMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mRobotHeadMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mRobotHeadMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mRobotHeadMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]);
    mRobotHeadMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]);

    mRobotMetalMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mRobotMetalMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mRobotMetalMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mRobotMetalMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mRobotMetalMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mRobotMetalMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mRobotBodyMaterial.setVec4(PhongShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mRobotBodyMaterial.setVec4(PhongShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mRobotBodyMaterial.setVec4(PhongShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mRobotBodyMaterial.setVec4(PhongShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mRobotBodyMaterial.setVec3(PhongShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mRobotBodyMaterial.setVec3(PhongShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mRobotRubberMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mRobotRubberMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mRobotRubberMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mRobotRubberMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mRobotRubberMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mRobotRubberMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    // ---------------------------- leaf

    mLeafBodyMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mLeafBodyMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mLeafBodyMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mLeafBodyMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mLeafBodyMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mLeafBodyMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mLeafBoxMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mLeafBoxMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mLeafBoxMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mLeafBoxMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mLeafBoxMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]);
    mLeafBoxMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]);

    // ---------------------------- car
    eye[0] = 4.0f;
    eye[1] = 0.0f;
    eye[2] = 3.0f * EYE_TO_OBJECT;
    eye[3] = 1.0f;

    mCarBodyMaterial.setVec4(PhongShader3.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mCarBodyMaterial.setVec4(PhongShader3.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mCarBodyMaterial.setVec4(PhongShader3.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mCarBodyMaterial.setVec4(PhongShader3.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mCarBodyMaterial.setVec3(PhongShader3.LIGHT_KEY, light[0], light[1], light[2]);
    mCarBodyMaterial.setVec3(PhongShader3.EYE_KEY, eye[0], eye[1], eye[2]);

    mCarTireMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mCarTireMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mCarTireMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mCarTireMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mCarTireMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mCarTireMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mCarGlassMaterial.setVec4(GlassShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mCarGlassMaterial.setVec4(GlassShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mCarGlassMaterial.setVec4(GlassShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mCarGlassMaterial.setVec4(GlassShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mCarGlassMaterial.setVec3(GlassShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mCarGlassMaterial.setVec3(GlassShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mCarWheelMaterial.setVec4(MetalShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mCarWheelMaterial.setVec4(MetalShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mCarWheelMaterial.setVec4(MetalShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mCarWheelMaterial.setVec4(MetalShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mCarWheelMaterial.setVec3(MetalShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mCarWheelMaterial.setVec3(MetalShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mCarBackMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mCarBackMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mCarBackMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mCarBackMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mCarBackMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mCarBackMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mCarGrillMaterial.setVec4(DiffuseShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mCarGrillMaterial.setVec4(DiffuseShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mCarGrillMaterial.setVec4(DiffuseShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mCarGrillMaterial.setVec4(DiffuseShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mCarGrillMaterial.setVec3(DiffuseShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mCarGrillMaterial.setVec3(DiffuseShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mCarLightMaterial.setVec4(GlassShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mCarLightMaterial.setVec4(GlassShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mCarLightMaterial.setVec4(GlassShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mCarLightMaterial.setVec4(GlassShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mCarLightMaterial.setVec3(GlassShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mCarLightMaterial.setVec3(GlassShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    mCarInsideMaterial.setVec4(PhongShader2.MAT1_KEY, matO[0], matO[4], matO[8], matO[12]);
    mCarInsideMaterial.setVec4(PhongShader2.MAT2_KEY, matO[1], matO[5], matO[9], matO[13]);
    mCarInsideMaterial.setVec4(PhongShader2.MAT3_KEY, matO[2], matO[6], matO[10], matO[14]);
    mCarInsideMaterial.setVec4(PhongShader2.MAT4_KEY, matO[3], matO[7], matO[11], matO[15]);
    mCarInsideMaterial.setVec3(PhongShader2.LIGHT_KEY, light[0], light[1], light[2]);
    mCarInsideMaterial.setVec3(PhongShader2.EYE_KEY, eye[0], eye[1], eye[2]);

    // ---------------------------- thumbnail glasses

    eye[0] = 0.0f;
    eye[1] = 0.0f;
    eye[2] = EYE_TO_OBJECT;
    eye[3] = 1.0f;

    mReflectionMaterial.setVec4(ReflectionShader.MAT1_KEY, matT[0], matT[4], matT[8], matT[12]);
    mReflectionMaterial.setVec4(ReflectionShader.MAT2_KEY, matT[1], matT[5], matT[9], matT[13]);
    mReflectionMaterial.setVec4(ReflectionShader.MAT3_KEY, matT[2], matT[6], matT[10], matT[14]);
    mReflectionMaterial.setVec4(ReflectionShader.MAT4_KEY, matT[3], matT[7], matT[11], matT[15]);
    mReflectionMaterial.setVec3(ReflectionShader.LIGHT_KEY, light[0], light[1], light[2]);
    mReflectionMaterial.setVec3(ReflectionShader.EYE_KEY, eye[0], eye[1], eye[2]);

    GVREyePointeeHolder pickedHolders[] = GVRPicker.pickScene(mGVRContext.getMainScene());
    if (SelectionMode && pickedHolders.length > 0) {
      GVRSceneObject pickedObject = pickedHolders[0].getOwnerObject();
      for (int i = 0; i < THUMBNAIL_NUM; ++i)
        if (ThumbnailObject[i].equals(pickedObject)) {
          ThumbnailSelected = i;
          break;
        }
      SelectionActive = true;
    } else SelectionActive = false;

    if (isSingleTapped) {
      SelectionMode = !SelectionMode;
      if (SelectionMode) {
        for (int i = 0; i < THUMBNAIL_NUM; ++i) {
          ThumbnailGlasses[i].setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right);
          Thumbnails[i]
              .getRenderData()
              .setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right);
        }
        for (int I = 0; I < THUMBNAIL_NUM; I++)
          for (int i = 0; i < Objects[I].getChildrenCount(); i++)
            Objects[I].getChildByIndex(i).getRenderData().setRenderMask(0);
      } else {
        for (int i = 0; i < THUMBNAIL_NUM; ++i) {
          ThumbnailGlasses[i].setRenderMask(0);
          Thumbnails[i].getRenderData().setRenderMask(0);
        }
        for (int I = 0; I < THUMBNAIL_NUM; I++)
          for (int i = 0; i < Objects[I].getChildrenCount(); i++)
            Objects[I].getChildByIndex(i).getRenderData().setRenderMask(0);
        for (int i = 0; i < Objects[ThumbnailSelected].getChildrenCount(); i++)
          Objects[ThumbnailSelected]
              .getChildByIndex(i)
              .getRenderData()
              .setRenderMask(GVRRenderMaskBit.Left | GVRRenderMaskBit.Right);
      }
    }
  }
Example #7
0
  protected void render() {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

    glLoadIdentity();

    camera.look();

    // Each frame we calculate the new frustum.  In reality you only need to
    // calculate the frustum when we move the camera.
    GameCore.gFrustum.calculateFrustum();

    // Initialize the total node count that is being draw per frame
    Octree.totalNodesDrawn = 0;

    glPushMatrix();
    // Here we draw the octree, starting with the root node and recursing down each node.
    // This time, we pass in the root node and just the original world model.  You could
    // just store the world in the root node and not have to keep the original data around.
    // This is up to you.  I like this way better because it's easy, though it could be
    // more error prone.
    octree.drawOctree(octree, g_World);
    glPopMatrix();

    // Render the cubed nodes to visualize the octree (in wire frame mode)
    if (g_bDisplayNodes) Octree.debug.drawBoundingBox();

    glPushMatrix();
    // If there was a collision, make the Orange ball Red.
    if (octree.isObjectColliding()) {
      glColor3f(1.0f, 0.0f, 0.0f);
    } else {
      glColor3f(1.0f, 0.5f, 0.0f); // Disable Lighting.
    }
    // Move the Ball into place.
    glTranslatef(g_BallEntity.x, g_BallEntity.y, g_BallEntity.z);

    glDisable(GL_LIGHTING);
    // Draw the Ground Intersection Line.
    glBegin(GL_LINES);
    glColor3f(1, 1, 1);
    glVertex3f(g_vGroundISector[0].x, g_vGroundISector[0].y, g_vGroundISector[0].z);
    glVertex3f(g_vGroundISector[1].x, g_vGroundISector[1].y, g_vGroundISector[1].z);
    glEnd();

    // Draw the Forward Intersection Line.
    glBegin(GL_LINES);
    glColor3f(1, 1, 0);
    glVertex3f(
        g_vForwardISector[0].x * 10.0f, g_vForwardISector[0].y, g_vForwardISector[0].z * 10.0f);
    glVertex3f(
        g_vForwardISector[1].x * 10.0f, g_vForwardISector[1].y, g_vForwardISector[1].z * 10.0f);
    glEnd();

    // Re-enable lighting.
    glEnable(GL_LIGHTING);

    // System.out.println("x " + g_BallEntity.x + " y " + g_BallEntity.y);
    // Draw it!
    pObj.draw(g_BallEntity.fRadius, 20, 20);

    glPopMatrix();

    screen.setTitle(
        "Triangles: "
            + Octree.maxTriangles
            + "  -Total Draw: "
            + Octree.totalNodesDrawn
            + "  -Subdivisions: "
            + Octree.maxSubdivisions
            + "  -FPS: "
            + FPSCounter.get()
            + "  -Node Collisions: "
            + Octree.numNodesCollided
            + "  -Object Colliding? "
            + octree.isObjectColliding());
  }