From ab242470b69a824dca356ede6245d5a37d49842a Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 27 Oct 2018 21:14:24 -0700 Subject: [PATCH] Added tilt and rotate to drag, made drag a bit cleaner --- PartInstance.cpp | 2 +- content/images/GrabRotateCursor.png | Bin 0 -> 2893 bytes main.cpp | 111 ++++++++++++++++++++++------ 3 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 content/images/GrabRotateCursor.png diff --git a/PartInstance.cpp b/PartInstance.cpp index a4ab474..b6f09e1 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -129,7 +129,7 @@ Vector3 PartInstance::getPosition() void PartInstance::setPosition(Vector3 pos) { position = pos; - cFrame = CoordinateFrame(pos); + cFrame = CoordinateFrame(cFrame.rotation,pos); changed = true; } CoordinateFrame PartInstance::getCFrame() diff --git a/content/images/GrabRotateCursor.png b/content/images/GrabRotateCursor.png new file mode 100644 index 0000000000000000000000000000000000000000..0cd0c1375a92495955fcd1608d78b0be5fe3d1b4 GIT binary patch literal 2893 zcmV-T3$pZyP)WdKxlWgsy)AWvg-ATls8H6SrEIx{jlGc_PBFgP$UA|Bi$00007bV*G` z2i5@t7Bn(UFs^w3000SaNLh0L01FWS01FWTe`H^g00004XF*Lt006O%3;baP000W4 zNkl7+l#gs3mibpSb z2y(GB#)nP$5Gz$YW-UmmNYt1`K~W0@AsCg5C<+L;j@%h$xDAu<^w91&PBVZrOpEP@q780tE^bC{Un4fdT~z z+y#}V8!#PYXJ`M?VzDfPsVSL4pM zX*^Ai6i%Et;b$_LBAF<&*}N2=U-tC$tOyJYj8m)C+E=e$sf|V>#l*x=Vqzk7cXv~5 zZ7nTXvLt-#)~!C+4+sef8G{-JacvvS=#F-Jd73CGtX;cy9#ppmn@O-mu=w`&_PBeZ{)KyCg|U?9{O0rw0W8ygGcb82d8=+UD`g7Vg{Ur#Gmte`7b zu26GxGm|;8XU`rzu4%k*;X*@UVPOYcyd0NZcXeB3r$EHJ1t4bQ;NakT?EV5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a/main.cpp +++ b/main.cpp @@ -69,9 +69,11 @@ static std::string clickSound = ""; static std::string dingSound = ""; static int cursorid = 0; static int cursorOvrid = 0; +static int cursorDragid = 0; static int currentcursorid = 0; static G3D::TextureRef cursor = NULL; static G3D::TextureRef cursorOvr = NULL; +static G3D::TextureRef cursorDrag = NULL; static bool mouseMovedBeginMotion = false; static const int CURSOR = 0; static const int ARROWS = 1; @@ -740,7 +742,7 @@ void Demo::onInit() { test->color = Color3(0.2F,0.3F,1); test->setSize(Vector3(24,1,24)); test->setPosition(Vector3(0,0,0)); - test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(54),toRadians(0))); + //test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(54),toRadians(0))); @@ -1403,33 +1405,40 @@ void Demo::onGraphics(RenderDevice* rd) { std::vector instances = dataModel->getWorkspace()->getAllChildren(); currentcursorid = cursorid; - bool onGUI = false; - std::vector guis = dataModel->getGuiRoot()->getAllChildren(); - for(size_t i = 0; i < guis.size(); i++) + if(!dragging) { - if(BaseButtonInstance* button = dynamic_cast(guis.at(i))) + bool onGUI = false; + std::vector guis = dataModel->getGuiRoot()->getAllChildren(); + for(size_t i = 0; i < guis.size(); i++) { - if(button->mouseInButton(dataModel->mousex,dataModel->mousey, renderDevice)) + if(BaseButtonInstance* button = dynamic_cast(guis.at(i))) { - onGUI = true; - break; + if(button->mouseInButton(dataModel->mousex,dataModel->mousey, renderDevice)) + { + onGUI = true; + break; + } + } + } + if(!onGUI) + for(size_t i = 0; i < instances.size(); i++) + { + if(PartInstance* test = dynamic_cast(instances.at(i))) + { + float time = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()).intersectionTime(test->getBox()); + //float time = testRay.intersectionTime(test->getBox()); + if (time != inf()) + { + currentcursorid = cursorOvrid; + break; + } + } } } - if(!onGUI) - for(size_t i = 0; i < instances.size(); i++) + else { - if(PartInstance* test = dynamic_cast(instances.at(i))) - { - float time = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()).intersectionTime(test->getBox()); - //float time = testRay.intersectionTime(test->getBox()); - if (time != inf()) - { - currentcursorid = cursorOvrid; - break; - } - - } + currentcursorid = cursorDragid; } glBindTexture( GL_TEXTURE_2D, currentcursorid); @@ -1461,6 +1470,60 @@ void Demo::onKeyPressed(int key) { deleteInstance(); } + if(dragging) + { + 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))); + } + } + } + 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)); + } + } + } + } + if(GetHoldKeyState(VK_LCONTROL)) + { + if(key == 'D') + { + if(g_selectedInstances.size() > 0) + { + AudioPlayer::playSound(dingSound); + std::vector newinst; + for(size_t i = 0; i < g_selectedInstances.size(); i++) + { + if(g_selectedInstances.at(i)->canDelete) + { + Instance* tempinst = g_selectedInstances.at(i); + + Instance* clonedInstance = g_selectedInstances.at(i)->clone(); + + newinst.push_back(tempinst); + } + /*tempinst->setPosition(Vector3(tempPos.x, tempPos.y + tempSize.y, tempPos.z)); + usableApp->cameraController.centerCamera(g_selectedInstances.at(0));*/ + } + g_selectedInstances = newinst; + if(g_selectedInstances.size() > 0) + usableApp->_propWindow->SetProperties(newinst.at(0)); + } + } + } } void Demo::onKeyUp(int key) { @@ -1785,6 +1848,7 @@ void Demo::run() { // Load objects here= cursor = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png")); cursorOvr = Texture::fromFile(GetFileInPath("/content/images/DragCursor.png")); + cursorDrag = Texture::fromFile(GetFileInPath("/content/images/GrabRotateCursor.png")); Globals::surface = Texture::fromFile(GetFileInPath("/content/images/surfacebr.png")); Globals::surfaceId = Globals::surface->getOpenGLID(); fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); @@ -1795,14 +1859,15 @@ void Demo::run() { sky = Sky::create(NULL, ExePath() + "/content/sky/"); - if (GLCaps::supports_GL_ARB_shadow()) { + /*if (GLCaps::supports_GL_ARB_shadow()) { shadowMap = Texture::createEmpty(512, 512, "Shadow map", TextureFormat::depth(), Texture::CLAMP, Texture::BILINEAR_NO_MIPMAP, Texture::DIM_2D, Texture::DEPTH_LEQUAL); - } + }*/ cursorid = cursor->openGLID(); currentcursorid = cursorid; + cursorDragid = cursorDrag->openGLID(); cursorOvrid = cursorOvr->openGLID(); RealTime now=0, lastTime=0; double simTimeRate = 1.0f;