• 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.

Archived

This topic is now archived and is closed to further replies.

glProgram

Camera Rotation

28 posts in this topic

Can anybody tell me a good way to do camera rotation using gluLookAt()? All tutorials I''ve seen did a terrible job and didn''t work. Also no one ever really explains gluLookAt(). Also it would help if it were done with the camera''s Position X, Y, Z and Look X, Y, Z, and Up X, Y, Z. And if possible can you include how to move in the direction the camera is looking at. Thanks.
0

Share this post


Link to post
Share on other sites
very similar to a post below, must be the new topic in class

if u want to do rotation on 3 axises (6DOF?)then u will need another method than eular angles eg angle/axis + quaternion/matrices which is much more complicated (check on the net for a lot of examples/tutorials).
if all u want to do is a quakelike movement FPS then u can get away with 1.5 axises using eulars

gluLookAt( cam.x, cam.y, cam.z, cam.x+camDIR.x, cam.y+camDIR.y, cam.z+camDIR.z, 0,1,0 )

cam is where the camera is
camDIR is the direction the camera is looking

the player can rotate on the ground plane 0..360 deg (like a compass) this is called the heading.
the player can also look up and down +90 (at sky) .. -90 (at feet) this is the pitch.(note u prolly want to limit that to 89 .. -89deg

ok to find the camera direction use the following

camDIR.x = cos(heading) * cos(pitch);
camDIR.y = sin(pitch);
camDIR.z = sin(heading) * cos(pitch);

now to move foward u ignore the pitch and just concentrate on the XZ plane

(foward key pressed)
cam.x += sin( heading )
cam.z += cos( heading )

piece of piss right?

note above u need to supply heading/pitch in radians and not degrees to convert degrees to radians multiple the degrees by (PI/180) about 0.017
0

Share this post


Link to post
Share on other sites
It still doesn''t work....
Here''s what I tried to find the direction:

right and up are the distance up or right for rotation.

camDIR.x = sin((camDIR.x+right)*(180/0.017))*cos((camDIR.y+up)*(180/0.17));
camDIR.y = sin((camDIR.y+up)*(180/0.17));
camDIR.z = sin((camDIR.x+right)*(180/0.017))*cos((camDIR.y+up)*(180/0.17));

0

Share this post


Link to post
Share on other sites
You''ll find your problem is that the computer works in radians. You are sending the angle in degrees and of course this wont work. Here are 2 inline functions that i use lots.

inline float cosd(float p_angle)
{
return cos(p_angle * (3.141592654 / 180));
}

inline float sind(float p_angle)
{
return sin(p_angle * (3.141592654 / 180));
}

This will allow you to enter a degrees angle and get the correct results back. Hope this helps =)
0

Share this post


Link to post
Share on other sites
Something is really messed up in the code but I can''t
figure out what! I used to be able to move around in the world
with glTranslatef() and the objects looked truley 3D(They still
do but...) and they would shrink as you got further away
and grow larger as you got closer as they should but now you
have to get real close to be able to see them... If you aren''t
real close it doesn''t draw them. The rotation still just spins
all the objects and shoves them either down or left(Even
if you rotate the opposite direction).
This is really starting to make me mad.
Anybody got any ideas? (Mabye if someone actually SHOWED
how to apply the suggestions because no one really gave
too detailed info)
0

Share this post


Link to post
Share on other sites
>>Something is really messed up in the code but I can''t
figure out what! I used to be able to move around in the world
with glTranslatef() and the objects looked truley 3D(They still
do but...) and they would shrink as you got further away
and grow larger as you got closer as they should but now you
have to get real close to be able to see them... If you aren''t
real close it doesn''t draw them. <<

perhaps try this look in your code for gluPerspective() or glFrustum() and make the last number 100x larger.
0

Share this post


Link to post
Share on other sites
inline float cosd(float p_angle)
{
return cos(p_angle * (3.141592654 / 180));
}

wouldnt it be better to precalculate 3.141592654 / 180
this would speed the function up!
0

Share this post


