•      Sign In
• Create Account

### #ActualMuzzy A

Posted 23 June 2013 - 04:40 AM

// Structs
struct Sphere
{
Vector3 center;
float radius;
};
struct Plane
{
Vector3 normal;
float offset;
};

// Collision Check
bool SphereToPlane( Vector3 &PointToSphere,Sphere &sphere,Plane &plane )
{
// Calculates the distance from the sphere center to the plane
float dist = DotProduct(plane.normal,sphere.center) - plane.offset;

// Save out the vector between the sphere and plane
PointToSphere = plane.normal*dist;

// Check to see if the sphere is straddling the plane
if(dist < -sphere.radius || dist > sphere.radius)
return false;

return true;
}
// Reacting to the collision
bool SphereToPlaneReaction( Sphere &sphere,Plane &plane )
{
Vector3 toPoint;

// Check if there was a collision
if( !SphereToPlane(toPoint,sphere,plane) )
return false;

// See how far they penetrated each other
float fLength = toPoint.length();
float penetrationDist = sphere.radius - fLength;

toPoint /= fLength; // Normalize

// Set it's position back so it's not colliding anymore
sphere.center += toPoint * penetrationDist;

return true;
}



Ok when i collide against a plane the direction that it moves the sphere back to is basically the reflection of what it is actually supposed to be.

if the plane is flat on the ground it works perfectly but as soon as it has rotation, the it gets put in the opposite direction that it's supposed to.

I tried reflecting the final position across the normal but that didnt work. any ideas?

EDIT: I fixed it, I was calculating the normal wrong for the plane

### #5Muzzy A

Posted 23 June 2013 - 04:03 AM

// Structs
struct Sphere
{
Vector3 center;
float radius;
};
struct Plane
{
Vector3 normal;
float offset;
};

// Collision Check
bool SphereToPlane( Vector3 &PointToSphere,Sphere &sphere,Plane &plane )
{
// Calculates the distance from the sphere center to the plane
float dist = DotProduct(plane.normal,sphere.center) - plane.offset;

// Save out the vector between the sphere and plane
PointToSphere = plane.normal*dist;

// Check to see if the sphere is straddling the plane
if(dist < -sphere.radius || dist > sphere.radius)
return false;

return true;
}
// Reacting to the collision
bool SphereToPlaneReaction( Sphere &sphere,Plane &plane )
{
Vector3 toPoint;

// Check if there was a collision
if( !SphereToPlane(toPoint,sphere,plane) )
return false;

// See how far they penetrated each other
float fLength = toPoint.length();
float penetrationDist = sphere.radius - fLength;

toPoint /= fLength; // Normalize

// Set it's position back so it's not colliding anymore
sphere.center += toPoint * penetrationDist;

return true;
}



Ok when i collide against a plane the direction that it moves the sphere back to is basically the reflection of what it is actually supposed to be.

if the plane is flat on the ground it works perfectly but as soon as it has rotation, the it gets put in the opposite direction that it's supposed to.

I tried reflecting the final position across the normal but that didnt work. any ideas?

### #4Muzzy A

Posted 23 June 2013 - 04:02 AM

// Structs
struct Sphere
{
Vector3 center;
float radius;
};
struct Plane
{
Vector3 normal;
float offset;
};

// Collision Check
bool SphereToPlane( Vector3 &PointToSphere,Sphere &sphere,Plane &plane )
{
// Calculates the distance from the sphere center to the plane
float dist = DotProduct(plane.normal,sphere.center) - plane.offset;

// Save out the vector between the sphere and plane
PointToSphere = plane.normal*dist;

// Check to see if the sphere is straddling the plane
if(dist < -sphere.radius || dist > sphere.radius)
return false;

return true;
}
// Reacting to the collision
bool SphereToPlaneReaction( IMovable *sphereObj,IMovable *planeObj,Sphere &sphere,Plane &plane )
{
Vector3 toPoint;

// Check if there was a collision
if( !SphereToPlane(toPoint,sphere,plane) )
return false;

// See how far they penetrated each other
float fLength = toPoint.length();
float penetrationDist = sphere.radius - fLength;

toPoint /= fLength; // Normalize

// Set it's position back so it's not colliding anymore
sphere.center += toPoint * penetrationDist;

return true;
}



Ok when i collide against a plane the direction that it moves the sphere back to is basically the reflection of what it is actually supposed to be.

if the plane is flat on the ground it works perfectly but as soon as it has rotation, the it gets put in the opposite direction that it's supposed to.

I tried reflecting the final position across the normal but that didnt work. any ideas?

### #3Muzzy A

Posted 23 June 2013 - 04:02 AM

// Structs
struct Sphere
{
Vector3 center;
float radius;
};
struct Plane
{
Vector3 normal;
float offset;
};

// Collision Check
bool SphereToPlane( Vector3 &PointToSphere,Sphere &sphere,Plane &plane )
{
// Calculates the distance from the sphere center to the plane
float dist = DotProduct(plane.normal,sphere.center) - plane.offset;

// Save out the vector between the sphere and plane
PointToSphere = plane.normal*dist;

// Check to see if the sphere is straddling the plane
if(dist < -sphere.radius || dist > sphere.radius)
return false;

return true;
}


// Reacting to the collision
bool SphereToPlaneReaction( IMovable *sphereObj,IMovable *planeObj,Sphere &sphere,Plane &plane )
{
Vector3 toPoint;

// Check if there was a collision
if( !SphereToPlane(toPoint,sphere,plane) )
return false;

// See how far they penetrated each other
float fLength = toPoint.length();
float penetrationDist = sphere.radius - fLength;

toPoint /= fLength; // Normalize

// Set it's position back so it's not colliding anymore
sphere.center += toPoint * penetrationDist;

return true;
}



Ok when i collide against a plane the direction that it moves the sphere back to is basically the reflection of what it is actually supposed to be.

if the plane is flat on the ground it works perfectly but as soon as it has rotation, the it gets put in the opposite direction that it's supposed to.

I tried reflecting the final position across the normal but that didnt work. any ideas?

### #2Muzzy A

Posted 23 June 2013 - 04:01 AM

// Structs
struct Sphere
{
Vector3 center;
float radius;
};
struct Plane
{
Vector3 normal;
float offset;
};

// Collision Check
bool SphereToPlane( Vector3 &PointToSphere,Sphere &sphere,Plane &plane )
{
// Calculates the distance from the sphere center to the plane
float dist = DotProduct(plane.normal,sphere.center) - plane.offset;

// Save out the vector between the sphere and plane
PointToSphere = plane.normal*dist;

// Check to see if the sphere is straddling the plane
if(dist < -sphere.radius || dist > sphere.radius)
return false;

return true;
}


// Reacting to the collision
bool SphereToPlaneReaction( IMovable *sphereObj,IMovable *planeObj,Sphere &sphere,Plane &plane )
{
Vector3 toPoint;

// Check if there was a collision
if( !SphereToPlane(toPoint,sphere,plane) )
return false;

// See how far they penetrated each other
float fLength = toPoint.length();
float penetrationDist = sphere.radius - fLength;

toPoint /= fLength; // Normalize

// Set it's position back so it's not colliding anymore
sphere.center += toPoint * penetrationDist;

return true;
}



Ok when i collide against a plane the direction that it moves the sphere back to is basically the reflection of what it is actually supposed to be.

### #1Muzzy A

Posted 23 June 2013 - 04:00 AM

// Structs
struct Sphere
{
Vector3 center;
float radius;
};
struct Plane
{
Vector3 normal;
float offset;
};


// Collision Check
bool SphereToPlane( Vector3 &PointToSphere,Sphere &sphere,Plane &plane )
{
// Calculates the distance from the sphere center to the plane
float dist = DotProduct(plane.normal,sphere.center) - plane.offset;

// Save out the vector between the sphere and plane
PointToSphere = plane.normal*dist;

// Check to see if the sphere is straddling the plane
if(dist < -sphere.radius || dist > sphere.radius)
return false;

return true;
}


// Reacting to the collision
bool SphereToPlaneReaction( IMovable *sphereObj,IMovable *planeObj,Sphere &sphere,Plane &plane )
{
Vector3 toPoint;

// Check if there was a collision
if( !SphereToPlane(toPoint,sphere,plane) )
return false;

// See how far they penetrated each other
float fLength = toPoint.length();
float penetrationDist = sphere.radius - fLength;

toPoint /= fLength; // Normalize

// Set it's position back so it's not colliding anymore
sphere.center += toPoint * penetrationDist;

return true;
}


PARTNERS