2D 사각형을 그리는 OpenGL 프로그래밍을하고 있습니다. OpenGL ES 2.0을 사용하고 있으므로 glTranslate/glRotate 등을 사용할 수 없습니다. 자체 행렬을 굴려야합니다. 나는 'halignment'와 'valignment'에 따라 스케일이나 회전의 원점이 달라지면서 회전과 스케일 값을 설정할 수 있기를 원합니다. 이 코드는 회전에 대해 올바르게 작동하지만 x, y 좌표는 여전히 약간 느껴지지만 작동하려면 배율을 어떻게 얻을 수 있습니까? 왼쪽 하단을 원점으로 사용하고 싶어하는 것 같습니다.행렬 - 원점이 중심에있는 것처럼 왼쪽 하단에 원점이있는 사각형을 회전하십시오.
vid.xratio/vid.yratio는 x, y, 너비 및 높이가 전달되는 로컬 좌표계에 대한 현재 화면의 비율입니다. 예를 들어, 로컬 좌표가 640x480 격자를 기반으로하는 경우 화면이 현재 1600x1200이면 좌표 (238, 185)는 (595, 462.5)가됩니다.
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->y, upVec->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);