Author Topic: Bug? getPolygonIDs problem.  (Read 5444 times)

Offline Ulrick

  • byte
  • *
  • Posts: 18
    • View Profile
Bug? getPolygonIDs problem.
« on: September 27, 2010, 04:06:51 pm »
Hi, I'm trying to develop a simple application for testing purpose, and I found a strange behavour of the getPolygonIDs function.

It actually work perfectly on my desktop environment (win XP), but the same code seem to not work on Android (Nexus One).

All other functionality seems to work, but this one do not work. Could be a bug? My mistake? I'm actually doing the same thing found if the sample code as shown below:

   public void collision(CollisionEvent e) {
      /**
       * Make sure that something collided with the ground and that this
       * was an actual entity (and not the camera or whatever).
       */
      if (e.getType()==CollisionEvent.TYPE_TARGET && e.getSource()!=null) {
         Object obj=e.getSource();
         /**
          * Make sure, that the source of the collision was really
          * a bullet.
          */
         if (obj instanceof Bullet) {
            Bullet bullet=(Bullet) obj;
            bullet.disable();
            Object3D ground=e.getObject();

            /**
             * Here, we have to calculate the position and orientation of the decal the
             * bullet leaves at the ground. This requires a call to calcMinDistance() and
             * to make sure that we are not triggering the CollisionListener again in that case,
             * we temporally disable collision events on the ground.
             */
            ground.disableCollisionListeners();
            SimpleVector za=bullet.getZAxis();
            SimpleVector tc=bullet.getTransformedCenter();
            float d=ground.calcMinDistance(tc, za, bullet.getSpeed()*10);
            if (d!=Object3D.COLLISION_NONE) {
               za.scalarMul(d*0.6f);
               tc.add(za);
               int[] ids=e.getPolygonIDs();
               if (ids!=null&&ids.length>0) {
                  int id=ids[0];
                  SimpleVector n=e.getObject().getPolygonManager().getTransformedNormal(id);
                  bulMan.createDecal(tc, n);
               }
            }
            /**
             * And on again...
             */
            ground.enableCollisionListeners();
         }
      }
   }
}


This is the code of the car demo (in the bulletTerrainListener file) and the function is used to place a decal when a shot hit the ground.

I don't undestand why on Android the function do not work and the issue is due to a null value of the function getPolygonIDs().

Thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Bug? getPolygonIDs problem.
« Reply #1 on: September 27, 2010, 09:34:53 pm »
I can't verify this. The bullets are using a ray-polygon collision detection. I'm using the same thing in my latest Android game Alien Runner, so i added a dummy CollisionListener to see what happens...and i got the polygon IDs just as expected. Are you sure that the listener on Android returns true on requiresPolygonIDs()?

Offline Ulrick

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Bug? getPolygonIDs problem.
« Reply #2 on: September 29, 2010, 04:34:27 am »
You are right!!!. Thanks!!.

Just another quick question, how to you place the decal with the correct transparency. I use the following code, but the result is a black square with the bitmap inside. Any idea?

The code is always from the prevoius desktop demo:

               obj.setTexture("decal");
               obj.getMesh().compress();
              
               obj.setTransparency(0);
               //obj.setTransparencyMode( Object3D.TRANSPARENCY_MODE_ADD );
               //obj.setLighting( Object3D.LIGHTING_NO_LIGHTS );
               //obj.setAdditionalColor( new RGBColor(255,255,255) );              
              
               /*obj.setTransparencyMode(TRANSPARENCY_MODE_ADD);
               obj.setTransparency(0); // was 3*/

I actually played a bit with different values, but noe seems to work. The  result is always the same.

Is there a specific color to use? or a specific way to create the texture?

Thanks again,