www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Schwapp on September 11, 2011, 03:56:46 pm

Title: Object3D.checkForCollisionEllipsoid(Unknown Source)
Post by: Schwapp on September 11, 2011, 03:56:46 pm
Hello!
I splitted um my Code which created a simple Scene and a moveable character.
Before i splitted it up to more classes (like player, or scene...) the collision worked fine.
But now I get  the exception you see in the title :

Object3D.checkForCollisionEllipsoid(Unknown Source)

The whole exception says:

Exception in thread "main" java.lang.NullPointerException
   at com.threed.jpct.Object3D.checkForCollisionEllipsoid(Unknown Source)
   at WWWGame.Game.loop(Game.java:131)
   at WWWGame.Game.start(Game.java:81)
   at Start.init(Start.java:30)
   at Start.main(Start.java:16)


So there must be a variable in line 131 which is null... but there isn't.

Thats the line:

moveRes = szene.getPlayer().getObject().checkForCollisionEllipsoid(moveRes,
            ellipsoid, 8);

All variabled are defined and not null.
Any idea what the problem is?
Title: Re: Object3D.checkForCollisionEllipsoid(Unknown Source)
Post by: Schwapp on September 11, 2011, 03:58:32 pm
lol, the  8) should be a  8 )^^
Title: Re: Object3D.checkForCollisionEllipsoid(Unknown Source)
Post by: EgonOlsen on September 11, 2011, 08:13:39 pm
Maybe the same reason as in this thread: http://www.jpct.net/forum2/index.php/topic,2226.msg16428.html (http://www.jpct.net/forum2/index.php/topic,2226.msg16428.html)? (I.e. failed to add the object to the world). The next release will handle this case with a better error message.
Title: Re: Object3D.checkForCollisionEllipsoid(Unknown Source)
Post by: neo187 on September 18, 2011, 05:42:46 pm
I'm actually having the same problem though the object has been added to the world. I'm trying to add collision detection to the Ninja from the Bones demo, this function is called in the initialization bit:

Code: [Select]
private void addNinja() {

AnimatedGroup ninja = masterNinja.clone(AnimatedGroup.MESH_DONT_REUSE);

ninja.getRoot().translate(0,0,-20);
ninja.getRoot().setCollisionMode(Object3D.COLLISION_CHECK_SELF);

ninja.addToWorld(world);

ninjas.add(ninja);
}
And upon pressing a button I try to check for collisions before applying the translations
Code: [Select]
directionVector = new SimpleVector(0,0,2);

.....

directionVector = ninjas.get(0).getRoot().checkForCollisionEllipsoid(directionVector, ellipsoid, 2);
ninjas.get(0).getRoot().translate(directionVector);

But I keep getting a Null error for the checkForCollision line?

EDIT:

Raft just helped me out with this. For an AnimatedGroup the set and check need to be done on the Animated3D object, not on the Object3D. In the Ninja demo ninjas.get(0) returns the animated group, ninjas.get(0).get(0) returns the Animated3D object:

Code: [Select]
ninjas.get(0).get(0).setCollisionMode(Object3D.COLLISION_CHECK_SELF);
directionVector = ninjas.get(0).get(0).checkForCollisionEllipsoid(directionVector, ellipsoid, 1);