Dragging/Translating snapping improvements.

master
sigonasr2 9 months ago
parent 67f2bf2318
commit 4c5781d0c9
  1. 28
      TiledCollisionEditor/main.cpp

@ -19,6 +19,8 @@ class TiledCollisionEditor : public olc::PixelGameEngine
std::string selectedObj=""; std::string selectedObj="";
int editingPoint=4; //0-3 for the index we are editing within editingQuad. int editingPoint=4; //0-3 for the index we are editing within editingQuad.
bool dragging=false; bool dragging=false;
bool dragTranslate=false;
vf2d upperLeftDragOffset{};
Renderable circle; Renderable circle;
@ -131,6 +133,14 @@ public:
(*editingQuad)[3]=vf2d{initialPoint.x,cursorPos.y}; (*editingQuad)[3]=vf2d{initialPoint.x,cursorPos.y};
} }
if(dragTranslate){
vf2d translateAmt=GetSnapPoint()-originalQuad[0]-upperLeftDragOffset;
for(size_t pointInd=0;vf2d&point:*editingQuad){
(*editingQuad)[pointInd]=originalQuad[pointInd]+translateAmt;
pointInd++;
}
}
if(GetMouse(Mouse::LEFT).bPressed){ if(GetMouse(Mouse::LEFT).bPressed){
#pragma region Select a point on a collision quad. #pragma region Select a point on a collision quad.
for(const Quadrilateral&quad:obj.collisionTiles){ for(const Quadrilateral&quad:obj.collisionTiles){
@ -145,8 +155,23 @@ public:
pointInd++; pointInd++;
} }
} }
exitCollisionCheck:
#pragma endregion #pragma endregion
for(const Quadrilateral&quad:obj.collisionTiles){
std::array<geom2d::triangle<float>,2>collisionTris{
geom2d::triangle<float>{quad[0],quad[1],quad[2]},
geom2d::triangle<float>{quad[0],quad[2],quad[3]},
};
for(geom2d::triangle<float>&tri:collisionTris){
if(geom2d::contains(tri,view.ScreenToWorld(GetMousePos()))){
dragTranslate=true;
editingQuad=const_cast<Quadrilateral*>(&quad);
upperLeftDragOffset=GetSnapPoint()-quad[0];
originalQuad=*editingQuad;
goto exitCollisionCheck;
}
}
}
exitCollisionCheck:
if(EditingQuad&&!dragging){ if(EditingQuad&&!dragging){
(*editingQuad)[editingPoint]=GetSnapPoint(); (*editingQuad)[editingPoint]=GetSnapPoint();
editingPoint++; editingPoint++;
@ -174,6 +199,7 @@ public:
(*editingQuad)[editingPoint]=GetSnapPoint(); (*editingQuad)[editingPoint]=GetSnapPoint();
editingPoint=4; editingPoint=4;
} }
dragTranslate=false;
} }
if(GetMouse(Mouse::RIGHT).bPressed||GetKey(ESCAPE).bPressed){ if(GetMouse(Mouse::RIGHT).bPressed||GetKey(ESCAPE).bPressed){

Loading…
Cancel
Save