Author Topic: World.checkCameraCollisionSpherical()  (Read 8196 times)

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
World.checkCameraCollisionSpherical()
« on: June 26, 2007, 02:50:14 pm »
Generally this method works without problem. But sometimes if my camera moves too fast, it will still bump out of walls/ceilings.

I'm sure this can be solved by changing some of the values in the parameters, so what to adjust?

FYI: Im using this version:

public boolean checkCameraCollisionSpherical(int mode, float radius, float moveSpeed, boolean slideMode)
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: World.checkCameraCollisionSpherical()
« Reply #1 on: June 26, 2007, 06:01:00 pm »
The spherical-stuff is (unlike the ellipsoid variant) not a swept approach, i.e. it detects collisions within the sphere's radius at the end-point of the movement. It doesn't care about collisions in between, which may happen if the speed excels the radius. Try ellipsoid collision detection instead, it will cover this case.

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Re: World.checkCameraCollisionSpherical()
« Reply #2 on: June 26, 2007, 06:51:03 pm »
This happens becausse the movement is more like a group of jumps than a continue movement, so if the jump if larger than the sphere diameter it wont detect the collision.

 o       |

    o    |

      o  |

       o |

        o|

         | o

maybe this can be fixed using the sphere collision detection by simulating a big jump as a set of smaller jumps.

a speed of 20f can be simulated by 10 iteration of movements of 2f on speed. checking each time the collition. This should be done for each thread iteration.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: World.checkCameraCollisionSpherical()
« Reply #3 on: June 26, 2007, 07:50:06 pm »
maybe this can be fixed using the sphere collision detection by simulating a big jump as a set of smaller jumps.
Yes, i forgot about this solution. That's possible too, if spherical collision detection is needed for whatever reason.

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Re: World.checkCameraCollisionSpherical()
« Reply #4 on: June 27, 2007, 02:06:50 am »
Is there any use of the sperical one instead of an ellipsoid with the same values for the 3 radius?

If not, why not to change content of the spherical to innerly use the ellipsoid ont taking the radius and setting the x, y, z and z raddios, on that way the sperical can be done using the ellipsoid.
Nada por ahora

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: World.checkCameraCollisionSpherical()
« Reply #5 on: June 27, 2007, 03:52:00 am »
Actually the problem is clear, because I couldn't find an ellipsoid version where the camera can slide. I will try to increase the radius first and see if it helps.
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: World.checkCameraCollisionSpherical()
« Reply #6 on: June 27, 2007, 08:41:35 am »
Is there any use of the sperical one instead of an ellipsoid with the same values for the 3 radius?
Yes, the algorithm is different so that the spherical one can push you out of collisions if they've already appeared (like when two objects insects right in the beginning of the calculation). The ellipsoid approach can't do this, it's there to avoid such cases.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: World.checkCameraCollisionSpherical()
« Reply #7 on: June 27, 2007, 08:52:01 am »
Actually the problem is clear, because I couldn't find an ellipsoid version where the camera can slide. I will try to increase the radius first and see if it helps.
You may have to tweak collideEllipsoidThreshold and/or recursion depth. The ellipsoid approach can slide. In fact it slides even better than the spherical approach. Have a look in the "manual" for a more detailed comparision of the two.

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: World.checkCameraCollisionSpherical()
« Reply #8 on: June 27, 2007, 12:48:45 pm »
Alright, i still haven't solved the problem though, but i think i got some more understanding about the issue. My camera is not first person!!! :o. It is an orbiting camera, so when the camera orbits the object, the velocity is not around a simple axis. Then does it mean that i should use this version:

public boolean checkCameraCollisionEllipsoid(SimpleVector direction, SimpleVector ellipsoid, float moveSpeed, int recursionDepth)

Unfortunately im not specialized in maths stuff. How do I get the correct "direction" parameter, would it be camPos.calcSub(oldCamPos); ???
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: World.checkCameraCollisionSpherical()
« Reply #9 on: June 27, 2007, 12:50:25 pm »
Just did the test, but the problem is that the checkCameraCollisionEllipsoid that accepts a SimpleVector as direction doesn't slide my camera. But i will stick to the SimpleVector version atm cos my camera won't go off.
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Re: World.checkCameraCollisionSpherical()
« Reply #10 on: June 27, 2007, 05:44:43 pm »
Does it works for small speeds? If so, then you can use the aproach I first told, by reducing the speed on sub speeds, is not fanci and may coplicate things but is easy after all.
Nada por ahora

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: World.checkCameraCollisionSpherical()
« Reply #11 on: June 28, 2007, 06:23:48 am »
Nope, it didn't work. But I think it's my problem understanding the issue (Mathematically 8)).

Take a look at this graph:


When the cam is orbiting and finally meet a wall, it will slide towards the target. This one is already working. But the problem is when the cam continue sliding (until it gets very close to the char), it suddenly goes to the location where my red arrow is pointing to (i.e. return to the original orbiting track).

Actually the problem is not with the collision algorithm, but with the parameters. Firstly, in this case you cannot simple use a camera constant to define the direction because the direction is always not around an axis. Secondly, I dunno how to determine the speed in this case.
« Last Edit: June 28, 2007, 06:30:18 am by hytparadisee »
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline halcor

  • byte
  • *
  • Posts: 28
    • View Profile
Re: World.checkCameraCollisionSpherical()
« Reply #12 on: June 28, 2007, 09:43:42 am »
Try thicker wall and/or smaller speed.

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: World.checkCameraCollisionSpherical()
« Reply #13 on: June 28, 2007, 09:52:23 am »
I think in karga this one was solved pretty well, it tries to move the cam closer to the avatar and at the same time lift the camera a bit up. Is that a home-brew solution?
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: World.checkCameraCollisionSpherical()
« Reply #14 on: June 28, 2007, 07:09:26 pm »
well, if i get you right, each frame you are moving camera starting from it's last position. the problem with this is, if camera ellipsoid is in contact with some polygons (like wall) it will get closer and closer to it each frame and at some point due to rounding errors jPCT will regard ellipsoid as slightly passed through otherside and eventually ellipsoid will pass through the wall. something similar happens when you pull down avatar for gravity each frame starting from its last position. for the gravity case, my solution is to take avatar slightly up (a safety height) then do the collision check for gravity. however this is harder for camera as there's no up direction there.

so what i do in karga for third person camera movement is: each frame i try to pull back camera from some position like avatar's head. pull back direction depends on both avatar's direction and camera's direction relative to avatar. this way if camera hits a wall it smoothly slides next to it. go next to a wall in karga in third person view and turn around, that effect is done by this

hope this helps
r a f t