* What is the difference between a normal bitmap and a rotated one?
* What happens to the bounding rectangle of the bitmap when you rotate the bitmap?
* What is the difference between a rotated quadrilateral in 3D graphics and a bounding rectangle of a bitmap?
You can rotate a bitmap many ways. If you really want to use 2D and not 3D vertices in that you want to rotate a blitted bitmap you can do this:
1. Set texture coords for each corner of the box.
2. Compute the new bounding box after rotation.
3. Polyfill the box using linear interpolation.
4. Figure out the x,y coords of pixel.
5. Figure out the u,v coords of texel.
Essentially linear interpolate for x,y and u,v.
To do a polyfill:
1. Create two arrays called leftside and rightside and clear to -1.
2. Start at the top of the figure.
3. Find the next vertex in either direction.
4. If vertex is lower than prev, it goes in leftside array
5. If vertex is higher than prev, it goes in rightside array.
6. Compute x's and u,v for leftside and rightside at point P on a line between CurVertex and NextVertex using formula for slope.
7. Save x's in leftside and rightside accordingly and increment a y line counter.
8. When done, start at y coord for top and set loopcounter to 0.
9. Draw textured line from leftside[loopcounter] to rightside[loopcounter]
10. Increment y and loop counter and check for loopcounter>y line counter.
11. If true, exit, else goto 9.
This is a simple old-school polygon fill algo used in many older DOS 3D games. It only works on convex shapes.
This will draw a bitmap w/o rotation and scaling.
This code is best suited for assembly. You can use inline or pure. I'll write an inline version here.
} while (dwHeightCounter<TextureHeight);
The assembly version could be sped up but my asm is a bit rusty.
void BitBltEx(WORD uX, WORD uY,
DWORD dwTexWidth,DWORD dwTexHeight,
// (ESP-4) DWORD dwTexOffset=0;
// (ESP-8) DWORD dwPixelOffset;
// (ESP-12) DWORD dwStartPixelOffset;
// (ESP-16) DWORD dwWidthCounter=0;
//Height counter not needed since LOOP decrements ECX
;Allocate stack space for local variables
;Compute surface offset
;Zero out counters
;Set up pointers
;Blit one pixel if cur pixel is not trans
;Retrieve current pixel
//esi and edi auto-increment according to direction flag
;clean up stack
This should work if you can get a pointer to surface memory and texture memory. However, I'm sure SDL provides a much better way. This is really old-school 2D BitBlts here.
Use the asm at your own risk. I wrote it here while looking at the C version, so I'm sure it has some bugs. I did refer to the IA32 Tech Ref for some of the instructions. For the most part it should give you the general idea.
Neither of these functions accounts for clipping to a bounding area.