#include <default.c>
#include <ackphysX.h>
#include <mtlFX.c>
PANEL* pInfo = NULL;
FONT* fA20b = "Arial#20b";
function fBallinit()
{
set(my,SHADOW|CAST);
pXent_settype(my,PH_RIGID,PH_SPHERE);
pXent_setmass(my,6);
pXent_setelasticity(my,100);
pXent_addvelcentral(my,vec_rotate(vector(1000,0,400),camera.pan));
pXent_addtorquelocal(my,vector(100,5,0));
wait(-30);
ent_remove(me);
}
function on_space_event()
{
ent_create ("basket_ball.mdl", camera.x, fBallinit);
}
function main()
{
PANEL* pInfo = pan_create(NULL,5);
pan_setdigits(pInfo,0,5,2,"%4.0f x", fA20b, 1, screen_size.x);
pan_setdigits(pInfo,0,50,2,"%4.0f", fA20b, 1, screen_size.y);
pan_setstring(pInfo,0,90,2, fA20b,str_create("PhysX Cloth Demo by Robert Judycki"));
pan_setstring(pInfo,0,5,40, fA20b,str_create("Press [Space] key to shoot a ball into the scene"));
set(pInfo, OUTLINE|SHADOW|SHOW);
shadow_stencil = 2;
fps_max = 60;
level_load("");
physX_open();
vec_set(sky_color,COLOR_BLUE);
vec_set(sun_angle.pan,vector(300,60,5000));
vec_set(camera.x,vector(-1200,0,500));
vec_set(camera.pan,vector(0,-10,0));
camera.arc = 90;
// generate ground plane
ENTITY *ground = ent_createterrain(NULL,vector(0,0,0),16,16,1000);
bmap_fill(bmap_for_entity(ground,0),COLOR_GREEN,100);
pXent_settype(NULL,PH_STATIC,PH_PLANE);
//////////////////////////////
// Cloth #1
//////////////////////////////
// generate flag pole
ENTITY *pole = ent_create(CUBE_MDL,vector(0,400,40*8),NULL);
vec_set(pole.scale_x,vector(0.5,.5,40));
vec_set(pole.pan,vector(0,0,0));
vec_set(pole.blue,COLOR_WHITE);
set(pole,SHADOW|CAST);
pXent_settype(pole,PH_STATIC,PH_BOX);
// generate flag
ENTITY *cloth = ent_create("clothflag.mdl",NULL,NULL);
vec_set(cloth.pan,vector(0,0,0));
cloth.material = mtl_twosided_alpha;
cloth.ambient = 50;
set(cloth,SHADOW|CAST);
set(cloth.material,PASS_SOLID); // required for shadow
ent_clone(cloth); // Prevents, that all clothes move the same way
// attach flag to pole
c_setminmax(pole);
c_setminmax(cloth);
vec_set(cloth.x,vector(
pole.x,
pole.y+(cloth.max_y-cloth.min_y)/2,
pole.z+pole.max_z-(cloth.max_z-cloth.min_z)/2));
// setup flag cloth
var cloth_options[40];
memcpy(cloth_options,CLOTH_DEFAULT,40*sizeof(var));
vec_set(cloth_options[25],vector(-1,-1,0)); // external acceleration
vec_set(cloth_options[28],vector(0,30,0)); // random wind acceleration
cloth_options[9] = 4; // Tear Factor
cloth_options[37] |= NX_CLF_GRAVITY|NX_CLF_BENDING|NX_CLF_COLLISION_TWOWAY|NX_CLF_SELFCOLLISION|NX_CLF_TEARABLE;
pXent_cloth(cloth,pole,NX_CLOTH_ATTACHMENT_TWOWAY,0,0,cloth_options);
//////////////////////////////
// Cloth #2
//////////////////////////////
//generate flag
ENTITY *cloth2 = ent_create("clothflag.mdl",NULL,NULL);
vec_set(cloth2.pan,vector(0,0,0));
cloth2.material = mtl_twosided_alpha;
cloth2.ambient = 50;
set(cloth2,SHADOW|CAST);
set(cloth2.material,PASS_SOLID); // required for shadow
ent_clone(cloth2); // Prevents, that all clothes move the same way
ENTITY *pole2 = ent_create(CUBE_MDL,vector(-300,-550,40*8),NULL);
vec_set(pole2.scale_x,vector(.5,.5,40));
vec_set(pole2.pan,vector(0,0,0));
vec_set(pole2.blue,COLOR_WHITE);
set(pole2,SHADOW|CAST);
pXent_settype(pole2,PH_STATIC,PH_BOX);
// attach flag to pole
c_setminmax(pole2);
c_setminmax(cloth2);
vec_set(cloth2.x,vector(pole2.x,pole2.y+(cloth2.max_y-cloth2.min_y)/2,pole2.z+pole2.max_z-(cloth2.max_z-cloth2.min_z)/2));
vec_set(cloth_options[25],vector(1,1,0)); // external acceleration
vec_set(cloth_options[28],vector(0,60,0)); // random wind acceleration
cloth_options[37] &= ~NX_CLF_TEARABLE;
pXent_cloth(cloth2,pole2,NX_CLOTH_ATTACHMENT_TWOWAY,0,0,cloth_options);
//////////////////////////////
// Cloth #3
//////////////////////////////
//generate flag
ENTITY *cloth3 = ent_create("clothflag.mdl",NULL,NULL);
vec_set(cloth3.pan,vector(0,0,0));
cloth3.pan = 180;
cloth3.material = mtl_twosided_alpha;
cloth3.ambient = 50;
set(cloth3,SHADOW|CAST);
set(cloth3.material,PASS_SOLID); // required for shadow
//ent_clone(cloth3); // Prevents, that all clothes move the same way
ENTITY *pole3 = ent_create(CUBE_MDL,vector(500,0,40*8),NULL);
vec_set(pole3.scale_x,vector(.5,.5,40));
vec_set(pole3.pan,vector(0,0,0));
vec_set(pole3.blue,COLOR_WHITE);
set(pole3,SHADOW|CAST);
pXent_settype(pole3,PH_STATIC,PH_BOX);
// attach flag to pole
c_setminmax(pole3);
c_setminmax(cloth3);
vec_set(cloth3.x,vector(pole3.x,pole3.y+cloth3.min_y,pole3.z+pole3.max_z-(cloth3.max_z-cloth3.min_z)/2));
vec_set(cloth_options[25],vector(0,1,0)); // external acceleration
vec_set(cloth_options[28],vector(0,-50,0)); // random wind acceleration
cloth_options[37] |= NX_CLF_TEARABLE;
pXent_cloth(cloth3,pole3,NX_CLOTH_ATTACHMENT_TWOWAY,0,0,cloth_options);
}