Carli wrote:Julio Jerez wrote:That is the function the engine used to read the force and or velocity at a contact point.
what result it is giniong you? and what do you expect it to be?
I get 0
and I expect a value >0 when it was a "real" hit.
I'm having a rock colliding with the ground and on each hit, it sould play a hit sound. (but not on rolling)
@ledahut: your solution does not have any effect on the velocity.
velocity still grows the longer the rock is rolling.
actually 0 is the correct value, what you are decribing teh engine is doing is a perfect physical behevoir,
it may look extrange to you but that is wha the law of physics will do in reality.
this is what happens, when rock body hit the floor it has in instavelocity at each conat point, thefore to prevene penetration teh engien apply and impulse.
this is why you see and velocity at eteh contact point.
bu the the goer to rest on the suface normal and teh engien no longe nee to apply inpulse to prevenet penetration, it only nee to apply a force.
so you get contac velocity zero, but to get a force andteh contac point.
niether one of those value are of any use for rolling sound effect.
however you can appli no only rilling effect but evne frition effect different tha rolling.
for a friction effect all you nee to do is measure the tangent speed at eh contact point if is larger tha some small value it means teh body is sliding at the contat point.
for rolling effect you you need to do is measure the contact absolute velocity,
using body velocity, angular velocity, conta point position and contat and you do this, here is the modified funtion to do that
- Code: Select all
void CheckIfBodiesCollide (NewtonBody* body)
{
// also determine if the body is in rolling motion
dVector omega;
dVector velocity;
NewtonBodyGetVelocity(body, velocity);
NewtonBodyGetVelocity(body, omega);
int maxImpactSpeed = 0;
int maxMaxRollingSpeed = 0;
for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (body); joint; joint = NewtonBodyGetNextContactJoint (body, joint)) {
for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {
dFloat speed;
dVector point;
dVector normal;
//dVector dir0;
//dVector dir1;
//dVector force;
NewtonMaterial* material;
material = NewtonContactGetMaterial (contact);
// you can get all the information you want
//NewtonMaterialGetContactForce (material, &force.m_x);
NewtonMaterialGetContactPositionAndNormal (material, &point.m_x, &normal.m_x);
//NewtonMaterialGetContactTangentDirections (material, &dir0.m_x, &dir1.m_x);
// get the impat velocity for impact sound
speed = NewtonMaterialGetContactNormalSpeed(material);
if (speed > maxImpactSpeed) {
maxImpactSpeed = speed;
// may wnat to save teh poition for 3d sound too.
}
// determine if the contact is rolling.
// get tangent vector to the normal and perpendicular to the body velocity
dVector lateralAxis (velocity * normal);
//Get the magnitude of the velocity along this
dFloat mag2 = lateralAxis % lateralAxis;
// check if it is significant
if (mag2 > (0.5f * 0.5f)) {
// the center is moving parallel to the contact get the speed of teh contact along thsi diretion
dFloat rollingAngularSpeed = fabsf ((omega % lateralAxis) / dSqrt (mag2));
if (rollingAngularSpeed > maxMaxRollingSpeed) {
maxMaxRollingSpeed = rollingAngularSpeed ;
// may wnat to save teh position also
}
}
}
}
if (maxImpactSpeed > someValue) {
// play impact sound
}
if (maxMaxRollingSpeed > someRollingValue) {
// play impact sound
// play the looping rolling sound and set the volume base on maxMaxRollingSpeed
// the sound mamager sould take care of when the sound in not playing more to stop it or re initializ it.
}
}
with that funtion you will see that you will get the hit sound, that it will stop, but ar eteh rock start to roll down teh hill it veloicity will grow gradually,
thefore the value of maxRolling sound will increase proportionally to the speed, and you will use that to control the volume of the rolling sound.
so as is move faster will is sound lowder.
if you is also save contact position it will also sound at the poistion that is support to.
is that what you want?