PDA

View Full Version : How to slide against plane in collision?


ikk
10-13-2005, 02:13 PM
How to slide against plane im colliding with, instead stopping permanently?

i have position before collision and after collision. how to determine vector that ll move point parallelly in desired lengh to plane?

zavie
10-13-2005, 02:22 PM
If I understand what you're willing to do, you want to use the projection of the position after collision on the plane, right?

Let's call A the point after collision, A' its projection on the plane, O some point of the plane, and N the normal. Then you have:
OA'=OA - (OA.N)

ikk
10-13-2005, 02:41 PM
im reading this article:
http://www.devmaster.net/articles/bsp-trees-physics/
somwhere in the middle is written exactly:

When collision between an object and a polygon or an object and another object is detected, the end position of the moving object needs to be corrected. In the case of collision versus a polygon, the corrected end position that is calculated with the following formula:

EndPosition += Polygon.Normal*(CollRadius-EndSideValue)

The effect of this formula will be that objects "slide" against the walls as opposite to get stuck against walls which would be the case if the end position was set to the start position every time a collision was detected.


but i only need to do point vs plane, not object vs polygon, like in article, how to do the "slide"?

how to code this in c ?

sorry, but what is OA' ? how can i get position from this that describes point after collision.

.oisyn
10-14-2005, 01:39 AM
In words: if your point crosses the plane, you'll need to move the point in the direction of the plane's normal onto the plane. So what you need to do is calculate the distance between the point and the plane, multiply that with the plane's normal and add it to the point's location. Your point is now on the plane, and you'll have the feeling of 'sliding' along it.

ikk
10-14-2005, 04:55 AM
im using this to test if camera movement intersects plane.
it not fully works. im using folowing code, this is done on every frame:

//
// pl - D3DXPLANE structure
// lpvOld - old point (camera) pos
// lpvNew - new point (camera) pos
FLOAT fDistOld = D3DXPlaneDotCoord( &pl, lpvOld ); //get distance from plane
FLOAT fDistNew = D3DXPlaneDotCoord( &pl, lpvNew );

// If the two points is on different sides of the plane, multiplying
// the two values will give a negative result, indicating that the
// object passed through the plane.
if( fDistOld * fDistNew < 0 ){
D3DXVECTOR3 vPlNormal = D3DXVECTOR3( pl.a, pl.b, pl.c );
*lpvCorrection = fDistOld * vPlNormal;
return 1;
}

later im adding 'lpvCorrection' to old position to determine final camera position, but when im doing that result is that camera is shaking and sometimes passes thru that plane. what could be wrong in my code ? plz help.

.oisyn
10-14-2005, 05:19 AM
You're doing it the other way around, you should use the distance for the new position to the plane, and add the correction vector to the new position :)

Here, take a look at this diagram:

http://crew.tweakers.net/oisyn/planesliding.png

What you're doing is moving the old position onto the plane. That won't give you a sliding sensation since it has nothing to do with the direction you're actually moving in. However, if you project the new position onto the plane, you'll get the feeling that the diagonal movement stops at point of impact, and slides along the plane with the "left-over energy" from the movement (the green arrow).

Note that you might need to change a sign (-fDistNew * vPlNormal), because you need to move toward the plane, not away from the plane.

zavie
10-14-2005, 05:33 AM
sorry, but what is OA' ? how can i get position from this that describes point after collision.

A' is the position after correcting. :-)
Look at .oisyn's the diagram.

ikk
10-14-2005, 05:33 AM
im reading

ikk
10-14-2005, 06:58 AM
as i said, im using vectors to move camera position. maybe my matrix calculations are wrong, bcos theyre quite mess. anyone know how to put my code (post #5) together with matrices calculation to move camera position + rotation ? maybe there is example somwhere?

Scuppy
10-24-2005, 04:02 PM
There was a good explaination and code on the old flipcode site. They called it ovoid collision detection or something because the world was scaled so that the object was a 1,1,1 sphere (simplifying the testing). It talked about what youre trying to do. I implemented the code and it worked really well.

Maybe someone else knows of this article, sorry it was a few years ago now.

Reedbeta
10-24-2005, 04:41 PM
The flipcode articles can still be viewed at http://flipcode.com/articles/ (there is no link from the index page, but all the articles are still there). There are several articles on collision detection there, although I didn't find the one you mention after a cursory search.

Scuppy
10-24-2005, 07:49 PM
Took a bit of googling to find it:
http://www.fluidstudios.com/pub/FluidStudios/CollisionDetection/Fluid_Studios_Generic_Collision_Detection_for_Game s_Using_Ellipsoids.pdf
Dont know if the author started up fluidstudios or what. I hope they dont mind me linking it.

ikk
10-25-2005, 01:36 AM
thanks for ur replies. ill check the article, maybe i have errors in my algoritm, so ill need to revrite it.

ikk
10-26-2005, 03:09 PM
http://members.lycos.co.uk/slvv/docs/coll01.JPG
ok, ive got folowing points: A2, B, D, and plane
How to get A3? or the orange line?

zavie
10-26-2005, 03:27 PM
You need N, the normalized normal vector to the plan P.

Then:
BD.N = A3D (BD projected on N)
But you have BD = BA3 + A3D
So BA3 = BD - BD.N

Do you get it?

moe
10-26-2005, 03:30 PM
You wrote that you have the point D. You also know how to determine the distance from any point to your plane. So, the question is do you know how to get a normal for your plane?

Simply take the (normalized) normal vector for your plane multiply it with the distance from D to the plane and then add it to the point D. That’s the new position (A3).

ikk
10-28-2005, 12:18 PM
thanks, things r starting to work now.
you should told me about that normalization earlier :yes:

.oisyn
11-01-2005, 01:55 AM
Euh, the definition of a "normal" is that it is "normalized". Hence it's name :)

dave_
11-01-2005, 02:23 AM
Euh, the definition of a "normal" is that it is "normalized". Hence it's name :)

Actually the definition of normal is that it is perpendicular to a plane

normalized means that it has been made into a unit vector.

http://en.wikipedia.org/wiki/Normal_%28mathematics%29

.oisyn
11-01-2005, 02:45 AM
yes, I didn't quite say what I meant. What I meant was: why do you think they call a normal a normal and the process of normalization normalization, and why are those words so similar? :)

('norm' means 'length')

Reedbeta
11-01-2005, 03:59 PM
The words all come from the Latin "norma", which referred to a carpenter's square. Because the edges of a square are perpendicular, so we have the word "normal" meaning "perpendicular" (i.e. a normal vector, normal line, or normal plane). However, the carpenter's square also evokes the idea of a rule or pattern, and so we have the word "norm" meaning rule or pattern; this gives a second meaning to "normal", that of being something that is ordinary because it conforms to a rule or pattern. From this, "normalize" means to make things conform to a rule or pattern, for instance scaling vectors so that they all have length 1. And from this, we have the modern mathematical meaning of "norm," a function that gives you a length or magnitude for a vector.