Collision with Skybox

Started by AGP, December 16, 2011, 08:57:14 PM

Previous topic - Next topic

AGP

Egon, I have a game that uses a sky sphere object that I wrote years ago. Now I want to convert it to the util.Skybox, because it's so much easier to deal the textures (not to mention easier to find stuff for). Problem is that this game requires me to collide with the sky. I could keep the sphere just for the collision bit, but I'd much rather be able to collide straight with the skybox (for one thing, it would save a good deal of polygons and for another it would be better for future games!). The best way to do this, I think, would be to get a method like Skybox.getObject3D(). Would you be willing to do that?

EgonOlsen

The SkyBox-class has a getWorld()-method. You can access the skyboy object from this world.


EgonOlsen

Just use the Enumeration of Object3Ds. The first (and only) one is the skybox.

AGP

To be perfectly honest, I never used it. Could you just point me in the right direction?

EgonOlsen

Something like:


Object3D boxObj=(Object3D) skybox.getWorld().getObjects().nextElement();

AGP

Thanks a lot. But the question that follows is: isn't this a little clumsy? After all, I have no way of testing for whether I got the right object.

EgonOlsen

Yes, it is. But you can simply extend SkyBox and add a getObject3D()-method that does this internally, if you want to hide it from the rest of the application. But "what if" this changes?...well, it won't. You can rely on the fact that the first object returned will be the sky box.

AGP

OK, thanks. Would you add that to the docs for future reference?

EgonOlsen


AGP

#10
Thanks.

Scratch what I just wrote afterwards, I just got it. :- )

AGP

Now I'm really going to sound like an idiot (it's a Java 5 quirk that I've never used too much):

theWorld.getObjects().nextElement().addCollisionListener(this);


doesn't work. I don't know whether I should (and where as I've tried on both ends of theWorld.getObjects().nextElement() put <Object3D>. And it can't find addCollisionListener without it.

AGP

I typecast it hope it works. Now here's another question: what happens when I replace the skybox (to change between levels)? Do I just keep calling nextElement()?

Again, I'm going to emphasize how clumsy this is.

EgonOlsen

If you replace the instance, the world inside will be replaced too.  If you can't get used to use the Enumeration (it's exists since Java 1.1...i'm not sure what you mean with Java 5 quirk...), just extend the SkyBox class, implement it once and forget about it.

AGP

#14
What do you mean? When I change levels, I call World.removeAll(). I don't reinitialize the world.

The <...> stuff (instead of good old typecasting) is a Java 5+ thing.

By the way, I'm not having any success in rotating the Skybox to match the game's orientation (the X/Y plane instead of the X/Z one).