Quad rotation

Hi!

I have a 64*64 partly transprent textured quad, then i strech it randomly, and rotate around the center by a certain degree, then i read it back with glReadPixels, to get the mask of that quad.
Because glReadpixels is preety slow, and i create about a 1000 different objects(same base texture, random width, height and degree of rotation), i would like to read exactlly the pixels i need…

Quad Height = b+2Height of the upper green triangle
Quad Width = a+2
Height of the left green triangle
So i need to calculate the heights of the green triangles, but i can’t do it…
I’m not too good at math (i’m 16 years old), so i hope you can help me.

I need this for a 2D strategy game, so i have 5 rock pics, and it looks like there were many different rocks.

Thanks for the help.
Bye.

I don’t have a single idea about what you try to accomplish.

If I undertstand you correctly, you want to find a bounding box for your rotated 2D rectangle. One way to do this is to rotate the 4 corners of the rectangle, then calculate a new bounds from the result.

First, for each rectangle vertex V, find the 
rotated vertex V'
  
     ( cos(A) -sin(A)  0 ) ( Vx )
V' = ( sin(A)  cos(A)  0 ) ( Vy ) 
     (  0        0     1 ) ( 1  )
 
     ( cos(A) * Vx - sin(A) * Vy )
   = ( sin(A) * Vx + cos(A) * Vy )
     (             1             )
 
where A is the angle of rotation.
  
Now, with the rotated vertices, we just loop to 
find the extents of the new rectangle.
  
// The incoming quad. 
Vertex q[4] = ???; 
 
// The angle to rotate the quad by.
float A = ???;
   
// The bounds of the rotated rectangle for xy.
Vertex min(999999,999999);
Vertex max(-999999,-999999);
    
// If the quad is not centered at the 
// origin, subtract q's center from each q[i] 
// before rotation, than add it back afterwards.
// (The center is the sum of all points     
// divided by the number of points)
   
float centerX = (q[0].x + q[1].x + q[2].x + q[3].x)/4.0;
float centerY = (q[0].y + q[1].y + q[2].y + q[3].y)/4.0;
   
// Loop over the quads vertices.
for( int i = 0; i < 4; i++ )
{         
    // Make vertex local.  
    float Vx = q[i].x - centerX;
    float Vy = q[i].y - centerY;    
 
    // Rotate vertex around the origin.
    float x = cos(A) * Vx - sin(A) * Vy; 
    float y = sin(A) * Vx + cos(A) * Vy; 
 
    // Move it back to world.
    x += centerX;
    y += centerY;
      
    // Compare rotated point to current bounds. 
    if( x < min.x ) min.x = x;
    if( x > max.x ) max.x = x;
    if( y < min.y ) min.y = y;
    if( y > max.y ) max.y = y;
}
 
// Now min and max define the bounds of the 
// rotated rectangle.
  
// Note that this will work in 3D too, just add 
// z to the mix.
 

I hope all this makes some sense.