Collision detection
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.
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 ) );
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 ) );
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement