• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Medo Mex

What's the appropriate value for step?

8 posts in this topic

You shouldn't call it at all. You add the vehicle to the world, and then this method will be called by bullet with the timestep value that bullet is configured to use.
0

Share this post


Link to post
Share on other sites
When I don't call it, the wheels are penetrating the terrain and the vehicle never move, when I call it the vehicle work and move normally, the wheels are perfectly adjusted, problem is I don't know what is the value I should use for 'step' parameter.
0

Share this post


Link to post
Share on other sites
You still should not call it.
Did you add the vehicle to the world? ( mDynamicsWorld->addVehicle(mRaycastVehicle); )

If you don't believe me, take a look at the VehicleDemo in the bullet examples. Works fine without any explicit call to updateVehicle.
0

Share this post


Link to post
Share on other sites
Yes, I added the vehicle to the dynamics world, I see that the wheels can rotate to the right and to the left, but the vehicle never move and half of the wheels are penetrating the terrain.
0

Share this post


Link to post
Share on other sites
Ok. There is something else wrong then.

A call to updateVehicle is not a solution, even though it might look like that in this particular case.
What that will do is that all suspension forces, engine forces and such are added twice. once in the real bullet update, and another time by you.
Depending on what you send in, it might also be scaled weirdly.

So its normal that you get different behaviour if you DO call it, but it can never be correct behaviour, and you still should NOT call it yourself.

There is probably something wrong with the tuning of your vehicle, or some other setup.
0

Share this post


