Author Topic: sphere and ellipsoid collision work, but ray won't  (Read 6896 times)

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
sphere and ellipsoid collision work, but ray won't
« on: March 25, 2008, 10:15:04 pm »
Hi, I was using sphere detection collision in an area of my code, but I decided to change to ray collision. The sphere works ok, but the ray type doesn't get a collision. The objects I used the sphere type are the same I am using for the ray-but it won't work. Here is the area where it is called.

Quote
      //tool.checkForCollisionSpherical(newSimpleVector(0,(tool.getTransformedCenter().y*-1)+30,0),100);
int obh = tool.checkForCollision(new SimpleVector(0,2,0),(tool.getTransformedCenter().y*-1));

When I uncomment the spherical and comment the ray, I get a collision, but when I run the code how it is here, I get no collision???
Config.collideOffset is 300. Any ideas?
Jman

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: sphere and ellipsoid collision work, but ray won't
« Reply #1 on: March 25, 2008, 10:35:14 pm »
First of all, the first parameter in checkForCollision is a direction vector, i.e. it should be of length 1. In your case, it's 2. However, this shouldn't prevent the method from working. Are you sure that, when going down the y-axis by the amount of tool.getTransformedCenter().y*-1 units (which is a strange way to give a translation IMHO...are you sure that this is your intention?), there is a collision?
In the spherical method, you are using a radius of 100 for the sphere and tool.getTransformedCenter().y*-1 defines the center. I'm not sure if your translation in the ray-based-method is really the one that you want.

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: sphere and ellipsoid collision work, but ray won't
« Reply #2 on: March 26, 2008, 12:11:48 am »
Hi, thanks for your quick reply. I tried out making the direction vector only 1 in the y. Doesn't work.

Quote
Are you sure that, when going down the y-axis by the amount of tool.getTransformedCenter().y*-1 units (which is a strange way to give a translation IMHO...are you sure that this is your intention?), there is a collision?

Yes, I'm positive. I can visually see there is one. What I am using this for is in terrain modification. What happens is there is a cylinder at a varying value x, -2100y, and a varying value z. The method checks to see if there is a collision if the cylinder were to move all the way down the y axis. Lying in the xz plane is the terrain that need modified. If there is a collision, the collision listener gets the affected polygons and through a round-about process modifies their vectors.

Using sphere-detection the console prints out the statements in the methods that get called in event of a collision and I can see the results. With the ray-detection nothing happens. Well, the int from the checkForCollision() is -100. So, if I understand correctly, that means no collision. Hope this helps. I am lost...

I change absolutely nothing in any other area of code when I switch from sphere to ray detection. Except for commenting out the sphere call. This should work right?
Jman
« Last Edit: March 26, 2008, 12:16:07 am by JavaMan »

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: sphere and ellipsoid collision work, but ray won't
« Reply #3 on: March 26, 2008, 02:54:24 am »
I think the collision checks an amount from the center of the object to something else, so it's a length from the center of the object in the direction of the vector.  It sort of looks like you're using the y position for the length or step as it's termed in the docs.  I think you would put the radius of the object there instead and I think it would always be positive, as it goes in the direction of the vector.
« Last Edit: March 26, 2008, 02:56:40 am by fireside »
click here->Fireside 7 Games<-

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: sphere and ellipsoid collision work, but ray won't
« Reply #4 on: March 26, 2008, 03:19:04 am »
Ok,thanks for the suggestion, I'll try out removing the multiplication of -1 on the y value.
Thats what you meant, right?

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: sphere and ellipsoid collision work, but ray won't
« Reply #5 on: March 26, 2008, 03:45:45 am »
If you're using the object3d collision, you don't need to get the transformed center.  You can set that in config as far as checking transformed, but the collision check is already going out from the center of the object.  You only supply the direction and the length of the ray.  In your case, I think the length of the ray you would be checking is the radius of the object.
click here->Fireside 7 Games<-

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: sphere and ellipsoid collision work, but ray won't
« Reply #6 on: March 26, 2008, 12:38:15 pm »
I looked in the Config class, but I can't find a name of a setting that would pertain to checking transformed. Could someone tell me what the setting is called?

Also, in the meantime, I have been making calls to setCenter(getTransformedCenter()) before the collision. I added some print statements that print before and after this call the values from transformedcenter. It seams that calling setCenter changes the transformed center of the object based on the transformations applied to the object. ??? I tried it out in a little program, and it does the same thing.

Jman

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: sphere and ellipsoid collision work, but ray won't
« Reply #7 on: March 26, 2008, 01:24:35 pm »
Also, in the meantime, I have been making calls to setCenter(getTransformedCenter()) before the collision. I added some print statements that print before and after this call the values from transformedcenter. It seams that calling setCenter changes the transformed center of the object based on the transformations applied to the object. ???
setCenter() sets the center in object space, getTransformedCenter() returns it in world space. If you feed the second into the first, you are mixing spaces, which usually isn't a good idea. Don't do this... ;)

About the collision thing: I'm with fireside here. I think you are not applying the right translation (that's what i tried to express in my first reply, but i was a bit too vague i think). I think that you should do something like this instead:

Code: [Select]
int obh = tool.checkForCollision(new SimpleVector(0,1,0),110);
« Last Edit: March 26, 2008, 01:58:26 pm by EgonOlsen »

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: sphere and ellipsoid collision work, but ray won't
« Reply #8 on: March 26, 2008, 01:51:05 pm »
Quote
I looked in the Config class, but I can't find a name of a setting that would pertain to checking transformed. Could someone tell me what the setting is called?

Ah, that was a mistake on my part.  I was thinking of an object3d setting for checking an ellipsoid collision.  Anyway, the collision check seems to work fine as far as I can tell so you don't need it.  I use it for my mouse jumping around to tell when he's landed on the ground.
click here->Fireside 7 Games<-

Offline JavaMan

  • long
  • ***
  • Posts: 231
    • View Profile
Re: sphere and ellipsoid collision work, but ray won't
« Reply #9 on: March 26, 2008, 02:20:37 pm »
Oh, ok.

I got it to work. I'm not sure what exactly what the problem was,I think it was a mixture of things(Config.collideOffset, the setCenter, and maybe some other stuff that i played around with), but the collision now happens. So, I can now move on...

Thanks
Jman