gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Scrolling/Rotating a background according to the 3D world

#154591 - Rajveer - Fri Apr 18, 2008 7:13 pm

Has anyone got any advice or links to resources that explain how I should be scrolling the background when rotating within the 3D world? I'm racking my brains out thinking of how to use the current 3D projection matrix and forming a 2x2 rotation matrix and scrolling vector to put into the background registers, but I want it so that the current fov e.t.c. affect how much of the bg is visible. The backgrounds will all be 256*256 so perhaps there's some shortcuts with constant scaling and stuff.

#154594 - kusma - Fri Apr 18, 2008 8:17 pm

Rajveer wrote:
Has anyone got any advice or links to resources that explain how I should be scrolling the background when rotating within the 3D world?

My first instinct is to take the view-vector, and find the rotation about the y-axis for the x-scroll. The dot product between the up-vector and the view-vector can possibly be used to find y-scroll. roll around the z-axis can be used to find a rotation amount. Fov can possibly affect scale.

What you end up with, is something similar of a cylindrical mapping, but I guess it breaks horribly when looking straight up etc :)

Quote:
I'm racking my brains out thinking of how to use the current 3D projection matrix[...]

Sure you don't mean the view and projection matrix? A projection matrix is usually considered as the eye->frustum transform. Personally I would stay away from trying to decomposing the matrix into the above the above components, and instead try to use the datas used to generate the matrix with in the first place.

#154596 - Rajveer - Fri Apr 18, 2008 10:04 pm

kusma wrote:
What you end up with, is something similar of a cylindrical mapping, but I guess it breaks horribly when looking straight up etc :)


That's the problem, my game lets the player rotate around all over the place! :D

Quote:
Sure you don't mean the view and projection matrix?


Opps yep that's what I meant!

#154622 - Rajveer - Sat Apr 19, 2008 11:20 am

Thinking about this more in depth, I'm not sure this is the way to go. It's fine for a game where you rotate mainly around 1 axis (e.g. Mario Kart DS and the y-axis) but not for a game where you can rotate all over the place. Another problem is wrapping the texture above and below, for instance look at this example:

[Images not permitted - Click here to view it]

The texture can't be wrapping properly one way and flipped the other, so I get this problem.

What do you guys think? I really don't want to use 3D geometry for the sky and would love to use a background, but can I get it working like I want?

#154625 - TwentySeven - Sat Apr 19, 2008 12:01 pm

Spend your ~6 polygons and make a skybox :)

The ds 3d hardware has approximately 4x the fillrate needed to draw the whole screen.. considering the % of your scene that is likely to actually be sky.. it's probably a total bargain even with a nice cloud layer etc.


As for doing it with a bg.. use a 64x64 tile bg and just set the flip x/y bits for the other 3 quadrants to reuse the initial 32x32 tiles

#154627 - M3d10n - Sat Apr 19, 2008 1:55 pm

The original Mario 64 and loads of Saturn games did what you want (using a flat 2D background in 3D environment), but I don't remember such games allowing full rotations (as in you couldn't rotate "up" until the camera ends upside down), and when you look "up" you usually only see a solid color or something, the BG only covering the area close to the horizon.

If you really want your BG to mirror-wrap like that, you can use a tilemap with flipped tiles for the flipped region.

#154629 - silent_code - Sat Apr 19, 2008 2:10 pm

depending on your game, you only may need a "half sky box". maybe even a four sided pyramid shape will be enough.
although i think it is totally doable to use a bg for the sky, like TwentySeven pointed out.

let us know what you'll go for! :^)

#154631 - Rajveer - Sat Apr 19, 2008 3:30 pm

Hmm, they're both interesting ideas, I could use a half-skybox with a cloud layer and fill the actual sky with clearcolor, or a gradient somehow. I think I'll first look into tilemapping so that artists can have actual artwork for the sky if they desire, and if that doesn't give the right results then go for the second idea. Now to dig up those tile mapping tutorials from the net! :D

P.S. TwentySeven, I'm not sure how tile maps work yet but out of curiosity why did you suggest 64x64 tiles, is there a size limit or something?

#154632 - silent_code - Sat Apr 19, 2008 3:48 pm

64 x 8 = 512 pixels ;^) iirc, there's up to 1024? pixels for a bg, but it comes with it's own limitations. you'd have to look it up, though.

EDIT: or was it 1024? tiles? i'm too lazy to look it up! ;^p


Last edited by silent_code on Sun Apr 20, 2008 2:55 am; edited 1 time in total

#154664 - TwentySeven - Sun Apr 20, 2008 2:14 am

Yeah, a 64x64 bg tilemap is the smallest one that'll hold 4 full screens worth of data. (512x512, and a screen is 256x192)

Each tile takes 2 bytes to define, and a couple of those bits can be used to flip the tile on the x and y axis.

See:
http://liranuna.drunkencoders.com/nds-2d-tuts/lesson-3/
(I end up linking this page alot, but its very succinct)

However, I honestly suggest you use polygons to do it. As I mentioned before, the DS actually has a fairly disgusting amount of fillrate (compared to the puny geometry budget), a couple of layers of blended clouds would look fairly spiffy imho.

#154834 - Rajveer - Tue Apr 22, 2008 12:06 am

In the end I just went with a simple skybox, with 6 128x128 x 256 colour textures. It's a shame though, right now I'm using VRAM F for palettes, and I thought I could use E for textures, now I have to look for something to fill it up with! Maybe a text library...

EDIT: Oh wait, need a cloud layer, that bank could really have come in useful!