iDevGames Forums
Getting A Classic Zelda View - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Getting A Classic Zelda View (/thread-6311.html)

Pages: 1 2 3


Getting A Classic Zelda View - Nick - Aug 21, 2004 10:54 PM

How can I get a classic Zelda view without the standard "distorting" of motion due to being full 3D with OpenGL? I'm really trying to get this down and implement it in a game I'm working on.


Getting A Classic Zelda View - Nick - Aug 22, 2004 12:36 AM

I've found that if I position my camera a ways up the Y axis and a little out the Z axis and look at the origin, it doesn't look too different (besides motion distortion). One thing I'm curious about is whether or not there is a way to create quads that a perpendicular to the camera's vector so that they appear perfect (whereas leaving them going straight along the Y axis would make the bottom look smaller)? If anybody knows how to create a method of fixing the motion distortion and how to make quads look perfect in this view, I would much appreciate it.


Getting A Classic Zelda View - Nick - Aug 22, 2004 12:58 AM

I have found that (see above post) to be a very inefficient way of getting the results I desire. I'm going to play a lot of Zelda, look at some screenshots, and then I'm going to try again.


Getting A Classic Zelda View - codemattic - Aug 22, 2004 01:38 AM

have you tried using an orthographic projection matrix?

man glOrtho
man gluOrtho2D


Getting A Classic Zelda View - Fenris - Aug 22, 2004 05:34 AM

I think what you want is a google search for "billboarding".


Getting A Classic Zelda View - Nick - Aug 22, 2004 08:41 AM

Thanks for the help Fenris. That's exactly what I need for the sprites. I'm looking into the gluOrtho2D and glOrtho right now and I'll let you know how that goes.


Getting A Classic Zelda View - Nick - Aug 22, 2004 09:12 AM

I've found a declaration of gluOrtho2D and glOrtho but I'm unsure how to use them and how they will help.


Getting A Classic Zelda View - skyhawk - Aug 22, 2004 09:27 AM

Code:
glMatrixMode(GL_PROJECTION);
    // set to 800x600 view
    glOrtho(0,600,800,0,-200,200);



Getting A Classic Zelda View - Skorche - Aug 22, 2004 09:33 AM

glOrtho(left, right, bottom, top, near, far)

It's quite simple. The left right top and bottom parameters should be fairly self explanatory, the near and far set the minimum and maximum z coordinates.

glOrtho2D is the exact same thing, but it automatically puts in -1, and 1 for the near and far parameters.


Getting A Classic Zelda View - Nick - Aug 22, 2004 09:45 AM

Here's my code so far and I'm not seeing anything on the screen:

Code:
void SizeOpenGLScreen(int width, int height) // Initialize The GL Window
{
    if (height==0) // Prevent A Divide By Zero error
    {
        height=1; // Make the Height Equal One
    }
    
    glViewport(0,0,width,height); // Make our viewport the whole window
                                  // We could make the view smaller inside
                                  // Our window if we wanted too.
                                  // The glViewport takes (x, y, width, height)
                                  // This basically means, what our our drawing boundries
    
    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glLoadIdentity(); // Reset The Projection Matrix
    
    gluOrtho2D(-10,10,-10,10);
    
    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    glLoadIdentity(); // Reset The Modelview Matrix
}


Code:
void RenderScene()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
    glLoadIdentity();                                   // Reset The matrix
    
    // Tell OpenGL where to point the camera
    g_Camera.Look();
    
    glBegin(GL_QUADS);
    glColor3ub(255,255,255);
    
    glVertex2f(-5,5);
    glVertex2f(5,5);
    glVertex2f(5,-5);
    glVertex2f(-5,-5);
    
    glEnd();
    
    // Swap the backbuffers to the foreground
    SDL_GL_SwapBuffers();  
}



Getting A Classic Zelda View - SOUR-Monkey - Aug 22, 2004 07:07 PM

Use glOrtho(-10, 10, -10, 10, 1, 20); to set it up. Then do a translate like below:
glTranslatef(0.0f, 0.0f, -10.0f);
before you do any rendering (ie. one of the first lines in your render function).

This will set up your orthographic screen, and translate the camera out so that you can see it.

EDIT: Also, don't pass ints if you should be passing floats. In your glVertex2f() calls you are passing int values, which is just plain silly. Use (+-)5.0f, or call glVertex2i() instead.


Getting A Classic Zelda View - codemattic - Aug 22, 2004 08:15 PM

for a more visual explaination check out http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html and scroll down to the section "Projection Transformations."


Getting A Classic Zelda View - arekkusu - Aug 22, 2004 09:07 PM

Typical 2D ortho projection is something like:
Code:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, game_width, game_height, 0);    // origin in TOP left
glViewport(0, 0, window_width, window_height);

Since the Z coordinate doesn't mean anything in a 2D projection, you don't have to translate the camera out.

Also, this is perfectly fine:
Code:
glVertex2f(5,5);
because the int->float conversion will be handled at compile time.

This:
Code:
int x = 5, y = 5;
glVertex2f(x,y);
is not as good because now the conversion is at runtime. glVertex2i isn't really any better because all coordinates will be converted into floats internally anyway.


Getting A Classic Zelda View - Nick - Aug 22, 2004 09:42 PM

Thanks. That got it working. I also had a problem with the fact that my camera class was still setting itself up awkwardly not in the right position so (0,0) wound up at the top of the middle of the screen because the camera was putting itself at (0,0).


Getting A Classic Zelda View - Nick - Aug 22, 2004 10:16 PM

A couple more questions. This gluOrtho2D sets my upper left corner to (0,0) (in your example, arekkusu) and my lower right to (gamewidth,gameheight) correct? So why when I draw things they seem to ignore this and act as they usually would (for instance subtracting from Y seems like it should move up with 0 being the top but it still moves down)?

Edit:
Also, how can I make sure that things that are higher in Y are drawn above the objects with lower Y values to simulate the Zelda look? For example:

--------
-----O-
-----P-
-------

P is large enough to go into O, how do I get it to draw P above O and still draw O (so that when I put in sprites with transparency O is still visible)?