• Create Account

### #ActualCreatureNZ

Posted 23 December 2012 - 06:05 AM

If you have your rendering working, start by creating and drawing to objects in the world/scene. ID3DXmeshs are nice and quick to create. If you can do that, try moving them around the world independently of each other. Once you have that working, create some very basic collision tests using spheres.

if the distance between the two spheres is less than the sum of the radii squared, the objects are colliding.

http://www.gamasutra.com/view/feature/3015/pool_hall_lessons_fast_accurate_.php

Once you have this working, you can use it to further improve your collision test accuracy.

D3DXIntersect is used to test a ray (3D vector) against a ID3DXmesh, i recently used it in a project that required object selection (similar to RTS games unit selection).

This can be used for collision tests if you want, but you should use the sphere tests first.

To use D3DXIntersect, you need two vectors; one for the starting position of the ray, and another for the direction of the ray.

You also need an ID3DXmesh to do the test against. Make sure you know if the object is in world space or model space. If its in model space, you will need to multiply your vectors by the inverse of the world matrix to get them into the same space.

BOOL bHit = FALSE;
FLOAT fDistance = 0.0f;
D3DXVECTOR3 tvec3Origin;
D3DXVECTOR3 tvec3Direction;

//Intersects the ray with the mesh, sets bool with the result
D3DXIntersect(m_pMesh, &tvec3Origin, &tvec3Direction, &bHit, NULL, NULL, NULL, &fDistance, NULL, NULL);

if(bHit = TRUE)
{
//the ray has collided with the mesh
{
}
}

While this would work, I'm sure there is a much much better way of testing for collisions. The problem with using D3DXIntersect in this manner is that the ray is infinite, if an object is heading towards another, it will show up as a hit, hence the need for the second check. They way I have shown it above kind of wastes the accuracy of D3DXIntersect. A basic spherical collision test could have been performed at a fraction of the cost.

Never tried to implement rag doll physics, so not much help in that regard.

### #2CreatureNZ

Posted 22 December 2012 - 02:18 AM

If you have your rendering working, start by creating and drawing to objects in the world/scene. ID3DXmeshs are nice and quick to create. If you can do that, try moving them around the world independently of each other. Once you have that working, create some very basic collision tests using spheres.

if the distance between the two spheres is less than the sum of the radii squared, the objects are colliding.

http://www.gamasutra.com/view/feature/3015/pool_hall_lessons_fast_accurate_.php

Once you have this working, you can use it to further improve your collision test accuracy.

D3DXIntersect is used to test a ray (3D vector) against a ID3DXmesh, i recently used it in a project that required object selection (similar to RTS games unit selection).

This can be used for collision tests if you want, but you should use the sphere tests first.

Never tried to implement rag doll physics, so not much help in that regard.

### #1CreatureNZ

Posted 22 December 2012 - 02:16 AM

If you have your rendering working, start by creating and drawing to objects in the world/scene. ID3DXmeshs are nice and quick to create. If you can do that, try moving them around the world independently of each other. Once you have that working, create some very basic collision tests using spheres.

if the distance between the two spheres is less than the sum of the radii squared, the objects are colliding.

Once you have this working, you can use it to further improve your collision test accuracy.

D3DXIntersect is used to test a ray (3D vector) against a ID3DXmesh, i recently used it in a project that required object selection (similar to RTS games unit selection).

This can be used for collision tests if you want, but you should use the sphere tests first.

Never tried to implement rag doll physics, so not much help in that regard.

PARTNERS