Zalo DS Blog

Sunday, February 24, 2008

Painting in 2D using 3D (II)

Ok, some people who read the previous post told me that they dindn't understand anything of what I was saying :D So I'll try to go explain everything a little bit more better this time. Let's just focus on the first issue I was talking about.

When you are painting on the screen and you are using a 3D Engine (like opengl) there is something called the pipeline. You just don't draw 2d vertices on the screen as usual, but in 3d. You are painting on 3d wether you like it or not. You can check this pipeline on the internet (here, for example http://june.ncviz.com/openglpipeline.html) Basically what goes on with a 3d vertex that you draw is that it is being transformed throught the pipeline until it is finally painted in 2d into the screen.

You can't avoid these transformations, all right? Let's focus on the first two steps of this pipeline. You define a vertex and it is first multiplied by the modelview matrix and then by the projection matrix (sometimes modelview martrix is divided into camera matrix and object transformation) and after that we don't care now (if you are interested read it in the previous link :D)



The first matrix transforms the vertex coordinates into view coordinates (still on 3d) and the second (which we are specially interested on) projects them on 3d according to the perspective we have defined. You usually define a 3d perspective with a frustrum (a truncated square pyramid). With thise kind of perspective closest objects are seen bigger than further ones


This is the way you paint on 3d. But there is also a special perspective known as orthographic in which the size of the objects doesn't depend on the distance to the camera. It doesn' matter how far they are you'll see them always the same. This kind of perspective is defined on OpenGl using glOrtho(). http://www.cs.utk.edu/~vose/c-stuff/opengl/glOrtho.html


void glOrtho( GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble zNear,
GLdouble zFar )

Using glOrtho(0, SCREEN_WIDHT, 0, SCREEN_HEIGHT, 1, 0) we can say that you have created a full screen canvas. Now if you paint a vertex on (x, y, z) the point will be painted on the screen on (x, y) and z will define wich point goes behind the others. Easy!!

Wednesday, February 20, 2008

Mario Kart, April 11 in Europe!!!!

Sorry, this is a little bit off-topic... but I have to post IT!!!!!!!!!!!!!!!!!!!

KIAAAAAAAAAAHHHH!!!! IAAAAAAAAAAAAAAAAHHH!!! AHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!

http://www.cubed3.com/screens/1221

Sorry, I am still working on the new post XDD

Monday, February 11, 2008

Painting in 2D using 3D (I)

Hi.

Well, now it is when I realize how annoying is to have a blog like this XDDD, why can't it just auto-update by itself... do I have to do everything :D? For those of you who think that I have abondoned DS homebrew I have something to say about it. I have been developing these moths, but I haven't updated the blog. And I think it is time to solve this. So I am going to explain deeply (well, more deeply than in previous posts) what I have been doing.

Let's begin with 2D stuff. For those of you not familiarized with the DS hardware you can think that it is stupid to write about painting in 2D using 3D. If you are familiarized with opengl then you know how to do that, and it is very simple:
1.- Call glOrtho and create a 2d View
2.- Paint a square with the texture you want to draw

As simple as this. And what happen with the DS then? Does this work? Well... hmm.. no. Why not? There are a few problems here.
1.- If you take a look at libnds implementation of glOrtho you can see the next line: MATRIX_MULT4x4 = divf32(inttof32(2), top - bottom); ; there is a division here. If you want to create a Canvas whose height has to be SCREEN_HEIGHT = 192 then you have a problem, because 2 / 192 = 0,010416666666666666666666... yes, one of those horrible numbers with infinite decimals. It doesn't matter if you use fixed point, it won't solve the problem

2.- Vertices format in DS is 4:12 so... What happen if you want to draw your texture
in (50, 50) for example? (remember that 4:12 range is -8 to 7)

Looking just to this two problems made me think if it was really possible to draw in 2D this way. What most games do is using the 2D capabilities of the DS in another layer and painting the sprites there... but this solution wasn't good for a multiplatform engine; and there is also the sprites size limitations this hardware have.

So, this was the problem. How can you solve this? See you on next post :D