Made physics let you move stuff

This commit is contained in:
Vulpovile
2022-10-02 14:28:29 -07:00
parent 226f2adda4
commit 316359a395
8 changed files with 65 additions and 18 deletions

View File

@@ -5,7 +5,7 @@
#include <windows.h> #include <windows.h>
#include <commctrl.h> #include <commctrl.h>
#include <richedit.h> #include <richedit.h>
#include "resource.h" #include "src/include/resource.h"

View File

@@ -1,10 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by dialogs.rc
//
#define IDI_ICON1 101
#define IDB_BITMAP1 102
#define IDD_DIALOG1 103
#define IDC_EDIT1 1001
#define IDC_PROPERTYGRID 2000

View File

@@ -49,6 +49,7 @@ public:
void setVelocity(Vector3); void setVelocity(Vector3);
void setRotVelocity(Vector3); void setRotVelocity(Vector3);
void setCFrame(CoordinateFrame); void setCFrame(CoordinateFrame);
void setCFrameNoSync(CoordinateFrame);
void setSize(Vector3); void setSize(Vector3);
void setShape(Enum::Shape::Value shape); void setShape(Enum::Shape::Value shape);
void setChanged(); void setChanged();

View File

@@ -3,7 +3,7 @@
#include "DatamodelV2/Instance.h" #include "DatamodelV2/Instance.h"
#include "DatamodelV2/PartInstance.h" #include "DatamodelV2/PartInstance.h"
class XplicitNgine : Instance class XplicitNgine : public Instance
{ {
public: public:
XplicitNgine(); XplicitNgine();
@@ -13,4 +13,6 @@ public:
dJointGroupID contactgroup; dJointGroupID contactgroup;
void createBody(PartInstance* partInstance); void createBody(PartInstance* partInstance);
void deleteBody(PartInstance* partInstance);
void updateBody(PartInstance* partInstance, CoordinateFrame * cFrame);
}; };

View File

@@ -1,7 +1,7 @@
#define IDC_PROPERTYGRID 2000 #define IDC_PROPERTYGRID 2000
#define IDC_STATIC 2 #define IDC_STATIC 2
#define IDE_EDIT 105 #define IDC_EDIT1 105
#define IDI_ICON1 102 #define IDI_ICON1 102
#define IDB_BITMAP1 103 #define IDB_BITMAP1 103
#define IDD_DIALOG1 104 #define IDD_DIALOG1 104

View File

