Geometry Question/Problem

Topics: User Forum
Nov 2, 2006 at 10:44 PM
I am having trouble defining the geometry for the rigid body. I have written a Vertex Plotter program that you load in a graphic, and then you can click around it and it will create the list of Vertices. The first problem I had was the coordinate system this system uses, since I figured it was the standard with top right quadruant being (,). I was getting some major collision problems, so I mapped out your sprite bottle, and found that your system is (+,-) in the top right Quad, is this correct?

Using this system, I am still getting some wierd results, even with a simple 4 point quad. Here is a sample list of vertices in the order I put them into the Vertices Collection and then into a PolygonRigidBody:

{-128,-53}
{127,126}
{127,46}
{-126,-129}

Very crude but this is the shape I think it should be:
|\
\\
\|


Am I missing something? In the engine, collisions are very hit and miss. Any ideas? Am I way off on how the geometry is calculated?

Thanks

Gudy
Nov 2, 2006 at 10:46 PM
|\
.\\
..\|

Spaces didn't post, ignore the periods, hope this helps.

Thanks again
Coordinator
Nov 3, 2006 at 4:49 AM
You need to list your vertices in a counter clock-wise fashion...

I think if you reverse what you have you should be good.

I plan to get some API documentation together soon... First I need to get some things ported over to XNA Beta 2.
Coordinator
Nov 3, 2006 at 4:54 AM
Also, the coordinate system doesn't matter as long as you are consistent and your vertice list for the geometries is counter-clockwise in whatever coordinate system you use.

The reason my demos are the way they are is because the 2D screen space for XNA sprites is +X to the right and +Y down... Y is reverse of what you are probably use to, but that's how a lot of screen coordinates are defined.
Nov 3, 2006 at 3:49 PM
Thanks for the info, one more question, does the center of the geometry need to be (0,0)? ie, could I have all positive values?

On a side note, I noticed you started adding some joints, I have played around with the springs a bit, and very nice!!!!!

Thanks again

Gudy
Nov 3, 2006 at 3:57 PM
fyi, the points listed above are in Counter Clockwise order. I switched them around and things really went haywire. I must have something else going on.

Also, after reading your response, I figured I have to use screen coordinates, as if I don't the shapes will be backwards since I do not modify the actual screen. Thanks for this, it really does help.

Gudy
Coordinator
Nov 3, 2006 at 5:50 PM
The vertices for the geometry should be such that the center of mass is at the orgin. Once built, you can then re-position the body all you want.

Now that you are using screen coordinates, is everything working a better?

I really need to get the API documented.
Coordinator
Nov 3, 2006 at 5:55 PM
Another thing to keep in mind is the MomentOfInertia value needs to match (or appximate) your geometry. I think for the demos, I calculate the MofI from the formula for a thin rectangle.
Nov 3, 2006 at 7:12 PM
That's what I figured, I do have it working, but the collisions are still interesting. I think the problem is my vertices being so far apart. I took the same shape, added 20 vertices, and it worked much better. It is almost like I am using PointRigidBody instead of PolygonRigidBody, because my shapes will fall through parts of the shape, but it will still collide if it is right on the vertices. I will keep playing with it.

Thanks for all the help!

Gudy
Coordinator
Nov 3, 2006 at 9:08 PM
It almost sounds like your geometry isn't quite matching the visible sprite.

It might be helpful if you could add some code to actually draw the lines of the geometry edges.

If you want to post a snippet of code I could take a look.
Nov 3, 2006 at 10:25 PM
Posting code would be tough as I read the verts in from a file, there is a lot going on. However, I did breakpoint to make sure the vertices are setting correctly, and they are. Do you know of any code that I can draw the geo lines with? Can you use the Drawline in Directx with xna?

I don't think that is the problem. If that were the case, why would there be a collision on the vertex? Here is picture of what I mean:

<imgsrc = "http://fshs.usd497.org/temp/balanceOnPoint.png">
this is resting on the point of the shape, right where a vertex should be.

<imgsrc = "http://fshs.usd497.org/temp/InsideLeft.png">
this time, i moved it from the left into the shape

<imgsrc = "http://fshs.usd497.org/temp/InsideRight.png">
this one from the right.

I don't see how it is possible that my geometry doesn't match my sprite. But just to be sure, can you give me a hint on how to draw lines in xna? I found Alex's post on Xbox Homebrew, and will try that but it looks like it draws in screen not in world. I have emailed him to get it in world.

Gudy
Nov 3, 2006 at 10:26 PM
Ahhh, no images, you will have to follow the links, sorry.

Gudy
Coordinator
Nov 4, 2006 at 10:33 AM
I don't have any good drawing code yet. You could just create some small sprites and put that at your verts. That should at least show you if your verts are mapping to your sprite correctly.

Nov 4, 2006 at 4:27 PM
It is not the verts, I did your idea mapping some small sprites to the verts, and they are right on. Have you ever used the PolygonRigidBody class for simple shapes like these? could there be a problem in there? It works great for verts that are close together, but when they are far apart, it seems to goof up. I have tried everything I can think of and can't get it right. Any other ideas?

<img src = "http://fshs.usd497.org/temp/verts.png">

this picture shows it resting on the point, but it still enters the shape like in the other pictures.

Thanks

Gudy
Coordinator
Nov 4, 2006 at 8:19 PM
Try going into the PolygonGeometry class and changing this line:

private float collionPrecisionFactor = .25f;

To something smaller like:

private float collionPrecisionFactor = .1f; (or .05)

Play around with it and see if it makes a difference.

This value determines the size of the grid cells that make up the Grid used for collision detection. For the PolygonGeometry I just set it to 1/4 the shortest side of the Geometries bounding box. It could be this is not a tight enough grid to get accurate collision detection.

Also, the way I'm doing collision detection, more vetices may be required. I explain how the collision detection algorithm works in the .pdf on the home page for this project.

If I get some time, I will use the verts you posted earlier and try to re-create what you are experiencing.

Hope this helps.
Nov 4, 2006 at 11:03 PM
I will give that a try once I get a chance. Thanks!

Gudy
Nov 4, 2006 at 11:59 PM
That did it! I used .05 and it works flawless, I will play with that number to get it as high as I can, since I did notice a slight performance hit. Thanks for all your help!

Gudy
Coordinator
Nov 5, 2006 at 1:12 AM
Ok, cool.

Yes, I haven't figured out a good way to "choose" that number based on the geometry.

Keep in mind, that number is really just being used to calculate the grid cell size based on the geometries bounding box size. This is just the firt technique I thought of for estimating a good grid cell size. (obviously you've shown the estimate does not work for all geometries)

I need to add an overload to the PolygonGeometry that lets you set the grid cell size explicitly.

Anyway, thanks for helping find the bug. I will give it some thought on how to make it more robust.
Nov 5, 2006 at 2:18 AM
For now I made it public so I could access it. I haven't had any time to play with the numbers yet, but I am very excited to get it working! Thanks again and keep up the good work, this is awsome!

Gudy