Jump to content
  • Advertisement
Sign in to follow this  
ollyb342

Plane/Sphere Collision Detection

This topic is 3076 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!