I have some problem with ray cast , it grab well, but when i release the joint sometime joint library.dll crash !maybe because newtonupdate is in another thread....
Here my code :
To pick :
- Code: Select all
///variable globale pour les fonction de picking
static NewtonBody* pickedBody = NULL;
static CPhysique* class_body = NULL;
static float pickedParam = 1.0f;
static dVector rayLocalNormal;
static bool isPickedBodyDynamics;
static dVector attachmentPoint;
static NewtonUserJoint* bodyPickController;
static bool mousePickMode = false;
///
CPhysique* MousePick(NewtonWorld* nWorld,int x,int y,bool create_joint)
{
dVector p0 (ScreenToWorld(dVector (x, y, 0.0f, 0.0f)));
dVector p1 (ScreenToWorld(dVector (x, y, 1.0f, 0.0f)));
class_body = NULL;
NewtonWorldRayCast(nWorld, &p0[0], &p1[0], RayCastFilter, NULL, get_pointeur_class); //raycastfilter nous donne le body
if (pickedBody&&create_joint)
{
dMatrix matrix;
mousePickMode = true;
NewtonBodyGetMatrix(pickedBody, &matrix[0][0]);
dVector p (p0 + (p1 - p0).Scale (pickedParam));
attachmentPoint = matrix.UntransformVector (p);
// convert normal to local space
rayLocalNormal = matrix.UnrotateVector(rayLocalNormal);
// Create PickBody Joint
bodyPickController = CreateCustomKinematicController (pickedBody, &p[0]);
CustomKinematicControllerSetPickMode (bodyPickController, 1);
CustomKinematicControllerSetMaxAngularFriction (bodyPickController, MAX_FRICTION_ANGULAR_GRAVITY);
CustomKinematicControllerSetMaxLinearFriction (bodyPickController, MAX_FRICTION_LINEAR_ACCELERATION);
}
if(pickedBody)
{
return class_body;
}
else
{
return NULL;
}
}
To release pick:
- Code: Select all
void realese_picking(newtworld* world)
{
if(mousePickMode)
{
if (pickedBody)
{
CustomKinematicControllerSetPickMode (bodyPickController, 0); //I don't really understand what these three line does ...
CustomKinematicControllerSetMaxAngularFriction (bodyPickController, 10.0f);
CustomKinematicControllerSetMaxLinearFriction (bodyPickController, MAX_FRICTION_LINEAR_ACCELERATION);
if (bodyPickController)
{
CustomDestroyJoint (bodyPickController);
}
bodyPickController = NULL;
}
mousePickMode = false;
}
}
Here the crash code of windows :
Nom d’événement de problème: APPCRASH
Nom de l’application: 34.exe
Version de l’application: 0.0.0.0
Horodatage de l’application: 4c56aa6d
Nom du module par défaut: JointLibrary.dll
Version du module par défaut: 0.0.0.0
Horodateur du module par défaut: 4a8436c9
Code de l’exception: c0000005
Décalage de l’exception: 00017ea8
Version du système: 6.1.7600.2.0.0.256.1
Identificateur de paramètres régionaux: 1036
Information supplémentaire n° 1: 0a9e
Information supplémentaire n° 2: 0a9e372d3b4ad19135b953a78882e789
Information supplémentaire n° 3: 0a9e
Information supplémentaire n° 4: 0a9e372d3b4ad19135b953a78882e789
Thank you to read me !