VehicleDemo port for BulletX (C# and XNA), but some problems

xenadu
Posts: 2
Joined: Mon Apr 14, 2008 11:33 pm

VehicleDemo port for BulletX (C# and XNA), but some problems

Post by xenadu »

I have completed a port of the VehicleDemo to BulletX, but I've run into some issues.

First, there were several places in BulletX that a Matrix was initialized this way:

Code: Select all

Matrix trans = new Matrix();
But the default constructor doesn't initialize the Matrix to identity. These lines should be changed to the following:

Code: Select all

Matrix trans = Matrix.Identity;
which is the accepted way to initialize a Matrix in XNA. This was a simple find and I'm sure someone could submit a patch for it. It was affecting the RaycastVehicle - the wheel transforms would always be off in the weeds because it was multiplying against a zero matrix instead of the Identity matrix.


The second issue is that the cylinder representing the wheels isn't rotated properly and I can't seem to get it right; adjusting the rotation matrix applied in Draw causes the steering offsets to be wrong, even when the wheels are drawn in the correct orientation to the vehicle. I'm sure it is just a matrix multiplication order problem somewhere. It may be that the RaycastVehicle isn't applying the correct transform to the wheels, or maybe the wheels are setup wrong.



The biggest issue is that the Vehicle class doesn't work from a dead stop. It just falls to the terrain and sits there motionless; none of the engine forces being applied ever translate into movement, unless you knock the vehicle in motion by impact with another body.

I didn't provide that code in the ZIP I uploaded*, but I did test the Vehicle inside the Concave demo and the only way I could get it to move was to knock it around with some boxes. If it ever came to a complete stop it would get stuck again, but as long as it kept moving you could accelerate or brake, as well as steer.


*My first attempt to port it was using the DemoGame base class and the Concave demo as a template but when that didn't work I assumed that I messed something up and I ported it from Bullet, with assistance from JBullet. In the end it appears to be a bug in BulletX since I'm seeing the same effects.



Anyway, unzip the file into the Source\XnaDevRu.BulletX folder and you should find VehicleTest.sln inside the VehicleTest folder.


Please take a look and determine if I broke the port somehow or if there is a bug in the BulletX port; if we can get this working I can clean it up and submit it as an official patch to the BulletX project.
You do not have the required permissions to view the files attached to this post.
xenadu
Posts: 2
Joined: Mon Apr 14, 2008 11:33 pm

Re: VehicleDemo port for BulletX (C# and XNA), but some problems

Post by xenadu »

Found at least one issue in my searching:


In CollisionWorld.cs, the ObjectQuerySingle method has brackets misplaced that result in the entire else.. if .IsConcave stuff being placed inside the .IsConvex if condition, meaning only Convex objects will ever get checked.

Correct the function along these lines:

Code: Select all

            public static void ObjectQuerySingle(ConvexShape castShape, Matrix rayFromTrans, Matrix rayToTrans,
						  CollisionObject collisionObject,
						  CollisionShape collisionShape,
						  Matrix colObjWorldTransform,
						  RayResultCallback resultCallback, short collisionFilterMask)
            {

            if (collisionShape.IsConvex)
            {
                      //stuff goes here
            }
            else
            {
                if (collisionShape.IsConcave)
                {
glimberg
Posts: 1
Joined: Fri Jul 11, 2008 11:33 am

Re: VehicleDemo port for BulletX (C# and XNA), but some problems

Post by glimberg »

Hello xenadu,

Have you successfully been using the Vehicle classes yet?
Im in kind of the same trouble... I have created a port of the VehicleDemo (bullet c++ version), but it dosent work.

When I apply enigne forces to the vehicle nothing happens :(

Regards
glimberg