Question

I don't usually make questions without some code in them but this time i cant find a starting point in what I want to do ,I want to split a sprite(uv ,vertices) to two other sprites(uv,vertices) between 2 points ,just like in fruit ninja where you split the fruits, but in 2d sprites.

enter image description here

I don't want you to write the code,just explain the general idea of how to do it . I am using Libgdx if that matters

Was it helpful?

Solution

This process is called clipping.

In your case, you have a polygon defined by 4 vertices (including their positions and UV coordinates). You split this via a line given by two points.

A simple algorithm would check on which side of the line each of the 4 points is. If it is on the left side, add it to your first result, if it is on the right side, add it to your second. If two consecutive vertices end up on different sides of the line, you need to compute the intersection of the line and that edge and add it to both results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top