[OpenGL ES 1.1] Move sprite using glTranslatef

Discussion in 'iOS Programming' started by Sergio10, Jun 11, 2009.

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hi,

    I need to implement next function:
    PHP:
    - (void)moveTo: (int)posX: (int)posY;
    It should move sprite. As I researched should use glTranslatef function. But when I call glTranslatef(0, 0, 0); sprite don't displays in left down corner of the screen
    I suggest need to convert translate matrix to iphone screen (320*480)

    So, How to solve my problem?
     
  2. kalimba macrumors regular

    Joined:
    Jun 10, 2008
    #2
    Learn how to properly use OpenGL to do what you're trying to do? :confused:
     
  3. Sergio10 thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #3
    Please give me the link or solution how to convert matrix to screen positioning
     
  4. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #4
    A matrix does not define a screen position. Get a copy of the The OpenGL Programming Guide (the Red Book), or read it online here.

    b e n
     
  5. Aranince macrumors 65816

    Joined:
    Apr 18, 2007
    Location:
    California
    #5
    AFAIK when you use glTranslate or glRotate...the parameters you pass are relative. Meaning if you pass glTranslatef(1.0, 1.0, 1.0) it will move the object 1 unit in all of those directions relative to where it already is instead of moving to position 1.0 1.0 1.0.
     
  6. Sergio10 thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #6
    Thanks, for answering.

    I understand that matrixes (rotation, translation, scaling) are not relative with screen position axes.
    So, I need to translate primitive in the left up corner. how to implement it?

    Here is my code I wrote:
    PHP:
        const GLfloat squareVertices[] = 
        {
            -
    5.0f, -5.0f,
            
    0.5f,  -0.5f,
            -
    0.5f,  0.5f,
            
    0.5f,   0.5f,
        };
                
        [
    EAGLContext setCurrentContext:context];    
        
    glBindFramebufferOES(GL_FRAMEBUFFER_OESviewFramebuffer);
        
    glViewport(00backingWidthbackingHeight);
        
        
    glMatrixMode(GL_PROJECTION);
        
    glLoadIdentity();
        
    glOrthof(-1.0f1.0f, -1.5f1.5f, -1.0f1.0f);
        
    glMatrixMode(GL_MODELVIEW);
        
        
    glClearColor(0.5f0.5f0.5f1.0f);
        
    glClear(GL_COLOR_BUFFER_BIT);
     
        
    glVertexPointer(2GL_FLOAT0squareVertices);
        
    glEnableClientState(GL_VERTEX_ARRAY);    
        
    glDrawArrays(GL_TRIANGLE_STRIP04);
    Thanks in advance.
     
  7. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #7
    Have a look at Chapter 3 on the link I posted. It explains how to use glTranslate, glRotate, glScale etc.

    b e n
     

Share This Page