🔒 Locked
homemade engine issues
Advertisement
Original Post
hi! this is my first post here, though i have been looking around and gleaming info for a while now (much thanks there!). :) so, the reason i have been floating around here trying to glean info is because i would like to build a 3d engine using opengl and have had some issues. well, my friend and i finally got to the point where we can move around using wasd and looking around with a mouse. however, we have run into two issues that concern us. 1. when moving with the keyboard alone everything looks find. when looking around with the mouse alone everything looks fine. however, when we move (left and right are the most pronounced, though surely forward and backward do it too but aren't as visible) and rotate the view with the mouse, normal mouse look like in an fps is the goal, we have an issue where the objects appear to be oscilating from one spot to another. i'm not sure how to describe this, but it is like the computer is rapidly flipping a childs flipbook and the pictures drawn aren't lining up so it seems to vibrate. originally we thought this was due to having a PostRedisplay call for the keyboard call back and the passive mouse motion call back. so to remedy that we looked around online and saw that different places were using the timer call back and doing the redisplay in there. so we are now doing that too, however we are still experiencing the same issue. also, online we noticed that most people suggest moving the world around the camera in the opposite direction that the input states (so to move left move the world right, etc etc). however, we started and still are doing it so that the actual eye position is the one moving and not the rest of the world. my questions on this are -- has anyone ever experienced this before, and if so how did you solve the issue? also, is it vital to move the world around the eye as opposed to the eye through the world? 2. my second major issue with the engine (that i know of :) ) is that when i press down on the keyboard to move there is a stutter before the movement starts. so, for example, if the eye is stationary (no translation or rotation occuring) and then i push 'w' to move forward, there is a slight move forward and a pause and then continuous movement until the key is released. this occurrs for all four directions (forward, backward, right, and left) but not for mouse look. my question is pretty much the same as before -- has anyone ever experienced anything like this before and if so, how did you solve the issue? i know i haven't posted any code here, but that is because the faq said not to be a "fix this for me" kind of person. :) i have done lots of searching online and tried to find a tutorial or paper or anything on how to effectively create a mouse look system, but haven't been very successful, only tutorials on how to get the mouse location. about the most useful mouse info i have found is how to warp the pointer around the screen (which is allowing us to have continuous movement as opposed to being locked at the edges). however, having said that, i would be glad to post any code that you might think helpful in diagnosing the issues. bonus question -- does anyone know where i can find out what is actually going on in glutMainLoop()? i have checked the man pages and what not, but i really would like to see the code in there or a list of what is happening and in what order. thanks! and, i would like to say thank you for all the help ya'll have provided so far (unwittingly ;)) and any that is to come.
Number one is probably an issue with applying the transformations and rotations, possibly in the wrong order. I haven't touched 3d code in some months so am not too sure about it. Your description is difficult to comprehend :) but from what you say it might be something else. Any chance of a screenshot?
Number two is most likely an issue with your keyboard polling / processing code. Think of how you press a key in a text editor. First one letter appears, then a pause, then others follow if the key is still down. Therefore, if you only move once for each keydown, you will get this initial stutter (I think). So you want to start moving on the first keydown and ignore subsequent keydowns of the same key until a keyup for that key is detected. (I might be digging my grave here tho :D)
Edit: answer to your bonus question
Edit2: You might wanna ditch GLUT :) I suppose it only brings some startup code and main loop code to the table, and that stuff is a write-and-forget non-issue. Write it once, your way, and you can keep using it. Portability is usually not an issue unless you are aiming at the small devices market or the console market or really want to impress linux users.
Number two is most likely an issue with your keyboard polling / processing code. Think of how you press a key in a text editor. First one letter appears, then a pause, then others follow if the key is still down. Therefore, if you only move once for each keydown, you will get this initial stutter (I think). So you want to start moving on the first keydown and ignore subsequent keydowns of the same key until a keyup for that key is detected. (I might be digging my grave here tho :D)
Edit: answer to your bonus question
Edit2: You might wanna ditch GLUT :) I suppose it only brings some startup code and main loop code to the table, and that stuff is a write-and-forget non-issue. Write it once, your way, and you can keep using it. Portability is usually not an issue unless you are aiming at the small devices market or the console market or really want to impress linux users.
Quote:
Your description is difficult to comprehend :) but from what you say it might be something else. Any chance of a screenshot?
yeah, i know, like i said, it is kinda hard to explain. i tried to grab a screen shot that demonstrated the issue i am seeing and i can't seem to do it. apparently the issue is then that the view is being drawn incorrectly like every other frame. this then raises a question of when the input is taken in. when using glut (which i really would like to get away from myself however my friend is dead set on it, i suggested we use the gl commands ourself write wrappers for what we need and let allegro do keyboard and mouse input if that is possible ... is it?) i don't know if keyboard and mouse are taken in at alternating times. my friend explains it as whenever the windows interupt is registered glut then deals with the respective call back. i'm not sure if that is how it is, but it doesn't explain why they can't be registered in the same loop and then have the transforms applied and then have the PostRedisplay called. that is what would make sense to me -- mess with stuff and then display it. if any of that made sense, can some one please comment on it?
Quote:
Number two is most likely an issue with your keyboard polling / processing code. Think of how you press a key in a text editor. First one letter appears, then a pause, then others follow if the key is still down. Therefore, if you only move once for each keydown, you will get this initial stutter (I think). So you want to start moving on the first keydown and ignore subsequent keydowns of the same key until a keyup for that key is detected. (I might be digging my grave here tho :D)
on this topic i did some research for what glut does with keyboard polling. this is what i came up with. at first i was really excited because it seemed to be what i wanted. however, it turns out that glutSetKeyRepeat() actually doesn't work in win32 and to do something similar you have to do glutIgnoreKeyRepeat(). in that case when you set it to ignore key repeats and use the glutMainLoop (man, this thing keeps popping up and i dislike it more and more ever time ...) you have to repress the key for it to reregister. now i freely admit that i really didn't know what to do after setting glutIgnoreKeyRepeat() to ignore. my guess is that there is a way to make it so that there is no need to keep repressing whatever key, but i don't know it. so any help there would be good.
Quote:
Edit: answer to your bonus question
thanks!
Quote:
Edit2: You might wanna ditch GLUT :) I suppose it only brings some startup code and main loop code to the table, and that stuff is a write-and-forget non-issue. Write it once, your way, and you can keep using it. Portability is usually not an issue unless you are aiming at the small devices market or the console market or really want to impress linux users.
yeah, that is what i'm thinking more and more. like i mentioned earlier in this post, i was contemplating dropping glut, writing my own main and wrappers that i know are working and how, and letting allegro get the keyboard and mouse data (because i don't know how opengl does it, but i am familiar with allegro). any suggestions there? think that will work?
again, thanks for the help so far! and remember, if you want to see any particular code i'm more than happy to post it if it means generating insight that i can use. :)
Quote:
Original post by supercat1
my guess is that there is a way to make it so that there is no need to keep repressing whatever key, but i don't know it. so any help there would be good.
What your probably could do is to store the key states in a table. You can use the callbacks described at the bottom of that page to reset the key's state in your table. Then every frame you check if the key is down according to your table, and if it is, commence movement. This should give smooth results.
Quote:
Original post by supercat1
yeah, that is what i'm thinking more and more. like i mentioned earlier in this post, i was contemplating dropping glut, writing my own main and wrappers that i know are working and how, and letting allegro get the keyboard and mouse data (because i don't know how opengl does it, but i am familiar with allegro). any suggestions there? think that will work?
OpenGL is a graphics library. Unlike DirectX, it does not provide for any input methods. Therefore, you really have to use another library (if moving away from GLUT). Apart from Allegro, there's also SDL input, and DirectX input. Someone in an old thread also suggested GL Framework (GLFW), although it seems to do a lot more than just input.
[Edited by - lightbringer on June 7, 2006 6:16:21 PM]
Hi,
Are you developing on XP/2000? If so, try looking up WM_INPUT on the msdn site. I use that and it works fine, I have a big if/else statement for the keyboard processing.
As for your objects being skewed, Sounds like you may have either
a) a problem with your FOV setup
or most likely
b) a problem with your camera code.
Are you using a vector system for you camera? If not, I would recomend using that.
Hope this helps somewhat.
( i need a new keyboard, so if there are any r's missing, that's my excuse )
Are you developing on XP/2000? If so, try looking up WM_INPUT on the msdn site. I use that and it works fine, I have a big if/else statement for the keyboard processing.
As for your objects being skewed, Sounds like you may have either
a) a problem with your FOV setup
or most likely
b) a problem with your camera code.
Are you using a vector system for you camera? If not, I would recomend using that.
Hope this helps somewhat.
( i need a new keyboard, so if there are any r's missing, that's my excuse )
The first issue is almost definitely a problem with the order that transformation are being applied. I had the same kind of problem until I fixed some bugs with matrix orders and stuff, then it worked - that was a good day.
The second issue is due to the keyboard repeat delay. Even at its fastest it is not quick enough. A better way is to poll the keyboard status in your main loop. If you're using Windows for example, call GetKeyboardState to find out which keys are currently depressed.
The second issue is due to the keyboard repeat delay. Even at its fastest it is not quick enough. A better way is to poll the keyboard status in your main loop. If you're using Windows for example, call GetKeyboardState to find out which keys are currently depressed.
For smooth keyboard input you can try:
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
Instead of checking the array or whatever you are storing key states in just use one of these in its place. You won't have any of the waiting when you use the default Windows keyboard stuff.
Also, its not that hard to create a real WinMain() and WndProc().
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
Instead of checking the array or whatever you are storing key states in just use one of these in its place. You won't have any of the waiting when you use the default Windows keyboard stuff.
Also, its not that hard to create a real WinMain() and WndProc().
Quote:
Original post by lightbringer
Edit: answer to your bonus question
I read: Answer to your bogus question
thanks for all the suggestions so far.
however, i'm still unable to find anything that is wrong. or more accurately, i'm not seeing it, cause there is definitely something wrong. furthermore, this is the third day in which i have been essentially alone in trying to figure this out. my friend who did much of the original coding has been anything but helpful in determining the problem and i'm getting very frustrated.
to that end, i'm contemplating just redoing the whole thing myself. however, if anyone would be willing to look at our code and could help me figure out the image thing (i can live with the key delay for now, that is definitely an easier fix) i would be extremely thankful, even if said help was just "start over, it's easier that way".
anyways, thanks for the help so far!
however, i'm still unable to find anything that is wrong. or more accurately, i'm not seeing it, cause there is definitely something wrong. furthermore, this is the third day in which i have been essentially alone in trying to figure this out. my friend who did much of the original coding has been anything but helpful in determining the problem and i'm getting very frustrated.
to that end, i'm contemplating just redoing the whole thing myself. however, if anyone would be willing to look at our code and could help me figure out the image thing (i can live with the key delay for now, that is definitely an easier fix) i would be extremely thankful, even if said help was just "start over, it's easier that way".
anyways, thanks for the help so far!
sorry for the double post, but i wanted to make sure that those who were helping me before saw this as a new post. to you all, i am very thankful.
now, i have essentially gone through what was the engine before now (as my friend had mostly written it) and forced it to fornicate with nehe's lesson 10 code. what it spawned was this:
any comments y'all have would be much appreciated. the jittery effect i was talking about before is still kinda present here, but not as bad. the key delay is here, but we have definitely discussed that into the ground. :)
any suggestions on how to further eliminate the jitteryness would be greatly appreciated.
[Edited by - supercat1 on June 8, 2006 12:43:23 AM]
now, i have essentially gone through what was the engine before now (as my friend had mostly written it) and forced it to fornicate with nehe's lesson 10 code. what it spawned was this:
// 6/7/06// Andrew Monshizadeh// OpenGL 3d engine using glut#include <GL/glut.h>#include <cmath>#include <iostream>#include <stdlib.h>#include <stdio.h>#include <string.h>using namespace std;// window global variablesint WINDOW_WIDTH = 800;int WINDOW_HEIGHT = 600;int windowids[1]; // can be used to store multiple window ids in case there are multiple windowschar title[13] = "test engine";// call back functions to be usedvoid initializecallbacks();void displaycallback();void keyboardcallback(unsigned char key, int x, int y);void passivemotioncallback(int x, int y);void reshapecallback(int w, int h);void timercallback(int time);// setup visual requirmentsvoid initializevisuals();// variables used for movementconst float piover180 = 0.0174532925f; // pi / 180, for degree to radian transformfloat heading; // direction character is facingfloat xpos; // x-axis position of the playerfloat zpos; // z-axis position of the playerfloat ypos = 0.5; // y-axis position of the playerGLfloat yrot; // y-axis rotationGLfloat lookupdown = 0.0f; // value to look up or downGLfloat z=0.0f; // Depth Into The Screenint mousebasex = WINDOW_WIDTH/2;int mousebasey = WINDOW_HEIGHT/2;int main(int argc, char* argv[]){ glutInit(&argc, argv); initializevisuals(); initializecallbacks(); glutMainLoop(); return 0;}//----------------------------------------------------------------------------//// call back section ////----------------------------------------------------------------------------//void initializecallbacks(){ // setting up the call back functions glutDisplayFunc(displaycallback); // display call back glutKeyboardFunc(keyboardcallback); // keyboard call back glutPassiveMotionFunc(passivemotioncallback); // passive mouse motion call back glutReshapeFunc(reshapecallback); // screen reshape call back glutTimerFunc(15, timercallback, 0); // timer call back}void keyboardcallback(unsigned char key, int x, int y){ switch (key) { // miscellaneous input case 27: // 'esc' exit(0); // end the program break; // movement input case 'a': xpos -= (float)sin(heading*piover180 + 90.0f*piover180) * 0.05f; zpos -= (float)cos(heading*piover180 + 90.0f*piover180) * 0.05f; break; case 'd': xpos += (float)sin(heading*piover180 + 90.0f*piover180) * 0.05f; zpos += (float)cos(heading*piover180 + 90.0f*piover180) * 0.05f; break; case 'w': xpos -= (float)sin(heading*piover180) * 0.05f; zpos -= (float)cos(heading*piover180) * 0.05f; break; case 's': xpos += (float)sin(heading*piover180) * 0.05f; zpos += (float)cos(heading*piover180) * 0.05f; } int dims[4]; glGetIntegerv(GL_VIEWPORT, dims); int dx = x - mousebasex; int dy = y - mousebasey; mousebasex = x; mousebasey = y; // if (x < 20)// {// glutWarpPointer(dims[2]/2, y);// mousebasex = dims[2]/2;// }// if (x > (dims[2]/2 - 20))// {// glutWarpPointer(dims[2]/2, y);// mousebasex = dims[2]/2;// } lookupdown += dy * 0.5f; heading -= dx * 0.5f; if(heading < 0.0f) heading = heading + 360.0f; else if(heading > 360.0f) heading = heading - 360.0f; yrot = heading;}void passivemotioncallback(int x, int y){ int dims[4]; glGetIntegerv(GL_VIEWPORT, dims); int dx = x - mousebasex; int dy = y - mousebasey; mousebasex = x; mousebasey = y; if (x < 20) { glutWarpPointer(dims[2]/2, y); mousebasex = dims[2]/2; } if (x > (dims[2] - 20)) { glutWarpPointer(dims[2]/2, y); mousebasex = dims[2]/2; } lookupdown += dy * 0.5f; heading -= dx * 0.5f; if(heading < 0.0f) heading = heading + 360.0f; else if (heading > 360.0f) heading = heading - 360.0f; yrot = heading;}void reshapecallback(int w, int h){ glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix}void timercallback(int time){ glutPostRedisplay(); glutTimerFunc(10, timercallback, 0);}void displaycallback(){ int dims[4]; glGetIntegerv(GL_VIEWPORT, dims); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Reset The View GLfloat xtrans = -xpos; GLfloat ztrans = -zpos; GLfloat ytrans = 0; // -walkbias-0.25f; GLfloat sceneroty = 360.0f - yrot; glRotatef(lookupdown,1.0f,0,0); glRotatef(sceneroty,0,1.0f,0); glTranslatef(xtrans, ytrans, ztrans); glBegin(GL_QUADS); glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Top) glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Top) glVertex3f(-0.5f, 0.5f, 0.5f); // Bottom Left Of The Quad (Top) glVertex3f( 0.5f, 0.5f, 0.5f); // Bottom Right Of The Quad (Top) glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange glVertex3f( 0.5f,-0.5f, 0.5f); // Top Right Of The Quad (Bottom) glVertex3f(-0.5f,-0.5f, 0.5f); // Top Left Of The Quad (Bottom) glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Bottom) glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Bottom) glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red glVertex3f( 0.5f, 0.5f, 0.5f); // Top Right Of The Quad (Front) glVertex3f(-0.5f, 0.5f, 0.5f); // Top Left Of The Quad (Front) glVertex3f(-0.5f,-0.5f, 0.5f); // Bottom Left Of The Quad (Front) glVertex3f( 0.5f,-0.5f, 0.5f); // Bottom Right Of The Quad (Front) glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Back) glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Back) glVertex3f(-0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Back) glVertex3f( 0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Back) glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue glVertex3f(-0.5f, 0.5f, 0.5f); // Top Right Of The Quad (Left) glVertex3f(-0.5f, 0.5f,-0.5f); // Top Left Of The Quad (Left) glVertex3f(-0.5f,-0.5f,-0.5f); // Bottom Left Of The Quad (Left) glVertex3f(-0.5f,-0.5f, 0.5f); // Bottom Right Of The Quad (Left) glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet glVertex3f( 0.5f, 0.5f,-0.5f); // Top Right Of The Quad (Right) glVertex3f( 0.5f, 0.5f, 0.5f); // Top Left Of The Quad (Right) glVertex3f( 0.5f,-0.5f, 0.5f); // Bottom Left Of The Quad (Right) glVertex3f( 0.5f,-0.5f,-0.5f); // Bottom Right Of The Quad (Right) glEnd(); // Done Drawing The Quad glFlush(); glutSwapBuffers();}void initializevisuals(){ // creating the window and drawing buffers glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); // create double buffer and z-depth buffer glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); // create window using predetermined window sizes glutInitWindowPosition(0,0); windowids[0]=glutCreateWindow(title); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background color to white glClearDepth(1.0); // enables clearing of the depth buffer glEnable(GL_DEPTH_TEST); // enable depth testing glDepthFunc(GL_LESS); // the type of depth test to do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // really nice perspective calculations, got from NeHe tutorial 10 int dims[4]; glGetIntegerv(GL_VIEWPORT, dims); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window gluPerspective(45.0f,(GLfloat)dims[2]/(GLfloat)dims[3],0.1f,100.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix}any comments y'all have would be much appreciated. the jittery effect i was talking about before is still kinda present here, but not as bad. the key delay is here, but we have definitely discussed that into the ground. :)
any suggestions on how to further eliminate the jitteryness would be greatly appreciated.
[Edited by - supercat1 on June 8, 2006 12:43:23 AM]
quadruple post ftw!
but this is a good triple post -- i got the issue fixed! turns out that what was causing the jumpy visuals was the fact that glut was poling the keyboard for key presses every time through glutMainLoop(). so after putting in a version of delay-less input (similar to what y'all suggested, but having to go through glut's messy call backs since i'm not building it only for win32). but anyways, i got the delay-less input coded, compiled, ran, and started to freak out. :) i was pretty happy to finally not have nausea inducing vibrating objects on the screen.
i can't say thank you enough to the people on this board that helped with the correction of this/these issues! my hat's off to y'all!
but this is a good triple post -- i got the issue fixed! turns out that what was causing the jumpy visuals was the fact that glut was poling the keyboard for key presses every time through glutMainLoop(). so after putting in a version of delay-less input (similar to what y'all suggested, but having to go through glut's messy call backs since i'm not building it only for win32). but anyways, i got the delay-less input coded, compiled, ran, and started to freak out. :) i was pretty happy to finally not have nausea inducing vibrating objects on the screen.
i can't say thank you enough to the people on this board that helped with the correction of this/these issues! my hat's off to y'all!
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement