• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Cydriic

OpenGL Camera Concept

9 posts in this topic

Hi Everyone,

 

Does anybody know where I could find a good tutorial for understanding how to program a Camera in OpenGL.

 

Meaning that I don't want tthe world to move according to Input, but have the world be rendered in fonction how the camera Moves through the World.

 

 

Thank guys I really Appreciate it.

 

 

Cydriic

0

Share this post


Link to post
Share on other sites

I don't know of any tutorials, but basically all you need to do is give your camera a transform matrix just like any other object in your world. When it comes time to render the scene, invert the Camera's matrix to get the view matrix. At the end of the day, your verts need to be in camera-relative space before doing the projection transformation. So, this last step of inverting the camera matrix to get the view matrix, and then multiplying your world-space verts with this view matrix, cannot be avoided. However, at least with this method, you can think in terms of the camera's position until the very end.

0

Share this post


Link to post
Share on other sites

In old opengl camera is imo just GluLookAt (yet with perspective settings), you need just some functions to move it in space

 

In modern opengl i dont know it this is still applicable (as i wasnt using yet modern ogl) Is it applicable in modern opengl? need some there in m-ogl write gluLookAt by self?

 

ps. camera can be a little confusing (by 'a little' i mean much ;/ )

presently i personaly am a bit lost in this, when i mend it i probably could share some more advice but not now (as i am angry with some details still) )

Edited by fir
0

Share this post


Link to post
Share on other sites

glu functions are not opengl, they are glu (gl-utility if i am right). They wrap opengl for convenience.

0

Share this post


Link to post
Share on other sites
With the above tutorial I highly suggest to stop reading at (or skipping) the chapter Euler Angles, unless first person is all you need. Mostly because otherwise it might be 1-2 weeks before a "I have gimbal lock and/or my camera rotation is acting funny"-thread. Also, the assumption that 0,1,0 is always a working approximation for "up" will fail if your camera can be upside down (flight simulator, space game, fancy camera movement in cutscenes).
 
The easiest way is to store a regular transformation matrix for your camera, treat it like any other object and invert it to get your view matrix:
 
//Quick inverse (transpose rotation part, multiply translation with transposed rotation)
Matrix Camera::getViewMatrix() 
{
    return Matrix(
        transformation[0], transformation[4], transformation[8], 0,
        transformation[1], transformation[5], transformation[9], 0,
        transformation[2], transformation[6], transformation[10], 0,
        -(transformation[0]*transformation[12] + transformation[1]*transformation[13] + transformation[2]*transformation[14]),
        -(transformation[4]*transformation[12] + transformation[5]*transformation[13] + transformation[6]*transformation[14]), 
        -(transformation[8]*transformation[12] + transformation[9]*transformation[13] + transformation[10]*transformation[14]), 1);
}
 
//Going the matrix route for translation is a bit overkill, but better demonstrates the difference between moving along local or global axes
void Camera::move(float x, float y, float z, bool global, float distance) 
{
    Matrix translation = Matrix::createTranslation(x,y,z);
    if (global)
        transformation = transformation * translation;
    else 
        transformation = translation * transformation;
}
 
void Camera::rotate(float deg, float x, float y, float z, bool global)
{
    Matrix rotation = Matrix::rotationFromAxisAngle(deg, x,y,z);
    if (global) 
        transformation = transformation * rotation;
    else 
        transformation = rotation * transformation;
}

Edit: well, thank the forum gods for deleting everything after the code block when editing.

If whatever matrix library doesn't let you access by index (or has a different memory layout):
0-3: x-axis aka "camera right" (x,y,z,0)
4-7: y-axis aka "camera up" (x,y,z,0)
8-11: z-axis aka "camera forward" (x,y,z,0) (might be backward, depending on handed-ness)
12-15: origin aka "camera position" (x,y,z,1)

If you need zoom, this goes into the projection matrix (simply reduce the fov). Zooming is NOT scaling and NOT "moving closer" (or any other weird thing that causes clipping errors when zooming "too much"). Edited by Trienco
0

Share this post


Link to post
Share on other sites

With the above tutorial I highly suggest to stop reading at (or skipping) the chapter Euler Angles, unless first person is all you need. Mostly because otherwise it might be 1-2 weeks before a "I have gimbal lock and/or my camera rotation is acting funny"-thread. Also, the assumption that 0,1,0 is always a working approximation for "up" will fail if your camera can be upside down (flight simulator, space game, fancy camera movement in cutscenes).

 

Hey Trienco,

You're right and make a good point about the tutorials only explaining the concept of a first person camera. I probably should have made it more clear in my post that this explains a first person camera only. I'll be sure to add an extra section to the camera tutorial later explaining its limitations to make things more clear, thanks.

0

Share this post


Link to post
Share on other sites

Hey Trienco,
You're right and make a good point about the tutorials only explaining the concept of a first person camera. I probably should have made it more clear in my post that this explains a first person camera only. I'll be sure to add an extra section to the camera tutorial later explaining its limitations to make things more clear, thanks.


Nah, your tutorial clearly states it's for an FPS style camera (one of the rare cases where even Euler Angles are just fine,  since you'll always rotate in a fixed order). I just pointed out the limitations since the OP didn't specify any particular requirements and I wanted to prevent the usual cycle of using Euler angles -> gimbal lock -> "quaternions are the only way" -> thread asking for help with quaternions -> never realizing that quaternions aren't magic and can't do anything matrices can as well -> continuing the cycle of preaching about how quaternions are the only way to do proper rotations.

0

Share this post


Link to post
Share on other sites

Hehe yeah oké :) thanks for clarifying. I'll make sure to add some extra statements nevertheless since it's a good insight that an FPS camera is not an all-round camera system with eular angles.

0

Share this post


Link to post
Share on other sites

Hehe yeah oké smile.png thanks for clarifying. I'll make sure to add some extra statements nevertheless since it's a good insight that an FPS camera is not an all-round camera system with eular angles.

 

Well, I guess it would work for third person as well. Pretty much any situation where your side to side rotation is always around the global y-axis should be safe and the look-at approach is fine if the rotation around x never goes to or beyond +/-90°.

 

Btw. there is one downside to storing the orientation as a matrix (or quaternion): floats suck. After a bunch of rotations, the vectors that should be will be no longer normalized and in the case of a matrix, the rotation part will be no long orthogonal on top of it. So every once in a while, the matrix will need to be re-orthonormalized (basically 2 cross products and 3 normalizations. With a quat, that should be only a single normalization.

 

While this sounds like a great advantage:

-it only needs to be done every once in a while.

-even if done once per frame, it's nothing compared to all the other things going on

-unless your pipeline can natively use quats, you'll still have to convert them to a matrix every frame (so you don't really win anything)

-if you need info from the camera (like view direction for bill boarding), simply reading the 3rd column of the matrix is easier than having to calculate it by transforming 0,0,1 by your stored quat

2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0