Link to post
Share on other sites
All the RigidBodies are working perfectly, I'm only having the problem with the vehicle, here is the vehicle class that I'm using:
[CODE]#include "Vehicle.h"
#include "d3d9.h"
#include "d3dx9.h"
#include "physics.h"
#include "BulletCollision/CollisionShapes/btShapeHull.h"
//#define DEFAULT_VEHICLE_SETUP
#define DEBUG_VEHICLE_WHEEL
#define SAFE_DELETE(p) { if (p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } }
D3DXMATRIX ConvertMatrix( btTransform &trn )
{
btVector3 R = trn.getBasis().getColumn(0);
btVector3 U = trn.getBasis().getColumn(1);
btVector3 L = trn.getBasis().getColumn(2);
btVector3 P = trn.getOrigin();
D3DXVECTOR3 vR, vU, vL, vP;
vR.x = R.x();vR.y = R.y();vR.z = R.z();
vU.x = U.x();vU.y = U.y();vU.z = U.z();
vL.x = L.x();vL.y = L.y();vL.z = L.z();
vP.x = P.x();vP.y = P.y();vP.z = P.z();
D3DXMATRIX matOutput;
matOutput._11 = vR.x;matOutput._12 = vR.y;matOutput._13 = vR.z;matOutput._14 = 0.f;
matOutput._21 = vU.x;matOutput._22 = vU.y;matOutput._23 = vU.z;matOutput._24 = 0.f;
matOutput._31 = vL.x;matOutput._32 = vL.y;matOutput._33 = vL.z;matOutput._34 = 0.f;
matOutput._41 = vP.x;matOutput._42 = vP.y;matOutput._43 = vP.z;matOutput._44 = 1.f;
return matOutput;
}
btBvhTriangleMeshShape *CreateBvhTriangleMeshShape(LPD3DXMESH pMesh, TriMeshData *pData)
{
DWORD numVertices = pMesh->GetNumVertices();
DWORD numFaces = pMesh->GetNumFaces();
Vertex *v = 0;
pMesh->LockVertexBuffer(0, (void**)&v);
// Extract vertices
pData->vertices = new btScalar[numVertices * 3];
for(DWORD i = 0; i < numVertices; i++)
{
pData->vertices[i*3+0] = v[i].position.x;
pData->vertices[i*3+1] = v[i].position.y;
pData->vertices[i*3+2] = v[i].position.z;
}
pMesh->UnlockVertexBuffer();
// Extract indices
pData->indices = new int[numFaces * 3];
WORD* ind = 0;
pMesh->LockIndexBuffer(0,(void**)&ind);

//memcpy( &indices, &ind, sizeof(ind));
for(DWORD i = 0; i < numFaces; i++)
{
pData->indices[i*3+0] = ind[i*3+0];
pData->indices[i*3+1] = ind[i*3+1];
pData->indices[i*3+2] = ind[i*3+2];
}
pMesh->UnlockIndexBuffer();
int indexStride = 3 * sizeof(int);
int vertStride = sizeof(btVector3);
pData->indexVertexArrays = new btTriangleIndexVertexArray(numFaces, pData->indices, indexStride,
numVertices, (btScalar*) &pData->vertices[0], sizeof(btScalar) * 3);
bool useQuantizedAabbCompression = true;
btBvhTriangleMeshShape *shape = new btBvhTriangleMeshShape(pData->indexVertexArrays, true);
// The indices, vertices, and array needs to be manually deleted else Bullet will get a access violation
//delete indices;
//delete vertices;
//delete indexVertexArrays;
return shape;
}
btConvexHullShape *CreateConvexHullShape( LPD3DXMESH pMesh )
{
TriMeshData trimeshshape;
btBvhTriangleMeshShape *triangleMeshShape = CreateBvhTriangleMeshShape( pMesh, &trimeshshape );
btTriangleMesh* triangleMesh = new btTriangleMesh();
for(DWORD i = 0; i < pMesh->GetNumFaces(); i++)
{
int index0 = trimeshshape.indices[i*3];
int index1 = trimeshshape.indices[i*3+1];
int index2 = trimeshshape.indices[i*3+2];
btVector3 vertex0(trimeshshape.vertices[index0*3], trimeshshape.vertices[index0*3+1],trimeshshape.vertices[index0*3+2]);
btVector3 vertex1(trimeshshape.vertices[index1*3], trimeshshape.vertices[index1*3+1],trimeshshape.vertices[index1*3+2]);
btVector3 vertex2(trimeshshape.vertices[index2*3], trimeshshape.vertices[index2*3+1],trimeshshape.vertices[index2*3+2]);
triangleMesh->addTriangle(vertex0,vertex1,vertex2);
}
btConvexShape* tmpConvexShape = new btConvexTriangleMeshShape(triangleMesh);
// Create a hull approximation
btShapeHull* hull = new btShapeHull(tmpConvexShape);
btScalar margin = tmpConvexShape->getMargin();
hull->buildHull(margin);

btConvexHullShape* simplifiedConvexShape = new btConvexHullShape();
for(int i= 0; i < hull->numVertices(); i++ )
{
simplifiedConvexShape->addPoint(hull->getVertexPointer()[i]);
}
delete triangleMeshShape;
delete triangleMesh;
delete tmpConvexShape;
delete hull;
return simplifiedConvexShape;
}
btRigidBody* CreateRigidBody(float mass, const btTransform& startTransform, btCollisionShape* shape)
{
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
shape->calculateLocalInertia(mass,localInertia);

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState( startTransform );
btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia);
btRigidBody* body = new btRigidBody(cInfo);
return body;
}

