PDA

View Full Version : Help me translate this c code to pascal!



JernejL
27-10-2006, 03:51 PM
I am really getting desparate getting new car physics for use with TDC (http://www.pascalgamedevelopment.com/forums/viewtopic.php?t=975&start=165) to work, i can't possibly find the problem, which makes the vehicle dance instead standing stable. The goal of this is, to find the bug, fix the code, and help me get the project back on track, i have here a MSVC project, which can be compiled with MSVC + Newton SDK, and Delphi 7 project (uses glscene).

The original code Was written by sergey / cyko74 from newton physics engine forum. The RCV is acronym for RayCast Vehicle, the most common way of eficiently simulating a vehicle (used by practically every car game out there), each tire is a ray, raycasted onto terrain with suspension, and simulated with great stability and widely adjustable realism, it also features a simulated differential, gearbox and a drivetrain.

The facts: delphi version does not work as expected, the car dances due to unknown misterious forces.

To get the program to run, edit glscene utils3ds.pas with this quich hack to allow loading 3ds files from Zmodeler properly:


// uncomment this line:

// if MatEntry.Tag <> MAT_ENTRY then ShowError(Error3DS_INVALID_CHUNK);

// and this line here:

MAT_DECAL:
; // don't know what do to with it
else
// ShowError(Error3DS_INVALID_CHUNK)


Source Code:

MSVC:
http://www.gtatools.com/TDC/Development/rcvcode/tdcrcv.rar
http://www.gtatools.com/TDC/Development/rcvcode/rcv%20project.rar (Newer version, more stable simulation, i can't even translate older properly)

Delphi 7:
http://www.gtatools.com/TDC/Development/rcvcode/delphircv.rar

There is also a working Delphi 7 demo that uses a much older version of RCV dll, i can't get newer dll's to work with delphi, due to weird MSVC memory alingment in records, but it is doable.
This is here just to show how stable the simulation is, under proper circumstances :)
http://www.gtatools.com/TDC/Development/rcvcode/delphi_with_dll.rar

The main code is in tdcvehicle.cpp, delphi pas file is TDC_RCV.pas.
The source code is free to use for everybody and has no restrictions placed on it, so feel free to use it in other games (if you can fix it ;))

beware, the whole translated code looks rather ugly, since i did extensive re-testing and cutting/pasting code trying to fix the bug, a single run thru jedi code formatter should clean it up a bit, and i intend to re-format, improve, optimize and cleanup the code when it works.

If you can help me get the code to work, i am sure we can work out some kind of fair compensation :)

JernejL
28-10-2006, 12:51 PM
Here is the most fresh translation of new code:

http://www.gtatools.com/TDC/Development/rcvcode/tdc_rcv2.pas

I did this again from scratch, and it ends up broken in same way as the old translation, i blame the matrix code for that. Please help.

savage
28-10-2006, 01:37 PM
Having a quick look. Will let you know how I go.

savage
28-10-2006, 02:00 PM
When I try and run the demo, Terrain.3ds crashes with the following error



---------------------------
Demo1
---------------------------
An invalid Chunk structure was encountered while reading
the database. Usually caused by a corrupt database or file.
---------------------------
OK
---------------------------

JernejL
28-10-2006, 02:30 PM
Read the first post, there's a quick fix / hack for that, it is glscene bug, one day i will make a proper fix and submit it to them.

edit: i suspect one of these routines to be faulty: RotateVector, UnrotateVector, dgRollMatrix. these are translated from newton SDK's vector class headers. each function has in code several implementations that i tried, but i didn't have much luck making proper ones, so that would be a good start to start searching for the bug.

savage
28-10-2006, 04:11 PM
Btw, have you looked at using OxNewton - http://www.dave.serveusers.com/oxNewton.html ?



It is a set of dynamic,static tools more...
Working only under GLScene environement, and now all is build under Turbo Delphi.
Dynamic and Static: Cube, Sphere, Cylinder, Capped Cylinder, ChamferCylinder,
Cone, FPS Character, Ragdoll, Ragdoll SMD format with bones, vehicle and more...
All of this is already ready to use.
The oxNewton component base have change now it is a inherited TGLScene editor component.
Vehicle and ragdoll have change too and it is not only little changes but it is not so hard to convert old project.
I have a lot updates too ready to add but in the moment it is in test, I start to add this new updates in the next coming week.

JernejL
28-10-2006, 04:27 PM
Btw, have you looked at using OxNewton - http://www.dave.serveusers.com/oxNewton.html ?


heard of it, but this is not to be used with glscene, but my own engine, glscene is used just for this sandbox app to test the code. this is not same as newton's vehicle joint.

savage
28-10-2006, 07:47 PM
I have not used GLScene so I'm not sure that would be the best way to sandbox it as GLScene may be doing things *its own way* that may not be directly compatible with Newton, hence the need for the OxNewteon component.

I could not find what was the problem. If I were to look into it further I would send an email to Sascha as I'm sure he would be more than happy to help with the intricasies of Newton.

Also take a look at http://newton.delphigl.de/ and in particular his http://www.delphigl.de/files/glNewtonCarDemo2.zip . Maybe that might shed some light. It's straight OpenGL ( IIRC ).

JernejL
28-10-2006, 11:09 PM
I have not used GLScene so I'm not sure that would be the best way to sandbox it as GLScene may be doing things *its own way* that may not be directly compatible with Newton, hence the need for the OxNewteon component.

I could not find what was the problem. If I were to look into it further I would send an email to Sascha as I'm sure he would be more than happy to help with the intricasies of Newton.

Also take a look at http://newton.delphigl.de/ and in particular his http://www.delphigl.de/files/glNewtonCarDemo2.zip . Maybe that might shed some light. It's straight OpenGL ( IIRC ).

i don't think i explained what this is properly, so i will try to again:

this is not a normal newton vehicle joint vehicle simulation, NGD vehicle joint uses rigid bodies for wheels, and therefore a such simulation has its drawback: instability and high processing need.

This project is implementing a raycast car for use with newton, raycast / hovercraft car instead of using bodies to simulate wheels, use raycasting where the wheel should be, and simulates the tire reactions, this is much less intensive way and more stable to simulate vehicles.

The code is implementation of RCV / raycast vehicle in C, i am trying to translate it to pascal, C version uses some utilities from newton sdk's own vector library which are probably not working in my translation. in delphi translated implementation, glscene is only used to render the vehicle, i don't use glscene's vector libs or anything else from glscene in the vehicle sim. code.