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

MSTerrain rendering terrain upside down and reversed...

Topics: Developer Forum, User Forum
Jan 19, 2012 at 9:51 PM
Edited Jan 19, 2012 at 9:53 PM

I'm assuming this is a very simple fix as I have not seen anyone else having ridiculous issues with the MSTerrain class. I know that this class is not meant to be a solid final solution, but I'm trying to get some basic ground work up and running to get over the "blank slate" blockade as fast as possible.

I spent the majority of yesterday evening and all afternoon today so far trying to figure out the basics of MSTerrain and I have become familiar with the operational logic fairly well; however, I am still a little lost on a couple of parameters. My black/white image for creating the terrain is 480x800. My instantiation is as follows:

terrain = new MSTerrain(physicsWorld, new AABB(new Vector2(0, 0), 4.8f, 8))
    PointsPerUnit = 100,
    CellSize = 25,
    SubCellSize = 5,
    Decomposer = Decomposer.Bayazit,
    Iterations = 2,


Below is a screen shot of the current result. The background you see is the texture I'm passing to the ApplyTexture method along with position (0, 0).

Screen shot:


As you can see, the terrain is being placed incorrectly and I have no idea what I'm doing wrong. I've been mulling this over in my head for a good while now and I cannot figure it out. Any help would be much appreciated.

Jan 20, 2012 at 1:04 AM

LULZ! I had my parameters reversed. I'm such a moron.

terrain = new MSTerrain(physicsWorld, new AABB(new Vector2(0, 0), 4.8f, 8))

should have been

terrain = new MSTerrain(physicsWorld, new AABB(new Vector2(0, 0), 8, 4.8f))


Jan 20, 2012 at 7:54 PM

Hi! It's me again. Sadly, the fix I mentioned above was only a portion of my problem. Now everything is almost drawn, but everything is being created upside down. Has anyone had a similar issue? I will probably spend some time this weekend writing my own MSTerrain using the provided one as a guide so that I can have a better feel for exactly what is going on and easier extendability as needed.

Updated image:

Any help would be greatly appreciated!



Feb 21, 2012 at 7:19 AM

Did you end up figuring out the issue with it being upside down?

Apr 16, 2012 at 6:43 AM
Edited Apr 16, 2012 at 5:45 PM

Line 326 of MSTerrain.cs has the following:

Vector2 scale = new Vector2(1f / PointsPerUnit, 1f / -PointsPerUnit);

There is a comment a moment later asking if it needs to be negative, and the answer is no. 

Change it to 

Vector2 scale = new Vector2(1f / PointsPerUnit, 1f / PointsPerUnit);

and you are going to be on the right track. The only issue is the offset at that point.

---- EDIT ----

You can correct the offset by changing line 107 

_topLeft = new Vector2(Center.X - (Width * 0.5f), Center.Y - (-Height * 0.5f) - Height * PointsPerUnit);