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.

Coding > What are some good ways to achieve this effect?

#23477 - benjamin - Tue Jul 13, 2004 8:08 pm

I am envisioning a certain way of showing perspective and am wondering about 2 possible techniques.

What I want to achieve is basically a view of a field of game entities that changes in both angle and distance from the ground.

Ideally I would be doing this in 3D and simple rotating a camera and dollying in or out.

Is a mode 7 emulation a good candidate for this? And if so is the GBA powerful enough to render mod 7-esque effects *and* still run the actual game code (i.e., I'm not looking to make just a demo here, there's AI and Sound cycles to consider too).

The other way I thought about was to possibly dynamically change tile sets to fake zooming in and out on the field, and use several sets of sprites to fake zooming in and out from the player entities..

Any suggestions?

#23478 - poslundc - Tue Jul 13, 2004 8:24 pm

Basic Mode7 is very computationally inexpensive to create, since most of the work is handled by the GPU. I haven't put much thought into it, but adding the ability to zoom in or out shouldn't be too taxing either, so long as you keep the pitch of the camera fixed and have a fast divide routine (a large reciprocal LUT would probably do nicely).

My project adds the ability to swivel the camera up and down, which required the use of a raycasting algorithm that is more computationally expensive. I've optimized it in assembly so there's still plenty of room left for most of the stuff I want to do, but it is not as cheap to create as plain Mode 7, or even Mode 7 that zooms. (I can't squeeze everything into VBlank, for example, and I have to do many of the calculations for the next cycle during VDraw.)

And if the ground is flat, Mode 7 is the way to go, especially if you are concerned about CPU cycles. Any other technique would probably require a bitmap mode and be incredibly wasteful.

Dan.

#23480 - benjamin - Tue Jul 13, 2004 9:31 pm

So with mode 7 I wouldn't be able to change the pitch, that kinda stinks as I was hoping to do that, but maybe I can get away without it. My ground is definitely flat btw.

Your project seems pretty cool, I don't suppose you'd be willing to share the source?

#23488 - poslundc - Wed Jul 14, 2004 1:34 am

The source is closed, but I'd be happy to answer any algorithmic questions you may have if you're trying to achieve the same effect.

Dan.

#23489 - benjamin - Wed Jul 14, 2004 3:00 am

Thanks for your offer of help. I should probably cut my teeth on Mode 7 style first. Is it a somewhat straightforward path from that to swiveling the camera?

In any case, I think this cearn tutorial on Mode 7 is one of the better ones right?

http://user.chem.tue.nl/jakvijn/tonc/mode7.htm

#23490 - sgeos - Wed Jul 14, 2004 3:14 am

[quote="poslundc"My project adds the ability to swivel the camera up and down, which required the use of a raycasting algorithm that is more computationally expensive.[/quote]
Do you need to cast any more than 160 rays (one for each scan line) every time the pitch is changed? Would you mind putting an image up on your site that expains how you calculate the pitch?

With a night backdrop, wouldn't it make more sense for the horizon to be black?

-Brendan

#23508 - poslundc - Wed Jul 14, 2004 1:49 pm

sgeos wrote:
Do you need to cast any more than 160 rays (one for each scan line) every time the pitch is changed? Would you mind putting an image up on your site that expains how you calculate the pitch?


I don't have access to tools at work that can let me do that, but pitch is just a stored variable that can be adjusted by user or game controls; it is not calculated.

And yes, it's just 160 rays for each scanline.

Quote:
With a night backdrop, wouldn't it make more sense for the horizon to be black?


My engine can use any colour for the horizon/fog effect, as well as for the gradient sky effect.

Dan.

#23509 - poslundc - Wed Jul 14, 2004 1:55 pm

benjamin wrote:
Thanks for your offer of help. I should probably cut my teeth on Mode 7 style first. Is it a somewhat straightforward path from that to swiveling the camera?


Yes and no... the basic Mode 7 effect doesn't require much thought about the geometry or 3D mathematics behind what you are doing. If you are using raycasting, you have to put a lot more thought into how you do things like calculate the background's x and y coordinates for each scanline. You will need a solid grasp of trigonometry and you will have to draw a bunch of diagrams.

If as you originally said zooming is all you require, that should be fairly easy to implement because you can just scale your distance values before you divide.

Dan.

#23513 - keldon - Wed Jul 14, 2004 3:17 pm

just scaling the screens x and y co-ordinates does not produce zooming, but enlargement.

To a zoom effect, you'd have to use trigonometry (which is pretty easy, they teach it to you at school in 2nd/3rd year).

But if an enlargement effect is all you want (which is completely different) then that is fine.

#23521 - tepples - Wed Jul 14, 2004 5:11 pm

benjamin wrote:
So with mode 7 I wouldn't be able to change the pitch, that kinda stinks as I was hoping to do that, but maybe I can get away without it.

It's algorithmically easy to fake changing the pitch: just scroll the entire screen up and down. You can still use a reciprocal table.

If you want to see a free software demo that actually changes the pitch in real time, go look up Tetanus On Drugs. Its fx.c contains a simple Mode 7 engine. Remember that if you need more speed, you can raycast only every other scanline and use linear interpolation to get the odd lines.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#23527 - poslundc - Wed Jul 14, 2004 5:53 pm

tepples wrote:
It's algorithmically easy to fake changing the pitch: just scroll the entire screen up and down. You can still use a reciprocal table.


I vaguely recall this as being an old Wolfenstein trick... it should suffice for reasonably small angle changes, but I don't think it will look very realistic if, for example, you want to swing into an entirely top-down view.

Quote:
Remember that if you need more speed, you can raycast only every other scanline and use linear interpolation to get the odd lines.


That's a neat suggestion. I'll keep it in mind if I ever need to tweak some extra cycles out of my program.

Dan.