Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, Quad), 903 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help to convert the code Physics car in aum 92 #440816
05/03/14 03:20
05/03/14 03:20
Joined: May 2008
Posts: 257
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

Joined: May 2008
Posts: 257
Hello !

Can you help me convert the code of the car with the Phyx physics engine found in 92 aum ? I tried but it does not work at all.

Code:
#include <acknex.h>

#include <default.c>

 

//vars, vectors, entities and angles

var constr_front_left;

var constr_front_right;

 

var constr_back_left;

var constr_back_right;

 

VECTOR mom_speed;

var max_angle;

var stear_contr;

 

var max_speed = 1500;

var ang_force;

var speed_contr;

 

VECTOR* vec_gravity = {x = 0; y = 0; z = -1800;}

 

ENTITY* chassis;

 

function wheel_physics_init()

{

       set (my, SHADOW);

       phent_settype (my, PH_RIGID, PH_SPHERE);

       phent_setmass (my, 30, PH_SPHERE);

       phent_setgroup (my, 2);

 

       phent_setfriction (my, 100);

       phent_setdamping (my, 20, 20);

       phent_setelasticity (my, 0, 100);

}

 

// front wheels

function front_tyre_left()

{

       wheel_physics_init();

       constr_front_left = phcon_add (PH_WHEEL, chassis, my);

       phcon_setparams1 (constr_front_left, my.x, vector (0,0,1), nullvector);

       phcon_setparams2 (constr_front_left, nullvector, nullvector, nullvector);

}

 

function front_tyre_right()

{

       wheel_physics_init();

       constr_front_right = phcon_add (PH_WHEEL, chassis, my);

       phcon_setparams1 (constr_front_right, my.x, vector (0,0,1), nullvector);

       phcon_setparams2 (constr_front_right, nullvector, nullvector, nullvector);

}

 

 

// rear wheels

function back_tyre_left()

{

       wheel_physics_init();

       constr_back_left = phcon_add (PH_WHEEL, chassis, my);

       phcon_setparams1 (constr_back_left, my.x, nullvector, vector (0,1,0));

       phcon_setparams2 (constr_back_left, nullvector, nullvector, nullvector);

}

 

function back_tyre_right()

{

       wheel_physics_init();

       constr_back_right = phcon_add (PH_WHEEL, chassis, my);

       phcon_setparams1 (constr_back_right, my.x, nullvector, vector (0,1,0));

       phcon_setparams2 (constr_back_right, nullvector, nullvector, nullvector);

}

 

function chassis_init()

{

       chassis = my;

       set (chassis, SHADOW);

       //init physics variables

       phent_settype (chassis, PH_RIGID, PH_BOX); // rigid and box as collision hull

       phent_setmass (chassis, 15, PH_BOX); // lighter than wheels to avoid tilt

       phent_setgroup (chassis, 2); // all parts of the car in one group --> no collision

 

       phent_setfriction (chassis, 20);

       phent_setdamping (chassis, 5, 5);

       phent_setelasticity (chassis, 10, 100); // only little bouncing

 

       //init car wheels

       //back

       ent_create ("car_tyre_left.mdl", vector (chassis.x - 65, chassis.y - 45, chassis.z - 20), back_tyre_left);

       ent_create ("car_tyre_right.mdl", vector (chassis.x - 65, chassis.y + 45, chassis.z - 20), back_tyre_right);

       //front

       ent_create ("car_tyre_left.mdl", vector (chassis.x + 65, chassis.y - 45, chassis.z - 20), front_tyre_left);

       ent_create ("car_tyre_right.mdl", vector (chassis.x + 65, chassis.y + 45, chassis.z - 20), front_tyre_right);

       wait(1);

}

 

void main()

{

       level_load ("test.wmb");

       //initialize the physics sub-system:

       ph_setgravity (vec_gravity);

       ph_fps_max_lock = 300;

       //init chassis

       ent_create ("chassis.mdl", vector (0,0, 100), chassis_init);

       while (!chassis) {wait (1);} // wait until the chassis appears in the level

       // speed and steering control

       while (1)

       {

               // steering control

               stear_contr = (key_d - key_a);//d = 1, a = -1, a & d = 0

 

               max_angle += stear_contr * 3 * time_step;

               max_angle = clamp (max_angle, -30, 30);

 

               if (stear_contr != 0)

               {

                       phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));

                       phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));

               }

               else

               {

                       max_angle = max_angle * (1 - (0.25 * time_step));

                       if (abs(max_angle) < 1)

                               max_angle = 0;

                       phcon_setparams2 (constr_front_left, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));

                       phcon_setparams2 (constr_front_right, vector (max_angle, max_angle, 0), nullvector, vector (95000, 500, 0));

               }

               // speed control

               speed_contr = (key_w - key_s);//w = 1, s = -1, w & s = 0

               ang_force = speed_contr * 1000 * time_step;

 

               phcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);

               phcon_setmotor (constr_back_left, nullvector, vector(-ang_force, max_speed, 0), nullvector);

 

            camera.x = chassis.x - 250 * cos(chassis.pan);

               camera.y = chassis.y - 250 * sin(chassis.pan);

               camera.pan = chassis.pan; // the camera and the car have the same pan angle

               camera.z = chassis.z + 50; // place the camera above the car, play with this value

               camera.tilt = -15; // look downwards

               

               wait(1);

       }

}



Thanks in advance Djfeeler

Re: Help to convert the code Physics car in aum 92 [Re: djfeeler] #440931
05/06/14 18:20
05/06/14 18:20
Joined: Aug 2003
Posts: 2,011
Bucharest, Romania
George Offline

Expert
George  Offline

Expert

Joined: Aug 2003
Posts: 2,011
Bucharest, Romania
I am sorry, but that is not my code. Maybe the author has an updated version of it.


Moderated by  George 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1