Plane/Sphere Collision Detection

Started by
3 comments, last by ollyb342 13 years, 9 months ago
Hey guys,

I've been making a little 3D pong clone using Direct3D 9 and C++. I've got my meshes created/textured/imported and the scene's all set up how I want it.

I'm just a little bit stumped on how to handle collisions between the ball and the paddle?

I've looked into AABB collision detection and I have a little bit set up:

<code>
BYTE* vertices;

HRESULT hr = paddle->theMesh->LockVertexBuffer(D3DLOCK_READONLY,(LPVOID *) &vertices);
if(FAILED(hr)) PostQuitMessage(0);
D3DXVECTOR3 minBounds, maxBounds;

D3DXComputeBoundingBox((D3DXVECTOR3 *)vertices,paddle->theMesh->GetNumVertices(),D3DXGetFVFVertexSize(paddle->theMesh->GetFVF()),&minBounds,&maxBounds);
paddle->theMesh->UnlockVertexBuffer();
</code>

All credit to http://www.toymaker.info/Games/html/collisions.html

But obviously this only gives me a bounding box for object space, how do I convert the minBounds and Maxbounds vectors into world space so I can test to see if the ball intersects with them?

As usual any help is appreciated.

Ollie.
Advertisement
Does the paddle have a fixed orientation? If so, just add the paddle's position to the min and max vectors of the AABB to yield the world-space AABB.
Thanks for the swift reply.

I'm not entirely sure what fixed orientation means.. But if I understand correctly then yes it does, the paddle does not rotate and can only move in the XY plane.

Please excuse my ignorance if I got that completely wrong! =P
Quote:Please excuse my ignorance if I got that completely wrong! =P
No, you got it right.
Great thanks =)

So I'll add the paddle's position vector to both the minBounds and maxBounds vector, then do the same thing with the sphere's and use the conventional methods to see if they intersect.

Thanks for all the help JyK.

This topic is closed to new replies.

Advertisement