visual c++ - Screen shakes when the object moves -
hello im working on project , got problem screen/ground shakes when moved main object.
normally when moved "w" button dont problem. if move while im rotating camera got problem.
to see: give degree 30 right mouse button.(do not release button) , keep w button while rotating object. see shake @ ground.
i think problem looat function calculation.
glulookat(sin(rot*pi/180)*(10-fabs(roty)/4) +movex ,3-(roty/2), cos(rot*pi/180)*(10-(fabs(roty)/4)) +movez , -sin(rot*pi/180)*6 + movex, roty, -cos(rot*pi/180)*6 +movez, 0, 1, 0);
here rotation function. draw after func.
void system::rotater(){ if(mousestates[2][0]==1 && mx!= savex && mx!=mousestates[2][1]){ rot += (mx-mousestates[2][1]) * 90 / glutget(glut_window_width)/2; if(rot>360)rot-=360; if(rot<0)rot= 360+rot; } glrotatef(rot,0,1,0); }
and last move option here:
if(a==87 || a==119){ movex -= sin(rot*pi/180)/3; movez -= cos(rot*pi/180)/3; }
i've found seen screen shaking issues commonly order in process events, update objects , camera, before drawing scene (or physics engine causing :p). high framerate might not notice small imperfections. might want add sleep/usleep expose these issues. example, if camera position based on camera rotation, update position before processing mouse events camera position/rotation can frame out of sync.
this reason process inputs, movement , rendering in separate stages.
your lookat function rather complex. lookat useful when want camera looks-at something, in case you're after camera looks-from camera position. easier implement manually constructing inverse transformations position camera object before drawing sceene. example, if want move left, translate else right (thus inverse)...
glloadidentity(); glrotatef(camera.rotx, 1.0f, 0.0f, 0.0f); glrotatef(camera.roty, 0.0f, 1.0f, 0.0f); glrotatef(camera.rotz, 0.0f, 0.0f, 1.0f); gltranslatef(-camera.posx, -camera.posy, -camera.posz);
Comments
Post a Comment