I have a line that I am drawing but the starting point of the drawing is always dead center of the container view. How can I get the drawing to occur just inside of the right side of the view??
//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"])
glColo开发者_如何学JAVAr4f(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;
}
In orthogonal view, you are setting the left and right to be -1 and 1, similarly top and bottom to be -1.5 and 1.5. Modify it to 0 to width and 0 to height to get the origin at top left corner (or bottom left corner based on the platform you are using)
glOrthof(0, width, 0, height, 1, 100);
精彩评论