Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sergio10

macrumors regular
Original poster
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?
 
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.
 
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_OES, viewFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);
	
    glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
 
    glVertexPointer(2, GL_FLOAT, 0, squareVertices);
    glEnableClientState(GL_VERTEX_ARRAY);    
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

Thanks in advance.
 
Have a look at Chapter 3 on the link I posted. It explains how to use glTranslate, glRotate, glScale etc.

b e n
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.