#include <default.c>
#include <ackphysX3.h>
ENTITY* TopCube;
ENTITY* BottomCube;
ENTITY* myGround;
int mTest_IsOk;
//========functions
void assert( int IsOK )
{
if (!IsOK ) {
printf("assert failed");
mTest_IsOk = IsOK;
return;
}
}
void On_w_Pressed()
{
assert( pX3ent_addforcecentral ( BottomCube, vector(5,0,0) ) );
}
void main_init()
{
fps_max = 60.0;
time_factor = 1.0;
time_smooth = 0.0;
physX3_open();
level_load(NULL);
pX3_setunit( 0.1 );
pX3_setgravity(vector(0,0,-10));
}
/////////////////main for testing for friction problems
void main()
{
ENTITY* e1;
int JointID;
main_init();
wait(2);
on_w = On_w_Pressed;
/////////////////////GROUND CUBE Beg (top face at z=0)
myGround = ent_create("cube.mdl", vector(0, 0, -80.), NULL);
myGround.scale_x =100;
myGround.scale_y =100;
myGround.scale_z =10;
c_setminmax (myGround);
assert( pX3ent_settype (myGround, PH_STATIC, PH_BOX ) );
/////////////////////GROUND CUBE End
///////////////////////TOP CUBE Beg
TopCube = ent_create("cube.mdl",vector(10,0,80),NULL);
e1 = TopCube;
assert( pX3ent_settype(e1,PH_RIGID, PH_CONVEX) ); //(PH_STATIC) PH_BOX, PH_CONVEX PH_SPHERE
pX3ent_setmass(e1, 1.0);
assert( pX3ent_setmassoffset(e1, vector(0,0,0), vector(1,1,1) ) );
///////////////////////TOP CUBE End
///////////////////////BOTTOM CUBE Beg
BottomCube = ent_create("cube.mdl",vector(10,0,30),NULL);
e1 = BottomCube;
assert( pX3ent_settype(e1,PH_RIGID, PH_CONVEX) ); //(PH_STATIC) PH_BOX, PH_CONVEX PH_SPHERE
pX3ent_setmass(e1, 1.0);
assert( pX3ent_setmassoffset(e1, vector(0,0,0), vector(1,1,1) ) );
///////////////////////BOTTOM CUBE End
//////////////////////JOINT Beg
assert( JointID = pX3con_add (PH_FIXED, TopCube, BottomCube, 0 ) ); //PH_SLIDER, PH_HINGE, PH_BALL PH_FIXED
/////////////////////JOINT End
//////////Setting friction values for ground and cubes
assert( pX3ent_setfriction(myGround, 0.0) ); //0=ice; 100=rubber on rubber
assert( pX3ent_setfriction(TopCube, 100.0) ); //0=ice; 100=rubber on rubber
assert( pX3ent_setfriction(BottomCube, 0.0) ); //0=ice; 100=rubber on rubber
//When the next line is uncomment the cubes will not move when W key is pressed (ie when a force is applied)
// assert( pX3ent_setfriction(TopCube, 100.0) ); //0=ice; 100=rubber on rubber
vec_set (camera.x, vector (-20,-160, 55 ));
vec_set (camera.pan, vector (80, -15, 0 ));
while(1)
{
VECTOR vPosn, vRotn;
assert( pX3con_getposition(JointID,vPosn,vRotn) );
draw_point3d( nullvector, vector(128,0,0), 100, 2); //Blue - Global Origin
draw_point3d( vPosn, vector(0,128,0), 100, 2); //Green- Joint position
wait(1);
}
}
//==============EOF