You should not have to set velocity every frame.
Any object should just move at the conveyor velocity as you said. If not that's a very fundamental bug.
I will check it out.
Moderators: Sascha Willems, walaber
2>ndDemoEntityManager.cpp
2>C:\dev\newton-dynamics-master\newton-4.00\applications\ndSandbox\ndDemoEntityManager.cpp(334,59): error C2259: 'ndBrainGpuContext': cannot instantiate abstract class
2>C:\dev\newton-dynamics-master\newton-4.00\sdk\dBrain\cpuEmulation\ndBrainGpuContext.h(25,7): message : see declaration of 'ndBrainGpuContext'
2>C:\dev\newton-dynamics-master\newton-4.00\applications\ndSandbox\ndDemoEntityManager.cpp(334,59): message : due to following members:
2>C:\dev\newton-dynamics-master\newton-4.00\applications\ndSandbox\ndDemoEntityManager.cpp(334,59): message : 'void ndBrainContext::Less(ndBrainFloatBuffer &,ndBrainFloat)': is abstract
/* Copyright (c) <2003-2022> <Newton Game Dynamics>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely
*/
#include "ndSandboxStdafx.h"
#include "ndSkyBox.h"
#include "ndDemoMesh.h"
#include "ndDemoCamera.h"
#include "ndPhysicsUtils.h"
#include "ndPhysicsWorld.h"
#include "ndMakeStaticMap.h"
#include "ndDemoEntityNotify.h"
#include "ndDemoEntityManager.h"
#include "ndDemoInstanceEntity.h"
class ContactNotify : public ndContactNotify
{
public:
bool disable = 0;
ContactNotify(ndScene* const scene) : ndContactNotify(scene)
{
}
bool OnAabbOverlap(const ndContact* const contact, ndFloat32 timestep) const
{
return (!disable);
}
};
static ndVector gravity (0.0f, -10.0f, 0.0f, 0.0f);
class BodyNotify : public ndBodyNotify
{
public:
BodyNotify()
:ndBodyNotify(gravity)
{
// here we set the application user data that
// goes with the game engine, for now is just null
m_applicationUserData = nullptr;
}
void OnApplyExternalForce(ndInt32, ndFloat32)
{
ndBodyDynamic* const dynamicBody = GetBody()->GetAsBodyDynamic();
if (dynamicBody)
{
ndVector massMatrix(dynamicBody->GetMassMatrix());
ndVector force(gravity.Scale(massMatrix.m_w));
dynamicBody->SetForce(force);
dynamicBody->SetTorque(ndVector::m_zero);
}
}
void OnTransform(ndInt32, const ndMatrix&)
{
}
void* m_applicationUserData;
};
static ndBodyDynamic* BuildBox (ndWorld &world, const ndMatrix& xform, ndFloat32 mass, const ndVector dim)
{
ndShapeInstance box(new ndShapeBox(dim[0], dim[1], dim[2]));
ndBodyDynamic* const body = new ndBodyDynamic();
body->SetNotifyCallback(new BodyNotify);
body->SetMatrix(xform);
body->SetCollisionShape(box);
if (mass>0.f) body->SetMassMatrix(mass, box);
ndSharedPtr<ndBody> bodyPtr(body);
world.AddBody(bodyPtr);
return body;
}
static ndBodyKinematic* BuildKinematicBox (ndWorld &world, const ndMatrix& xform, ndFloat32 mass, const ndVector dim)
{
assert (mass > 0.f);
ndShapeInstance box(new ndShapeBox(dim[0], dim[1], dim[2]));
ndBodyKinematic* const body = new ndBodyKinematic();
body->SetNotifyCallback(new BodyNotify);
body->SetMatrix(xform);
body->SetCollisionShape(box);
if (mass>0.f) body->SetMassMatrix(mass, box);
ndSharedPtr<ndBody> bodyPtr(body);
world.AddBody(bodyPtr);
return body;
}
void ndBasicRigidBody(ndDemoEntityManager* const scene)
{
constexpr ndFloat32 groundHeight = 0.f;
constexpr double PI = 3.1415926535897932384626433832795029;
ndPhysicsWorld &world = *scene->GetWorld();
world.SetSubSteps(2);
world.SetSolverIterations(12);
world.SetThreadCount(1);
ContactNotify *contactNotify = new ContactNotify(world.GetScene());
world.SetContactNotify(contactNotify);
ndVector origin(0.0f, 0.0f, 0.0f, 1.0f);
ndMatrix xform = ndGetIdentityMatrix();
ndMatrix groundXF;
ndBody *groundBody = 0;
if (1) // flat floor and walls
{
ndFloat32 angle = 0.f / 180.f * float(PI);
ndQuaternion q (ndVector (0.f,0.f,1.f,0.f), angle);
groundXF = ndCalculateMatrix (q, origin + ndVector(15.f, groundHeight + 4.f, 0.f, 0.f));
ndFloat32 size = 100;
groundXF.m_posit = origin + ndVector(0.f, -.5f+groundHeight, 0.f, 0.f);
//ndBodyDynamic* bodyFloor = BuildBox(world, groundXF, 0.f, ndVector(size * 2.f, 1.0f, size * 2.f, 0.0f));
ndBodyKinematic* bodyFloor = BuildKinematicBox(world, groundXF, 10000.f, ndVector(size * 2.f, 1.0f, size * 2.f, 0.0f));
groundBody = (ndBody*)bodyFloor;
bodyFloor->SetVelocity(ndVector(0.f,0.f,-0.1f,0.f)); // does not work; dynamic box stops moving and starts wobbling after 10 sec (newton bug?)
ndMatrix xf = groundXF;
xf.m_posit = origin + xf.RotateVector(ndVector( size, 0.f, 0.f, 0.f)); BuildBox(world, xf, 0.f, ndVector(1.0f, 5.0f, size * 2.f, 0.0f));
xf.m_posit = origin + xf.RotateVector(ndVector(-size, 0.f, 0.f, 0.f)); BuildBox(world, xf, 0.f, ndVector(1.0f, 5.0f, size * 2.f, 0.0f));
xf.m_posit = origin + xf.RotateVector(ndVector(0.f, 0.f, size, 0.f)); BuildBox(world, xf, 0.f, ndVector(size * 2.f, 5.0f, 1.0f, 0.0f));
xf.m_posit = origin + xf.RotateVector(ndVector(0.f, 0.f, -size, 0.f)); BuildBox(world, xf, 0.f, ndVector(size * 2.f, 5.0f, 1.0f, 0.0f));
}
if (1) // dynamic box, stops and starts wobbling
{
xform.m_posit = origin + ndVector(7.0f, 10.0f, 0.0f, 0.0f);
ndBodyDynamic* box = BuildBox (world, xform, 10.f, ndVector (5.f, 0.5f, 1.0f, 0.f));
}
if (1) // another dynamic box, stops at the same time
{
xform.m_posit = origin + ndVector(0.0f, 7.0f, 0.0f, 0.0f);
ndBodyDynamic* box = BuildBox (world, xform, 10.f, ndVector (1.f, 0.5f, 1.0f, 0.f));
}
ndMatrix matrix(ndGetIdentityMatrix());
matrix.m_posit.m_x -= 5.0f;
matrix.m_posit.m_y += 2.0f;
ndQuaternion rotation(ndVector(0.0f, 1.0f, 0.0f, 0.0f), -30.0f * ndDegreeToRad);
scene->SetCameraMatrix(rotation, matrix.m_posit);
}
//ndFloat32 size = 100;
//ndBodyDynamic* bodyFloor = BuildBox(world, groundXF, 0.f, ndVector(size * 2.f, 1.0f, size * 2.f, 0.0f));
//ndBodyKinematic* bodyFloor = BuildKinematicBox(world, groundXF, 10000.f, ndVector(size * 2.f, 1.0f, size * 2.f, 0.0f));
//ndSharedPtr<ndBody> bodyFloor (BuildFloorBox(scene, groundXF, true));
ndSharedPtr<ndBody> bodyFloor(BuildFlatPlane(scene, true, true));
groundBody = *bodyFloor;
// does not work; dynamic box stops moving and starts wobbling after 10 sec (newton bug?)
bodyFloor->SetVelocity(ndVector(0.f, 0.f, -0.1f, 0.f));
bodyFloor->SetVelocity(ndVector(0.f, 0.f, 0.0f, 0.f));
//ndMatrix xf = groundXF;
//xf.m_posit = origin + xf.RotateVector(ndVector(size, 0.f, 0.f, 0.f));
//BuildBox(world, xf, 0.f, ndVector(1.0f, 5.0f, size * 2.f, 0.0f));
//
//xf.m_posit = origin + xf.RotateVector(ndVector(-size, 0.f, 0.f, 0.f));
//BuildBox(world, xf, 0.f, ndVector(1.0f, 5.0f, size * 2.f, 0.0f));
//
//xf.m_posit = origin + xf.RotateVector(ndVector(0.f, 0.f, size, 0.f));
//BuildBox(world, xf, 0.f, ndVector(size * 2.f, 5.0f, 1.0f, 0.0f));
//
//xf.m_posit = origin + xf.RotateVector(ndVector(0.f, 0.f, -size, 0.f));
//BuildBox(world, xf, 0.f, ndVector(size * 2.f, 5.0f, 1.0f, 0.0f));
for (ndInt32 i = 0; i < 3; ++i)
{
if (ndAbs(covariance[i][i]) < ndFloat32(1.0e-8f))
{
for (ndInt32 j = 0; j < 3; ++j)
{
covariance[i][j] = ndFloat32(0.0f);
covariance[j][i] = ndFloat32(0.0f);
}
covariance[i][i] = ndFloat32(1.0e-8f);
}
}
Julio Jerez wrote:when the covariance matrix has a zero entry in the main diagonal, the eigen values come out wrong.
and it may mick a wrong average plane to select contacts.
#if 1
// Joe, this works, but maybe you should check what is the
// purpose of having so many overlaping background objects
ndFloat32 size = 100;
ndMatrix xf = groundXF;
xf.m_posit = origin + xf.RotateVector(ndVector(size, 0.f, 0.f, 0.f));
BuildBox(world, xf, 0.f, ndVector(1.0f, 5.0f, size * 2.f, 0.0f));
JoeJ wrote:So the velocity seems ignored, and the contacts become very soft.
I've noticed this only by pasting in my code snippet again.
With your demo they keep moving correctly, but not with mine.
So i have removed the 4 overlapping bodies forming a fence around my ground box, and then it all works as expected.![]()
.
Users browsing this forum: Google Adsense [Bot] and 84 guests