@@ -43,6 +43,11 @@ void DataModelInstance::resetEngine()
delete xplicitNgine; delete xplicitNgine;
xplicitNgine = new XplicitNgine(); xplicitNgine = new XplicitNgine();
g_xplicitNgine = xplicitNgine; g_xplicitNgine = xplicitNgine;
for(size_t i = 0; i < getWorkspace()->partObjects.size(); i++)
{
PartInstance* partInstance = getWorkspace()->partObjects[i];
partInstance->physBody = NULL;
}
} }
XplicitNgine * DataModelInstance::getEngine() XplicitNgine * DataModelInstance::getEngine()
@@ -53,6 +58,8 @@ XplicitNgine * DataModelInstance::getEngine()
void DataModelInstance::toggleRun() void DataModelInstance::toggleRun()
{ {
running = !running; running = !running;
//if(!running)
//resetEngine();
} }
bool DataModelInstance::isRunning() bool DataModelInstance::isRunning()
{ {

View File

@@ -8,6 +8,7 @@
PartInstance::PartInstance(void) PartInstance::PartInstance(void)
{ {
PVInstance::PVInstance(); PVInstance::PVInstance();
physBody = NULL;
glList = glGenLists(1); glList = glGenLists(1);
name = "Unnamed PVItem"; name = "Unnamed PVItem";
className = "Part"; className = "Part";
@@ -25,7 +26,6 @@ PartInstance::PartInstance(void)
left = Enum::SurfaceType::Smooth; left = Enum::SurfaceType::Smooth;
bottom = Enum::SurfaceType::Smooth; bottom = Enum::SurfaceType::Smooth;
shape = Enum::Shape::Block; shape = Enum::Shape::Block;
physBody = NULL;
} }
@@ -110,6 +110,7 @@ void PartInstance::setSurface(int face, Enum::SurfaceType::Value surface)
void PartInstance::setParent(Instance* prnt) void PartInstance::setParent(Instance* prnt)
{ {
g_dataModel->getEngine()->deleteBody(this);
Instance * cparent = getParent(); Instance * cparent = getParent();
while(cparent != NULL) while(cparent != NULL)
{ {
@@ -144,7 +145,7 @@ PartInstance::PartInstance(const PartInstance &oinst)
setParent(oinst.parent); setParent(oinst.parent);
anchored = oinst.anchored; anchored = oinst.anchored;
size = oinst.size; size = oinst.size;
setCFrame(oinst.cFrame); setCFrameNoSync(oinst.cFrame);
color = oinst.color; color = oinst.color;
velocity = oinst.velocity; velocity = oinst.velocity;
rotVelocity = oinst.rotVelocity; rotVelocity = oinst.rotVelocity;
@@ -156,7 +157,6 @@ PartInstance::PartInstance(const PartInstance &oinst)
bottom = oinst.bottom; bottom = oinst.bottom;
shape = oinst.shape; shape = oinst.shape;
changed = true; changed = true;
physBody = NULL;
} }
void PartInstance::setSize(Vector3 newSize) void PartInstance::setSize(Vector3 newSize)
@@ -222,7 +222,7 @@ void PartInstance::setShape(Enum::Shape::Value shape)
void PartInstance::setPosition(Vector3 pos) void PartInstance::setPosition(Vector3 pos)
{ {
position = pos; position = pos;
cFrame = CoordinateFrame(cFrame.rotation, pos); setCFrame(CoordinateFrame(cFrame.rotation, pos));
changed = true; changed = true;
} }
@@ -231,6 +231,12 @@ CoordinateFrame PartInstance::getCFrame()
return cFrame; return cFrame;
} }
void PartInstance::setCFrame(CoordinateFrame coordinateFrame) void PartInstance::setCFrame(CoordinateFrame coordinateFrame)
{
g_dataModel->getEngine()->updateBody(this, &coordinateFrame);
setCFrameNoSync(coordinateFrame);
}
void PartInstance::setCFrameNoSync(CoordinateFrame coordinateFrame)
{ {
cFrame = coordinateFrame; cFrame = coordinateFrame;
position = coordinateFrame.translation; position = coordinateFrame.translation;

View File

@@ -66,6 +66,20 @@ void collisionCallback(void *data, dGeomID o1, dGeomID o2)
} }
} }
void XplicitNgine::deleteBody(PartInstance* partInstance)
{
if(partInstance->physBody != NULL)
{
while(dBodyGetNumJoints(partInstance->physBody) > 0) {
dJointDestroy(dBodyGetJoint(partInstance->physBody, 0));
}
dBodyDestroy(partInstance->physBody);
dGeomDestroy(partInstance->physGeom[0]);
printf("Body should be destroyed");
partInstance->physBody = NULL;
}
}
void XplicitNgine::createBody(PartInstance* partInstance) void XplicitNgine::createBody(PartInstance* partInstance)
{ {
// calculate collisions // calculate collisions
@@ -131,7 +145,7 @@ void XplicitNgine::createBody(PartInstance* partInstance)
// Probably should be done AFTER we get physics KINDA working!!! // Probably should be done AFTER we get physics KINDA working!!!
const dReal* physRotation = dGeomGetRotation(partInstance->physGeom[0]); const dReal* physRotation = dGeomGetRotation(partInstance->physGeom[0]);
//partInstance->setPosition(Vector3(physPosition[0], physPosition[1], physPosition[2])); //partInstance->setPosition(Vector3(physPosition[0], physPosition[1], physPosition[2]));
partInstance->setCFrame(CoordinateFrame( partInstance->setCFrameNoSync(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]),
@@ -141,4 +155,31 @@ void XplicitNgine::createBody(PartInstance* partInstance)
dWorldQuickStep(physWorld,0.05F); dWorldQuickStep(physWorld,0.05F);
dJointGroupEmpty(contactgroup); dJointGroupEmpty(contactgroup);
}
void XplicitNgine::updateBody(PartInstance *partInstance, CoordinateFrame * cFrame)
{
if(partInstance->physBody != NULL)
{
printf("Position is supposed to be set\n");
Vector3 position = cFrame->translation;
dBodySetPosition(partInstance->physBody,
position[0],
position[1],
position[2]
);
Matrix3 g3dRot = cFrame->rotation;
float rotation [12] = { g3dRot[0][0], g3dRot[0][1], g3dRot[0][2], 0,
g3dRot[1][0], g3dRot[1][1], g3dRot[1][2], 0,
g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0};
dBodySetRotation(partInstance->physBody, rotation);
}
else
{
printf("Null???\n");
}
} }