Advertisement

Calculating Cylinder Shape Radius and Width

Started by June 19, 2013 04:05 AM
10 comments, last by Medo Mex 11 years, 8 months ago
I have LPD3DXMESH which is actually a cylinder mesh. How do I calculate width and radius?
Basically, I want to create btCylinderShapeX from LPD3DXMESH.

btCylinderShape* cylinder = new btCylinderShape(btVector3(width, radius, radius)); // How to get width and radius from the mesh (LPD3DXMESH)?

If bullet uses something like left handed system and where Y is up, and i think you should create your cylinder like in the picture:

cylinder1.jpg

then you calculate min & max of bounding box, so you can calculate cylinder width & radius:


float width = bbox.max.x - bbox.min.x;
float radius = (bbox.max.y - bbox.min.y) * 0.5f;
Advertisement

Tried that, but not getting a valid result, I even tried to different ways, but still not getting a valid result (physical shape not the same as visual mesh):


LPD3DXMESH pMesh = GetMesh();
D3DXVECTOR3 *pVertices;
pMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
D3DXVECTOR3 bMin, bMax;
D3DXComputeBoundingBox(pVertices, pMesh->GetNumVertices(), D3DXGetFVFVertexSize(pMesh->GetFVF()), &bMin, &bMax);

D3DXVECTOR3 boundingBox = (bMax - bMin);

boundingBox.x = abs(boundingBox.x);
boundingBox.y = abs(boundingBox.y);
boundingBox.z = abs(boundingBox.z);

DWORD wheelWidth = boundingBox.x * 0.5f;
DWORD wheelRadius = boundingBox.x;

pMesh->UnlockVertexBuffer();

btCylinderShape* cylinderShape = new btCylinderShape(btVector3(wheelRadius, wheelWidth, wheelRadius));

Bullet is using half extent in btCylinderShape constructor?

Change this:

DWORD wheelWidth = boundingBox.x * 0.5f;
DWORD wheelRadius = boundingBox.x;

to:

DWORD wheelWidth = boundingBox.x * 0.5f;
DWORD wheelRadius = boundingBox.y * 0.5f;

or to:

DWORD wheelWidth = boundingBox.y * 0.5f;
DWORD wheelRadius = boundingBox.x * 0.5f;

and see which one is right.

I notice that the physical shape radius is a little smaller than the actual mesh radius.

How much is "smaller" ? Be more descriptive.

Advertisement

Not much, but still get a sort of undesired mesh intersection.

The physical shape is getting like 90% of the actual mesh size.

NOTE: I noticed it's affecting the entire mesh size, not just the radius, so the physical shape is about 90% of the actual mesh size.


LPD3DXMESH pMesh = GetMesh();
D3DXVECTOR3* pVertices;
pMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
D3DXVECTOR3 bMin, bMax;
D3DXComputeBoundingBox(pVertices, pMesh->GetNumVertices(), D3DXGetFVFVertexSize(pMesh->GetFVF()), &bMin, &bMax);

D3DXVECTOR3 boundingBox = (bMax - bMin) * 0.5f;

DWORD wheelWidth = boundingBox.x;
DWORD wheelRadius = boundingBox.y;

pMesh->UnlockVertexBuffer();

btCylinderShape* cylinder = new btCylinderShapeX(btVector3(wheelWidth, wheelRadius, wheelRadius));

I would suggest one thing to clear all confusion.

Make a cylinder in modeling editor (try to create one so that height/width is not same as radius so you can easy spot the difference when debugging), write down dimensions you have used there and export mesh. Use those dimensions to create bullet shape with those hard-coded values and see if it fits visually and physically. Then compare same dimensions values with one that you calculate with bounding box to see if it is different somehow.

You know how to use breakpoints and inspect variable values at run time?

Before, I do that.

First, I tried to set the values manually according to the values in 3Ds Max, and even though it's not work, getting different shape size :/


DWORD wheelRadius = 18.881 / 2;
DWORD wheelWidth = 6.781 / 2;

btCylinderShape* cylinder = new btCylinderShapeX(btVector3(wheelWidth, wheelRadius, wheelRadius));

[attachment=16391:3Ds Max C.png]

In 3ds max Add "Reset X form" to be at top of your modifier stack

If you use Panda exportee enable/check "left handed axis" checkbox before export.

Check that Bullet is using that system too. Check that Bullet "engine" creation properties doesn't set some "skin/penetration" offsets and what not.

This topic is closed to new replies.

Advertisement