Trying to cut a Shape with image texture.

I have some code where by i can cut convex polygons with lines. Imagine like a fruit ninja game where once you cut a shape, now you have two shapes with their own positions, velocities etc. So I am able to break one convex polygon for example into two pieces when i draw a line. Now, I wanted to be able to paint the polygon with an image and then i'd be able to cut an image with lines too. The trouble I have is in texture mapping. I am using textureMode(NORMAL).

Say I have a rectangle image. To make things easy, i started out drawing a rectangular shape as well to render the image with the texture function. I am able to draw the texture where by I map the points of the vertices to the vertices necessary for when i render the shape useing the vertex function, having it take four params now. But the thing I'm having trouble with is every time i make a cut to create a new polygon, the texture vertices are not being mapped correctly. because it looks like the two resulting shapes have overlappign portions in the texture. I'm wondering how to ensure that I will always be able to make sure that i'm cutting the piece appropriately.

github link to stuff done so far

https://github.com/aarondbaron/ProcessingSketches/tree/master/testDrawingShapeWithImage

Tagged:

Answers

  • Elaborating further after some attempts

    Each time after i make a cut, the shapes move away from each other, so their locations are going to change. .

    When i start out with drawing the texture points, I know that the centroid of the image texture is .5, .5.

    Each time I make a cut with a rectangular image, now i'l have two new shapes. (Im given two new sets of absolue points...I can get the relative points of the vertices of the image). I need though to have the corresponding texture points. And i can't do a simple mapping becaues the new shape pieces move. Were i making many cuts first and then giving velocities to the new shapes, then i could do that. but each time i make a cut, the shapes will move apart.

    what do i need to be passing through from the parent shape to the new shape to make sure i'm referencing the correct texture coordinates?

Sign In or Register to comment.