Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
void Graphics_RenderFrame() { Graphics_ClearBackBuffer(); Graphics_RenderImage(); Graphics_Flip(); } // Graphics_RenderFrame() void Graphics_ClearBackBuffer() { RECT rClient; GetClientRect(Game.hWndMain, &rClient); // Get client size FillRect(dcBackBuffer, &rClient, (HBRUSH)GetStockObject(WHITE_BRUSH)); // Paint client window white } // Graphics_ClearBackBuffer() void Graphics_RenderImage() { double pi = 3.14159265; POINT Point[3]; Point[0].x = 0 + (-24/2 * cos(90.0 * pi / 180.0) + 24/2 * sin(90.0 * pi / 180.0)); Point[0].y = 0 + (-24/2 * sin(90.0 * pi / 180.0) + 24/2 * cos(90.0 * pi / 180.0)); Point[1].x = 0 + (-24/2 * cos(90.0 * pi / 180.0) + 24/2 * sin(90.0 * pi / 180.0)); Point[1].y = 0 + (-24/2 * sin(90.0 * pi / 180.0) + 24/2 * cos(90.0 * pi / 180.0)); Point[2].x = 0 + (-24/2 * cos(90.0 * pi / 180.0) + 24/2 * sin(90.0 * pi / 180.0)); Point[2].y = 0 + (-24/2 * sin(90.0 * pi / 180.0) + 24/2 * cos(90.0 * pi / 180.0)); PlgBlt(Player.dcPlayerDCs, Point, Player.dcPlayerDCs, 0, 0, 24, 24, 0, 0, 0); TransparentBlt(dcBackBuffer, Player.x_pos, Player.y_pos, 24, 24, Player.dcPlayerDCs, 0, 0, 24, 24, RGB(0, 255, 0)); } // Graphics_RenderImage() void Graphics_Flip() { HDC dcRenderTarget; RECT rClient; GetClientRect(Game.hWndMain, &rClient); // Get client size dcRenderTarget = GetDC(Game.hWndMain); // Get DC of main window BitBlt(dcRenderTarget, 0, 0, rClient.right, rClient.bottom, dcBackBuffer, 0, 0, SRCCOPY); ReleaseDC(Game.hWndMain, dcRenderTarget); // Set free main windows DC } // Graphics_Flip() |
Zitat
p[0].x = o.x + (-w/2 * cos(a) + h/2 * sin(a))
p[0].y = o.y + (-w/2 * sin(a) - h/2 * cos(a))
p[1].x = o.x + (w/2 * cos(a) + h/2 * sin(a))
p[1].y = o.y + (w/2 * sin(a) - h/2 * cos(a))
p[2].x = o.x + (-w/2 * cos(a) - h/2 * sin(a))
p[2].y = o.y + (-w/2 * sin(a) + h/2 * cos(a))
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
#include <windows.h> #include <cmath> LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); const float PI = 4.0f * atanf( 1.0f ); const float HALF_PI = PI * .5f; inline float Deg2Rad( float f ) { return f * ( PI / 180.0f ); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, PSTR, int ) { MSG msg; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = GetSysColorBrush( COLOR_BTNFACE ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = "RotateWndCls"; wc.lpszMenuName = NULL; RegisterClass( &wc ); HWND hWnd = CreateWindow( "RotateWndCls", "Rotate", WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, NULL, NULL, hInstance, NULL ); ShowWindow( hWnd, SW_SHOW ); UpdateWindow( hWnd ); while ( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return ( int )msg.wParam; } LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { static HBITMAP hBitmap; static int width, height; switch ( uMsg ) { case WM_CREATE: hBitmap = ( HBITMAP )LoadImage( NULL, "bild.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); if ( !hBitmap ) { MessageBox( hWnd, "Cannot load bild.bmp", "Error", MB_OK ); } { BITMAP bmp; GetObject( hBitmap, sizeof( BITMAP ), &bmp ); width = bmp.bmWidth; height = bmp.bmHeight; } break; case WM_CLOSE: PostQuitMessage( 0 ); break; case WM_PAINT: { PAINTSTRUCT ps; HDC hDC, hMemDC; POINT dest[ 3 ]; POINT p[ 2 ]; POINT pos; float angle; float halfW, halfH; hDC = BeginPaint( hWnd, &ps ); hMemDC = CreateCompatibleDC( hDC ); SelectObject( hMemDC, hBitmap ); angle = Deg2Rad( 92.0f ); halfW = width / 2.0f; halfH = height / 2.0f; p[ 0 ].x = ( LONG )( cos( angle ) * halfW ); p[ 0 ].y = ( LONG )( sin( angle ) * halfW ); p[ 1 ].x = ( LONG )( cos( angle + HALF_PI ) * halfH ); p[ 1 ].y = ( LONG )( sin( angle + HALF_PI ) * halfH ); pos.x = 0; pos.y = 0; //! Rotationszeugs dest[ 0 ].x = ( LONG )( halfW + pos.x - p[ 0 ].x - p[ 1 ].x ); dest[ 0 ].y = ( LONG )( halfH + pos.x - p[ 0 ].y - p[ 1 ].y ); dest[ 1 ].x = ( LONG )( halfW + pos.x - p[ 1 ].x + p[ 0 ].x ); dest[ 1 ].y = ( LONG )( halfH + pos.x - p[ 1 ].y + p[ 0 ].y ); dest[ 2 ].x = ( LONG )( halfW + pos.x - p[ 0 ].x + p[ 1 ].x ); dest[ 2 ].y = ( LONG )( halfH + pos.x - p[ 0 ].y + p[ 1 ].y ); PlgBlt( hDC, dest, hMemDC, 0, 0, width, height, NULL, 0, 0 ); DeleteDC( hMemDC ); EndPaint( hWnd, &ps ); } break; default: return DefWindowProc( hWnd, uMsg, wParam, lParam ); } return 0; } |
Zitat von »"$nooc"«
oho .. plgblt liefert jetzt 1 (true) zurück..
aber das bild dreht sich trotzdem nicht.. (hab statt 90 30 genommen)
Zitat von »"msdn2"«
The PlgBlt function performs a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the destination device context.
Zitat von »"msdn2"«
Die Funktion PlgBlt führt eine Bit-Blockübertragung der Farbdaten eines angegebenen Rechtecks, in einem Quell -Device Context, zu einem festgelegten Parallelogram in einem Ziel-Device Context durch.
Werbeanzeige