Link to post
Share on other sites
Thanks, DeathWish. I added glLoadIdentity() and now it
appears to be somewhat closer!
There''s still that problem with distance.(You have to be REAL close)(And also note that when rotating the camera I can
see that object wireframes will get cut off near the camera
and at the ends that are far from the camera.
I did mess with gluPerspective with no sucess.
Currently I can''t tell if it really looks like it is rotating
the camera or rotationg the objects themselves.
It also appears the everythings rotating the opposite direction they''re supposed to.
Also the camera doesn''t move/translate the direction it is facing
And I did put the CamDIR.x/y/z+x/y/z in gluLookAt()
0

Share this post


Link to post
Share on other sites
Personally I''ve never used gluLookAt(), I hardly use the glu library except for mipmaps and quadratic shapes. You could try it using just the standard glRotatef() and glTranslatef(), or you could do what I do in my basic 3D engine and translate all the co-ordinates by generating my own translation matrix and keeping the camera at 0,0,0.

Or, one thing you could try:

glLoadIdentity();
glPushMatrix();
// translate, rotate, render
glPopMatrix();

I''m not too sure about it though, so I may be totally wrong on the matrix push/pops... I hardly use them

(BTW, if you want to use your own translation matrix then I''m more than happy to help you if you don''t know how.)

DeathWish
0

Share this post


Link to post
Share on other sites
Another thought... you could try reverse transforming your camera. (Transform -x -y -z, rotate -z -y -x)

DeathWish
0

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
inline float cosd(float p_angle)
{
return cos(p_angle * (3.141592654 / 180));
}

wouldnt it be better to precalculate 3.141592654 / 180
this would speed the function up!


The compiler will do that for you. The only real optimization with sine and cosine is to precalculate them (they are horrendously expensive functions):
  
float Sine[360], Cosine[360];
const float M_PI = 3.141592654;
void CreateTrigLUTs( void )
{
for( int i = 0; i < 360; i++ )
{
Sine[i] = (float)sin( i * M_PI / 180 );
Cosine[i] = (float)cos( i * M_PI / 180 );
}
}


EDIT: i as array index.


Edited by - Oluseyi on September 17, 2001 1:10:35 PM
0

Share this post


Link to post
Share on other sites
using a LUT for a couple of sin''s cos''s will most likely be slower than using sin(A).
the LUT really is only benificial when youre doing heaps of sin''s at a time

http://members.xoom.com/myBollux
0

Share this post


Link to post
Share on other sites
Hey, none of that was really a reply to my last post.
Does anybody got any clues about the distance problem?
0

Share this post


Link to post
Share on other sites
Ok, I''ve got an idea:

glMatrixMode(GL_PERSPECTIVE);
gluPerspective(...);

glMatrixMode(GL_MODELVIEW);
gluLookAt(...);
glBegin(...);
...
glEnd();
0

Share this post


Link to post
Share on other sites
Actually I believe it''s GL_PROJECTION, not GL_PERSPECTIVE.
And that didn''t help at ALL.
You can''t use gluLookAt() in the GL_MODELVIEW matrix.
And I already do use gluPerspective in GL_PROJECTION and it can only be used in that matrix.
0

Share this post


Link to post
Share on other sites
>>There''s still that problem with distance.(You have to be REAL close)(And also note that when rotating the camera I can
see that object wireframes will get cut off near the camera<<

decrease your near planes depth value + increase the far planes value
in gluPerspective they are the 3rd+4th variable

http://members.xoom.com/myBollux
0

Share this post


Link to post
Share on other sites
zedzeek, that is very obvious and it keeps getting repeated here. I have tried that 3 times! I''ve tried a near distance
of 0.0f and a far distance of 100000.0f, no effect.
0

Share this post


Link to post
Share on other sites
Are you doing...

glLoadIdentity()
glLookAt(...)
push
glRotate() or glTranslate etc...
pop

make sure that the values to glLookAt are not huge numbers...
0

Share this post


Link to post
Share on other sites
um.... where exactly were you planning to use gluLookAt if not on the modelview matrix? That is exactly where it should be used, regardless of your projection.

Follow Ansi2000''s structure (rendering objects between the matrix push and pop), making sure that all these operations are done on the modelview matrix.
0

Share this post


Link to post
Share on other sites
OK! I added gluPerspective to the rotation and movement
functions, and it seems to work!!!
Though the camera still doesn''t want to move in the
direction it is facing
(And I DO use camDIR.x/y/z+x/y/z in gluLookAt center params)

ANSI2000, no I don''t and no I don''t use large numbers.
0

Share this post


Link to post
Share on other sites
Sorry didn''t see that there was 2 pages...
Bad Monkey, what are you talking about?
You CAN''T use gluLookAt in the MODEL_VIEW matrix!
And what difference would push or pop make?
0

Share this post


Link to post
Share on other sites