This project has moved and is read-only. For the latest updates, please go here.

Landscape "chunking" and origins

Topics: User Forum
Nov 18, 2008 at 2:31 PM
I've been reading through the documentation provided, and it says to split the object used for landscape into multiple smaller objects. Makes sense, until you try and do it...because the physics engine positions based on the center of an object, I can't find an easy way to position each chunk of the landscape to draw. So what's the easier way of doing this? I have a really large landscape that I'm looking at splitting into chunks of 256x256 and 512x512 images and I'd like to be able to easily peice it back together...but when I try images wind up way off alignment even though I'm trying to simply position by adding the width and position.x and height and position.y from the previous image... Any suggestions? is there a way to add an object to the collision engine without adding a body?
Nov 18, 2008 at 4:44 PM
I'm pretty sure you only need one body.  Each body can be given multiple geometries, and the broadphase looks for geometries, not bodies.

I'd imagine that, as long as a body 'IsStatic', the center point doesn't need to be at the center of gravity.  So theorhetically, you could position the static body at 0,0, and have the geometry verticies set to their absolute positions.  Someone would need to confirm this however.
Nov 18, 2008 at 6:24 PM
Can I use multiple textures to build 1 body? because XNA only supports 2048x2048 textures, and the level is closer to 4096x2048 in size
Nov 18, 2008 at 8:38 PM
@Yota: Yep, you are right. You can use multiple geometries with one body. It's right on the frontpage ;)

@seiggy: The texture does not need to be split up. Only the geometries. This is to improve performance (Minimize the number of narrow phase collisions. Yeah, even the number of broad phase collisions). You would have one texture, one body and X number of geometries that makes up the landscape.

Look under Known Issues in our manual (click here: Known issues). It's not really an issue as it's part of our design. :) The one you are looking for is number 3.

In newer versions of Farseer Physics, we center the geometries around the centroid (real center) instead of "fake center" of the geometry (width/2, height/2).
Nov 19, 2008 at 11:10 PM
I think I've figured out how to position my bodies properly using a grid method:

land[i, j].Position =

new Vector2(512 * j + land[i,j].Origin.X, 512 * i + land[i,j].Origin.Y);


This should take the current row/column...multiply by the width of the texture to get where I want the upper left hand corner of the texture and then offset it by the origin so I can get the real position...