Author Topic: Collision with Skybox  (Read 3095 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Collision with Skybox
« Reply #15 on: December 18, 2011, 10:49:31 pm »
You might call that on your world, but not on the SkyBox' world, don't you? I wouldn't make any sense. Just create a new SkyBox instance, don't fiddle around with its internal world for this.

The sky box is static, it doesn't move at all. All that happens is that the internal world's camera will be adjusted to match the rotation of the one in your world when you call render(..) on the sky box. It should be possible to rotate the sky in any way you like. At least i've no idea why it shouldn't.... ???

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Collision with Skybox
« Reply #16 on: December 18, 2011, 11:17:05 pm »
The <...> stuff (instead of good old typecasting) is a Java 5+ thing.
Yes...and i would have used that, but that would have broken compatibility with older Java versions. I lost 1.1 compatibility anyway because you can't compile to 1.1 with anything higher than the 1.4 compiler and i can't use the 1.4 compiler any longer, because it can't read the latest lwjgl-jars. So jPCT is now compatible to 1.4 and up instead of 1.1 and up. But still no generics support. When you look at jPCT-AE, you'll notice that the i'm using them there.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Collision with Skybox
« Reply #17 on: December 18, 2011, 11:53:29 pm »
I didn't know it was on a separate World instance. Seems counter-intuitive. Would you add that to the docs? The code

Code: [Select]
skyboxObject.rotateZ((float)Math.PI*-.5f);
skyboxObject.rotateMesh();
skyboxObject.clearRotation();
skyboxObject.build();//JUST IN CASE BUT PROBABLY UNECESSARY (AND UNDESIRED)

doesn't work.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Collision with Skybox
« Reply #18 on: December 19, 2011, 06:42:45 am »
No, doing a rotateMesh() won't work, because the sky box is a compiled object and it already has been compiled at that stage. Just do the rotation and leave out the rest.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Collision with Skybox
« Reply #19 on: December 19, 2011, 05:35:43 pm »
That makes sense. So the rotateMesh() wasn't doing anything and clearRotation() was undoing the rotation.

Here's another question: is collision with the Skybox possible for the player character? It seems to me that it's translating along with the camera (which it probably is, come to think of it).

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Collision with Skybox
« Reply #20 on: December 19, 2011, 07:39:00 pm »
Anyway, to circumvent the issue, I'm cloning it. The initial skybox will have the size of the entire level, then I apply the following code:
Code: [Select]
skyboxObject.rotateX((float)Math.PI*.5f);//CAN'T rotateMesh() OR clearRotation(): IT'S COMPILED
skyboxObject = skyboxObject.cloneObject();//CLONE IT SO skyboxObject IS A SNAPSHOT OF THE Skybox AS IT WAS CREATED AND DOESN'T MOVE ALONG WITH THE CAMERA
skyboxObject.setCulling(false);
skyboxObject.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS | Object3D.COLLISION_CHECK_SELF );
skyboxObject.setCollisionOptimization(true);
skyboxObject.addCollisionListener(this);//Skybox.addCollisionListener()

And I am setting the skybox visibility to true before checking for collision. No collision is happening.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Collision with Skybox
« Reply #21 on: December 19, 2011, 07:39:52 pm »
Yes, in theory it's possible. The sky box rotates with the camera, but it doesn't move. However, if you are in a situation where you collide with the sky box, your sky box was probably too small...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Collision with Skybox
« Reply #22 on: December 19, 2011, 07:41:15 pm »
And I am setting the skybox visibility to true before checking for collision. No collision is happening.
Keep in mind that the sky box consist of some very large polygons. You need a pretty high collision offset in Config to detect a collision with that. However, why do you want to detect collisions with the sky box in the first place? Wouldn't it be sufficient to make a simple distance check instead?

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Collision with Skybox
« Reply #23 on: December 19, 2011, 08:16:47 pm »
Sure, if you want to be rational. :- ) But this was a game I made some six or seven years ago (jpct was way under version 1 then). That must have been the first idea I had. I was just trying to do a straight conversion just now, but I suppose I may as well change it now.