Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: Translating heavy math code from c/c++ to pascal [ Award!! ]

  1. #1

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    This is source code for a c++ implementation of a raycast car for newton dynamics:

    http://www.gtatools.com/TDC/Developm...ascal_test.rar

    - Archive contains working delphi 7 demo that is using a bit older version of C++ DLL
    - archive contains a test program made with c++ using c++ dll, there is also source code for the whole dll and initialization part of test program, sources compile with MSVC 6.x with no problem.
    - there is also a non-working translation of code from c to pascal (sources in TDC_RCV.pas, rcv_records.pas contains the records), it all compiles but the car doesn't work as it should (note that there may be parts of code translated i commented out or added while testing it all).

    There's also a small hack for glscene to make the 3d model i used to load, the whole thing compiles with delphi 7.

    To whoever who can fix / translate the c++ code properly into pascal code (so that it compiles and works properly in test apps), i'm giving a copy of, err, nostalgic delphi 1 in excellent condition (not a scratch! ), which would look good in anyone's collection! I think it is client/server.. i know that delphi 2 to 7 also came with delphi 1 for free, but this is a original delphi 1 release with cd key and all (but no dead tree manuals)



    It's not much, but it's the best i can offer atm, but everybody would benefit from this: whole source code of this project will be availible to public, and it implements a stable raycast car dynamics for newton physics engine, with gearbox and a differential, which is quite a awesome thing in itself.

    The translated source code is free for use in any project.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  2. #2

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    Where's the rest of the C source? It's missing files like the MSVC project file, resman.h, parse.h, game1.h and many others.

  3. #3

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    There is no source code for the c++ test app, since that's not what is to translate, the goal is, to translate the DLL library source code in directory "RCV pascal test.rar\RCV pascal test\original C rcv project\rcv project\source\tdcvehicle\", the game1.cpp is just there to show how the demo program initializes the variables which are used in the gamelab3.exe which works with the dll which should be translated (except that pascal translation isn't a DLL but a normal pascal unit).
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  4. #4

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    Ok, it's been 4 days, topic got 80 views, is anybody even remotely interested in helping? the whole problem with the code is probably just a simple wrongly translated vector/matrix routine :/
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  5. #5

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    I do not think its a matter of interest, but rather of knowledge and time.

  6. #6

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    Your matrix multiplication code is wrong
    Here's the right version
    [pascal]
    function MultiplyMatrix(m, w: Tmatrix4FC): Tmatrix4FC;
    var
    x, y, i: integer;
    begin
    for x := 0 to 3 do
    for y := 0 to 3 do
    begin
    result.arr[x,y] := 0;
    for i := 0 to 3 do
    result.arr[x, y] := result.arr[x, y]+ m.arr[x, i] * w.arr[i, y];
    end;
    end;
    [/pascal]
    I couldn't figure the orientation out. You might need to transpose the result
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #7

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    Small addition: doing matrix multiplication with embedded cycle is really bad for CPUs. For performance reason you need to unroll your loop.
    There are only 10 types of people in this world; those who understand binary and those who don't.

  8. #8

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    TDC_RCV.pas line 925 - procedure DriveTrainUpdate is strange.
    in C code is :

    Code:
    void DriveTrainUpdate(TDriveTrain* pDTrain, float gas, int gear)
    {
    	float fActiveRPM;
    	static int counter = 0;
    	counter += 1;
    	float brakeCoef;
    	// telemetry
    	RCVehicle* pv = (RCVehicle*)pDTrain->pRcv;
    	dFloat* ts = pv->fTimeSlice;
    	int ofs = 45;
    
    	PrintDebug("-DriveTrainUpdate [%d]-\n", counter);
    in Pascal is :
    [pascal]
    procedure DriveTrainUpdate(var pDTrain: TDriveTrain; gas: single; gear: integer);
    var
    fActiveRPM: single;
    counter: integer;
    begin
    counter := 0;
    counter := counter + 1;

    // PrintDebug("-----DriveTrainUpdate [%d] -------\n", counter);[/pascal]


    I think there should be :

    [pascal]procedure DriveTrainUpdate(var pDTrain: TDriveTrain; gas: single; gear: integer);
    var
    fActiveRPM: Single;
    counter: Integer;
    brakeCoef: Single;
    pv: RCVehicle;
    ts: TFriction;
    ofs: Integer;
    begin
    counter := 0;
    Inc(counter);
    pv := pDTrain.pRcv;
    ts := pv.fTimeSlice;
    ofs := 45;[/pascal]


    Also from line 1019 it is strange...


    there should be in pascal this ( I think you forgot brakeCoef variable in there)

    This is just my short look.Maybe I'm wrong.
    I'll take deeper look inside...this is just first thing that I've seen...

  9. #9

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    Most of these counter and ofs variables were part of histogram in original code which i haven't translated since they are just for debugging variables. i admit my translation of the code looks very rough and bad, so it may need another re-translation to get it right

    I was suspecting force and torque newton callback to have an error and the code i uploaded isn't proper since i was doing some experiments there, this should be proper callback routine (still doesn't fix the issue):

    Code:
    procedure BaseBodyForceAndTorqueCallback(const body: PNewtonBody); cdecl;
    var
      veh: PRCVehicle;
    
      Force, torque, v: Vector;
      i: integer;
    begin
    
      veh := NewtonBodyGetUserData(body);
    
    	force:= veh.vTotal;
    	torque:= makevector(0,0,0);
    
    	for i:= 0 to 3 do
    	begin
    		force:= AddVectors(force, veh.sRay[i].vTotal);
        v:= RotateVector(veh.sRay[i].vlCol, veh.mBody);
    		torque:= AddVectors(torque, MulVectors(v, veh.sRay[i].vTotal));
    	end;
    
    	torque:= AddVectors(torque, veh.vTorque);
    
    	NewtonBodyAddForce(veh.pBody, @force);
    	NewtonBodyAddTorque(veh.pBody, @torque);
    
    	NewtonBodyGetForce(veh.pBody, @force);
    	NewtonBodyGetTorque(veh.pBody, @torque);
    
    end;
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  10. #10

    Translating heavy math code from c/c++ to pascal [ Award!! ]

    anybody else checked out anything? i'm still running in circles
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •