From 2f3cb4380727c88180a21072003537f121fa6205 Mon Sep 17 00:00:00 2001 From: Modnark <66146584+Modnark@users.noreply.github.com> Date: Sat, 1 Oct 2022 17:32:48 -0400 Subject: [PATCH 01/14] init --- Blocks3D.vcproj | 31 ++-- src/include/Application.h | 2 + src/include/CameraController.h | 1 + src/include/DataModelV2/Instance.h | 4 - src/include/DataModelV2/PVInstance.h | 1 + src/include/DataModelV2/PartInstance.h | 2 + src/include/DataModelV2/WorkspaceInstance.h | 1 + src/include/Globals.h | 3 +- src/include/XplicitNgine/XplicitNgine.h | 15 ++ src/include/resource.h | 7 + src/include/winver.h | 5 - src/source/Application.cpp | 182 +++---------------- src/source/CameraController.cpp | 5 + src/source/DataModelV2/DataModelInstance.cpp | 3 +- src/source/DataModelV2/Instance.cpp | 1 + src/source/DataModelV2/PartInstance.cpp | 12 +- src/source/DataModelV2/WorkspaceInstance.cpp | 8 +- src/source/Globals.cpp | 1 + src/source/PropertyWindow.cpp | 2 +- src/source/Tool/ArrowTool.cpp | 24 --- src/source/XplicitNgine/XplicitNgine.cpp | 117 ++++++++++++ src/source/main.cpp | 17 +- src/source/propertyGrid.cpp | 5 +- 23 files changed, 228 insertions(+), 221 deletions(-) create mode 100644 src/include/XplicitNgine/XplicitNgine.h create mode 100644 src/include/resource.h delete mode 100644 src/include/winver.h create mode 100644 src/source/XplicitNgine/XplicitNgine.cpp diff --git a/Blocks3D.vcproj b/Blocks3D.vcproj index 9aa5681..dd4dfb1 100644 --- a/Blocks3D.vcproj +++ b/Blocks3D.vcproj @@ -79,7 +79,6 @@ OutputFile="./Blocks3D.exe" LinkIncremental="1" SuppressStartupBanner="true" - AdditionalManifestDependencies="" ProgramDatabaseFile=".\Release/Blocks3D.pdb" SubSystem="2" TargetMachine="1" @@ -146,7 +145,7 @@ + + + + - - @@ -882,21 +885,25 @@ > + + + + - - #include "propertyGrid.h" #include "map" - -#ifdef NO_SPRINTF -#define sprintf_s sprintf -#endif //#include "Properties/BoolProperty.h" class Instance diff --git a/src/include/DataModelV2/PVInstance.h b/src/include/DataModelV2/PVInstance.h index 67aa4b1..79ac705 100644 --- a/src/include/DataModelV2/PVInstance.h +++ b/src/include/DataModelV2/PVInstance.h @@ -1,6 +1,7 @@ #pragma once #include "instance.h" #include "enum.h" +#include class PVInstance : public Instance diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index 40a345f..4179c83 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -30,6 +30,8 @@ public: Color3 color; bool canCollide; bool anchored; + dBodyID physBody; + dGeomID physGeom[3]; //Getters Vector3 getPosition(); diff --git a/src/include/DataModelV2/WorkspaceInstance.h b/src/include/DataModelV2/WorkspaceInstance.h index 9a62304..459f144 100644 --- a/src/include/DataModelV2/WorkspaceInstance.h +++ b/src/include/DataModelV2/WorkspaceInstance.h @@ -9,5 +9,6 @@ public: WorkspaceInstance(void); ~WorkspaceInstance(void); void clearChildren(); + void zoomToExtents(); std::vector partObjects; }; diff --git a/src/include/Globals.h b/src/include/Globals.h index 76f10d9..1bb249b 100644 --- a/src/include/Globals.h +++ b/src/include/Globals.h @@ -1,6 +1,6 @@ #pragma once #include "DataModelV2/DataModelInstance.h" - +#include "XplicitNgine/XplicitNgine.h" class Application; @@ -28,6 +28,7 @@ extern std::vector postRenderStack; extern std::vector g_selectedInstances; extern bool running; extern DataModelInstance* g_dataModel; +extern XplicitNgine* g_xplicitNgine; extern Application* g_usableApp; extern GFontRef g_fntdominant; diff --git a/src/include/XplicitNgine/XplicitNgine.h b/src/include/XplicitNgine/XplicitNgine.h new file mode 100644 index 0000000..ae23224 --- /dev/null +++ b/src/include/XplicitNgine/XplicitNgine.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include "DatamodelV2/PartInstance.h" + +class XplicitNgine +{ +public: + XplicitNgine(); + ~XplicitNgine(); + dWorldID physWorld; + dSpaceID physSpace; + dJointGroupID contactgroup; + + void createBody(PartInstance* partInstance); +}; \ No newline at end of file diff --git a/src/include/resource.h b/src/include/resource.h new file mode 100644 index 0000000..1673d3d --- /dev/null +++ b/src/include/resource.h @@ -0,0 +1,7 @@ +#define IDC_PROPERTYGRID 2000 +#define IDC_STATIC 2 + +#define IDE_EDIT 105 +#define IDI_ICON1 102 +#define IDB_BITMAP1 103 +#define IDD_DIALOG1 104 diff --git a/src/include/winver.h b/src/include/winver.h deleted file mode 100644 index e72f685..0000000 --- a/src/include/winver.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef WINVER -#define _WIN32_WINNT 0x0400 -#define _WIN32_WINDOWS 0x0400 -#define WINVER 0x0400 -#endif \ No newline at end of file diff --git a/src/source/Application.cpp b/src/source/Application.cpp index 104de26..fb8ec39 100644 --- a/src/source/Application.cpp +++ b/src/source/Application.cpp @@ -1,13 +1,14 @@ #include #include #include -#include "../../resource.h" +#include "resource.h" #include "DataModelV2/Instance.h" #include "DataModelV2/PartInstance.h" #include "DataModelV2/TextButtonInstance.h" #include "DataModelV2/ImageButtonInstance.h" #include "DataModelV2/DataModelInstance.h" #include "DataModelV2/GuiRootInstance.h" +#include "XplicitNgine/XplicitNgine.h" #include "CameraController.h" #include "AudioPlayer.h" #include "Globals.h" @@ -188,9 +189,11 @@ void Application::onInit() { _dataModel->font = g_fntdominant; g_dataModel = _dataModel; - //initGUI(); + _xplicitNgine = new XplicitNgine(); + g_xplicitNgine = _xplicitNgine; #ifdef LEGACY_LOAD_G3DFUN_LEVEL + // Anchored this baseplate for XplicitNgine tests PartInstance* test = makePart(); test->setParent(_dataModel->getWorkspace()); test->color = Color3(0.2F,0.3F,1); @@ -198,7 +201,8 @@ void Application::onInit() { test->setPosition(Vector3(0,0,0)); test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(0),toRadians(0))); test->setSurface(TOP, Enum::SurfaceType::Bumps); - + test->anchored = true; + test = makePart(); test->setParent(_dataModel->getWorkspace()); test->color = Color3(.5F,1,.5F); @@ -262,9 +266,6 @@ void Application::onInit() { test->setPosition(Vector3(-2,5,0)); test->setSurface(TOP, Enum::SurfaceType::Bumps); - - - test = makePart(); test->setParent(_dataModel->getWorkspace()); test->color = Color3::gray(); @@ -294,86 +295,20 @@ void Application::onInit() { } - - - - - void Application::onCleanup() { clearInstances(); sky->~Sky(); } - - -/* - -Class HyperSnapSolver - -function getCollisionDepth(Part colliding, part collider); -function getFaceCollision(Part colliding, part collider); - -function eject(Part colliding, Part collider) -{ - if(!colliding.canCollide || !collider.canCollide) - return; - if(getCollisionDepth(colliding, collider) != 0) { - int ejectMultiplier, ejectMultipliery = 1-(collider.Friction+colliding.Friction), ejectMultiplierz = 1-(collider.Friction/2+colliding.Friction/2); - if(colliding.Anchored) - ejectMultiplier = collider.elasticity; - int faceCollided = getFaceCollision(colliding, collider); - if(faceCollided % 3 == 1) - { - ejectMultipliery = ejectMultiplier; - ejectMultiplier = 1-(collider.Friction+colliding.Friction/2); - } - else if(faceCollided % 3 == 2) - { - ejectMultiplierz = ejectMultiplier; - ejectMultiplier = 1-(collider.Friction+colliding.Friction/2); - } - - collider.Velocity *= Vector3.new(colliding.Velocity.x*ejectMultiplier,colliding.Velocity.y*ejectMultipliery,colliding.Velocity.z) - } -} - -*/ - -double grav = 0.32666666666666666666666666666667; -void simGrav(PartInstance * collider) -{ - if(!collider->anchored) - { - collider->setPosition(collider->getPosition()+collider->getVelocity()); - collider->setVelocity(collider->getVelocity()-Vector3(0,grav,0)); - } -} - -void eject(PartInstance * colliding, PartInstance * collider) -{ - if(colliding == collider || !colliding->canCollide || !collider->canCollide) - return; - if(G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(collider->getBox(), colliding->getBox())) - collider->setVelocity(collider->getVelocity().reflectionDirection(colliding->getCFrame().upVector())/1.3F); - -} - - - -void Application::onLogic() { - //PhysicsStart - for_each (_dataModel->getWorkspace()->partObjects.begin(), _dataModel->getWorkspace()->partObjects.end(), simGrav); +void Application::onLogic() { + // XplicitNgine Start for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++) { - for(size_t j = 0; j < _dataModel->getWorkspace()->partObjects.size(); j++) - { - eject(_dataModel->getWorkspace()->partObjects[i], _dataModel->getWorkspace()->partObjects[j]); - } - } + PartInstance* partInstance = _dataModel->getWorkspace()->partObjects[i]; + _xplicitNgine->createBody(partInstance); + } } - - void Application::onNetwork() { // Poll net messages here } @@ -407,95 +342,29 @@ void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { } -/*double getOSVersion() { - OSVERSIONINFO osvi; - - ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - - GetVersionEx(&osvi); - std::string version = Convert(osvi.dwMajorVersion) + "." + Convert(osvi.dwMinorVersion); - return ::atof(version.c_str()); -}*/ -/* -bool IsHolding(int button) -{ - return (GetKeyState(button) >> 1)>0; -} - -*/ - void Application::onUserInput(UserInput* ui) { if(mouseMoveState) { mouseMoveState = false; tool->onMouseMoved(mouse); } - /* - if(GetHoldKeyState(VK_LCONTROL)) - { - if(GetHoldKeyState('D')) - { - _messageTime = System::time(); - if(debugMode()) - _message = "Debug Mode Disabled"; - else - _message = "Debug Mode Enabled"; - setDebugMode(!debugMode()); - } - } - */ + if(GetHoldKeyState(VK_F8)) { _dataModel->getGuiRoot()->setDebugMessage("FOV Set to 10", System::time()); } - //} - //_dataModel->mousex = ui->getMouseX(); - //_dataModel->mousey = ui->getMouseY(); mouse.setMouseDown((GetKeyState(VK_LBUTTON) & 0x100) != 0); - if (GetHoldKeyState(VK_LBUTTON)) { - /* if (_dragging) { - PartInstance* part = NULL; - if(g_selectedInstances.size() > 0) - part = (PartInstance*) g_selectedInstances.at(0); - Ray dragRay = cameraController.getCamera()->worldRay(mouse.x, mouse.y, renderDevice->getViewport()); - std::vector instances = _dataModel->getWorkspace()->getAllChildren(); - for(size_t i = 0; i < instances.size(); i++) - { - if(PartInstance* moveTo = dynamic_cast(instances.at(i))) - { - float __time = testRay.intersectionTime(moveTo->getBox()); - float __nearest=std::numeric_limits::infinity(); - if (__time != inf()) - { - if (__nearest>__time) - { - // BROKEN - //Vector3 closest = (dragRay.closestPoint(moveTo->getPosition()) * 2); - //part->setPosition(closest); - //part->setPosition(Vector3(floor(closest.x),part->getPosition().y,floor(closest.z))); - } - } - } - } - Sleep(10); - }*/ - } - // Camera KB Handling { - if (GetKPBool(VK_OEM_COMMA)) //Left - g_usableApp->cameraController.panLeft(); - else if (GetKPBool(VK_OEM_PERIOD)) // Right - g_usableApp->cameraController.panRight(); - else if (GetKPBool(0x49)) // Zoom In (I) - g_usableApp->cameraController.Zoom(1); - else if (GetKPBool(0x4F)) // Zoom Out (O) - g_usableApp->cameraController.Zoom(-1); - // } - - //readMouseGUIInput(); - // Add other key handling here + // Camera KB Handling + if (GetKPBool(VK_OEM_COMMA)) //Left + g_usableApp->cameraController.panLeft(); + else if (GetKPBool(VK_OEM_PERIOD)) // Right + g_usableApp->cameraController.panRight(); + else if (GetKPBool(0x49)) // Zoom In (I) + g_usableApp->cameraController.Zoom(1); + else if (GetKPBool(0x4F)) // Zoom Out (O) + g_usableApp->cameraController.Zoom(-1); } void Application::changeTool(Tool * newTool) @@ -793,11 +662,6 @@ void Application::onKeyPressed(int key) { _dataModel->getOpen(); } - if ((GetHoldKeyState(VK_LCONTROL) || GetHoldKeyState(VK_RCONTROL)) && key=='A') - { - std::vector vec = _dataModel->getWorkspace()->getAllChildren(); - g_selectedInstances.insert(g_selectedInstances.end(), vec.begin(), vec.end()); - } tool->onKeyDown(key); } void Application::onKeyUp(int key) @@ -948,6 +812,8 @@ void Application::run() { RealTime rdt = timeStep; SimTime sdt = timeStep * rate; SimTime idt = desiredFrameDuration * rate; + + onSimulation(rdt,sdt,idt); m_simulationWatch.tock(); diff --git a/src/source/CameraController.cpp b/src/source/CameraController.cpp index dc47011..30654e0 100644 --- a/src/source/CameraController.cpp +++ b/src/source/CameraController.cpp @@ -159,6 +159,11 @@ void CameraController::tiltDown() setFrame(frame); } +void CameraController::zoomExtents() +{ + // do some weird jank math +} + void CameraController::centerCamera(Instance* selection) { CoordinateFrame frame = CoordinateFrame(g3dCamera.getCoordinateFrame().translation); diff --git a/src/source/DataModelV2/DataModelInstance.cpp b/src/source/DataModelV2/DataModelInstance.cpp index 07e4db5..989bc9c 100644 --- a/src/source/DataModelV2/DataModelInstance.cpp +++ b/src/source/DataModelV2/DataModelInstance.cpp @@ -13,7 +13,6 @@ using namespace std; using namespace rapidxml; - DataModelInstance::DataModelInstance(void) { Instance::Instance(); @@ -519,6 +518,7 @@ bool DataModelInstance::getOpen() of.lpstrFile[0]='\0'; of.nMaxFile=500; of.lpstrTitle="Hello"; + of.Flags = OFN_FILEMUSTEXIST; ShowCursor(TRUE); BOOL file = GetOpenFileName(&of); if (file) @@ -526,7 +526,6 @@ bool DataModelInstance::getOpen() _loadedFileName = of.lpstrFile; load(of.lpstrFile,true); } - //else MessageBox(NULL, "Failed to open dialog", "Failure", MB_ICONHAND | MB_OK); return true; } void DataModelInstance::setMessage(std::string msg) diff --git a/src/source/DataModelV2/Instance.cpp b/src/source/DataModelV2/Instance.cpp index 1f51b50..4cb1279 100644 --- a/src/source/DataModelV2/Instance.cpp +++ b/src/source/DataModelV2/Instance.cpp @@ -1,3 +1,4 @@ +#define WINVER 0x0400 #include #include "DataModelV2/Instance.h" diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index 9a04254..d001057 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -25,6 +25,7 @@ PartInstance::PartInstance(void) left = Enum::SurfaceType::Smooth; bottom = Enum::SurfaceType::Smooth; shape = Enum::Shape::Block; + physBody = NULL; } @@ -279,7 +280,6 @@ void PartInstance::render(RenderDevice* rd) { changed=false; Vector3 renderSize = size/2; glNewList(glList, GL_COMPILE); - //glScalef(0.5f,0.5f,0.5f); renderShape(this->shape, renderSize, color); renderSurface(TOP, this->top, renderSize, this->controller, color); renderSurface(FRONT, this->front, renderSize, this->controller, color); @@ -297,6 +297,16 @@ void PartInstance::render(RenderDevice* rd) { PartInstance::~PartInstance(void) { glDeleteLists(glList, 1); + /* + // Causes some weird ODE error + // Someone, please look into this + + dBodyDestroy(physBody); + for (int i = 0; i < 3; i++) { + if (physGeom[i] != NULL) + dGeomDestroy(physGeom[i]); + } + */ } char pto[512]; diff --git a/src/source/DataModelV2/WorkspaceInstance.cpp b/src/source/DataModelV2/WorkspaceInstance.cpp index cf36ffb..ff64068 100644 --- a/src/source/DataModelV2/WorkspaceInstance.cpp +++ b/src/source/DataModelV2/WorkspaceInstance.cpp @@ -1,5 +1,6 @@ #include "DataModelV2/WorkspaceInstance.h" - +#include "Globals.h" +#include "Application.h" WorkspaceInstance::WorkspaceInstance(void) { @@ -15,6 +16,11 @@ void WorkspaceInstance::clearChildren() Instance::clearChildren(); } +void WorkspaceInstance::zoomToExtents() +{ + g_usableApp->cameraController.zoomExtents(); +} + WorkspaceInstance::~WorkspaceInstance(void) { } diff --git a/src/source/Globals.cpp b/src/source/Globals.cpp index fc67cba..d24c61b 100644 --- a/src/source/Globals.cpp +++ b/src/source/Globals.cpp @@ -12,6 +12,7 @@ std::vector postRenderStack = std::vector(); std::vector g_selectedInstances = std::vector(); DataModelInstance* g_dataModel = NULL; +XplicitNgine* g_xplicitNgine = NULL; bool running = false; G3D::TextureRef Globals::surface; diff --git a/src/source/PropertyWindow.cpp b/src/source/PropertyWindow.cpp index 1be5656..d32641b 100644 --- a/src/source/PropertyWindow.cpp +++ b/src/source/PropertyWindow.cpp @@ -1,7 +1,7 @@ #define _WINSOCKAPI_ #include #include "WindowFunctions.h" -#include "../../resource.h" +#include "resource.h" #include "PropertyWindow.h" #include "Globals.h" #include "strsafe.h" diff --git a/src/source/Tool/ArrowTool.cpp b/src/source/Tool/ArrowTool.cpp index f6f9c7a..9bbd1b4 100644 --- a/src/source/Tool/ArrowTool.cpp +++ b/src/source/Tool/ArrowTool.cpp @@ -69,30 +69,6 @@ void ArrowTool::onKeyDown(int key) { lctrlDown = true; } - else if(key == 'R') - { - if(g_selectedInstances.size() > 0) - { - Instance* selectedInstance = g_selectedInstances.at(0); - AudioPlayer::playSound(clickSound); - if(PartInstance* part = dynamic_cast(selectedInstance)) - { - part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,toRadians(90),0)); - } - } - } - else if(key == 'T') - { - if(g_selectedInstances.size() > 0) - { - Instance* selectedInstance = g_selectedInstances.at(0); - AudioPlayer::playSound(clickSound); - if(PartInstance* part = dynamic_cast(selectedInstance)) - { - part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,0,toRadians(90))); - } - } - } } void ArrowTool::onKeyUp(int key) diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp new file mode 100644 index 0000000..afe5e1d --- /dev/null +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -0,0 +1,117 @@ +#include "XplicitNgine/XplicitNgine.h" +#include "Globals.h" + +#define SIDE (0.5f) +#define MASS (1.0) + +// constraints +#define MAX_BODIES 65535 +#define OBJ_DENSITY (5.0) +#define MAX_CONTACT_PER_BODY 4 + +XplicitNgine::XplicitNgine() +{ + physWorld = dWorldCreate(); + physSpace = dHashSpaceCreate(0); + contactgroup = dJointGroupCreate(0); + + dWorldSetGravity(physWorld, 0, -0.5, 0); + dGeomID ground_geom = dCreatePlane(physSpace, 0, 1, 0, 0); +} + +XplicitNgine::~XplicitNgine() +{ + dJointGroupDestroy (contactgroup); + dSpaceDestroy (physSpace); + dWorldDestroy (physWorld); + dCloseODE(); +} + +void collisionCallback(void *data, dGeomID o1, dGeomID o2) +{ + int i,n; + + dBodyID b1 = dGeomGetBody(o1); + dBodyID b2 = dGeomGetBody(o2); + if (b1 && b2 && dAreConnected(b1, b2)) + return; + + const int N = 4; + dContact contact[N]; + n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); + if (n > 0) { + for (i=0; iphysWorld,g_xplicitNgine->contactgroup,contact+i); + dJointAttach (c,dGeomGetBody(o1),dGeomGetBody(o2)); + } + } +} + +void XplicitNgine::createBody(PartInstance* partInstance) +{ + // calculate collisions + dSpaceCollide (physSpace,0,&collisionCallback); + + if(partInstance->physBody == NULL) + { + // init body + partInstance->physBody = dBodyCreate(physWorld); + + // init geom + partInstance->physGeom[0] = dCreateBox(physSpace, + partInstance->getSize()[0], + partInstance->getSize()[1], + partInstance->getSize()[2] + ); + + dVector3 result; + dGeomBoxGetLengths(partInstance->physGeom[0], result); + printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n", + result[0], + result[1], + result[2] + ); + + printf("[XplicitNgine] Created Geom for PartInstance\n"); + + dBodySetPosition(partInstance->physBody, + partInstance->getPosition()[0], + partInstance->getPosition()[1], + partInstance->getPosition()[2] + ); + + printf("[XplicitNgine] Created Body for PartInstance\n"); + + dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); + } else { + // There is 100% a better way of doing this, but for now, anchored parts can be like this? + if(partInstance->anchored) { + dBodySetPosition(partInstance->physBody, + partInstance->getPosition()[0], + partInstance->getPosition()[1], + partInstance->getPosition()[2] + ); + + dBodySetLinearVel(partInstance->physBody, 0, 0, 0); + } + + const dReal* physPosition = dBodyGetPosition(partInstance->physBody); + + // I hate matricies + const dReal* physRotation = dGeomGetRotation(partInstance->physGeom[0]); + partInstance->setPosition(Vector3(physPosition[0], physPosition[1], physPosition[2])); + + } + + dWorldQuickStep(physWorld,0.05); + dJointGroupEmpty(contactgroup); +} \ No newline at end of file diff --git a/src/source/main.cpp b/src/source/main.cpp index 40ec0d4..541355c 100644 --- a/src/source/main.cpp +++ b/src/source/main.cpp @@ -1,6 +1,10 @@ // TODO: Move toolbar buttons with resized window. -#include "winver.h" -#include "../../resource.h" +#define _WIN32_WINNT 0x0400 +#define _WIN32_WINDOWS 0x0400 +#define WINVER 0x0400 +#define _CRTBLD + +#include "resource.h" #include "Application.h" #include "WindowFunctions.h" #include "ax.h" @@ -144,12 +148,7 @@ LRESULT CALLBACK G3DProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) int main(int argc, char** argv) { - - long double a = 1; - -#ifndef IGNORE_CATCH try{ -#endif hresult = OleInitialize(NULL); /* IInternetSecurityManager *pSecurityMgr; @@ -174,7 +173,7 @@ int main(int argc, char** argv) { icc.dwSize = sizeof(icc); icc.dwICC = ICC_WIN95_CLASSES/*|ICC_COOL_CLASSES|ICC_DATE_CLASSES| - // ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES*/; + ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES*/; InitCommonControlsEx(&icc); AudioPlayer::init(); @@ -215,12 +214,10 @@ int main(int argc, char** argv) { Globals::mainHwnd = hwndMain; Application app = Application(hwndMain); app.run(); - #ifndef IGNORE_CATCH } catch(...) { OnError(-1); } - #endif return 0; } diff --git a/src/source/propertyGrid.cpp b/src/source/propertyGrid.cpp index 8f27aab..2de3fae 100644 --- a/src/source/propertyGrid.cpp +++ b/src/source/propertyGrid.cpp @@ -31,12 +31,13 @@ //DWM 1.9: Suppress POCC Warning "Argument x to 'sscanf' does not match the format string; // expected 'unsigned char *' but found 'unsigned long'" -#include "winver.h" - #ifdef __POCC__ #pragma warn(disable:2234) #endif +#ifndef _WIN32_WINNT // Necessary for WM_MOUSEWHEEL support +#define _WIN32_WINNT 0x0400 +#endif // MSVC++ Support #ifndef _CRT_SECURE_NO_WARNINGS From 8e73755d804436af04690da619bf6b468d57b69b Mon Sep 17 00:00:00 2001 From: Modnark <66146584+Modnark@users.noreply.github.com> Date: Sat, 1 Oct 2022 21:13:40 -0400 Subject: [PATCH 02/14] anchoring Anchoring kinda works now --- Blocks3D.vcproj | 2 +- src/source/DataModelV2/PartInstance.cpp | 1 + src/source/XplicitNgine/XplicitNgine.cpp | 44 +++++++++++++----------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Blocks3D.vcproj b/Blocks3D.vcproj index dd4dfb1..d92fa8e 100644 --- a/Blocks3D.vcproj +++ b/Blocks3D.vcproj @@ -172,7 +172,7 @@ /> 0) { for (i=0; iphysWorld,g_xplicitNgine->contactgroup,contact+i); - dJointAttach (c,dGeomGetBody(o1),dGeomGetBody(o2)); + + // Create joints + dJointID c = dJointCreateContact( + g_xplicitNgine->physWorld, + g_xplicitNgine->contactgroup, + contact+i + ); + + dJointAttach (c,b1,b2); } } } @@ -66,13 +72,14 @@ void XplicitNgine::createBody(PartInstance* partInstance) // init body partInstance->physBody = dBodyCreate(physWorld); - // init geom + // Create geom partInstance->physGeom[0] = dCreateBox(physSpace, partInstance->getSize()[0], partInstance->getSize()[1], partInstance->getSize()[2] ); + // Debug output dVector3 result; dGeomBoxGetLengths(partInstance->physGeom[0], result); printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n", @@ -81,8 +88,8 @@ void XplicitNgine::createBody(PartInstance* partInstance) result[2] ); + // Create rigid body printf("[XplicitNgine] Created Geom for PartInstance\n"); - dBodySetPosition(partInstance->physBody, partInstance->getPosition()[0], partInstance->getPosition()[1], @@ -91,22 +98,17 @@ void XplicitNgine::createBody(PartInstance* partInstance) printf("[XplicitNgine] Created Body for PartInstance\n"); - dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); + if(!partInstance->anchored) + dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); + } else { - // There is 100% a better way of doing this, but for now, anchored parts can be like this? - if(partInstance->anchored) { - dBodySetPosition(partInstance->physBody, - partInstance->getPosition()[0], - partInstance->getPosition()[1], - partInstance->getPosition()[2] - ); - - dBodySetLinearVel(partInstance->physBody, 0, 0, 0); - } + if(partInstance->anchored) + return; const dReal* physPosition = dBodyGetPosition(partInstance->physBody); - // I hate matricies + // 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])); From bc9a5bfc72168b3159f4f9e37d9424559152c656 Mon Sep 17 00:00:00 2001 From: FlareMicrosystems Date: Sat, 1 Oct 2022 19:30:57 -0700 Subject: [PATCH 03/14] Added rotation --- src/source/XplicitNgine/XplicitNgine.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index d7f4c30..89d557d 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -96,6 +96,13 @@ void XplicitNgine::createBody(PartInstance* partInstance) partInstance->getPosition()[2] ); + 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, + g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0}; + + dBodySetRotation(partInstance->physBody, rotation); + printf("[XplicitNgine] Created Body for PartInstance\n"); if(!partInstance->anchored) @@ -110,8 +117,12 @@ void XplicitNgine::createBody(PartInstance* partInstance) // 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->setPosition(Vector3(physPosition[0], physPosition[1], physPosition[2])); + partInstance->setCFrame(CoordinateFrame( + Matrix3(physRotation[0],physRotation[1],physRotation[2], + physRotation[4],physRotation[5],physRotation[6], + physRotation[8],physRotation[9],physRotation[10]), + Vector3(physPosition[0], physPosition[1], physPosition[2]))); } dWorldQuickStep(physWorld,0.05); From ce999d226d0da5f7aa45b767a2a00bf579828b99 Mon Sep 17 00:00:00 2001 From: FlareMicrosystems Date: Sat, 1 Oct 2022 22:03:54 -0700 Subject: [PATCH 04/14] Fixed icons --- Blocks3D.vcproj | 1850 ++++++++++++++++----------------- Dialogs.rc | 2 +- src/source/PropertyWindow.cpp | 2 +- 3 files changed, 927 insertions(+), 927 deletions(-) diff --git a/Blocks3D.vcproj b/Blocks3D.vcproj index d92fa8e..ed1e501 100644 --- a/Blocks3D.vcproj +++ b/Blocks3D.vcproj @@ -1,925 +1,925 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Dialogs.rc b/Dialogs.rc index 81fbf6c..cb89866 100644 --- a/Dialogs.rc +++ b/Dialogs.rc @@ -5,7 +5,7 @@ #include #include #include -#include "resource.h" //Should not have to do this... +#include "resource.h" diff --git a/src/source/PropertyWindow.cpp b/src/source/PropertyWindow.cpp index d32641b..1be5656 100644 --- a/src/source/PropertyWindow.cpp +++ b/src/source/PropertyWindow.cpp @@ -1,7 +1,7 @@ #define _WINSOCKAPI_ #include #include "WindowFunctions.h" -#include "resource.h" +#include "../../resource.h" #include "PropertyWindow.h" #include "Globals.h" #include "strsafe.h" From d3f9b74ba136be9f04f7a89d5b97e77db221be19 Mon Sep 17 00:00:00 2001 From: FlareMicrosystems Date: Sat, 1 Oct 2022 23:12:55 -0700 Subject: [PATCH 05/14] Made cylinders and spheres act as spheres --- src/source/PropertyWindow.cpp | 5 - src/source/XplicitNgine/XplicitNgine.cpp | 260 ++++++++++++----------- 2 files changed, 135 insertions(+), 130 deletions(-) diff --git a/src/source/PropertyWindow.cpp b/src/source/PropertyWindow.cpp index 1be5656..c9c7399 100644 --- a/src/source/PropertyWindow.cpp +++ b/src/source/PropertyWindow.cpp @@ -7,11 +7,6 @@ #include "strsafe.h" #include "Application.h" -/*typedef struct typPRGP { - Instance* instance; // Declare member types - Property ∝ -} PRGP;*/ - std::vector prop; std::vector children; Instance * selectedInstance; diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index 89d557d..4f4cc01 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -1,130 +1,140 @@ -#include "XplicitNgine/XplicitNgine.h" -#include "Globals.h" - -#define SIDE (0.5f) -#define MASS (1.0) - -// constraints -#define MAX_BODIES 65535 -#define OBJ_DENSITY (5.0) -#define MAX_CONTACT_PER_BODY 4 - -XplicitNgine::XplicitNgine() -{ - physWorld = dWorldCreate(); - physSpace = dHashSpaceCreate(0); - contactgroup = dJointGroupCreate(0); - - dWorldSetGravity(physWorld, 0, -0.5, 0); - //dGeomID ground_geom = dCreatePlane(physSpace, 0, 1, 0, 0); -} - -XplicitNgine::~XplicitNgine() -{ - dJointGroupDestroy (contactgroup); - dSpaceDestroy (physSpace); - dWorldDestroy (physWorld); - dCloseODE(); -} - -void collisionCallback(void *data, dGeomID o1, dGeomID o2) -{ - int i,n; - - dBodyID b1 = dGeomGetBody(o1); - dBodyID b2 = dGeomGetBody(o2); - if (b1 && b2 && dAreConnected(b1, b2)) - return; - - const int N = 4; - dContact contact[N]; - n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); - if (n > 0) { - for (i=0; iphysWorld, - g_xplicitNgine->contactgroup, - contact+i - ); - - dJointAttach (c,b1,b2); - } - } -} - -void XplicitNgine::createBody(PartInstance* partInstance) -{ - // calculate collisions - dSpaceCollide (physSpace,0,&collisionCallback); - - if(partInstance->physBody == NULL) - { - // init body - partInstance->physBody = dBodyCreate(physWorld); - - // Create geom - partInstance->physGeom[0] = dCreateBox(physSpace, - partInstance->getSize()[0], - partInstance->getSize()[1], - partInstance->getSize()[2] - ); - - // Debug output - dVector3 result; - dGeomBoxGetLengths(partInstance->physGeom[0], result); - printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n", - result[0], - result[1], - result[2] - ); - - // Create rigid body - printf("[XplicitNgine] Created Geom for PartInstance\n"); - dBodySetPosition(partInstance->physBody, - partInstance->getPosition()[0], - partInstance->getPosition()[1], - partInstance->getPosition()[2] - ); - - 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, - g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0}; - - dBodySetRotation(partInstance->physBody, rotation); - - printf("[XplicitNgine] Created Body for PartInstance\n"); - - if(!partInstance->anchored) - dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); - - } 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])); +#include "XplicitNgine/XplicitNgine.h" +#include "Globals.h" + +#define SIDE (0.5f) +#define MASS (1.0) + +// constraints +#define MAX_BODIES 65535 +#define OBJ_DENSITY (5.0) +#define MAX_CONTACT_PER_BODY 4 + +XplicitNgine::XplicitNgine() +{ + physWorld = dWorldCreate(); + physSpace = dHashSpaceCreate(0); + contactgroup = dJointGroupCreate(0); + + dWorldSetGravity(physWorld, 0, -0.5, 0); + //dGeomID ground_geom = dCreatePlane(physSpace, 0, 1, 0, 0); +} + +XplicitNgine::~XplicitNgine() +{ + dJointGroupDestroy (contactgroup); + dSpaceDestroy (physSpace); + dWorldDestroy (physWorld); + dCloseODE(); +} + +void collisionCallback(void *data, dGeomID o1, dGeomID o2) +{ + int i,n; + + dBodyID b1 = dGeomGetBody(o1); + dBodyID b2 = dGeomGetBody(o2); + if (b1 && b2 && dAreConnected(b1, b2)) + return; + + const int N = 4; + dContact contact[N]; + n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); + if (n > 0) { + for (i=0; iphysWorld, + g_xplicitNgine->contactgroup, + contact+i + ); + + dJointAttach (c,b1,b2); + } + } +} + +void XplicitNgine::createBody(PartInstance* partInstance) +{ + // calculate collisions + dSpaceCollide (physSpace,0,&collisionCallback); + + if(partInstance->physBody == NULL) + { + // init body + partInstance->physBody = dBodyCreate(physWorld); + + // Create geom + if(partInstance->shape == Enum::Shape::Block) + { + partInstance->physGeom[0] = dCreateBox(physSpace, + partInstance->getSize()[0], + partInstance->getSize()[1], + partInstance->getSize()[2] + ); + + dVector3 result; + dGeomBoxGetLengths(partInstance->physGeom[0], result); + printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n", + result[0], + result[1], + result[2] + ); + } + else + { + partInstance->physGeom[0] = dCreateSphere(physSpace, partInstance->getSize()[0]/2); + } + + + // Debug output + + + // Create rigid body + printf("[XplicitNgine] Created Geom for PartInstance\n"); + dBodySetPosition(partInstance->physBody, + partInstance->getPosition()[0], + partInstance->getPosition()[1], + partInstance->getPosition()[2] + ); + + 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, + g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0}; + + dBodySetRotation(partInstance->physBody, rotation); + + printf("[XplicitNgine] Created Body for PartInstance\n"); + + if(!partInstance->anchored) + dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); + + } 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( Matrix3(physRotation[0],physRotation[1],physRotation[2], physRotation[4],physRotation[5],physRotation[6], physRotation[8],physRotation[9],physRotation[10]), - Vector3(physPosition[0], physPosition[1], physPosition[2]))); - } - - dWorldQuickStep(physWorld,0.05); - dJointGroupEmpty(contactgroup); + Vector3(physPosition[0], physPosition[1], physPosition[2]))); + } + + dWorldQuickStep(physWorld,0.05); + dJointGroupEmpty(contactgroup); } \ No newline at end of file From 226f2adda4a7308dc2dfdae2d4f287f0feb5a2e7 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 11:24:05 -0700 Subject: [PATCH 06/14] Made XplicitNgine secret instance of DataModel --- Blocks3D.vcproj | 32 +++++++-------- src/include/Application.h | 2 - src/include/DataModelV2/DataModelInstance.h | 4 ++ src/include/XplicitNgine/XplicitNgine.h | 3 +- src/source/Application.cpp | 5 +-- src/source/DataModelV2/DataModelInstance.cpp | 16 ++++++++ src/source/XplicitNgine/XplicitNgine.cpp | 42 +++++++++++--------- 7 files changed, 62 insertions(+), 42 deletions(-) diff --git a/Blocks3D.vcproj b/Blocks3D.vcproj index ed1e501..806210b 100644 --- a/Blocks3D.vcproj +++ b/Blocks3D.vcproj @@ -631,6 +631,14 @@ + + + + - - - - + + + + - - - - +#include "DatamodelV2/Instance.h" #include "DatamodelV2/PartInstance.h" -class XplicitNgine +class XplicitNgine : Instance { public: XplicitNgine(); diff --git a/src/source/Application.cpp b/src/source/Application.cpp index fb8ec39..a3e5341 100644 --- a/src/source/Application.cpp +++ b/src/source/Application.cpp @@ -188,9 +188,6 @@ void Application::onInit() { _dataModel->setName("undefined"); _dataModel->font = g_fntdominant; g_dataModel = _dataModel; - - _xplicitNgine = new XplicitNgine(); - g_xplicitNgine = _xplicitNgine; #ifdef LEGACY_LOAD_G3DFUN_LEVEL // Anchored this baseplate for XplicitNgine tests @@ -305,7 +302,7 @@ void Application::onLogic() { for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++) { PartInstance* partInstance = _dataModel->getWorkspace()->partObjects[i]; - _xplicitNgine->createBody(partInstance); + _dataModel->getEngine()->createBody(partInstance); } } diff --git a/src/source/DataModelV2/DataModelInstance.cpp b/src/source/DataModelV2/DataModelInstance.cpp index 989bc9c..a3cfa20 100644 --- a/src/source/DataModelV2/DataModelInstance.cpp +++ b/src/source/DataModelV2/DataModelInstance.cpp @@ -33,7 +33,21 @@ DataModelInstance::DataModelInstance(void) _loadedFileName="..//skooter.rbxm"; listicon = 5; running = false; + xplicitNgine = NULL; + resetEngine(); +} +void DataModelInstance::resetEngine() +{ + if(xplicitNgine != NULL) + delete xplicitNgine; + xplicitNgine = new XplicitNgine(); + g_xplicitNgine = xplicitNgine; +} + +XplicitNgine * DataModelInstance::getEngine() +{ + return xplicitNgine; } void DataModelInstance::toggleRun() @@ -47,6 +61,7 @@ bool DataModelInstance::isRunning() DataModelInstance::~DataModelInstance(void) { + delete xplicitNgine; } #ifdef _DEBUG @@ -448,6 +463,7 @@ bool DataModelInstance::load(const char* filename, bool clearObjects) std::string hname = sfilename.substr(begin); std::string tname = hname.substr(0, hname.length() - 5); name = tname; + resetEngine(); return true; } else diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index 4f4cc01..98a86fd 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -16,6 +16,8 @@ XplicitNgine::XplicitNgine() contactgroup = dJointGroupCreate(0); dWorldSetGravity(physWorld, 0, -0.5, 0); + + this->name = "PhysicsService"; //dGeomID ground_geom = dCreatePlane(physSpace, 0, 1, 0, 0); } @@ -41,14 +43,16 @@ void collisionCallback(void *data, dGeomID o1, dGeomID o2) n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); if (n > 0) { for (i=0; iphysGeom[0], partInstance->physBody); } 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( - Matrix3(physRotation[0],physRotation[1],physRotation[2], - physRotation[4],physRotation[5],physRotation[6], - physRotation[8],physRotation[9],physRotation[10]), - Vector3(physPosition[0], physPosition[1], physPosition[2]))); + if(!partInstance->anchored) + { + 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( + Matrix3(physRotation[0],physRotation[1],physRotation[2], + physRotation[4],physRotation[5],physRotation[6], + physRotation[8],physRotation[9],physRotation[10]), + Vector3(physPosition[0], physPosition[1], physPosition[2]))); + } } - dWorldQuickStep(physWorld,0.05); + dWorldQuickStep(physWorld,0.05F); dJointGroupEmpty(contactgroup); } \ No newline at end of file From 316359a39555ccc9c736b8f39c292f3cee97ff38 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 14:28:29 -0700 Subject: [PATCH 07/14] Made physics let you move stuff --- Dialogs.rc | 2 +- resource.h | 10 ----- src/include/DataModelV2/PartInstance.h | 1 + src/include/XplicitNgine/XplicitNgine.h | 4 +- src/include/resource.h | 2 +- src/source/DataModelV2/DataModelInstance.cpp | 7 ++++ src/source/DataModelV2/PartInstance.cpp | 14 +++++-- src/source/XplicitNgine/XplicitNgine.cpp | 43 +++++++++++++++++++- 8 files changed, 65 insertions(+), 18 deletions(-) delete mode 100644 resource.h diff --git a/Dialogs.rc b/Dialogs.rc index cb89866..2f4904e 100644 --- a/Dialogs.rc +++ b/Dialogs.rc @@ -5,7 +5,7 @@ #include #include #include -#include "resource.h" +#include "src/include/resource.h" diff --git a/resource.h b/resource.h deleted file mode 100644 index c126a1e..0000000 --- a/resource.h +++ /dev/null @@ -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 - diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index 4179c83..7a0d346 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -49,6 +49,7 @@ public: void setVelocity(Vector3); void setRotVelocity(Vector3); void setCFrame(CoordinateFrame); + void setCFrameNoSync(CoordinateFrame); void setSize(Vector3); void setShape(Enum::Shape::Value shape); void setChanged(); diff --git a/src/include/XplicitNgine/XplicitNgine.h b/src/include/XplicitNgine/XplicitNgine.h index b117cda..ac92f66 100644 --- a/src/include/XplicitNgine/XplicitNgine.h +++ b/src/include/XplicitNgine/XplicitNgine.h @@ -3,7 +3,7 @@ #include "DatamodelV2/Instance.h" #include "DatamodelV2/PartInstance.h" -class XplicitNgine : Instance +class XplicitNgine : public Instance { public: XplicitNgine(); @@ -13,4 +13,6 @@ public: dJointGroupID contactgroup; void createBody(PartInstance* partInstance); + void deleteBody(PartInstance* partInstance); + void updateBody(PartInstance* partInstance, CoordinateFrame * cFrame); }; \ No newline at end of file diff --git a/src/include/resource.h b/src/include/resource.h index 1673d3d..8f6e7c3 100644 --- a/src/include/resource.h +++ b/src/include/resource.h @@ -1,7 +1,7 @@ #define IDC_PROPERTYGRID 2000 #define IDC_STATIC 2 -#define IDE_EDIT 105 +#define IDC_EDIT1 105 #define IDI_ICON1 102 #define IDB_BITMAP1 103 #define IDD_DIALOG1 104 diff --git a/src/source/DataModelV2/DataModelInstance.cpp b/src/source/DataModelV2/DataModelInstance.cpp index a3cfa20..e19c8a4 100644 --- a/src/source/DataModelV2/DataModelInstance.cpp +++ b/src/source/DataModelV2/DataModelInstance.cpp @@ -43,6 +43,11 @@ void DataModelInstance::resetEngine() delete xplicitNgine; xplicitNgine = new 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() @@ -53,6 +58,8 @@ XplicitNgine * DataModelInstance::getEngine() void DataModelInstance::toggleRun() { running = !running; + //if(!running) + //resetEngine(); } bool DataModelInstance::isRunning() { diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index d6c0410..9026210 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -8,6 +8,7 @@ PartInstance::PartInstance(void) { PVInstance::PVInstance(); + physBody = NULL; glList = glGenLists(1); name = "Unnamed PVItem"; className = "Part"; @@ -25,7 +26,6 @@ PartInstance::PartInstance(void) left = Enum::SurfaceType::Smooth; bottom = Enum::SurfaceType::Smooth; shape = Enum::Shape::Block; - physBody = NULL; } @@ -110,6 +110,7 @@ void PartInstance::setSurface(int face, Enum::SurfaceType::Value surface) void PartInstance::setParent(Instance* prnt) { + g_dataModel->getEngine()->deleteBody(this); Instance * cparent = getParent(); while(cparent != NULL) { @@ -144,7 +145,7 @@ PartInstance::PartInstance(const PartInstance &oinst) setParent(oinst.parent); anchored = oinst.anchored; size = oinst.size; - setCFrame(oinst.cFrame); + setCFrameNoSync(oinst.cFrame); color = oinst.color; velocity = oinst.velocity; rotVelocity = oinst.rotVelocity; @@ -156,7 +157,6 @@ PartInstance::PartInstance(const PartInstance &oinst) bottom = oinst.bottom; shape = oinst.shape; changed = true; - physBody = NULL; } void PartInstance::setSize(Vector3 newSize) @@ -222,7 +222,7 @@ void PartInstance::setShape(Enum::Shape::Value shape) void PartInstance::setPosition(Vector3 pos) { position = pos; - cFrame = CoordinateFrame(cFrame.rotation, pos); + setCFrame(CoordinateFrame(cFrame.rotation, pos)); changed = true; } @@ -231,6 +231,12 @@ CoordinateFrame PartInstance::getCFrame() return cFrame; } void PartInstance::setCFrame(CoordinateFrame coordinateFrame) +{ + g_dataModel->getEngine()->updateBody(this, &coordinateFrame); + setCFrameNoSync(coordinateFrame); +} + +void PartInstance::setCFrameNoSync(CoordinateFrame coordinateFrame) { cFrame = coordinateFrame; position = coordinateFrame.translation; diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index 98a86fd..dc504ca 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -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) { // calculate collisions @@ -131,7 +145,7 @@ void XplicitNgine::createBody(PartInstance* partInstance) // 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->setCFrameNoSync(CoordinateFrame( Matrix3(physRotation[0],physRotation[1],physRotation[2], physRotation[4],physRotation[5],physRotation[6], physRotation[8],physRotation[9],physRotation[10]), @@ -141,4 +155,31 @@ void XplicitNgine::createBody(PartInstance* partInstance) dWorldQuickStep(physWorld,0.05F); 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"); + } } \ No newline at end of file From e17aa16086fc1aceb465af89d406435def5eede5 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 15:54:38 -0700 Subject: [PATCH 08/14] Made physics work --- src/include/DataModelV2/PartInstance.h | 3 +- src/include/XplicitNgine/XplicitNgine.h | 2 +- src/source/Application.cpp | 17 +++++---- src/source/DataModelV2/DataModelInstance.cpp | 10 ++++++ src/source/DataModelV2/PartInstance.cpp | 7 ++++ src/source/PropertyWindow.cpp | 2 +- src/source/XplicitNgine/XplicitNgine.cpp | 36 +++++++++++--------- 7 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index 7a0d346..06cf62d 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -54,6 +54,7 @@ public: void setShape(Enum::Shape::Value shape); void setChanged(); void setSurface(int face, Enum::SurfaceType::Value surface); + float getMass(); //Collision bool collides(PartInstance * part); @@ -70,4 +71,4 @@ private: bool changed; Box itemBox; GLuint glList; -}; +}; \ No newline at end of file diff --git a/src/include/XplicitNgine/XplicitNgine.h b/src/include/XplicitNgine/XplicitNgine.h index ac92f66..842254e 100644 --- a/src/include/XplicitNgine/XplicitNgine.h +++ b/src/include/XplicitNgine/XplicitNgine.h @@ -12,7 +12,7 @@ public: dSpaceID physSpace; dJointGroupID contactgroup; - void createBody(PartInstance* partInstance); + void createBody(PartInstance* partInstance, float stepSize); void deleteBody(PartInstance* partInstance); void updateBody(PartInstance* partInstance, CoordinateFrame * cFrame); }; \ No newline at end of file diff --git a/src/source/Application.cpp b/src/source/Application.cpp index a3e5341..7591a36 100644 --- a/src/source/Application.cpp +++ b/src/source/Application.cpp @@ -298,12 +298,7 @@ void Application::onCleanup() { } void Application::onLogic() { - // XplicitNgine Start - for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++) - { - PartInstance* partInstance = _dataModel->getWorkspace()->partObjects[i]; - _dataModel->getEngine()->createBody(partInstance); - } + } void Application::onNetwork() { @@ -323,8 +318,18 @@ std::vector Application::getSelection() void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { if(_dataModel->isRunning()) + { + // XplicitNgine Start + for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++) + { + PartInstance* partInstance = _dataModel->getWorkspace()->partObjects[i]; + _dataModel->getEngine()->createBody(partInstance, sdt*15/_dataModel->getWorkspace()->partObjects.size()); + } + onLogic(); + } + _dataModel->getGuiRoot()->update(); if(_dataModel->name != _title) diff --git a/src/source/DataModelV2/DataModelInstance.cpp b/src/source/DataModelV2/DataModelInstance.cpp index e19c8a4..9be2659 100644 --- a/src/source/DataModelV2/DataModelInstance.cpp +++ b/src/source/DataModelV2/DataModelInstance.cpp @@ -292,6 +292,7 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode) xml_node<> *propNode = node->first_node(); xml_node<> *cFrameNode=0; xml_node<> *sizeNode=0; + xml_node<> *anchoredNode=0; xml_node<> *shapeNode=0; xml_node<> *colorNode=0; xml_node<> *brickColorNode=0; @@ -307,6 +308,10 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode) if (xmlValue=="CFrame" | xmlValue=="CoordinateFrame") { cFrameNode = partPropNode; + } + if (xmlValue=="Anchored") + { + anchoredNode = partPropNode; } if (xmlValue=="Name") { @@ -418,6 +423,11 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode) { test->color = bcToRGB(atoi(brickColorNode->value())); } + if(anchoredNode) + { + printf("AAAAAAAAAAAAAAAAAAAA %s\n", anchoredNode->value()); + test->anchored = stricmp(anchoredNode->value(), "true") == 0; + } test->setSize(Vector3(sizeX,sizeY+_modY,sizeZ)); test->setName(newName); CoordinateFrame cf; diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index 9026210..1d0a36e 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -28,6 +28,13 @@ PartInstance::PartInstance(void) shape = Enum::Shape::Block; } +float PartInstance::getMass() +{ + if(shape == Enum::Shape::Block) + return size.x*size.y*size.z*0.7F; + else + return 1.3333333333333333333333333333333F*(size.x/2)*(size.y/2)*(size.z/2)*0.7F; +} Vector3 PartInstance::getVelocity() { diff --git a/src/source/PropertyWindow.cpp b/src/source/PropertyWindow.cpp index c9c7399..39e67a8 100644 --- a/src/source/PropertyWindow.cpp +++ b/src/source/PropertyWindow.cpp @@ -1,7 +1,7 @@ #define _WINSOCKAPI_ #include #include "WindowFunctions.h" -#include "../../resource.h" +#include "resource.h" #include "PropertyWindow.h" #include "Globals.h" #include "strsafe.h" diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index dc504ca..1121d7b 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -75,12 +75,11 @@ void XplicitNgine::deleteBody(PartInstance* partInstance) } 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, float stepSize) { // calculate collisions dSpaceCollide (physSpace,0,&collisionCallback); @@ -101,37 +100,46 @@ void XplicitNgine::createBody(PartInstance* partInstance) dVector3 result; dGeomBoxGetLengths(partInstance->physGeom[0], result); - printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n", - result[0], - result[1], - result[2] - ); + //printf("[XplicitNgine] Part Geom Size: %.1f, %.1f, %.1f\n", + // result[0], + // result[1], + // result[2] + //); } else { partInstance->physGeom[0] = dCreateSphere(physSpace, partInstance->getSize()[0]/2); } + dMass mass; + mass.setBox(partInstance->getSize().x, partInstance->getSize().y, partInstance->getSize().z, 0.7F); + dBodySetMass(partInstance->physBody, &mass); // Debug output // Create rigid body - printf("[XplicitNgine] Created Geom for PartInstance\n"); + //printf("[XplicitNgine] Created Geom for PartInstance\n"); dBodySetPosition(partInstance->physBody, partInstance->getPosition()[0], partInstance->getPosition()[1], partInstance->getPosition()[2] ); + dGeomSetPosition(partInstance->physGeom[0], + partInstance->getPosition()[0], + partInstance->getPosition()[1], + partInstance->getPosition()[2]); + 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, g3dRot[2][0], g3dRot[2][1], g3dRot[2][2], 0}; + dGeomSetRotation(partInstance->physGeom[0], rotation); dBodySetRotation(partInstance->physBody, rotation); - printf("[XplicitNgine] Created Body for PartInstance\n"); + //printf("[XplicitNgine] Created Body for PartInstance\n"); if(!partInstance->anchored) dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); @@ -152,8 +160,8 @@ void XplicitNgine::createBody(PartInstance* partInstance) Vector3(physPosition[0], physPosition[1], physPosition[2]))); } } - - dWorldQuickStep(physWorld,0.05F); +//STEP SHOULD NOT BE HERE! + dWorldQuickStep(physWorld, stepSize); dJointGroupEmpty(contactgroup); } @@ -161,8 +169,6 @@ void XplicitNgine::updateBody(PartInstance *partInstance, CoordinateFrame * cFra { if(partInstance->physBody != NULL) { - - printf("Position is supposed to be set\n"); Vector3 position = cFrame->translation; dBodySetPosition(partInstance->physBody, @@ -178,8 +184,4 @@ void XplicitNgine::updateBody(PartInstance *partInstance, CoordinateFrame * cFra dBodySetRotation(partInstance->physBody, rotation); } - else - { - printf("Null???\n"); - } } \ No newline at end of file From 8c47024960fcce5015bda34afae15388103eef11 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 16:20:35 -0700 Subject: [PATCH 09/14] a --- src/source/Renderer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/source/Renderer.cpp b/src/source/Renderer.cpp index 4273a7a..38e286e 100644 --- a/src/source/Renderer.cpp +++ b/src/source/Renderer.cpp @@ -224,8 +224,9 @@ void renderShape(const Enum::Shape::Value& shape, const Vector3& size, const Col glPopMatrix(); /*Plusses, can possibly integrate into cylinder code later on*/ glVertexPointer(2, GL_FLOAT,0, square_arr); - glColor3f(127,127,127); glPushMatrix(); + glDisable(GL_COLOR_ARRAY); + glColor3f(127,127,127); glRotatef(90,0,1,0); glTranslatef(0,0,-(size.z+0.001F)); glScalef(0.75,0.75,0.75); @@ -233,9 +234,11 @@ void renderShape(const Enum::Shape::Value& shape, const Vector3& size, const Col glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glScalef(1/(size.x*8),size.x*8,1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glEnable(GL_COLOR_ARRAY); glPopMatrix(); glPushMatrix(); + glDisable(GL_COLOR_ARRAY); glRotatef(-90,0,1,0); glTranslatef(0,0,-(size.z+0.001F)); glScalef(0.75,0.75,0.75); @@ -243,6 +246,7 @@ void renderShape(const Enum::Shape::Value& shape, const Vector3& size, const Col glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glScalef(1/(size.x*8),size.x*8,1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glEnable(GL_COLOR_ARRAY); glPopMatrix(); } From df77572fe7930f9bcf9c99a5b26f3266aeb16241 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 16:44:59 -0700 Subject: [PATCH 10/14] Made anchoring togglable in play mode --- src/include/DataModelV2/PartInstance.h | 4 +++- src/source/Application.cpp | 2 +- src/source/DataModelV2/DataModelInstance.cpp | 3 +-- src/source/DataModelV2/PartInstance.cpp | 15 +++++++++++++-- src/source/XplicitNgine/XplicitNgine.cpp | 4 ++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/include/DataModelV2/PartInstance.h b/src/include/DataModelV2/PartInstance.h index 06cf62d..c9a21fe 100644 --- a/src/include/DataModelV2/PartInstance.h +++ b/src/include/DataModelV2/PartInstance.h @@ -29,7 +29,6 @@ public: //Variables Color3 color; bool canCollide; - bool anchored; dBodyID physBody; dGeomID physGeom[3]; @@ -54,6 +53,8 @@ public: void setShape(Enum::Shape::Value shape); void setChanged(); void setSurface(int face, Enum::SurfaceType::Value surface); + void setAnchored(bool anchored); + bool isAnchored(); float getMass(); //Collision @@ -64,6 +65,7 @@ public: virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); private: + bool anchored; Vector3 position; Vector3 size; Vector3 velocity; diff --git a/src/source/Application.cpp b/src/source/Application.cpp index 7591a36..b40c972 100644 --- a/src/source/Application.cpp +++ b/src/source/Application.cpp @@ -198,7 +198,7 @@ void Application::onInit() { test->setPosition(Vector3(0,0,0)); test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(0),toRadians(0))); test->setSurface(TOP, Enum::SurfaceType::Bumps); - test->anchored = true; + test->setAnchored(true); test = makePart(); test->setParent(_dataModel->getWorkspace()); diff --git a/src/source/DataModelV2/DataModelInstance.cpp b/src/source/DataModelV2/DataModelInstance.cpp index 9be2659..3add80d 100644 --- a/src/source/DataModelV2/DataModelInstance.cpp +++ b/src/source/DataModelV2/DataModelInstance.cpp @@ -425,8 +425,7 @@ bool DataModelInstance::scanXMLObject(xml_node<> * scanNode) } if(anchoredNode) { - printf("AAAAAAAAAAAAAAAAAAAA %s\n", anchoredNode->value()); - test->anchored = stricmp(anchoredNode->value(), "true") == 0; + test->setAnchored(stricmp(anchoredNode->value(), "true") == 0); } test->setSize(Vector3(sizeX,sizeY+_modY,sizeZ)); test->setName(newName); diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index 1d0a36e..db45cf6 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -230,9 +230,20 @@ void PartInstance::setPosition(Vector3 pos) { position = pos; setCFrame(CoordinateFrame(cFrame.rotation, pos)); - changed = true; } +void PartInstance::setAnchored(bool anchored) +{ + this->anchored = anchored; + g_dataModel->getEngine()->deleteBody(this); +} + +bool PartInstance::isAnchored() +{ + return this->anchored; +} + + CoordinateFrame PartInstance::getCFrame() { return cFrame; @@ -359,7 +370,7 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) } else if(strcmp(item->lpszPropName, "Anchored") == 0) { - anchored= item->lpCurValue == TRUE; + setAnchored(item->lpCurValue == TRUE); } else if(strcmp(item->lpszPropName, "Offset") == 0) { diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index 1121d7b..d167a43 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -141,11 +141,11 @@ void XplicitNgine::createBody(PartInstance* partInstance, float stepSize) //printf("[XplicitNgine] Created Body for PartInstance\n"); - if(!partInstance->anchored) + if(!partInstance->isAnchored()) dGeomSetBody(partInstance->physGeom[0], partInstance->physBody); } else { - if(!partInstance->anchored) + if(!partInstance->isAnchored()) { const dReal* physPosition = dBodyGetPosition(partInstance->physBody); From c27aa6a114394caa0d8593dfab618ee26129e2dc Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 17:17:40 -0700 Subject: [PATCH 11/14] Fixed models crashing game --- src/source/Application.cpp | 16 ++++++++++++++-- src/source/DataModelV2/GroupInstance.cpp | 4 +--- src/source/DataModelV2/PartInstance.cpp | 10 +++++----- src/source/Listener/GUDButtonListener.cpp | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/source/Application.cpp b/src/source/Application.cpp index b40c972..0ad5702 100644 --- a/src/source/Application.cpp +++ b/src/source/Application.cpp @@ -320,12 +320,24 @@ void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { if(_dataModel->isRunning()) { // XplicitNgine Start + std::vector toDelete; for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++) { PartInstance* partInstance = _dataModel->getWorkspace()->partObjects[i]; - _dataModel->getEngine()->createBody(partInstance, sdt*15/_dataModel->getWorkspace()->partObjects.size()); + if(partInstance->getPosition().y < -20) + { + toDelete.push_back(partInstance); + } + else + _dataModel->getEngine()->createBody(partInstance, sdt*15/_dataModel->getWorkspace()->partObjects.size()); + } + while(toDelete.size() > 0) + { + PartInstance * p = toDelete.back(); + toDelete.pop_back(); + p->setParent(NULL); + delete p; } - onLogic(); } diff --git a/src/source/DataModelV2/GroupInstance.cpp b/src/source/DataModelV2/GroupInstance.cpp index c392f07..45492b9 100644 --- a/src/source/DataModelV2/GroupInstance.cpp +++ b/src/source/DataModelV2/GroupInstance.cpp @@ -34,13 +34,11 @@ void GroupInstance::PropUpdate(LPPROPGRIDITEM &pItem) std::vector GroupInstance::unGroup() { - std::vector child; while(children.size() > 0) { - child.push_back(children[0]); children[0]->setParent(parent); } - return child; + return std::vector(); } void GroupInstance::render(RenderDevice * rd) diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index db45cf6..20b619f 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -123,22 +123,22 @@ void PartInstance::setParent(Instance* prnt) { if(WorkspaceInstance* workspace = dynamic_cast(cparent)) { - std::cout << "Removed from partarray " << std::endl; workspace->partObjects.erase(std::remove(workspace->partObjects.begin(), workspace->partObjects.end(), this), workspace->partObjects.end()); - break; } cparent = cparent->getParent(); } Instance::setParent(prnt); - while(parent != NULL) + cparent = getParent(); + while(cparent != NULL) { - if(WorkspaceInstance* workspace = dynamic_cast(parent)) + if(WorkspaceInstance* workspace = dynamic_cast(cparent)) { workspace->partObjects.push_back(this); break; } - parent = parent->getParent(); + cparent = cparent->getParent(); } + } PartInstance::PartInstance(const PartInstance &oinst) diff --git a/src/source/Listener/GUDButtonListener.cpp b/src/source/Listener/GUDButtonListener.cpp index 4e00f43..0195b0d 100644 --- a/src/source/Listener/GUDButtonListener.cpp +++ b/src/source/Listener/GUDButtonListener.cpp @@ -39,6 +39,7 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) else if(button->name == "Group") { GroupInstance * inst = new GroupInstance(); + inst->setParent(g_dataModel->getWorkspace()); for(size_t i = 0; i < g_selectedInstances.size(); i++) { if(g_selectedInstances.at(i)->canDelete) @@ -52,7 +53,6 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) /*tempinst->setPosition(Vector3(tempPos.x, tempPos.y + tempSize.y, tempPos.z)); g_usableApp->cameraController.centerCamera(g_selectedInstances.at(0));*/ } - inst->setParent(g_dataModel->getWorkspace()); g_selectedInstances.clear(); g_selectedInstances.push_back(inst); if(g_selectedInstances.size() > 0) From af8823c50827e084fc9e4c7653a34aff8f44e657 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 17:56:50 -0700 Subject: [PATCH 12/14] Improved Physics --- Blocks3D-2003.sln | 35 -- Blocks3D-2003.vcproj | 649 ----------------------- src/include/XplicitNgine/XplicitNgine.h | 3 +- src/source/Application.cpp | 6 +- src/source/XplicitNgine/XplicitNgine.cpp | 11 +- 5 files changed, 16 insertions(+), 688 deletions(-) delete mode 100644 Blocks3D-2003.sln delete mode 100644 Blocks3D-2003.vcproj diff --git a/Blocks3D-2003.sln b/Blocks3D-2003.sln deleted file mode 100644 index f494330..0000000 --- a/Blocks3D-2003.sln +++ /dev/null @@ -1,35 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Blocks3D", "Blocks3D-2003.vcproj", "{6C4D6EEF-B1D1-456A-B850-92CAB17124BE}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {6C4D6EEF-B1D1-456A-B850-92CAB17124BE}.Debug.ActiveCfg = Debug|Win32 - {6C4D6EEF-B1D1-456A-B850-92CAB17124BE}.Debug.Build.0 = Debug|Win32 - {6C4D6EEF-B1D1-456A-B850-92CAB17124BE}.Release.ActiveCfg = Release|Win32 - {6C4D6EEF-B1D1-456A-B850-92CAB17124BE}.Release.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6C4D6EEF-B1D1-456A-B850-92CAB17124BE}.Debug|Win32.ActiveCfg = Debug|Win32 - {6C4D6EEF-B1D1-456A-B850-92CAB17124BE}.Debug|Win32.Build.0 = Debug|Win32 - {6C4D6EEF-B1D1-456A-B850-92CAB17124BE}.Release|Win32.ActiveCfg = Release|Win32 - {6C4D6EEF-B1D1-456A-B850-92CAB17124BE}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Blocks3D-2003.vcproj b/Blocks3D-2003.vcproj deleted file mode 100644 index 75f2202..0000000 --- a/Blocks3D-2003.vcproj +++ /dev/null @@ -1,649 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/include/XplicitNgine/XplicitNgine.h b/src/include/XplicitNgine/XplicitNgine.h index 842254e..0c33a3b 100644 --- a/src/include/XplicitNgine/XplicitNgine.h +++ b/src/include/XplicitNgine/XplicitNgine.h @@ -12,7 +12,8 @@ public: dSpaceID physSpace; dJointGroupID contactgroup; - void createBody(PartInstance* partInstance, float stepSize); + void step(float stepSize); + void createBody(PartInstance* partInstance); void deleteBody(PartInstance* partInstance); void updateBody(PartInstance* partInstance, CoordinateFrame * cFrame); }; \ No newline at end of file diff --git a/src/source/Application.cpp b/src/source/Application.cpp index 0ad5702..44b5e3a 100644 --- a/src/source/Application.cpp +++ b/src/source/Application.cpp @@ -329,7 +329,7 @@ void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { toDelete.push_back(partInstance); } else - _dataModel->getEngine()->createBody(partInstance, sdt*15/_dataModel->getWorkspace()->partObjects.size()); + _dataModel->getEngine()->createBody(partInstance); } while(toDelete.size() > 0) { @@ -338,6 +338,10 @@ void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { p->setParent(NULL); delete p; } + for(int i = 0; i < 8; i++) + { + _dataModel->getEngine()->step(sdt*2); + } onLogic(); } diff --git a/src/source/XplicitNgine/XplicitNgine.cpp b/src/source/XplicitNgine/XplicitNgine.cpp index d167a43..b5e8fa2 100644 --- a/src/source/XplicitNgine/XplicitNgine.cpp +++ b/src/source/XplicitNgine/XplicitNgine.cpp @@ -79,10 +79,10 @@ void XplicitNgine::deleteBody(PartInstance* partInstance) } } -void XplicitNgine::createBody(PartInstance* partInstance, float stepSize) +void XplicitNgine::createBody(PartInstance* partInstance) { // calculate collisions - dSpaceCollide (physSpace,0,&collisionCallback); + //dSpaceCollide (physSpace,0,&collisionCallback); if(partInstance->physBody == NULL) { @@ -161,6 +161,13 @@ void XplicitNgine::createBody(PartInstance* partInstance, float stepSize) } } //STEP SHOULD NOT BE HERE! + //dWorldQuickStep(physWorld, stepSize); + //dJointGroupEmpty(contactgroup); +} + +void XplicitNgine::step(float stepSize) +{ + dSpaceCollide (physSpace,0,&collisionCallback); dWorldQuickStep(physWorld, stepSize); dJointGroupEmpty(contactgroup); } From 4ff212f2f31e117346a93688d128357ed69671b1 Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 18:05:40 -0700 Subject: [PATCH 13/14] Improved Physics again --- src/source/Application.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/source/Application.cpp b/src/source/Application.cpp index 44b5e3a..19f0706 100644 --- a/src/source/Application.cpp +++ b/src/source/Application.cpp @@ -324,7 +324,7 @@ void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++) { PartInstance* partInstance = _dataModel->getWorkspace()->partObjects[i]; - if(partInstance->getPosition().y < -20) + if(partInstance->getPosition().y < -255) { toDelete.push_back(partInstance); } @@ -338,7 +338,7 @@ void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { p->setParent(NULL); delete p; } - for(int i = 0; i < 8; i++) + for(int i = 0; i < 6; i++) { _dataModel->getEngine()->step(sdt*2); } From e0be70f5e634188c74c506debde8d6d84d82089c Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Sun, 2 Oct 2022 20:17:07 -0700 Subject: [PATCH 14/14] Last physics iteration for this one --- ODE Copyright.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 ODE Copyright.txt diff --git a/ODE Copyright.txt b/ODE Copyright.txt new file mode 100644 index 0000000..2863cf7 --- /dev/null +++ b/ODE Copyright.txt @@ -0,0 +1,6 @@ +Open Dynamics Engine + +Copyright (c) 2001-2004, +Russell L. Smith. + +All rights reserved. \ No newline at end of file