iphone - How to move incrementally in a 3D world using glRotatef() and glTranslatef() -


i have 3d models render in opengl in 3d space, , i'm experiencing headaches in moving 'character' (that camera) rotations , translation inside world.

i receive input (ie coordinates move/the dregrees turn) extern event (image user input or data gps+compass device) , kind of event rotation or translation .

i've wrote method manage these events:

- (void)movetheplayerpositiontranslatinglat:(double)translatedlat long:(double)translatedlong androtating:(double)degrees{      [super startdrawingframe];     if (degrees != 0)     {         glrotatef(degrees, 0, 0, 1);     }      if (translatedlat != 0)     {         gltranslatef(translatedlat, -translatedlong, 0);     }     [self redrawview]; } 

then in redrawview i'm actualy drawing scene , models. like:

glclear( gl_color_buffer_bit | gl_depth_buffer_bit);  nsinteger nmodels = [models count];  (nsinteger = 0; < nmodels; i++)  {     md2object * mdobj = [models objectatindex:i];     glpushmatrix();     double * deltas = calloc(sizeof(double),2);      deltas[0] = currentcoords[0] - mdobj.modelposition[0];     deltas[1] = currentcoords[1] - mdobj.modelposition[1];      gltranslatef(deltas[0], -deltas[1], 0);      free(deltas);     [mdobj setupforrendergl];     [mdobj rendergl];        [mdobj cleanupafterrendergl];     glpopmatrix();  } [super drawview]; 

the problem when translation rotation events called 1 after other: example when i'm rotating incrementally iterations (still around origin) translate , rotate again appears last rotation not occur around current (translated) position around old 1 (the old origin). i'm aware happens when order of transformations inverted, believed after drawing new center of world given translated system.

what missing? how can fix this? (any reference opengl appreciated too)

i recommend not doing cummulative transformations in event handler, internally storing current values transformation , transforming once, don't know if behaviour want.

pseudocode:

someevent(lat, long, deg) {   currentlat += lat;   currentlong += long;   currentdeg += deg; }  redraw() {   glclear()   glrotatef(currentdeg, 0, 0, 1);   gltranslatef(currentlat, -currentlong, 0);   ... // draw stuff } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -