Posted By: 3run
pXent_setposition - 03/22/13 19:34
I tried to make simple drag/drop example with "pXent_setposition", but I've noticed, that while I pick the object up, it's still affected by the gravity, and when I drop it down, it moves down very fast (as if gravity force was increasing while it was picked up). Is that a normal behavior, or one more bug?
Here is the dirty code example:
Just come close to the box, so the red square touches it (the end of the trace), to drop the box, press mouse left.
You'll notice, that as soon as you pick the box up, it slowly starts to move downwards (while it's position is changed by pXent_setposition).
Here is the dirty code example:
Code:
#include <acknex.h> #include <default.c> #include <ackphysX.h> ENTITY* movedEnt; void cubeEvent(){ // if we have the pointer, function invalid: if(movedEnt != NULL){ return; } // we are moving: movedEnt = my; } void cube(){ // flags: set(my, SHADOW | CAST | LIGHT); // random color: vec_set(my.blue, vector(150 + random(100), random(100), 0)); // set random size vec_fill(my.scale_x, 0.6 + random(0.4)); // activate physics pXent_settype(my, PH_RIGID, PH_BOX); // restitution: pXent_setelasticity(my, 30); // set random initial speed pXent_addvelcentral(my, vector(1 - random(2), 1 - random(2), 0)); // event type: my.emask |= (ENABLE_SHOOT); // event: my.event = cubeEvent; } void main(){ // shadows: shadow_stencil = 2; // limit fps: fps_max = 60; // open physX engine: physX_open(); // load empty level: level_load(""); // place camera: vec_set(camera.x, vector(-180, 0, 30)); // create ground plate ENTITY* ground = ent_create(CUBE_MDL, nullvector, NULL); // scale the cube model: vec_set(ground.scale_x, vector(20, 20, 1)); // register it as a static object: pXent_settype(ground, PH_STATIC, PH_BOX); // set it's friction: pXent_setfriction(ground, 10); // create three cubes: ent_create(CUBE_MDL, vector(random(20), random(20), 170), cube); ent_create(CUBE_MDL, vector(random(20), random(20), 170), cube); ent_create(CUBE_MDL, vector(random(20), random(20), 170), cube); // vector: VECTOR temp; // variable: var traceTime = 0; // free vector: vec_fill(temp.x, 0); // move camera: def_move(); // loop: while(1){ // define trace position: vec_set(temp.x, vector(50, 0, 0)); vec_rotate(temp.x, camera.pan); vec_add(temp.x, camera.x); // draw end position of the trace: draw_point3d(temp.x, COLOR_RED, 100, 1); // if we have moving entity: if(movedEnt != NULL){ // move entity: pXent_setposition(movedEnt, temp.x); // if we press mouse left: if(mouse_left && traceTime <= 0){ // reset pointer: movedEnt = NULL; // set timer: traceTime = 0.5; } } else{ // if needed: if(traceTime > 0){ // count down: traceTime -= time_step / 16; } else{ // define trace mode: trace_mode = IGNORE_PASSABLE | IGNORE_PASSENTS | ACTIVATE_SHOOT; // trace: c_trace(camera.x, temp.x, trace_mode); } } // wait one frame: wait(1); } }
You'll notice, that as soon as you pick the box up, it slowly starts to move downwards (while it's position is changed by pXent_setposition).