|
|
|
@ -19,6 +19,8 @@ class TiledCollisionEditor : public olc::PixelGameEngine |
|
|
|
|
std::string selectedObj=""; |
|
|
|
|
int editingPoint=4; //0-3 for the index we are editing within editingQuad.
|
|
|
|
|
bool dragging=false; |
|
|
|
|
bool dragTranslate=false; |
|
|
|
|
vf2d upperLeftDragOffset{}; |
|
|
|
|
|
|
|
|
|
Renderable circle; |
|
|
|
|
|
|
|
|
@ -131,6 +133,14 @@ public: |
|
|
|
|
(*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){ |
|
|
|
|
#pragma region Select a point on a collision quad. |
|
|
|
|
for(const Quadrilateral&quad:obj.collisionTiles){ |
|
|
|
@ -145,8 +155,23 @@ public: |
|
|
|
|
pointInd++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
exitCollisionCheck: |
|
|
|
|
#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){ |
|
|
|
|
(*editingQuad)[editingPoint]=GetSnapPoint(); |
|
|
|
|
editingPoint++; |
|
|
|
@ -174,6 +199,7 @@ public: |
|
|
|
|
(*editingQuad)[editingPoint]=GetSnapPoint(); |
|
|
|
|
editingPoint=4; |
|
|
|
|
} |
|
|
|
|
dragTranslate=false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(GetMouse(Mouse::RIGHT).bPressed||GetKey(ESCAPE).bPressed){ |
|
|
|
|