pXcon_add ( var constraintType, ENTITY* entity1, ENTITY* entity2, var intern_collision ); |
Establishes a new constraint on entity1 and entity2. The type of constraint is specified by constraintType. When successful, a constraint_id is returned which can be used in subsequent pXcon_ calls. entity2 can be set to 0 for most constraints (excluding PH_WHEEL, which requires 2 entities)- in this case entity1 is constrained to the world instead. Some constraints automatically set up default values, PH_HINGE and PH_BALL set the anchor point to lie in the middle between the entities' origins.
Parameters: |
constraintType |
one of the supported constraint constants PH_HINGE, PH_WHEEL, PH_BALL, PH_SLIDER (also used by the ODE physics ) |
entity1 |
first entity of constraint |
entity2 |
second entity of constraint or NULL when not required |
intern_collision |
1 = let entity1 and entity2 collide, 0 = no intern collision |
Returns: |
constraint_id - unique identifier of this constraint.
Speed: |
Medium
... var hingeID; var axis[3]= 1,0,0; // pendulum is allowed to rotate only along the x-axis var anchor[3]; vec_set( anchor, blade_entity.x ); anchor.z = ceiling_height; // anchor point is now above blade at the specified height // this sets up a hinged pendulum, suspended from the ceiling hingeID= pXcon_add( PH_HINGE, blade_entity,NULL,0); pXcon_setparams1(hingeID,anchor,axis,nullvector); ... function joints_test() { chain1 = ent_create("shell2.mdl",vector(-40,100,65),NULL); chain2 = ent_create("shell2.mdl",vector(-40,100,39),NULL); chain3 = ent_create("shell2.mdl",vector(-40,100,13),NULL); set(chain1,PASSABLE); set(chain2,PASSABLE); set(chain3,PASSABLE); pXent_settype(chain1,1,PH_CAPSULE); pXent_settype(chain2,1,PH_CAPSULE); pXent_settype(chain3,1,PH_CAPSULE); pXcon_add ( PH_SLIDER, chain1, NULL, 0 ); pXcon_add ( PH_HINGE, chain2, chain1, 0 ); pXcon_add ( PH_BALL, chain3, chain2, 1 ); pXcon_setparams1 (chain1, vector(chain1.x,chain1.y,chain1.z+chain1.max_z), vector(0,-1,0), nullvector ); pXcon_setparams1 (chain2, vector(chain2.x,chain2.y,chain2.z+chain2.max_z), vector(-1,0,0), nullvector ); pXcon_setparams1 (chain3, vector(chain3.x,chain3.y,chain3.z+chain3.max_z), vector(0,-1,0), nullvector ); pXcon_setparams2 (chain1, vector(-1.6,1.6,50), nullvector, nullvector ); pXcon_setparams2 (chain2, vector(-45,45,0), nullvector, nullvector ); pXcon_setparams2 (chain3, vector(-45,45,0), nullvector, nullvector ); pXent_setsleep(chain1, 1); pXent_setsleep(chain2, 1); pXent_setsleep(chain3, 1); }
pXcon_remove, pXcon_setparams1, pXcon_setparams2, pXcon_add6djoint