Posted By: tex
Problem with Static Collidable Object - 08/27/14 11:56
Can someone help? I have been using the earlier version of 3DGS, pre-physX. Now I need to rewrite my code to suit the new phys engine - all good. But I can't seem to get static objects (cylinder sides) to be collidable (with the ball entities which can be picked up and moved around) - see below.
What am i doing wrong?
Cheers. (and, yes, i know I should iterate the ents but this is for some noob students to use and its easier for them to see the individual entities listed...)
What am i doing wrong?
Cheers. (and, yes, i know I should iterate the ents but this is for some noob students to use and its easier for them to see the individual entities listed...)
Code:
#include <default.c> #include <ackphysx.h> BMAP* cursor_pcx = "cursor.pcx"; ENTITY* pFocus; ENTITY* Ball; ENTITY* BOXX; ENTITY* emptyCylinderBase; ENTITY* emptyCylinderSide01; ENTITY* emptyCylinderSide02; ENTITY* emptyCylinderSide03; ENTITY* emptyCylinderSide04; ENTITY* emptyCylinderSide05; ENTITY* emptyCylinderSide06; ENTITY* emptyCylinderSide07; ENTITY* emptyCylinderSide08; ENTITY* emptyCylinderSide09; ENTITY* emptyCylinderSide10; ENTITY* emptyCylinderSide11; ENTITY* emptyCylinderSide12; var tempO[3]; //temp for orbit VECTOR vSpeed, vAngularSpeed, vForce, vMove; var light = 0.001; var heavy = 1; var gForce = -10; var cam_dist=300; var rotspd=1; ANGLE cam_ang; var minang= 0.01; var maxang=70; var mindist=20; var maxdist=3000; TEXT* tHelp = { pos_x = 10; pos_y = 10; font = "Arial#18bi"; flags = SHADOW; string("Use the following Controls:", " ", " Left Mouse Button to pick up a Block", " Shift Key after picking up a Block to rotate it", " Right Mouse Button to rotate scene", " Mouse Wheel to zoom in and out", " Arrows on the keyboard to pan around", " Arrows after picking up a Block to move it around"); } function move_that_object() { if (event_type == EVENT_CLICK) { var dist; var initialMouse[3]; var offset[3]; vec_set(offset, my.x); vec_to_screen(offset, camera); vec_sub(offset, mouse_pos); vec_set(initialMouse, mouse_pos); dist = vec_dist(camera.x,my.x); pXent_settype(my, 0, 0); mouse_pos.x = my.x; mouse_pos.y = my.y; while(mouse_left) { var temp[3]; vec_set(temp, mouse_pos); vec_add(temp, offset); temp[2] = dist; vec_for_screen(temp, camera); vec_set(my.x, temp); if(key_shift) { var temp2[3]; temp2[0] = 0.0; temp2[1] = mouse_force.y * 10; temp2[2] = mouse_force.x * 10; vec_rotate(temp2,camera.pan); //rotates mouse x and y perpendicular to camera vec_add(my.pan, temp2); } wait (1); } pXent_settype(my,PH_RIGID,PH_SPHERE); //phent_clearvelocity(my); pXent_setmass(my,light); pXent_setelasticity(my,50); pXent_setdamping(my,70,70); pXent_setmaxspeed(my,500); pXent_setfriction(my,90); //pXent_setcollisionflag //pXent_setcollisions(20000, 100); //pX_setautodisable(1.0,1.0); //this sets the physics objects to rest when not colliding } } action move_object_sphereType() { c_setminmax(my); //set(my,SHADOW); pXent_settype(my,PH_RIGID,PH_SPHERE); pXent_setmass(my,1); pXent_setfriction(my,90); pXent_setelasticity(my,50); pXent_setdamping(my,70,70); my.emask |= (ENABLE_CLICK); my.event = move_that_object; //pX_setautodisable(1.0,1.0); //this sets the physics objects to rest when not colliding } function main() { physX_open(); video_mode = 9; //shadow_stencil = 0; d3d_antialias = 1; level_load("baseX.hmp"); // load the terrain level //sun_angle.pan %= 360; //sun_angle.tilt = 45; mouse_mode = 1; // show the mouse pointer mouse_map = cursor_pcx; // set the mouse pointer bitmap set(tHelp,VISIBLE); ///////////////////////// DICE //////////////////// ent_create("ball.mdl",vector(-10,-20,70),move_object_sphereType); ent_create("ball.mdl",vector(-10,-10,70),move_object_sphereType); ent_create("ball.mdl",vector(-20,0,70),move_object_sphereType); ent_create("ball.mdl",vector(0,-20,70),move_object_sphereType); ent_create("ball.mdl",vector(-20,-10,70),move_object_sphereType); ent_create("ball.mdl",vector(0,0,70),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,80),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,90),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,100),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,60),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,50),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,40),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,30),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,20),move_object_sphereType); ent_create("ball.mdl",vector(-20,-20,10),move_object_sphereType); BOXX = ent_create("boxx.mdl",vector(140,140,40),NULL); pXent_settype(BOXX,PH_RIGID,PH_BOX); //pXent_setcollisionflag(BOXX,NULL,NX_NOTIFY_ON_START_TOUCH); ///////////////////////// EMPTY BOX //////////////////// emptyCylinderBase = ent_create("emptyCylinderBase.mdl",vector(40,40,0),NULL); emptyCylinderSide01 = ent_create("emptyCylinderSide01.mdl",vector(40,40,0),NULL); emptyCylinderSide02 = ent_create("emptyCylinderSide02.mdl",vector(40,40,0),NULL); emptyCylinderSide03 = ent_create("emptyCylinderSide03.mdl",vector(40,40,0),NULL); emptyCylinderSide04 = ent_create("emptyCylinderSide04.mdl",vector(40,40,0),NULL); emptyCylinderSide05 = ent_create("emptyCylinderSide05.mdl",vector(40,40,0),NULL); emptyCylinderSide06 = ent_create("emptyCylinderSide06.mdl",vector(40,40,0),NULL); emptyCylinderSide07 = ent_create("emptyCylinderSide07.mdl",vector(40,40,0),NULL); emptyCylinderSide08 = ent_create("emptyCylinderSide08.mdl",vector(40,40,0),NULL); emptyCylinderSide09 = ent_create("emptyCylinderSide09.mdl",vector(40,40,0),NULL); emptyCylinderSide10 = ent_create("emptyCylinderSide10.mdl",vector(40,40,0),NULL); emptyCylinderSide11 = ent_create("emptyCylinderSide11.mdl",vector(40,40,0),NULL); emptyCylinderSide12 = ent_create("emptyCylinderSide12.mdl",vector(40,40,0),NULL); set(emptyCylinderBase,TRANSLUCENT); //set(emptyCylinderSide01,TRANSLUCENT); set(emptyCylinderSide02,TRANSLUCENT); set(emptyCylinderSide03,TRANSLUCENT); set(emptyCylinderSide04,TRANSLUCENT); set(emptyCylinderSide05,TRANSLUCENT); set(emptyCylinderSide06,TRANSLUCENT); set(emptyCylinderSide07,TRANSLUCENT); set(emptyCylinderSide08,TRANSLUCENT); set(emptyCylinderSide09,TRANSLUCENT); set(emptyCylinderSide10,TRANSLUCENT); set(emptyCylinderSide11,TRANSLUCENT); set(emptyCylinderSide12,TRANSLUCENT); pXent_settype(emptyCylinderSide01,PH_RIGID,PH_BOX); //pXent_enable( emptyCylinderSide01, 1); //pXent_setcollisionflag(emptyCylinderSide01,NULL,NX_NOTIFY_ON_START_TOUCH); ///////////////////////// ORBIT FUNCTION //////////////////// //pFocus = ent_create(NULL,vector(0,0,10),NULL); pFocus = ent_create(NULL,vector(40,40,0),NULL); //pX_setgravity(vector(0,0,gForce)); //pX_setautodisable(10,10); //this sets the physics objects to rest when not colliding // initial view //vec_set(camera.x,vector(200,0,10)); //camera z-pos vec_set(camera.x,vector(40,40,0)); //camera z-pos //camera.pan = 179.99; //to stop gimble lock cam_ang.tilt = 45; //to stop gimble lock while(1) { mouse_pos.x = mouse_cursor.x; // allow the mouse pointer to move mouse_pos.y = mouse_cursor.y; // on the x and y axis // current distance from focus and ang //camera move if(mouse_right) { cam_ang.pan+= (-rotspd*mouse_force.x)*2; cam_ang.tilt+= (rotspd*mouse_force.y)*2; cam_ang.tilt=clamp(cam_ang.tilt,minang,maxang); } // zoom with mousewheel cam_dist-=integer(mickey.z)*0.1; cam_dist=clamp(cam_dist,mindist,maxdist); // do some trig to find camera location and then aim it at pFocus camera.x=pFocus.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt)); camera.y=pFocus.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt)); camera.z=pFocus.z+sin(cam_ang.tilt)*cam_dist; vec_set(tempO,pFocus.x); vec_sub(tempO,camera.x); vec_to_angle(camera.pan,tempO); vForce.x = 3 * (key_cuu - key_cud); // forward vForce.y = 3 * (key_cul - key_cur); // sideward vForce.z = 3 * (key_pgup - key_pgdn); // up/down vec_accelerate(vMove,vSpeed,vForce,0.5); vec_rotate(vMove,camera.pan); vec_add(camera.x,vMove);//moves camera with arrow keys vec_add(pFocus.x,vMove);//moves pFocus with camera/arrow keys wait(1); } }