Improved snap solver
Uses ODE collision detection instead
This commit is contained in:
@@ -249,7 +249,7 @@ void Application::onInit() {
|
|||||||
test3->setSize(Vector3(4,1,2));
|
test3->setSize(Vector3(4,1,2));
|
||||||
test3->setPosition(Vector3(4,3,0));
|
test3->setPosition(Vector3(4,3,0));
|
||||||
test3->setSurface(TOP, Enum::SurfaceType::Bumps);
|
test3->setSurface(TOP, Enum::SurfaceType::Bumps);
|
||||||
JointsSvc->createSnap(test2, test3);
|
//JointsSvc->createSnap(test2, test3);
|
||||||
|
|
||||||
|
|
||||||
test = makePart();
|
test = makePart();
|
||||||
@@ -265,7 +265,7 @@ void Application::onInit() {
|
|||||||
test->setSize(Vector3(4,1,2));
|
test->setSize(Vector3(4,1,2));
|
||||||
test->setPosition(Vector3(1,4,0));
|
test->setPosition(Vector3(1,4,0));
|
||||||
test->setSurface(TOP, Enum::SurfaceType::Bumps);
|
test->setSurface(TOP, Enum::SurfaceType::Bumps);
|
||||||
JointsSvc->createSnap(test, test3);
|
//JointsSvc->createSnap(test, test3);
|
||||||
//JointsSvc->solvePartSnap(test3, test);
|
//JointsSvc->solvePartSnap(test3, test);
|
||||||
|
|
||||||
test = makePart();
|
test = makePart();
|
||||||
|
|||||||
@@ -33,39 +33,20 @@ void JointsService::destroyPartSnap(PartInstance* Part)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointsService::solvePartSnap(PartInstance* Part, PartInstance* Part2)
|
void JointsService::solvePartSnap(PartInstance* Part1, PartInstance* Part2)
|
||||||
{
|
{
|
||||||
float MoE = 0.05f;
|
XplicitNgine* Phys = g_dataModel->getEngine();
|
||||||
float TopSurface = (Part->getPosition().y + Part->getSize().y / 2);
|
float TopSurface = (Part1->getPosition().y + Part1->getSize().y / 2);
|
||||||
float RightRECT = (Part->getPosition().x + Part->getSize().x / 2) - MoE;
|
|
||||||
float LeftRECT = (Part->getPosition().x - Part->getSize().x / 2) + MoE;
|
|
||||||
float TopRECT = (Part->getPosition().z - Part->getSize().z / 2) + MoE;
|
|
||||||
float BottomRECT = (Part->getPosition().z + Part->getSize().z / 2) - MoE;
|
|
||||||
|
|
||||||
float BottomSurface2 = (Part2->getPosition().y - Part2->getSize().y / 2);
|
float BottomSurface2 = (Part2->getPosition().y - Part2->getSize().y / 2);
|
||||||
float RightRECT2 = (Part2->getPosition().x + Part2->getSize().x / 2);
|
const int N = 4;
|
||||||
float LeftRECT2 = (Part2->getPosition().x - Part2->getSize().x / 2);
|
|
||||||
float TopRECT2 = (Part2->getPosition().z - Part2->getSize().z / 2);
|
|
||||||
float BottomRECT2 = (Part2->getPosition().z + Part2->getSize().z / 2);
|
|
||||||
|
|
||||||
std::cout << "TopSurface: " << TopSurface << std::endl;
|
|
||||||
std::cout << "BottomSurface2: " << BottomSurface2 << std::endl;
|
|
||||||
if (TopSurface == BottomSurface2)
|
if (TopSurface == BottomSurface2)
|
||||||
{
|
{
|
||||||
std::cout << "Same Y cordinate!!!" << std::endl;
|
Phys->createBody(Part1);
|
||||||
//https://gamedev.stackexchange.com/questions/586/what-is-the-fastest-way-to-work-out-2d-bounding-box-intersection
|
Phys->createBody(Part2);
|
||||||
bool Intersect = !(LeftRECT2 > RightRECT
|
dContact contact[N];
|
||||||
|| RightRECT2 < LeftRECT
|
int n = dCollide (Part1->physGeom[0],Part2->physGeom[0],N,&contact[0].geom,sizeof(dContact));
|
||||||
|| TopRECT2 > BottomRECT
|
if (n > 0)
|
||||||
|| BottomRECT2 < TopRECT);
|
createSnap(Part1, Part2);
|
||||||
if (Intersect){
|
|
||||||
std::cout << "Intersects!!!" << std::endl;
|
|
||||||
createSnap(Part, Part2);
|
|
||||||
}else{
|
|
||||||
std::cout << "Does not Intersect!!!" << std::endl;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
std::cout << "Y cordinate does not match!!!" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
XplicitNgine::XplicitNgine()
|
XplicitNgine::XplicitNgine()
|
||||||
{
|
{
|
||||||
|
|
||||||
physWorld = dWorldCreate();
|
physWorld = dWorldCreate();
|
||||||
physSpace = dHashSpaceCreate(0);
|
physSpace = dHashSpaceCreate(0);
|
||||||
contactgroup = dJointGroupCreate(0);
|
contactgroup = dJointGroupCreate(0);
|
||||||
@@ -159,7 +158,8 @@ void XplicitNgine::createBody(PartInstance* partInstance)
|
|||||||
dGeomSetData(partInstance->physGeom[0], partInstance);
|
dGeomSetData(partInstance->physGeom[0], partInstance);
|
||||||
|
|
||||||
dMass mass;
|
dMass mass;
|
||||||
mass.setBox(sqrt(partSize.x*2), sqrt(partSize.y*2), sqrt(partSize.z*2), 0.7F);
|
mass.setBox(sqrt(partSize.x*20), sqrt(partSize.y*20), sqrt(partSize.z*20), 0.01F);
|
||||||
|
//mass.setBox(sqrt(partSize.x*2), sqrt(partSize.y*2), sqrt(partSize.z*2), 0.7F);
|
||||||
dBodySetMass(partInstance->physBody, &mass);
|
dBodySetMass(partInstance->physBody, &mass);
|
||||||
|
|
||||||
// Create rigid body
|
// Create rigid body
|
||||||
|
|||||||
Reference in New Issue
Block a user