我有一条正在绘制的线,但是图形的起点始终是容器视图的死点。如何使绘图仅出现在视图的右侧?

//Code

- (void)drawView {


    // Replace the implementation of this method to do your own custom drawing




    GLfloat lineVertices[maxCurvePoint*2];
    GLfloat lineVerticesGrid[GRID_LINES_HORZ*GRID_LINES_VERT*4];
    GLfloat lineVerticesGridTexCoords[GRID_LINES_HORZ*GRID_LINES_VERT*4];
    float currLevel = curve[(maxCurvePoint+curveStart-1)%maxCurvePoint];

    int i;
    for (i=0; i<maxCurvePoint; i++) {
        lineVertices[i*2] = i/(maxCurvePoint/2.0)-1.0; // X
        lineVertices[i*2+1] = curve[(i+curveStart)%maxCurvePoint]; // Y
    }

    for (i=0; i<GRID_LINES_HORZ; i++) {
        float yval = 4.0*i/GRID_LINES_HORZ-2.0;
        lineVerticesGrid[i*4] = -2.0; // X
        lineVerticesGrid[i*4+1] = yval; // Y
        lineVerticesGrid[i*4+2] = 2.0; // X
        lineVerticesGrid[i*4+3] = yval; // Y
        lineVerticesGridTexCoords[i*4] = -2.3/1.4; // X
        lineVerticesGridTexCoords[i*4+1] = (yval-currLevel)/1.4; // Y
        lineVerticesGridTexCoords[i*4+2] = 1.7/1.4; // X
        lineVerticesGridTexCoords[i*4+3] = (yval-currLevel)/1.4+0.7; // Y
    }

    for (i=0; i<GRID_LINES_VERT; i++) {
        int j = (GRID_LINES_HORZ+i)*4;
        float xval = 4.0*i/GRID_LINES_VERT-2.0;
        lineVerticesGrid[j] = 4.0*i/GRID_LINES_VERT-2.0; // X
        lineVerticesGrid[j+1] = -2.0; // Y
        lineVerticesGrid[j+2] = 4.0*i/GRID_LINES_VERT-2.0; // X
        lineVerticesGrid[j+3] = 2.0; // Y
        lineVerticesGridTexCoords[j] = (xval-0.7)/1.4; // X
        lineVerticesGridTexCoords[j+1] = currLevel/1.4+1.4+0.5; // Y
        lineVerticesGridTexCoords[j+2] = (xval-0.7)/1.4+0.7; // X
        lineVerticesGridTexCoords[j+3] = currLevel/1.4-1.4+0.5; // Y
    }

    [EAGLContext setCurrentContext:context];

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
    //glEnable(GL_LINE_SMOOTH);
    glEnable(GL_POINT_SMOOTH);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glScalef(0.8, 0.8, 1.0);
    glTranslatef(-0.2, 0, 0);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_TEXTURE_2D);

    glVertexPointer(2, GL_FLOAT, 0, spriteVertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glTexCoordPointer(2, GL_SHORT, 0, spriteTexcoords);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glPushMatrix();
    glTranslatef(1.0, currLevel, -0.01);


    glColor4f(0.0, 0.0, 0.0, 1.0); //SpotLight - Should be kinda light

    /*
    if([colorTheme isEqualToString:@"blue"]) //SpotLight - Should be kinda light
      glColor4f(0.0, 0.0, 0.0, 1.0);
    else if ([colorTheme isEqualToString:@"red"])
      glColor4f(0.5, 0.0, 0.0, 1.0);
    else if ([colorTheme isEqualToString:@"green"])
        glColor4f(0.0, 0.5, 0.0, 1.0);
    else if ([colorTheme isEqualToString:@"orange"])
        glColor4f(255.f/255.f, 101/255.f, 3/255.f, 1.0);
    else
        glColor4f(0.0, 0.0, 0.0, 1.0); */



    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glPopMatrix();

    glVertexPointer(2, GL_FLOAT, 0, lineVerticesGrid);
    glEnableClientState(GL_VERTEX_ARRAY);

    glTexCoordPointer(2, GL_FLOAT, 0, lineVerticesGridTexCoords);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glLineWidth(1.0);

    glColor4f(0.0, 0.0, 0.0, 1.0);//Grid Lines behind spotlight...Very faint

    /*
    if([colorTheme isEqualToString:@"blue"]) //Grid Lines behind spotlight...Very faint
          glColor4f(0.0, 0.0, 0.0, 1.0);
    else if ([colorTheme isEqualToString:@"red"])
          glColor4f(0.4, 0.0, 0.0, 1.0);
    else if ([colorTheme isEqualToString:@"green"])
        glColor4f(0.0, 0.4, 0.0, 1.0);
    else if ([colorTheme isEqualToString:@"orange"])
        glColor4f(255.f/255.f, 204/255.f, 7/255.f, 1.0);
     else
        glColor4f(0.0, 0.0, 0.0, 1.0); */

    glDrawArrays(GL_LINES, 0, (GRID_LINES_HORZ+GRID_LINES_VERT)*2);

    glDisable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);

    glVertexPointer(2, GL_FLOAT, 0, lineVertices);
    glEnableClientState(GL_VERTEX_ARRAY);

    glLineWidth(9.0);
    glPointSize(9.0);


    if([colorTheme isEqualToString:@"blue"])  //Wave line before cursor outside color... little faint
       glColor4f(0.0, 0.5, 1.0, 0.2);
    else if ([colorTheme isEqualToString:@"red"])
        glColor4f(0.5, 0.0, 0.0, 0.2);
    else if ([colorTheme isEqualToString:@"green"])
        glColor4f(0.0, 0.5, 0.0, 0.2);
    else if ([colorTheme isEqualToString:@"orange"])
        glColor4f(255.f/255.f, 194/255.f, 12/255.f, 0.2);
    else
        glColor4f(0.0, 0.0, 0.0, 1.0);


    glDrawArrays(GL_LINE_STRIP, 0, maxCurvePoint);
    glTranslatef(0, 0, .01);
    glDrawArrays(GL_POINTS, 0, maxCurvePoint);
    glPointSize(15.0);
    glDrawArrays(GL_POINTS, maxCurvePoint-1, 1);

    glTranslatef(0, 0, .01);

    glLineWidth(3.0);
    glPointSize(3.0);


    //Wave line before cursor inside
    if([colorTheme isEqualToString:@"blue"])
        glColor4f(0.0, 0.5, 1.0, 0.7);
    else if ([colorTheme isEqualToString:@"red"])
        glColor4f(0.5, 0.0, 1.0, 0.7);
    else if ([colorTheme isEqualToString:@"red"])
        glColor4f(0.0, 0.5, 1.0, 0.7);
    else if ([colorTheme isEqualToString:@"orange"])
        glColor4f(255.f/255.f, 220/255.f, 11/255.f, 0.7);
    else
        glColor4f(0.0, 0.0, 0.0, 1.0);


    glDrawArrays(GL_LINE_STRIP, 0, maxCurvePoint);
    glTranslatef(0, 0, .01);
    glDrawArrays(GL_POINTS, 0, maxCurvePoint);
    glPointSize(9.0);
    glDrawArrays(GL_POINTS, maxCurvePoint-1, 1);

    glTranslatef(0, 0, .01);

    glLineWidth(1.0);
    glPointSize(1.0);
    glColor4f(1.0, 1.0, 1.0, 1.0);
    glDrawArrays(GL_LINE_STRIP, 0, maxCurvePoint);
    glPointSize(5.0);
    glDrawArrays(GL_POINTS, maxCurvePoint-1, 1);

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];

    if (demoMode){

        if (randomMode)
           curve[ curveStart ] =  ((rand()%32768)/32768.0)*0.4-0.2;
        else
            curve[ curveStart ] =  ekgMap[ curveStart ]; // ((rand()%32768)/32768.0)*0.4-0.2;
    //  DLog(@"%f", ekgMap[ curveStart ]);

     }  else{


         if ([dataPoints count] ==0){

             curve[ curveStart ] =  0.0;

         }else {

             if (!inverted) {

                 curve[curveStart] =  scaleByMid(self.min, self.max, [[dataPoints dequeue] floatValue]) /scaleFactor; //   [[dataPoints dequeue] floatValue] /scaleFactor;

                // DLog(@"Queue Length: %d", [dataPoints count]);

             } else{

                 float point = scaleByMid(self.min, self.max, [[dataPoints dequeue] floatValue]) /scaleFactor;
                 curve[curveStart] =  (point -(point *2));


             }
         }
    }

    curveStart = (curveStart+1)%maxCurvePoint;

}

最佳答案

在正交视图中,您将左右设置为-1和1,类似地将上和下设置为-1.5和1.5。将其修改为0的宽度和0的高度,以获取原点在左上角(或根据您使用的平台,左下角)

glOrthof(0,width,0,height,1,100);

关于iphone - OpenGL Noob问题:绘图的起始位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5720308/

10-10 23:13