Skip to main content
GameDev.net gamedev.net
🔒 Locked

Collision detection

Started by click Nov 7, 2002 at 11:22 AM 3 replies 250+ views
Original Post
click
click
I use bounding sphere algorithm for collision detection in my engine. I created an algoritm for calculate sphere''s center and radius. It is calculate correctly radius and center of my object. My question is When my object is moving, how can I move the Center of my object, excatly? (I know the radius should not be changed, because sphere is simetrical.) D3DXVECTOR CenterPlane; //Center of Plane object. D3DXMATRIX mat_PlaneMatrix; // Moving matrix of my plane. Show me the way. Thanks.
Fuzztrek
Fuzztrek
PLEASE learn to RESPECT the forums! You have posted this same question TEN times.

¬_¬
Lightrocker
Lightrocker
Hi click,

I use a hierarchical bounding sphere system for object culling. Transforming the center of the sphere is simple, because it is like transforming any other point in space:

D3DXMATRIX mtrxTransform; // transformation matrix of the object
D3DXVECTOR3 vct3Center; // sphere center in object space
D3DXVECTOR3 vct3AbsoluteCenter; // sphere center in world space

D3DXVec3TransformCoord( &vct3AbsoluteCenter, &vct3Center, &mtrxTransform );

Because a matrix can change the size of an object by scaling, you should also transform the radius. But it is not so easy when you want to get the correct value in a fast way. You have to transform some good points from the surface of the sphere. From the resulting points you should use the maximum to get the transform radius value.
If you only use scaling with equal values in all three dimensions, then you are able to use the following formula:
fAbsoluteRadius = D3DXVec3Length( D3DXVec3TransformNormal( &vct3Radius, &D3DXVECTOR3( D3DXVECTOR3( 0.57735f, 0.57735f, 0.57735f ) * fRadius ), &mtrxTransform ) );
lucid999
lucid999
It''s not that hard.

You move your object X units.

newCenter = oldCenter + X;

I really hope I''m misunderstanding your question. If I''m not, then maybe you need more math before attempting graphics programming.
Lightrocker
Lightrocker
If moving means the translation of the object then lucid999 is correct, but when the motion by transformation is meant then you have to transform the center, too.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.