Hello,
Is anybody can tell me how to simulate a conveyor using Newton please? I just want to move some boxes on it...
Thanks in advance.
Moderator: Alain
var
dir: TVector;
Material: PNewtonMaterial;
ThisContact: PNewtonJoint;
begin
dir := VectorMake(-1, 0, 0); // -X
ThisContact := NewtonContactJointGetFirstContact(contact);
while ThisContact <> nil do
begin
Material := NewtonContactGetMaterial(ThisContact);
NewtonMaterialContactRotateTangentDirections(Material, @dir);
NewtonMaterialSetContactTangentAcceleration(Material,
10, 0);
ThisContact := NewtonContactJointGetNextContact(contact, ThisContact);
end;
end;
procedure TProcess.ConvoyeurProcess(NGDMaterialPair: TNGDMaterialPair;
contact: PNewtonJoint; timestep: Single);
var
dir: TVector;
Material: PNewtonMaterial;
ThisContact: PNewtonJoint;
ActualSpeed: Single;
begin
dir := VectorMake(-1, 0, 0); // -X
ThisContact := NewtonContactJointGetFirstContact(contact);
while ThisContact <> nil do
begin
Material := NewtonContactGetMaterial(ThisContact);
NewtonMaterialContactRotateTangentDirections(Material, @dir);
ActualSpeed := NewtonMaterialGetContactTangentSpeed(Material, 0);
NewtonMaterialSetContactElasticity(Material, 0);
NewtonMaterialSetContactTangentAcceleration(Material,
(ConvoyeurSpeed - ActualSpeed) / timestep, 0);
ThisContact := NewtonContactJointGetNextContact(contact, ThisContact);
end;
end;
Julio Jerez wrote:well is does, if you set the contact tanget velocity in teh contact call back, by setting a material.
void ConvejorBellMaterialCallback (OgreNewt::ContactJoint &contactJoint, Ogre::Real timeStep, int threadIndex)
{
Body* body0 = contactJoint.getBody0();
Body* body1 = contactJoint.getBody1();
// first, find which body represents the conveyor belt!
ConveyorBelt* belt = NULL;
OgreNewt::Body* object = NULL;
// find which body is the body floor
if (body0->getType() == mConveyorID)
{
belt = (ConveyorBelt*)body0->getUserData();
object = body1;
}
else if (body1->getType() == mConveyorID)
{
belt = (ConveyorBelt*)body1->getUserData();
object = body0;
}
if (belt)
{
// okay, found the belt... let's adjust the collision based on this.
Ogre::Vector3 thedir = belt->getGlobalDir();
for( OgreNewt::Contact contact = contactJoint.getFirstContact(); contact; contact = contact.getNext() )
{
contact.rotateTangentDirections (thedir);
Vector3 contactPos, contactNorm;
contact.getPositionAndNormal(contactPos, contactNorm);
Vector3 objectPos;
Quaternion objectOri;
object->getPositionOrientation(objectPos, objectOri);
Vector3 objectContactPointVel = object->getVelocity() + (contactPos - objectPos)*object->getOmega();
float result_accel = belt->getSpeed() - thedir.dotProduct(objectContactPointVel);
result_accel *= 10; // looks nicer
contact.setTangentAcceleration( result_accel, 0 );
}
}
}
Julio Jerez wrote:here is a contact callback to make a convefor belt king of body
- Code: Select all
void ConvejorBellMaterialCallback (OgreNewt::ContactJoint &contactJoint, Ogre::Real timeStep, int threadIndex)
{
Body* body0 = contactJoint.getBody0();
Body* body1 = contactJoint.getBody1();
// first, find which body represents the conveyor belt!
ConveyorBelt* belt = NULL;
OgreNewt::Body* object = NULL;
// find which body is the body floor
if (body0->getType() == mConveyorID)
{
belt = (ConveyorBelt*)body0->getUserData();
object = body1;
}
else if (body1->getType() == mConveyorID)
{
belt = (ConveyorBelt*)body1->getUserData();
object = body0;
}
if (belt)
{
// okay, found the belt... let's adjust the collision based on this.
Ogre::Vector3 thedir = belt->getGlobalDir();
for( OgreNewt::Contact contact = contactJoint.getFirstContact(); contact; contact = contact.getNext() )
{
contact.rotateTangentDirections (thedir);
Vector3 contactPos, contactNorm;
contact.getPositionAndNormal(contactPos, contactNorm);
Vector3 objectPos;
Quaternion objectOri;
object->getPositionOrientation(objectPos, objectOri);
Vector3 objectContactPointVel = object->getVelocity() + (contactPos - objectPos)*object->getOmega();
float result_accel = belt->getSpeed() - thedir.dotProduct(objectContactPointVel);
result_accel *= 10; // looks nicer
contact.setTangentAcceleration( result_accel, 0 );
}
}
}
Julio Jerez wrote:I can add a demo to the SDK to do just that.
Users browsing this forum: No registered users and 3 guests