Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I haven't played with OpenGL ES, just a bit with OpenGL.</p> <p>It sounds like you want to transform from a different position as opposed to the origin, not sure, but can you try to do the transforms and draws that bit within <a href="http://www.khronos.org/opengles/documentation/opengles1_0/html/glPushMatrix.html" rel="nofollow noreferrer">glPushMatrix() and glPopMatrix()</a> ?</p> <pre><code>e.g. // source and dest are arbitrary rectangles. float scaleX = dest.width / source.width; float scaleY = dest.height / source.height; float translateX = dest.x - source.x; float translateY = dest.y - source.y; glPushMatrix(); glScalef(scaleX, scaleY, 0.0); glTranslatef(translateX, translateY, 0.0); // Draw geometry in question with its normal verts. //as if it were drawn from 0,0 glPopMatrix(); </code></pre> <p>Here's a simple Processing sketch I wrote to illustrate the point:</p> <pre><code>import processing.opengl.*; import javax.media.opengl.*; void setup() { size(500, 400, OPENGL); } void draw() { background(255); PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; GL gl = pgl.beginGL(); gl.glPushMatrix(); //transform the 'pivot' gl.glTranslatef(100,100,0); gl.glScalef(10,10,10); //draw something from the 'pivot' gl.glColor3f(0, 0.77, 0); drawTriangle(gl); gl.glPopMatrix(); //matrix poped, we're back to orginin(0,0,0), continue as normal gl.glColor3f(0.77, 0, 0); drawTriangle(gl); pgl.endGL(); } void drawTriangle(GL gl){ gl.glBegin(GL.GL_TRIANGLES); gl.glVertex2i(10, 0); gl.glVertex2i(0, 20); gl.glVertex2i(20, 20); gl.glEnd(); } </code></pre> <p>Here is an image of the sketch running, the same green triangle is drawn, with translation and scale applied, then the red one, outsie the push/pop 'block', so it is not affected by the transform:</p> <p><img src="https://i984.photobucket.com/albums/ae330/orgicus/glPushMatrix.gif" alt="alt text"></p> <p>HTH, George</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload