PDA

View Full Version : Bounding spheres but Walls :))



DoğanÇoruh
07-05-2000, 03:04 PM
We can simply use bounding spheres for collision detection but walls?

;))

Gelero
07-05-2000, 04:58 PM
Hey man...
i'm actually writing a collision detection to my engine. but i found a bug that i really can't explain.
Here is the problem.
i'm using two cubes to implementation.
when i move one of the cubes around and he touchs another one, my collision system detects the event but sometimes a consider distance to each other and another time when they are face to face. and i write the code over and over. How did your collision system works ??? use a spheres around the objects ??

And, are you work with Delphi correct ???

[]'s

[This message has been edited by Gelero (edited 07-05-2000).]

DoğanÇoruh
07-06-2000, 05:11 AM
Yes guy you know immortal delphi ehehe

himmm you say that you wrote the code over and over
hım

the thing that you must do is

our first cube's sphere's radius is r1
second sphere's raidus is r2

first sphere's position is x1,y1,z1
second sphere's position is x2,y2,z2

you must calculate

R:=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));

if R<r1+r2 then collision is occured...

but the walls the topis signs it :))=) and i am asking it , walls?

when we strike the walls how can i detect the striking :))) ?

regards
bye

DoğanÇoruh
07-06-2000, 05:16 AM
Sorry for my bad english :)

El Jefe
07-06-2000, 07:02 AM
I know this is getting more off the topic, but you don't really need to do the sqrt when you check the distance between the two objects....well, at least as long as you store the radius squared of each of the objects you are checking collision against. Simple optimisation, but if you have a slow computer or are doing lots of distance checks, it can add up to a lot of savings.

DFrey
07-06-2000, 07:54 AM
A simple sphere-plane collision check is this, extend a line from the center of the sphere to a point P in the plane of the wall. Parameterize this line by d so that at the center of the sphere d=0 and on the surface of the sphere where the line intersect the sphere d=1. Then solve for the parameter d of point P. If 0<=d(P)<=1, then the sphere collides. Another note, this line is parallel to the normal of the wall as well. You can make the parameter on the sphere equal the radius R instead of 1 if you also change the check to 0<=d(P)<=R.

Also to be absoultely correct, you should also check to see if P lies within or on (inclusive) the boundary of the wall.

[This message has been edited by DFrey (edited 07-06-2000).]

Gelero
07-06-2000, 12:11 PM
Nice...
But DoğanÇoruh, how about your performance ??
I mean, your FPS ??
you in your last post, you wrote that you`re drawing walls and walls, but if i draw a lot of walls here, ohh god, there`s a XT in my front..
And my computer it`s a PII, 466 MHZ, 64M and no 3D Card. It's not a super machine but i really guess that i can reach more...
Can I ???

So, how its your optimization about wall and stuff ??

[]'s

DoğanÇoruh
07-06-2000, 03:29 PM
Galero I think my way is best for you and your machine :))

hım dfrey says some way but the way must support the sky by wall i dont know what can i explain :)

in q3 if we strike to a wall and if our angle between wall's plane and camera vector is not 90 degree we sky by the wall

x:=x+sin(angle);
y:=y+cos(angle);

did anyone understand something from this the simple function? if yes good and please help me :)) i know all of techniques but i can add a way to another :) hum :(

;))

regards

DoğanÇoruh
07-06-2000, 03:31 PM
Excuse me! :))

x:=x+sin(angle);
z:=z+cos(angle);

y is for jumping or flying for camera :))

Gelero
07-06-2000, 07:17 PM
Yeah...
So can you provide me some source...
just to take a look...

thanx

[]'s

JD
07-07-2000, 03:52 AM
Originally posted by DoğanÇoruh:

x:=x+sin(angle);
z:=z+cos(angle);


so angle is what the angle of the wall or the angle of our player. Or the combined angle of the player against the wall?

Relic
07-07-2000, 09:22 AM
This makes sense if angle is between the surface normal and the player's direction vector (-90 to 90 degrees if frontfacing the wall).
Draw this on paper with x going right, z going down, (x,z) a point on the wall and the player's direction vector ending in (x,z)
With (x,y) = (0, 0) that is z-axis is the wall and x axis is the surface normal and everything becomes clear.
Then (sin(angle), cos(angle)) points in the orthogonal direction of the player's direction.

So with sin(a) you have a projection from your player's direction vector onto the wall. You could use it to slide along the wall.

Gelero
07-07-2000, 10:55 AM
Sure...
but sorry about my stupid question.
I know what the normal angle is, but how can i find it ??
i mean, how can i find a normal of any surface, for example ???

DoğanÇoruh
07-07-2000, 02:00 PM
Relic : you had explained what i try to explain :) good but how can we add these two way to eachother? :) ha? friend :))

Relic
07-09-2000, 09:11 AM
"Sure...
but sorry about my stupid question.
I know what the normal angle is, but how can i find it ??
i mean, how can i find a normal of any surface, for example ???"

The angle between two vectors is the acos() of the dot product of those two vectors. Mind the order of the vectors. Mathematically positive is counterclockwise.

The normal of a surface is the crossproduct of two base vectors (i.e. two nonlinear unit vectors) of that surface. If you have a wall simply take the bottom and up edge vector and normalize properly.

Though, basically the post I wrote before does not need specifically the angle between surface normal and player's direction. But if you're calculating with the surface normal, you can easily get some kind of "culling" information. If the dot product is negative, your direction points to the back of the wall.

"Relic : you had explained what i try to explain http://www.opengl.org/discussion_boards/ubb/smile.gif good but how can we add these two way to eachother? http://www.opengl.org/discussion_boards/ubb/smile.gif ha? friend http://www.opengl.org/discussion_boards/ubb/smile.gif)"

I thought you were looking for vector you need to let your player slide along the wall. Well, the direction of that is the wall vector itself, the speed is the sin(angle)* playerSpeed.
I'm actually not sure what the cos(angle) in your formula is needed for, except that it gives a nice orthogonal direction, which could be useful to split some other forces.

Gelero
07-09-2000, 01:00 PM
Relic: thats pretty clear for you man...
my english is poor, so i think if i saw your explanation in code, it will be more easy to understood.
Can your write a sample showing how can i find the normal vector of any surface ????

thanx for your attention...

[]'s

DoğanÇoruh
07-09-2000, 01:07 PM
Thanks for everything relic and galero that help to be formed some 3d minds :) really thnx ;)

Relic
07-09-2000, 11:26 PM
For an implementation look into the GLUT library file glut_shapes.c.

Please learn to find such stuff yourself with a simple query on the internet. It's all there.
For example try www.alltheweb.com (http://www.alltheweb.com) with "cross product vector normal" and you'll even get an interactive Java tutorial where you can manipulate the vectors and see what happens. http://www.phy.syr.edu/courses/java-suite/crosspro.html

That is cool and explains the need for normalization!