Hi, first up, great work on the physics engine Norbo, it's great - I've used it in a few things of my own recently and it's proven to be really useful.
Now onto my question:
At the moment I'm creating a procedural 'shatter' effect for a pane of glass. I have done the maths for this part in 2d, as it seemed to make sense to me to do it that way (the problem is mainly a 2d one that just needs extruding). I pass my convex hull generator the face dimensions (assumed to be rectangular/square), and the and the shatter point of impact. Then it performs calculations, extrudes into 3d prisms and returns a load of 3d ConvexHulls.
I want to allow the user to pick through the screen into the face of the cuboid (the pane) and then get a) the face dimensions as a 2d rectangle, and b) the ray intersection position in cuboid face co-ordinates. My description isn't great so I'll give an example. Say I have a square pane with dimensions [X=512, Y=512, Z=4] and someone clicks directly in the centre of this pane. The co-ordinate i want back would be (X=255.5, Y=255.5). It happens that my origin in that co-ordinate space is the top left corner, but if that's not what I need I could possibly alter that (although I would rather not, since it would mean re-doing the maths since I derived the trigonometry equations working in that co-ordinate space).
As well as being able to this with a ray, it would be neat if I could also get this point of impact mentioned above from collisions with other objects too. I would imagine this has something to do with setting an event handler for ContactCreated?
Either way, I'm a bit puzzled over this whole problem, so I thought I'd ask for some input.
Thanks in advance,
RH
Contact point in local 2d face co-ordinates
-
- Posts: 5
- Joined: Fri Dec 09, 2011 1:14 pm
Re: Contact point in local 2d face co-ordinates
Thanks!Hi, first up, great work on the physics engine Norbo, it's great - I've used it in a few things of my own recently and it's proven to be really useful.
Create the picking ray and use it in a Space.RayCast or ray cast the specific entity.CollisionInformation. That result will be in world space, but it's possible to transform it into a local space of the pane to easily determine the face coordinates.I want to allow the user to pick through the screen into the face of the cuboid (the pane) and then get a) the face dimensions as a 2d rectangle, and b) the ray intersection position in cuboid face co-ordinates. My description isn't great so I'll give an example. Say I have a square pane with dimensions [X=512, Y=512, Z=4] and someone clicks directly in the centre of this pane. The co-ordinate i want back would be (X=255.5, Y=255.5).
If you transform the hit location by the inverse of the entity's WorldTransform, it will be in the shape's local space. Assuming the entity was built in an axis aligned way, the local space will also be axis aligned. You could apply an extra rotation if you wanted to swap which axes the face is aligned with.
Once in the desired local space, you can take the hit's X, Y, or Z coordinates directly and use them as face coordinates.
You could get the ray origin into the local space if you needed it by doing the same thing. If you need the hit normal in local space, you can apply the inverse (transpose) OrientationMatrix to the world space normal. You could also do this with the ray direction.
You could use a ContactCreated handler if you wanted. The Contact provided will have a position, normal, and normal force among other things. The position and normal can be transformed in the same way as the ray cast result.As well as being able to this with a ray, it would be neat if I could also get this point of impact mentioned above from collisions with other objects too. I would imagine this has something to do with setting an event handler for ContactCreated?
You could also use the entity.CollisionInformation.Pairs.Contacts collections. This might be a little more natural to include in the flow of your program, since you can loop through the pairs and contact lists at any time external to a space update.
Re: Contact point in local 2d face co-ordinates
By the way, things are generally most stable when individual entities are in the range of 0.5 to 10 units in dimension. Going outside of this range is usually fine, but staying within it has pretty strong guarantees of stability.
If your pane breaks into many pieces that are small relative to the original pane, you may need the original dimensions to be larger- like 32x32 or something. 512x512 will probably work okay, but it might be on the edge of robustness.
If your pane breaks into many pieces that are small relative to the original pane, you may need the original dimensions to be larger- like 32x32 or something. 512x512 will probably work okay, but it might be on the edge of robustness.