Original Post
🔒 Locked
Collision Detection
Advertisement
im going 2 explain a simple Bounding sphere collision detection.
First for this tutorial we assume objects dont move really fast (ie 1/10 of there size per frame) and secondly that there are only spheres.
Now a sphere only needs 2 Vars
1 --> A Position --> CVector3 Position;
2 --> A Radius --> float Radius;
class Sphere
{
CVector3 Pos;
float Radius;
};
void CheckSpearAgainstSkyBox(Sphere *p)
{
if (p.x > Max.x - p.Raduis) p.x = max.x-p.Raduis;
if (p.x < Min.x + p.Raduis) p.x = Min.x+p.Raduis;
.. And continue this with all the y and z axis
};
void CheckSphereAgainstSphere(Sphere s1,s2)
{
if (Distance(s1.Pos,s2.Pos) < s1.Radius + s2.Radius)
{ // Move both spheres back
s1.Pos = s1.Pos + (s1.Pos-s2.Pos) / 2;
s1.Pos = s1.Pos - (s2.Pos-s1.Pos) / 2;
}
}
First for this tutorial we assume objects dont move really fast (ie 1/10 of there size per frame) and secondly that there are only spheres.
Now a sphere only needs 2 Vars
1 --> A Position --> CVector3 Position;
2 --> A Radius --> float Radius;
class Sphere
{
CVector3 Pos;
float Radius;
};
void CheckSpearAgainstSkyBox(Sphere *p)
{
if (p.x > Max.x - p.Raduis) p.x = max.x-p.Raduis;
if (p.x < Min.x + p.Raduis) p.x = Min.x+p.Raduis;
.. And continue this with all the y and z axis
};
void CheckSphereAgainstSphere(Sphere s1,s2)
{
if (Distance(s1.Pos,s2.Pos) < s1.Radius + s2.Radius)
{ // Move both spheres back
s1.Pos = s1.Pos + (s1.Pos-s2.Pos) / 2;
s1.Pos = s1.Pos - (s2.Pos-s1.Pos) / 2;
}
}
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement