www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on February 06, 2011, 07:58:26 pm

Title: Unexpected Behavior with Collision
Post by: AGP on February 06, 2011, 07:58:26 pm
The QG ground planes were always set to invisible. When they're loaded, they're set to plane.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS); Now this collision isn't happening. Did something get changed with Object3D.setVisibility(boolean)?

Code: [Select]
      private void moveByMouse() {//CALLED ONCE TO SETUP THE WALK DIRECTION
mouseWalk = true;
SimpleVector ray = Interact2D.reproject2D3D(theCamera, buffer, mouseX, mouseY);

if (ray != null) {
     SimpleVector norm = ray.normalize();
     Matrix mat = theCamera.getBack();
     mat = mat.invert3x3();
     norm.matMul(mat);

     SimpleVector ws = new SimpleVector(ray);
     ws.matMul(theCamera.getBack().invert3x3());
     ws.add(theCamera.getPosition());

     float f = theWorld.calcMinDistance(theCamera.getPosition(), norm, 1000);
     if (f != Object3D.COLLISION_NONE) {//THIS IS TESTING NEGATIVE
System.out.println("Collision section"); //THIS ISN'T BEING PRINTED
SimpleVector offset = new SimpleVector(norm);
norm.scalarMul(f);
norm = norm.calcSub(offset);
SimpleVector heroCenter = hero.getTransformedCenter();
SimpleVector destination = new SimpleVector(norm);
destination.x += theCamera.getPosition().x;
destination.z += theCamera.getPosition().z;
destination.y = heroCenter.y; // Make y the same as for the hero to avoid moving up/down.
hero.setRotationMatrix(destination.calcSub(heroCenter).getRotationMatrix());
target = new SimpleVector(destination);
     }
}
System.out.println("End of moveByMouse. Is ray null? "+(ray==null) +" Is target? "+(target==null));
      }
Title: Re: Unexpected Behavior with Collision
Post by: AGP on February 06, 2011, 09:30:35 pm
I got an older version of jpct and proved that jpct's behavior did in fact change (it's back to working). Would it be possible to change it back so I wouldn't fear updating it? :- )
Title: Re: Unexpected Behavior with Collision
Post by: EgonOlsen on February 06, 2011, 09:42:48 pm
Which version was that and what does it have to do with setVisibility(..)? Is that plane invisible?
Title: Re: Unexpected Behavior with Collision
Post by: AGP on February 06, 2011, 09:53:34 pm
When the plane is visible, the newer versions as well as the older versions of jpct work. But when the plane is invisible, as it has to be in this case (2d backgrounds), only the older versions of jpct get into that block. I must not have noticed sooner because I was testing the camera (thus the planes had to be visible). Is it possible to go back to the earlier behavior?
Title: Re: Unexpected Behavior with Collision
Post by: EgonOlsen on February 06, 2011, 09:58:23 pm
It was actually a bug that calcMinDistance didn't care about visibility. 1.22 fixed this. The solution in your case is simple: Set it to visible, do the calculation and set it to invisible again. No collision related method in jPCT should take invisible objects into account.
Title: Re: Unexpected Behavior with Collision
Post by: AGP on February 06, 2011, 10:03:35 pm
I figured you'd say that. But isn't it so much more convenient to invisible objects that collide? Didn't you say so yourself that none of your collision objects are the ones you render? Why not just make a separate setActive(boolean) method that disables everything and let invisible objects collide?
Title: Re: Unexpected Behavior with Collision
Post by: EgonOlsen on February 06, 2011, 10:17:55 pm
I sometimes use special collision objects, not always. In most cases, what i render is what i use for collisions too. I agree that toggling visibility feels a bit strange but adding an extra method feels even more strange as it would be the third method to have an influence on collisions. Apart from that, it would break existing code.