1 registered members (AndrewAMD),
552
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Newton 2 wrapper
[Re: yorisimo]
#395777
02/27/12 15:27
02/27/12 15:27
|
Joined: Oct 2011
Posts: 1,082 Germany
Ch40zzC0d3r
Serious User
|
Serious User
Joined: Oct 2011
Posts: 1,082
Germany
|
Hey me again. I added this to my project to the bullet:
ent_create("shells/9mm.mdl", player.x, bullet_phys);
action bullet_phys()
{
wait(3);
newton_addentity(me, (float)75, NEWTON_CYLINDER, onforceandtorque);
//set(me, PASSABLE);
//pXent_settype(me,PH_RIGID,PH_CAPSULE );
//pXent_setccdskeleton( me, vector(0, 0, 0), 0 );
//pXent_setelasticity(my, 10);
}
Now its crashing with this message: Empty function called in newton_addentity What im doing wrong?
|
|
|
Re: Newton 2 wrapper
[Re: Heri]
#399812
04/20/12 14:25
04/20/12 14:25
|
Joined: Apr 2012
Posts: 62
wrekWIRED
Junior Member
|
Junior Member
Joined: Apr 2012
Posts: 62
|
I was also looking for a hinge code. can't find it or i just pass by it. By the way. Already got the grab code working but i wasn't the one i needed. It was the power mouse but i still have to figure out how to pick stuffs while in FP view and apply weight to objects. If someone can help me regarding this one i would be thankfull.
Last edited by wrekWIRED; 04/20/12 19:27.
|
|
|
Re: Newton 2 wrapper
[Re: Pappenheimer]
#399846
04/21/12 03:53
04/21/12 03:53
|
Joined: Apr 2012
Posts: 62
wrekWIRED
Junior Member
|
Junior Member
Joined: Apr 2012
Posts: 62
|
Anyone can help in converting or intigrating this newton code to lite-c? http://newtondynamics.com/forum/viewtopic.php?f=9&t=6706
/*
Containing class vars:
handOrn = target orientation quaternion
hand pos = target position
... interpolated values to follow point in front player camera somewhat smoothly
*/
void AccumulateForce (float timestep)
{
//position... (code from older newton demos)
if (!pickedBody) return;
float MOUSE_PICK_DAMP = 20.0f;
float MOUSE_PICK_STIFFNESS = 150.0f;
float ANGULAR_STIFFNESS = 0.1f;
float mass;
float Ixx;
float Iyy;
float Izz;
sVec3 com;
sVec3 veloc;
sMat4 matrix;
BodyGetMatrix(pickedBody, matrix);
BodyGetVelocity (pickedBody, veloc);
BodyGetMassMatrix (pickedBody, mass, Ixx, Iyy, Izz);
sVec3 pickedForce = handPos - matrix[3]; // body position
float mag2 = pickedForce.SqL();
if (mag2 > 20.0f * 20.0f) pickedForce *= 20.0f / sqrt (mag2);
sVec3 force (pickedForce * mass * MOUSE_PICK_STIFFNESS);
sVec3 dampForce (veloc * mass * MOUSE_PICK_DAMP);
force -= dampForce;
sVec3 grav (0.0f, mass * GRAVITY_Y, 0.0f);
force -= grav;
BodyData *data = (BodyData*) BodyGetUserData (pickedBody); // containing force and torque vectors, which are the applied in the callback
data->force += force;
// orientation...
sQuat q;
BodyGetRotation (pickedBody, q);
sVec3 curAngVel;
BodyGetAngVel (pickedBody, curAngVel); // == NewtonBodyGetOmega
sVec3 targetAngVel = AngVelFromAToB (q, handOrn) * (1 / timestep * ANGULAR_STIFFNESS);
sVec3 torque = ConvertAngVelToTorque (targetAngVel, curAngVel, matrix, timestep, mass, Ixx, Iyy, Izz);
data->torque += torque;
BodyActivate (pickedBody);
}
// utilitys...
// convert rotational offset to angular velocity (divide by time afterwards)
inline sVec3 AngVelFromAToB (const sQuat &qA, const sQuat &qB)
{
const float matchTolerance = 0.01f;
const float faultTolerance = 0.05f;
sQuat q = QuatFromAToB (qA, qB);
sVec3 *omegaDir = (sVec3*)&q;
float sql = omegaDir->SqL();
if (sql < (matchTolerance * matchTolerance))
return sVec3 (0, 0, 0);
float length = sqrt (sql);
if (q[3] < -1) q[3] = -1;
if (q[3] > 1) q[3] = 1;
sVec3 angVel = (*omegaDir / length) * (2.0 * acos(q[3]));
if (length < faultTolerance) angVel *= (length - matchTolerance) / (faultTolerance - matchTolerance);
return angVel;
}
// choose shortest rotation between 2 orientations
inline sQuat QuatFromAToB (const sQuat &qA, const sQuat &qB)
{
sQuat q;
if (qA.Dot(qB) < 0.0f)
{
q[0] = qA[0]; q[1] = qA[1]; q[2] = qA[2];
q[3] = -qA[3];
}
else
{
q[0] = -qA[0]; q[1] = -qA[1]; q[2] = -qA[2];
q[3] = qA[3];
}
return qB * q;
}
inline sVec3 ConvertAngVelToTorque ( sVec3 &targetAngVel, sVec3 ¤tAngVel, sMat4 &matrix,
float timestep, float mass, float Ixx, float Iyy, float Izz)
{
sVec3 torque = (targetAngVel - currentAngVel) / timestep;
torque = matrix.Unrotate (torque);
torque[0] *= Ixx;
torque[1] *= Iyy;
torque[2] *= Izz;
torque = matrix.Rotate (torque);
return torque;
}
I understand some of newton dynamic's function but don't understand the variables thats why i use 3dgs to make my game. Wish i can translate the code my self but been working for weeks now just to get my game physics working and can't go on without it. Thanks guys.
Last edited by wrekWIRED; 04/24/12 11:39.
|
|
|
|