Have you thought about creating a special type of shape for
envelopes?
Use Case 1: Curved boundary
I've just read
this:
samtny wrote:when the ball is moving at high speed towards a curved "turn in the road", the ball tends to "stick" in the wall of the curve and bounce backwards, instead of proceeding smoothly around the curve at high speed.
samtny was using line segments. I think this use case would be the most popular.
I imagine that it would be a composite of special line segments: infinite in length and solid on one side. I propose cpLineBoundry.
I'm thinking on my feet now but is it possible to create such an object with an infinite area triangle? I.e. A cpPolyShape with vertices {{0,INFINITY}, {0, -INFINITY}, {-INFINITY, -INFINITY}}, thus creating a boundary that collides with any object with nonpositive x position. What would the consequences of this be? I guess it would be impossible to rotate...
I digress, the constructor would need three inputs:
Code: Select all
cpLineBoundry * cpLineBoundryInit(cpLineBoundry *shape, cpBody *body, cpFloat a, cpFloat b, cpFloat outside)
Where y = a.x + b and outside would specify a y coordinate in the solid area of the object.
E.g.
Code: Select all
cpLineBoundryInit(shape, body, 0.0f, 0.0f, -INFINITY)
Would create a horizontal wall preventing an object to pass 'below' 0.0 (assuming up is positive).
A special case would be needed for a vertical boundary:
Code: Select all
cpLineBoundry * cpLineBoundryVerticalInit(cpLineBoundry *shape, cpBody *body, cpFloat x, cpFloat outside)
Alternatively, (better now that I think of it) the line could be specified with two 'vertices' that lay on it or the line's axes interception points:
Code: Select all
cpLineBoundry * cpLineBoundryInit(cpLineBoundry *shape, cpBody *body, cpFloat xIntercept, cpFloat yIntercept, cpFloat outside)
cpLineBoundry * cpLineBoundryInitWithVectors(cpLineBoundry *shape, cpBody *body, cpVector a, cpVector b, cpFloat outside)
An envelope could be created with many cpLineBoundries. Technically an envelope should be specified with an equation and resolution (defined as either the number of lines or step interval along the x axis, assuming a cartesian equation). Better yet, use a parametric equation with values supplied via user callback function. Better yet, define some sort of cpPath (too complex?
KISS). Or just leave the implementation up to the user (I mean developer).
Scott, is cpLineBoundry possible? I don't know the ins and outs of collision detection... I guess it doesn't have a bounding box and would need special consideration. If you give me a few pointers I'd have a crack at it if I can find the time.
Use Case 2: Concave Shapes
Assuming that cpLineBoundry exists would it then be possible to define cpLineBoundrySegment? Whereby a bounding box is given to a cpLineBoundry and the line is 'one-way'. Meaning that collisions only occur if the colliding shape approaches the line in the 'right' direction and if the colliding shape was in the solid region of the bounding box then it must pass through as if there were no boundary.
Imagine, building a shape with boxes where only one side of the box had any effect! This would allow a concave surface and convex polygons come to think of it.
I guess calculating moment of inertia and torque would be difficult, I dunno...
I suppose cpLineBoundry could be approximated with a cpLineBoundrySegment (if it made the math easier).
What do you think? Is the math for this hard (nontrivial, computationally expensive)? I would love to see this addition to the already excellent chipmunk library!