Vehicle::Vehicle(void)
{
mChassisShape = NULL;
mCompoundShape = NULL;
mVehicleRaycaster = NULL;
mRaycastVehicle = NULL;
mWheelDebugMesh = NULL;
mChassisMesh = NULL;
mWheelMesh = NULL;
mSteeringValue = 0.f;
mMaxEngineForce = 3000.f; // This should be engine/velocity dependent
mMaxBreakingForce = 100.f;
mSteeringIncrement = 0.04f;
mSteeringClamp = 0.4f;
mEngineForce = 0.f;
mBreakingForce = 0.f;
mSuspensionStiffness = 20.f;
mSuspensionDamping = 2.3f;
mSuspensionCompression = 4.4f;
mWheelFriction = 1000;//1e30f;
mRollInfluence = 0.1f;//1.0f;
mChassisMesh = NULL;
mWheelMesh = NULL;
mWheelDebugMesh = NULL;
#ifdef DEFAULT_VEHICLE_SETUP
mWheelWidth = 0.4f;
mWheelRadius = 0.5f;
#else
mWheelWidth = 4.4f;
mWheelRadius = 20.5f;
#endif
mSize = 4.7f;
}
Vehicle::~Vehicle(void)
{
Destroy();
}
void Vehicle::Destroy()
{
mDynamicsWorld->removeVehicle( mRaycastVehicle );
SAFE_DELETE( mCompoundShape );
SAFE_DELETE( mChassisShape );
SAFE_DELETE( mVehicleRaycaster );
SAFE_DELETE( mRaycastVehicle );
//SAFE_RELEASE( mWheelDebugMesh );
SAFE_DELETE( mChassisMesh );
SAFE_DELETE( mWheelMesh );
SAFE_DELETE( mSimplifiedConvexShape );
}
bool Vehicle::Create( LPDIRECT3DDEVICE9 device, btDynamicsWorld *_dynamicsWorld, btVector3 &position, btScalar mass )
{
mDevice = device;
mDynamicsWorld = _dynamicsWorld;
mChassisMesh = GetChassisMesh(); // Prototype: LPD3DXMESH GetChassisMesh();
mWheelMesh = GetWheelsMesh(); // Prototype: LPD3DXMESH GetWheelsMesh();
#ifdef DEFAULT_VEHICLE_SETUP
// create a chassis shape that is proportfion to the size
mChassisShape = new btBoxShape(btVector3(1.f * mSize, 0.5f, 2.0f * mSize));
#else
mSize = 4.7f;
mChassisShape = new btConvexHullShape();
// Extract vertices from vehicle mesh
Vertex *v = 0;
mChassisMesh->LockVertexBuffer(0, (void**)&v);
for( DWORD i = 0; i < mChassisMesh->GetNumVertices(); i++ )
{
((btConvexHullShape*)mChassisShape)->addPoint( btVector3( v[i].position.x, v[i].position.y, v[i].position.z ) );
}
mChassisMesh->UnlockVertexBuffer();
#endif
mSimplifiedConvexShape = CreateConvexHullShape( mChassisMesh );
mCompoundShape = new btCompoundShape();
//mWheelWidth = 0.4f * mSize;
//mWheelRadius = 0.5f * mSize;
btTransform localTrans;
localTrans.setIdentity();
localTrans.setOrigin( btVector3(0.0f, 1.0f, 0.0f ) );
#ifdef DEFAULT_VEHICLE_SETUP
mCompoundShape->addChildShape(localTrans, mChassisShape);
#else
mCompoundShape->addChildShape(localTrans, mSimplifiedConvexShape);
#endif
localTrans.setOrigin( position );
mChassisRigidBody = CreateRigidBody( mass, localTrans, mCompoundShape );
mChassisRigidBody->setCenterOfMassTransform( localTrans );
mChassisRigidBody->setLinearVelocity(btVector3(0,0,0));
mChassisRigidBody->setAngularVelocity(btVector3(0,0,0));
mDynamicsWorld->addRigidBody(mChassisRigidBody );
mDynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(mChassisRigidBody->getBroadphaseHandle(), mDynamicsWorld->getDispatcher());
int rightIndex = 0;
int upIndex = 1;
int forwardIndex = 2;
btVector3 wheelDirectionCS0(0,-1,0);
btVector3 wheelAxleCS(-1,0,0);
btScalar suspensionRestLength(0.6);
mVehicleRaycaster = new btDefaultVehicleRaycaster(mDynamicsWorld);
mRaycastVehicle = new btRaycastVehicle(mVehicleTuning, mChassisRigidBody, mVehicleRaycaster);
// Never deactivate the vehicle
mChassisRigidBody->setActivationState(DISABLE_DEACTIVATION);
mDynamicsWorld->addVehicle(mRaycastVehicle);
#ifdef DEFAULT_VEHICLE_SETUP
float connectionHeight = 1.2f;
#else
float connectionHeight = 18.9f;
#endif
bool isFrontWheel = true;
//choose coordinate system
mRaycastVehicle->setCoordinateSystem(rightIndex, upIndex, forwardIndex);
btVector3 connectionPointCS0(mSize-(.3f*mWheelWidth),connectionHeight,2.f*mSize-mWheelRadius);
mRaycastVehicle->addWheel(btVector3(35.76, -2.0, 20.37),wheelDirectionCS0,wheelAxleCS,suspensionRestLength,mWheelRadius,mVehicleTuning,isFrontWheel);
connectionPointCS0 = btVector3(-mSize+(.3f*mWheelWidth),connectionHeight,2.f*mSize-mWheelRadius);
mRaycastVehicle->addWheel(btVector3(-35.76, -2.0, 20.37),wheelDirectionCS0,wheelAxleCS,suspensionRestLength,mWheelRadius,mVehicleTuning,isFrontWheel);
connectionPointCS0 = btVector3(-mSize+(.3f*mWheelWidth),connectionHeight,-2.f*mSize+mWheelRadius);
isFrontWheel = false;
mRaycastVehicle->addWheel(btVector3(35.76, -2.0, -20.37),wheelDirectionCS0,wheelAxleCS,suspensionRestLength,mWheelRadius,mVehicleTuning,isFrontWheel);
connectionPointCS0 = btVector3(mSize-(.3f*mWheelWidth),connectionHeight,-2.f*mSize+mWheelRadius);
mRaycastVehicle->addWheel(btVector3(-35.76, -2.0, -20.37),wheelDirectionCS0,wheelAxleCS,suspensionRestLength,mWheelRadius,mVehicleTuning,isFrontWheel);
for (int i=0;i<mRaycastVehicle->getNumWheels();i++)
{
btWheelInfo& wheel = mRaycastVehicle->getWheelInfo(i);
wheel.m_suspensionStiffness = mSuspensionStiffness;
wheel.m_wheelsDampingRelaxation = mSuspensionDamping;
wheel.m_wheelsDampingCompression = mSuspensionCompression;
wheel.m_frictionSlip = mWheelFriction;
wheel.m_rollInfluence = mRollInfluence;
}
// Create a wheel shape
#ifdef DEBUG_VEHICLE_WHEEL
btCylinderShapeX wheelShape(btVector3(mWheelWidth,mWheelRadius,mWheelRadius));
int upAxis = ((btCylinderShapeX)wheelShape).getUpAxis();
float radius = ((btCylinderShapeX)wheelShape).getRadius();
float halfHeight = ((btCylinderShapeX)wheelShape).getHalfExtentsWithMargin()[upAxis];
D3DXCreateCylinder( mDevice, radius, radius, halfHeight* 2.0f, 15, 10, &mWheelDebugMesh, NULL );
#endif
return true;
}
void Vehicle::Update( float elapsedTime )
{
if(GetKeyState( VK_UP ) & 0x8000 )
{
mEngineForce = mMaxEngineForce;
mBreakingForce = 0.f;
}
else
{
mEngineForce = 0.f;
}
if(GetKeyState( VK_DOWN ) & 0x8000 )
{
mEngineForce = -mMaxEngineForce;
mBreakingForce = 0.f;
}
else
{
mBreakingForce = 0.f;
}
if(GetKeyState( VK_LEFT ) & 0x8000 )
{
mSteeringValue -= mSteeringIncrement;
if ( mSteeringValue < -mSteeringClamp)
mSteeringValue = -mSteeringClamp;
}
else
{
// Return wheel to original position
if ( mSteeringValue <= 0.0f )
mSteeringValue += mSteeringIncrement;
}
if(GetKeyState( VK_RIGHT ) & 0x8000 )
{
mSteeringValue += mSteeringIncrement;
if(mSteeringValue > mSteeringClamp)
mSteeringValue = mSteeringClamp;
}
else
{
// Return wheel to original position
if( mSteeringValue >= 0.0f )
mSteeringValue -= mSteeringIncrement;
}
int wheelIndex = 2;
mRaycastVehicle->applyEngineForce(mEngineForce,wheelIndex);
mRaycastVehicle->setBrake(mBreakingForce,wheelIndex);
wheelIndex = 3;
mRaycastVehicle->applyEngineForce(mEngineForce,wheelIndex);
mRaycastVehicle->setBrake(mBreakingForce,wheelIndex);
wheelIndex = 0;
mRaycastVehicle->setSteeringValue(mSteeringValue,wheelIndex);
wheelIndex = 1;
mRaycastVehicle->setSteeringValue(mSteeringValue,wheelIndex);
// Update vehicle direction
btWheelInfo& wheel = mRaycastVehicle->getWheelInfo( 0 );
btVector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS;
const btVector3& right = wheel.m_raycastInfo.m_wheelAxleWS;
mForward = up.cross(right);
mForward.normalize();
}
void Vehicle::Render()
{
// Draw wheels (cylinders)
for (int i=0;i<mRaycastVehicle->getNumWheels();i++)
{
//synchronize the wheels with the (interpolated) chassis worldtransform
mRaycastVehicle->updateWheelTransform(i, true );
D3DXMATRIX matWorld = ConvertMatrix( mRaycastVehicle->getWheelInfo(i).m_worldTransform );
btVector3 pos = mRaycastVehicle->getWheelInfo(i).m_worldTransform.getOrigin();
#ifndef DEFAULT_VEHICLE_SETUP
mDevice->SetTransform( D3DTS_WORLD, &matWorld );
if( mWheelMesh )
{
//mWheelMesh->DrawSubset( 0 );
}
#endif
#ifdef DEBUG_VEHICLE_WHEEL
D3DXMATRIX matRot;
D3DXMatrixRotationZ( &matRot, D3DXToRadian(-90.0f));
D3DXMatrixMultiply(&matWorld, &matRot, &matWorld);
mDevice->SetTransform( D3DTS_WORLD, &matWorld );
//mWheelDebugMesh->DrawSubset( 0 );
mWheelMesh->DrawSubset( 0 );
#endif
}
// Draw chassis
{
btTransform trn;
mRaycastVehicle->getRigidBody()->getMotionState()->getWorldTransform( trn );
#ifndef DEFAULT_VEHICLE_SETUP
if( mChassisMesh )
{
D3DXMATRIX matWorld = ConvertMatrix( trn );
D3DXMATRIX matRot, matTrans, matScale;
// offset 1.0 for the wheel
D3DXMatrixTranslation( &matTrans, 0.0f, 1.0f, 0.0f );
D3DXMatrixMultiply(&matWorld, &matTrans, &matWorld);
mDevice->SetTransform( D3DTS_WORLD, &matWorld );
mChassisMesh->DrawSubset( 0 );
}
#else
if( shapeDrawer )
{
shapeDrawer->Render( mRaycastVehicle->getRigidBody()->getCollisionShape(), trn );
}
#endif
}
}
[/CODE]
0

Share this post


Link to post
Share on other sites
[quote name='Medo3337' timestamp='1354281937' post='5005678']
Yes, I added the vehicle to the dynamics world, I see that the wheels can rotate to the right and to the left, but the vehicle never move and half of the wheels are penetrating the terrain.
[/quote]

Have you tried to initialize the vehicle some meters over the floor? Maybe is stuck inside the floor...
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0