Hi all,
does anybody know of any tutorial/book chapter that teaches how to create a matrix based camera for a 2d game? Basically, I want to replicate those cool effects from SNES games, like zooming in/out on the player, stretching and shaking the camera and so on.
Any help is welcomed.
thanks!
2d matrix based camera
Hi, are you talking about the mode 7 that looks as a pseudo 3d effect?
What to you want to realize exactly?
What to you want to realize exactly?
There's nothing all that special about it really. In fact, you can probably do away with the matrix concept unless you need to support arbitrary rotation -- for zoom/ stretch/shake all you really need is camera coordinates centered on the view, and some representation of scale on the x and y axis -- which could be simple scaling factor, or computed from a view window (basically, the 2D equivalent of a view frustum).
If you want rotations, shears, etc. then a matrix-based camera would come in handy.
If you're after mode-7-like "3D" effects, ala F-Zero or Mario Kart, they achieved those effects with a simple 2D matrix by changing that matrix between each scan-line, which isn't really possible on PCs or modern graphics architectures in general, so if you wanted to recreate those kind of affects in the same way as they did them on the SNES, you'd have to emulate them in software yourself.
If you want rotations, shears, etc. then a matrix-based camera would come in handy.
If you're after mode-7-like "3D" effects, ala F-Zero or Mario Kart, they achieved those effects with a simple 2D matrix by changing that matrix between each scan-line, which isn't really possible on PCs or modern graphics architectures in general, so if you wanted to recreate those kind of affects in the same way as they did them on the SNES, you'd have to emulate them in software yourself.
There's nothing all that special about it really. In fact, you can probably do away with the matrix concept unless you need to support arbitrary rotation -- for zoom/ stretch/shake all you really need is camera coordinates centered on the view, and some representation of scale on the x and y axis -- which could be simple scaling factor, or computed from a view window (basically, the 2D equivalent of a view frustum).
If you want rotations, shears, etc. then a matrix-based camera would come in handy.
If you're after mode-7-like "3D" effects, ala F-Zero or Mario Kart, they achieved those effects with a simple 2D matrix by changing that matrix between each scan-line, which isn't really possible on PCs or modern graphics architectures in general, so if you wanted to recreate those kind of affects in the same way as they did them on the SNES, you'd have to emulate them in software yourself.
Hi!
I'm really looking for camera effects, not the mode 7. I had in my mind the camera from super mario world, where it closed in/out from mario and effects from other games like shaking, zoom, rotation (of the camera, not necessarily of the game scene). I'm interested too in zoom in / zoom out effects like that in Samurai Shodown and aquaria. How are those accomplished?
Below you list practically everything I want to accomplish. Where can I read / get more info?
There's nothing all that special about it really. In fact, you can probably do away with the matrix concept unless you need to support arbitrary rotation -- for zoom/ stretch/shake all you really need is camera coordinates centered on the view, and some representation of scale on the x and y axis -- which could be simple scaling factor, or computed from a view window (basically, the 2D equivalent of a view frustum).
If you need camera rotation then the matrix is the easiest way to go. You can probably glean some information if you can find Mode-7 documentation (plenty of info available in the homebrew scene) The GBA also had a similar capability, so there's information on that too. The only real difficulty there is that both of those pieces of hardware sort of work "in reverse". Since the SNES/GBA is basically constantly going "I'm drawing this pixel, what color do I need?" it takes the pixel coordinate and then works backwards through the projection to first get the corresponding tile from the tile map, and then the corresponding texel from that tile. Nowadays we don't often use such scan-line algorithms.
Anyhow, for a 2D camera matrix supporting everything you need, you'll want a 3x3 (you might get away with 3x2) matrix that looks like this:
[sx, ox, tx]
[oy, sy, ty]
[iw, jw, w]
where s is the scaling component per axis, and t is the translation component per axis. Elements beginning with 'o' are used in certain other capacities such as rotations or shears -- think of it as how much x is changed per y, and how much y is changed per x. The w components are rarely used, basically just for non-affine transformations like perspective projection. You can set that row to [0, 0, 1] for your purposes.
For more info, read this.
Also, when transforming your coordinates, you'll extend them with a '1' for vertices representing points in space, and '0' for vertices representing pure vectors (directions). In other words, a point [px, py] becomes [px, py, 1] and a vector <vx, vy> becomes <vx, vy, 0>.
To perform the transformation, you just multiply the point/vector through the matrix using standard matrix math (linear algebra).
Anyhow, for a 2D camera matrix supporting everything you need, you'll want a 3x3 (you might get away with 3x2) matrix that looks like this:
[sx, ox, tx]
[oy, sy, ty]
[iw, jw, w]
where s is the scaling component per axis, and t is the translation component per axis. Elements beginning with 'o' are used in certain other capacities such as rotations or shears -- think of it as how much x is changed per y, and how much y is changed per x. The w components are rarely used, basically just for non-affine transformations like perspective projection. You can set that row to [0, 0, 1] for your purposes.
For more info, read this.
Also, when transforming your coordinates, you'll extend them with a '1' for vertices representing points in space, and '0' for vertices representing pure vectors (directions). In other words, a point [px, py] becomes [px, py, 1] and a vector <vx, vy> becomes <vx, vy, 0>.
To perform the transformation, you just multiply the point/vector through the matrix using standard matrix math (linear algebra).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement