Sprite System Coordinates

rated by 0 users
This post has 8 Replies | 2 Followers

Top 50 Contributor
Posts 73
SunBurn_Community_Licensee
paul_blamire Posted: 08-29-2010 6:43 PM

Hi there,

I've been using the new sprite system, and have got the hang of the resolution independent nature of everything now (which I love).

One thing is still confusing me though, when I begin rendering I use the following overload.

 _sceneState.BeginFrameRendering(Vector2.Zero,
                1,
                GraphicsDevice.Viewport.AspectRatio,
                gameTime,
                _environment,
                true);

I'm just drawing tiles at the moment and everything is great except the x-axis starts at 0.5 on the left of the screen and runs to -0.5 on the right. I expected it to go from -0.5 to 0.5 (l to r), maybe my expectation is wrong.

Anyway I've been trying to work out how I can flip the axis, but I can't seem to make any progress. For info I basically started from the 2D sample and added my code on top  so all the basic rendering setup should be the same.

I imagine the problem is probably my lack of understanding, any help at all would be greatly appreciated.

Kind regards,

Paul Blamire

 

Top 10 Contributor
Posts 630
SunBurn_Community_Licensee
SunBurn_Contributor

Mmm... have you tried turning your monitor upside down?  Just kidding  ;-)

AFAIK it should run -ve to +ve (left to right).  I've not had much time to look at the 2D system yet and my first instinct was it was something to do with the camera position (as if you're looking at the scene from the wrong side)... but then I realised the BeginFrameRendering overload uses a Vector2 so you can't specify a Z coord.

Have you tried increasing the width of the view to see if that makes a difference?  Are your sprites appearing the right way up?  I'm just wondering if there is some rotation of the camera occurring somewhere?  Although I can't see how that would be possible.

Top 50 Contributor
Posts 73
SunBurn_Community_Licensee

Thanks for the reply. I don't really know, maybe my expectations are wrong, but the y axis is -ve at the bottom, +ve at the top, which is what I would have expected.

Like you say it's like the camera is looking at the scene from the wrong place. To answer one of your questions in my experiments I've tried all kinds of view widths and that doesn't seem to matter.

As it turns out my sprite was rotated. I checked out the starter 2d sample and compared the floor tile in that project and that appears to be rotated too (The right image is just the raw image)

In the 2D starter I don't see any code at all for setting up a camera, which is probably what I would expect as you would always want the projection aligned with the screen. I've read that rendering to a rendertarget then using it as a texture would be the way to use it within a 3d scene, so I can't really see the need for a camera for the 2D (other than the implicit one).

Thanks for your suggestions, I'll keep looking into it.

Top 10 Contributor
Posts 630
SunBurn_Community_Licensee
SunBurn_Contributor

I'm beginning to think this is a bug in Sunburn (or maybe a feature??).

I've just modified the Sunburn 2D template project (as shown in your pics above) to omit drawing the "bottom-left" corner tile (i.e. the first tile!).  So in theory, it should not draw the tile at position (-5, -5) - since the world size is set to 10x10.  Guess what.... it's the bottom-right tile that is missing!!  Meaning that the bottom right coord is (-5, -5)... not (5, -5) as we would expect.

There definitely seems to be some sort of 'flipping' going on here.  Hopefully one of the Sunburn team can help.

 

Top 50 Contributor
Posts 73
SunBurn_Community_Licensee

Thanks for taking the time to check that out. That at least proves the behaviour is consistent and isn't a quirk of some of my code. I feel like I'm missing something but I'm stumped so I'll work around it for now by flipping my coordinates (and ignoring the rotation). Like you say it would be nice to get the definitive word on this from the team. Luckily from reading these forums I know that the support is excellent, so it's probably just a case of waiting for time-zones to align.

Thanks for all your help in investigating this

Top 10 Contributor
Posts 4,546
Employee
SunBurn_Studio_Licensee

Hi guys,

I have a write-up of the 2D scene coordinate system here, which also explains the relationship of the screen width, aspect ratio, and perspective.  This has caused some confusion before, so we're also looking for feedback regarding how users would expect the coordinate system to be oriented.

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Top 10 Contributor
Posts 630
SunBurn_Community_Licensee
SunBurn_Contributor

Thanks John.  That clears it up.  I guess originally (before I looked at the Sunburn 2D template) I was expecting the coord system to match the XNA 2D coord system, so the top-left corner would be (0, 0).  It would be nice though if it matched the 3D system by default, so (0,0) is the center with -ve to +ve left to right and bottom to top.

 

Top 50 Contributor
Posts 73
SunBurn_Community_Licensee

Thanks for that. I'm a complete self-confessed noob so I'll just explain where my expectations came from (in case my thinking is wrong)

Because XNA uses the right hand coordinate system, I expected the positive x-axis to point to the right and the positive y-axis to point up. Obviously this is different to:

  • center = 0, 0
  • upper left = half_viewwidth, half_viewwidth
  • lower right = -half_viewwidth, -half_viewwidth

Also, as place holder graphics for testing I was using the blocks from the XNA platformer starter kit. When rendered, the blocks appeared rotated by 180 degrees as compared to the native pngs.

In order to have my sprites rotated as I'd intended them to be I was applying a Z-rotation of 180 degrees. This had the side effect of flipping the x-axis to align with my expectations. Having got to that point I just ended up negating my y axis values so I could think in my terms of my original expectations.

Now that I understand how the system works I can easily work around everything. I don't have enough experience to give any useful feedback on which way I'd prefer things to work (being easily able to integrate with farseer would be cool, so maybe I'll love the current way soon) so you'll have to make do with my feedback on why I was initially confused :-)

Maybe a comment could be added in the 2D starter project code to just highlight the axis layout, for when noobs like me start hacking.

Thanks again for the prompt answer

 

Top 10 Contributor
Posts 4,546
Employee
SunBurn_Studio_Licensee

Hi guys,

Excellent feedback, this is exactly what we're looking for.  I'll log these comments in our feature tracking system.  Along with other comments we received (which are very similar) we should be able to make the system more intuitive.

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Page 1 of 1 (9 items) | RSS