# Bounding spheres but Walls :))

We can simply use bounding spheres for collision detection but walls?

;))

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).]

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

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.

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§<=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§<=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).]

Nice…
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 ???

[]'s

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

Excuse me! :))

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

y is for jumping or flying for camera :))

Yeah…
So can you provide me some source…
just to take a look…

thanx

[]'s

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?

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.

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 ???

Relic : you had explained what i try to explain good but how can we add these two way to eachother? ha? friend :))

“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 good but how can we add these two way to eachother? ha? friend )”

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.

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 ???