Made cylinders and spheres act as spheres

This commit is contained in:
FlareMicrosystems
2022-10-01 23:12:55 -07:00
parent ce999d226d
commit d3f9b74ba1
2 changed files with 135 additions and 130 deletions

View File

@@ -7,11 +7,6 @@
#include "strsafe.h" #include "strsafe.h"
#include "Application.h" #include "Application.h"
/*typedef struct typPRGP {
Instance* instance; // Declare member types
Property ∝
} PRGP;*/
std::vector<PROPGRIDITEM> prop; std::vector<PROPGRIDITEM> prop;
std::vector<Instance*> children; std::vector<Instance*> children;
Instance * selectedInstance; Instance * selectedInstance;

View File

@@ -1,130 +1,140 @@
#include "XplicitNgine/XplicitNgine.h" #include "XplicitNgine/XplicitNgine.h"
#include "Globals.h" #include "Globals.h"
#define SIDE (0.5f) #define SIDE (0.5f)
#define MASS (1.0) #define MASS (1.0)
// constraints // constraints
#define MAX_BODIES 65535 #define MAX_BODIES 65535
#define OBJ_DENSITY (5.0) #define OBJ_DENSITY (5.0)
#define MAX_CONTACT_PER_BODY 4 #define MAX_CONTACT_PER_BODY 4
XplicitNgine::XplicitNgine() XplicitNgine::XplicitNgine()
{ {
physWorld = dWorldCreate(); physWorld = dWorldCreate();
physSpace = dHashSpaceCreate(0); physSpace = dHashSpaceCreate(0);
contactgroup = dJointGroupCreate(0); contactgroup = dJointGroupCreate(0);
dWorldSetGravity(physWorld, 0, -0.5, 0); dWorldSetGravity(physWorld, 0, -0.5, 0);
//dGeomID ground_geom = dCreatePlane(physSpace, 0, 1, 0, 0); //dGeomID ground_geom = dCreatePlane(physSpace, 0, 1, 0, 0);
} }
XplicitNgine::~XplicitNgine() XplicitNgine::~XplicitNgine()
{ {
dJointGroupDestroy (contactgroup); dJointGroupDestroy (contactgroup);
dSpaceDestroy (physSpace); dSpaceDestroy (physSpace);
dWorldDestroy (physWorld); dWorldDestroy (physWorld);
dCloseODE(); dCloseODE();
} }
void collisionCallback(void *data, dGeomID o1, dGeomID o2) void collisionCallback(void *data, dGeomID o1, dGeomID o2)
{ {
int i,n; int i,n;
dBodyID b1 = dGeomGetBody(o1); dBodyID b1 = dGeomGetBody(o1);
dBodyID b2 = dGeomGetBody(o2); dBodyID b2 = dGeomGetBody(o2);
if (b1 && b2 && dAreConnected(b1, b2)) if (b1 && b2 && dAreConnected(b1, b2))
return; return;
const int N = 4; const int N = 4;
dContact contact[N]; dContact contact[N];
n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact));
if (n > 0) { if (n > 0) {
for (i=0; i<n; i++) { for (i=0; i<n; i++) {
contact[i].surface.mode = dContactSlip1 | dContactSlip2 | dContactSoftERP | dContactSoftCFM | dContactApprox1; contact[i].surface.mode = dContactSlip1 | dContactSlip2 | dContactSoftERP | dContactSoftCFM | dContactApprox1;
// Define contact surface properties // Define contact surface properties
contact[i].surface.mu = 0.5; contact[i].surface.mu = 0.5;
contact[i].surface.slip1 = 0.0; contact[i].surface.slip1 = 0.0;
contact[i].surface.slip2 = 0.0; contact[i].surface.slip2 = 0.0;
contact[i].surface.soft_erp = 0.8; contact[i].surface.soft_erp = 0.8;
contact[i].surface.soft_cfm = 0.01; contact[i].surface.soft_cfm = 0.01;
// Create joints // Create joints
dJointID c = dJointCreateContact( dJointID c = dJointCreateContact(
g_xplicitNgine->physWorld, g_xplicitNgine->physWorld,
g_xplicitNgine->contactgroup, g_xplicitNgine->contactgroup,
contact+i contact+i
); );
dJointAttach (c,b1,b2); dJointAttach (c,b1,b2);
} }
} }
} }
void XplicitNgine::createBody(PartInstance* partInstance) void XplicitNgine::createBody(PartInstance* partInstance)
{ {
// calculate collisions // calculate collisions
dSpaceCollide (physSpace,0,&collisionCallback); dSpaceCollide (physSpace,0,&collisionCallback);
if(partInstance->physBody == NULL) if(partInstance->physBody == NULL)
{ {
// init body // init body
partInstance->physBody = dBodyCreate(physWorld); partInstance->physBody = dBodyCreate(physWorld);
// Create geom // Create geom
partInstance->physGeom[0] = dCreateBox(physSpace, if(partInstance->shape == Enum::Shape::Block)
partInstance->getSize()[0], {
partInstance->getSize()[1], partInstance->physGeom[0] = dCreateBox(physSpace,
partInstance->getSize()[2] partInstance->getSize()[0],
); partInstance->getSize()[1],
partInstance->getSize()[2]
// Debug output );
dVector3 result;
dGeomBoxGetLengths(partInstance->physGeom[0], result); dVector3 result;
printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n", dGeomBoxGetLengths(partInstance->physGeom[0], result);
result[0], printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n",
result[1], result[0],
result[2] result[1],
); result[2]
);
// Create rigid body }
printf("[XplicitNgine] Created Geom for PartInstance\n"); else
dBodySetPosition(partInstance->physBody, {
partInstance->getPosition()[0], partInstance->physGeom[0] = dCreateSphere(physSpace, partInstance->getSize()[0]/2);
partInstance->getPosition()[1], }
partInstance->getPosition()[2]
);
// Debug output
Matrix3 g3dRot = partInstance->getCFrame().rotation;
float rotation [12] = { g3dRot[0][0], g3dRot[0][1], g3dRot[0][2], 0,
g3dRot[1][0], g3dRot[1][1], g3dRot[1][2], 0, // Create rigid body
g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0}; printf("[XplicitNgine] Created Geom for PartInstance\n");
dBodySetPosition(partInstance->physBody,
dBodySetRotation(partInstance->physBody, rotation); partInstance->getPosition()[0],
partInstance->getPosition()[1],
printf("[XplicitNgine] Created Body for PartInstance\n"); partInstance->getPosition()[2]
);
if(!partInstance->anchored)
dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); Matrix3 g3dRot = partInstance->getCFrame().rotation;
float rotation [12] = { g3dRot[0][0], g3dRot[0][1], g3dRot[0][2], 0,
} else { g3dRot[1][0], g3dRot[1][1], g3dRot[1][2], 0,
if(partInstance->anchored) g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0};
return;
dBodySetRotation(partInstance->physBody, rotation);
const dReal* physPosition = dBodyGetPosition(partInstance->physBody);
printf("[XplicitNgine] Created Body for PartInstance\n");
// TODO: Rotation code
// Probably should be done AFTER we get physics KINDA working!!! if(!partInstance->anchored)
const dReal* physRotation = dGeomGetRotation(partInstance->physGeom[0]); dGeomSetBody(partInstance->physGeom[0], partInstance->physBody);
//partInstance->setPosition(Vector3(physPosition[0], physPosition[1], physPosition[2]));
} else {
if(partInstance->anchored)
return;
const dReal* physPosition = dBodyGetPosition(partInstance->physBody);
// TODO: Rotation code
// Probably should be done AFTER we get physics KINDA working!!!
const dReal* physRotation = dGeomGetRotation(partInstance->physGeom[0]);
//partInstance->setPosition(Vector3(physPosition[0], physPosition[1], physPosition[2]));
partInstance->setCFrame(CoordinateFrame( partInstance->setCFrame(CoordinateFrame(
Matrix3(physRotation[0],physRotation[1],physRotation[2], Matrix3(physRotation[0],physRotation[1],physRotation[2],
physRotation[4],physRotation[5],physRotation[6], physRotation[4],physRotation[5],physRotation[6],
physRotation[8],physRotation[9],physRotation[10]), physRotation[8],physRotation[9],physRotation[10]),
Vector3(physPosition[0], physPosition[1], physPosition[2]))); Vector3(physPosition[0], physPosition[1], physPosition[2])));
} }
dWorldQuickStep(physWorld,0.05); dWorldQuickStep(physWorld,0.05);
dJointGroupEmpty(contactgroup); dJointGroupEmpty(contactgroup);
} }