Note that there are some explanatory texts on larger screens.

plurals
  1. POMatrices - Rotate a rectangle with origin at bottom left as if origin were in center
    primarykey
    data
    text
    <p>I'm doing some OpenGL programming, drawing 2D rectangles. I am using OpenGL ES 2.0, so I cannot use glTranslate/glRotate, etc... have to roll my own matrix. I want to be able to set a rotation and scale value for them, with the origin of scale or rotation varying depending on the 'halignment' and 'valignment'. This code works correctly for the rotation (however the x, y coords still seem a little off), but how can I get the scaling to work? It still seems to want to use the bottom left as the origin.</p> <p>vid.xratio/vid.yratio is the ratio of the current screen to the local coordinate system that x, y, width, and height are passed in. So for example, if the local coordinates are based on a 640x480 grid, but your screen is currently 1600x1200, the coordinates (238, 185) will be (595, 462.5).</p> <pre><code>const byte picVerts[] = {0, 0, 1, 0, 1, 1, 0, 1}; // // DrawPictureSize // // Draws a picture on the 2D screen, width and height specified. // void DrawPictureSize(float x, float y, float width, float height, float scalex, float scaley, Vector::vector_t *upVec, byte alpha, Texture::texture_t *texture, int halignment, int valignment) { if (!texture) return; float matrix[16]; Matrix::LoadIdentity(matrix); width *= scalex * vid.xratio; height *= scaley * vid.yratio; float angle = U_Rad2Deg(atan2(upVec-&gt;y, upVec-&gt;x)) - 90; float xalign = 0; float yalign = 0; // Move into position if (halignment == Font::HALIGN_CENTER) xalign = width/2; else if (halignment == Font::HALIGN_RIGHT) xalign = width; if (valignment == Font::VALIGN_CENTER) yalign = height/2; else if (valignment == Font::VALIGN_TOP) yalign = height; // Move into position Matrix::Translate(matrix, x * vid.xratio, y * vid.yratio, 0.0f); // Translate to the origin before doing scaling/rotation Matrix::Translate(matrix, xalign, yalign, 0); Matrix::Rotate(matrix, angle, 0, 0, 1); Matrix::Translate(matrix, -xalign, -yalign, 0); // Expand square to image size Matrix::Scale(matrix, width, height, 1.0f); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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