@Override
  protected void initScene() {
    // Remember to call super.initScene() to allow TangoRajawaliArRenderer to set-up
    super.initScene();

    // Add a directional light in an arbitrary direction
    DirectionalLight light = new DirectionalLight(1, 0.2, -1);
    light.setColor(1, 1, 1);
    light.setPower(0.8f);
    light.setPosition(3, 2, 4);
    getCurrentScene().addLight(light);

    // Set-up a material: green with application of the light
    Material material = new Material();
    material.setColor(0xff009900);
    material.enableLighting(true);
    material.setDiffuseMethod(new DiffuseMethod.Lambert());

    // Build a pyramid and place it roughly in front and a bit to the right
    Object3D object1 = new NPrism(4, 0f, 0.2f, 0.2f);
    object1.setMaterial(material);
    object1.setPosition(-0.25, 0, -1);
    getCurrentScene().addChild(object1);

    // Build a sphere and place it roughly in front and a bit to the left
    object1 = new Sphere(0.1f, 24, 24);
    object1.setMaterial(material);
    object1.setPosition(0.25, 0, -1);
    getCurrentScene().addChild(object1);
  }
    @Override
    protected void initScene() {
      mLight = new DirectionalLight(1.0, 0.2, -1.0); // set the direction
      mLight.setColor(1.0f, 1.0f, 1.0f);
      mLight.setPower(2);

      getCurrentScene().addLight(mLight);

      try {
        Material material = new Material();
        material.addTexture(new Texture("earthColors", R.drawable.earthtruecolor_nasa_big));
        material.setColorInfluence(0);
        mSphere = new Sphere(1, 24, 24);
        mSphere.setMaterial(material);
        getCurrentScene().addChild(mSphere);
      } catch (ATexture.TextureException e) {
        e.printStackTrace();
      }

      getCurrentCamera().setLookAt(0, 0, 0);
      getCurrentCamera().setZ(6);
    }
    @Override
    protected void initScene() {
      try {
        DirectionalLight light = new DirectionalLight();
        light.setLookAt(1, -1, 1);
        light.enableLookAt();
        light.setPower(1.5f);
        getCurrentScene().addLight(light);

        light = new DirectionalLight();
        light.setLookAt(-1, 1, -1);
        light.enableLookAt();
        light.setPower(1.5f);
        getCurrentScene().addLight(light);

        DebugVisualizer debugViz = new DebugVisualizer(this);
        debugViz.addChild(new GridFloor());
        getCurrentScene().addChild(debugViz);

        final LoaderAWD parser =
            new LoaderAWD(mContext.getResources(), mTextureManager, R.raw.awd_suzanne);
        parser.parse();

        final Object3D monkey = parser.getParsedObject();

        Material material = new Material();
        material.enableLighting(true);
        material.setDiffuseMethod(new DiffuseMethod.Lambert());
        material.setColor(0x990000);

        monkey.setMaterial(material);
        getCurrentScene().addChild(monkey);

        material = new Material();
        material.enableLighting(true);
        material.setDiffuseMethod(new DiffuseMethod.Lambert());
        material.setColor(0x999900);

        Object3D monkey2 = monkey.clone();
        monkey2.setMaterial(material);
        monkey2.setPosition(-3, 3, 3);
        getCurrentScene().addChild(monkey2);

        ArcballCamera arcball =
            new ArcballCamera(mContext, ((Activity) mContext).findViewById(R.id.content_frame));
        arcball.setPosition(4, 4, 4);
        getCurrentScene().replaceAndSwitchCamera(getCurrentCamera(), arcball);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
Example #4
0
    private Matrix4 createLightViewProjectionMatrix(DirectionalLight light) {
      //
      // -- Get the frustum corners in world space
      //
      mCamera.getFrustumCorners(mFrustumCorners, true);
      //
      // -- Get the frustum centroid
      //
      mFrustumCentroid.setAll(0, 0, 0);
      for (int i = 0; i < 8; i++) mFrustumCentroid.add(mFrustumCorners[i]);
      mFrustumCentroid.divide(8.0);

      //
      // --
      //

      BoundingBox lightBox = new BoundingBox(mFrustumCorners);
      double distance = mFrustumCentroid.distanceTo(lightBox.getMin());
      Vector3 lightDirection = light.getDirectionVector().clone();
      lightDirection.normalize();
      Vector3 lightPosition =
          Vector3.subtractAndCreate(
              mFrustumCentroid, Vector3.multiplyAndCreate(lightDirection, distance));

      //
      // --
      //

      mLightViewMatrix.setToLookAt(lightPosition, mFrustumCentroid, Vector3.Y);

      for (int i = 0; i < 8; i++) mFrustumCorners[i].multiply(mLightViewMatrix);

      BoundingBox b = new BoundingBox(mFrustumCorners);
      mLightProjectionMatrix.setToOrthographic(
          b.getMin().x, b.getMax().x, b.getMin().y, b.getMax().y, -b.getMax().z, -b.getMin().z);

      mLightModelViewProjectionMatrix.setAll(mLightProjectionMatrix);
      mLightModelViewProjectionMatrix.multiply(mLightViewMatrix);
      return mLightModelViewProjectionMatrix;
    }
Example #5
0
 @Override
 public void applyParams() {
   super.applyParams();
   mMaterialPlugin.setLightModelViewProjectionMatrix(mVertexShader.getLightViewProjectionMatrix());
   mMaterialPlugin.setLightDirection(mLight.getDirectionVector());
 }
  @Override
  public void initScene() {
    // Set singleton renderer to current object to be referenced by various Managers.
    currentRenderer = this;

    // Set frame rate.
    setFrameRate(30);

    // Set up lights.
    DirectionalLight light = new DirectionalLight(0.2f, -1f, 0f);
    light.setPower(.7f);
    getCurrentScene().addLight(light);

    light = new DirectionalLight(0.2f, 1f, 0f);
    light.setPower(1f);
    getCurrentScene().addLight(light);

    // Set cropping plane.
    getCurrentCamera().setFarPlane(1000);

    // Background.
    getCurrentScene().setBackgroundColor(0x000000);

    // Create the surrounding.
    createFloor();

    // Instantiate game state to kick off the game.
    state = new GameState(getCurrentScene(), this);

    // Create sample asteroid
    Material material = new Material();
    material.enableLighting(true);
    material.setDiffuseMethod(new DiffuseMethod.Lambert());
    material.setColor(0);

    Texture earthTexture = new Texture("Asteroid", R.drawable.asteroid_small);
    try {
      material.addTexture(earthTexture);

    } catch (TextureException error) {
      RajLog.i("DEBUG TEXTURE ERROR");
    }

    // Set up crosshair.
    centralPane = new Plane(1, 1, 1, 1);
    Material crosshairMaterial = getStandardMaterial();
    Bitmap crosshairBitmap =
        BitmapFactory.decodeResource(mContext.getResources(), R.drawable.crosshair);
    //        Bitmap crosshairBitmap = drawTextToBitmap(mContext, "HELLO POINTS!!!");

    Texture tex = (Texture) crosshairMaterial.getTextureList().get(0);
    tex.setBitmap(crosshairBitmap);

    centralPane.setMaterial(crosshairMaterial);
    centralPane.setDoubleSided(true);
    centralPane.setTransparent(true);
    getCurrentScene().addChild(centralPane);

    leftTopPlane = new Plane(2, 2, 1, 1);
    leftTopPlane.setMaterial(getStandardMaterial());
    leftTopPlane.setTransparent(true);
    leftTopPlane.setDoubleSided(true);
    getCurrentScene().addChild(leftTopPlane);

    leftBottomPlane = new Plane(1, 1, 1, 1);
    leftBottomPlane.setMaterial(getStandardMaterial());
    leftBottomPlane.setTransparent(true);
    leftBottomPlane.setDoubleSided(true);
    //        getCurrentScene().addChild(leftBottomPlane);

    super.initScene();
  }
    @Override
    protected void initScene() {
      DirectionalLight light = new DirectionalLight(0, 0, 1.0);
      light.setPower(2.0f);
      getCurrentScene().addLight(light);

      mPointLight = new PointLight();
      mPointLight.setPower(1.5f);

      getCurrentScene().addLight(mPointLight);

      // -- create sky sphere
      mSphere = new Sphere(400, 8, 8);
      Material sphereMaterial = new Material();
      try {
        sphereMaterial.addTexture(new Texture("skySphere", R.drawable.skysphere));
        sphereMaterial.setColorInfluence(0);
      } catch (ATexture.TextureException e1) {
        e1.printStackTrace();
      }
      mSphere.setMaterial(sphereMaterial);
      mSphere.setDoubleSided(true);
      getCurrentScene().addChild(mSphere);

      mRaptor = new Sphere(1.0f, 24, 24);
      Material raptorMaterial = new Material();
      SpecularMethod.Phong phongMethod = new SpecularMethod.Phong();
      phongMethod.setShininess(180);
      sphereMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
      sphereMaterial.setSpecularMethod(phongMethod);
      sphereMaterial.enableLighting(true);
      mRaptor.setMaterial(raptorMaterial);
      mRaptor.setColor(0xffff00ff);
      getCurrentScene().addChild(mRaptor);

      // -- create a bunch of cubes that will serve as orientation helpers

      mCubes = new Object3D[30];

      mRootCube = new Cube(1);
      Material rootCubeMaterial = new Material();
      rootCubeMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
      rootCubeMaterial.enableLighting(true);
      try {
        rootCubeMaterial.addTexture(new Texture("camouflage", R.drawable.camouflage));
        rootCubeMaterial.setColorInfluence(0);
      } catch (ATexture.TextureException e) {
        e.printStackTrace();
      }
      mRootCube.setMaterial(rootCubeMaterial);
      mRootCube.setY(-1f);
      // -- similar objects with the same material, optimize
      mRootCube.setRenderChildrenAsBatch(true);
      getCurrentScene().addChild(mRootCube);
      mCubes[0] = mRootCube;

      for (int i = 1; i < mCubes.length; ++i) {
        Object3D cube = mRootCube.clone(true);
        cube.setY(-1f);
        cube.setZ(i * 30);
        mRootCube.addChild(cube);
        mCubes[i] = cube;
      }

      // -- create a chase camera
      // the first parameter is the camera offset
      // the second parameter is the interpolation factor
      ChaseCamera chaseCamera = new ChaseCamera(new Vector3(0, 3, 16));
      // -- tell the camera which object to chase
      chaseCamera.setLinkedObject(mRaptor);
      // -- set the far plane to 1000 so that we actually see the sky sphere
      chaseCamera.setFarPlane(1000);
      getCurrentScene().replaceAndSwitchCamera(chaseCamera, 0);
    }