News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Rotation

Started by stefan.velicu, March 30, 2014, 06:34:45 PM

Previous topic - Next topic

stefan.velicu

    Hi. I have a project where i must simulate somethink like a servomotor. I need your help, because I don't know how to load a image from resources and rotate it accordingly to the angle of rotation given by the user.
    Thank you, cheers!

jj2007

Hi Stefan,

Can you give us some details?
- what is the context (homework, professional, other)?
- is is 90 degree only, or arbitrary angles?
- what have you tried so far?
- why don't you do it in C/CUDA?
- what do you think of the Arabnia solution?

Welcome to the Forum :icon14:

stefan.velicu

Hi and thank you for your prompt answer. It's a homework, but unfortunately it's mandatory to be in MASM only (not c, c++ or anythnig). So far, I've only managed to open the window  :lol:. About the rotation of the object, it must be a full one, so 360 degrees.
I'll search the Arabnia solution, I don't know it.

Thank you, cheers.

Gunther

Hi Stefan,

you should post your code and we'll see. Welcome to the forum.

Gunther
You have to know the facts before you can distort them.

stefan.velicu

Thank you, Gunther. Here's the code that loads the image that i must rotate.


.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\masm32.lib

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

.DATA
ClassName db "WinClass", 0
AppName db "Simple Window", 0
MouseClick db 0
ImageName1 db "C:\masm32\Images\star.bmp", 0
BigPict dd FALSE

.Data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
maxX DD ?
maxY DD ?
ShapeNumber dd ?
startpoint POINT <>
endpoint POINT <>
hMemDC HDC ?
Bitmap HBITMAP ?
hBitmap HBITMAP ?

.CODE
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke WinMain,hInstance, NULL, NULL, 0
invoke GetCommandLine
mov CommandLine,eax
invoke ExitProcess,eax

invoke LoadImage, hInstance, ADDR ImageName1, IMAGE_BITMAP, 2, 2, LR_LOADFROMFILE
mov hBitmap,eax

WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
local wc:WNDCLASSEX
local msg:MSG
local hwnd:HWND
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInst
pop wc.hInstance
mov wc.lpszClassName, offset ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset ClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov wc.hIcon, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx, 0, addr ClassName, addr AppName, WS_OVERLAPPEDWINDOW or

WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
NULL, hInst, NULL
mov hwnd, eax
.while TRUE
invoke GetMessage, addr msg, NULL, 0, 0
.break .if (!eax)
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
.endw
mov eax, msg.wParam
ret
WinMain endp


mov CommandLine,eax

        invoke LoadImage, hInstance, ADDR ImageName1, IMAGE_BITMAP, 100, 100,

LR_LOADFROMFILE
        mov hBitmap,eax

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
                LOCAL hDC:HDC
                LOCAL ps:PAINTSTRUCT
                LOCAL rect:RECT
                LOCAL hInnerDC:HDC
       
        invoke CreateCompatibleDC,hMemDC
        mov hInnerDC,eax

    .IF uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL

     .ELSEIF uMsg==WM_PAINT
      invoke BeginPaint,hWnd, ADDR ps
        mov hDC,eax
        invoke CreateCompatibleDC,hMemDC
        mov hInnerDC,eax
        invoke SelectObject, hInnerDC,hBitmap
        ;.IF BigPict
        ;invoke BitBlt, hMemDC, startpoint.x, startpoint.y, 226, 229, hInnerDC, 0,

0, SRCCOPY ; dimensiunea
        ;.ELSE
        invoke BitBlt, hMemDC, startpoint.x, startpoint.y, 226, 229, hInnerDC, 0,

0, SRCCOPY ;
        ;.ENDIF
        invoke GetClientRect,hWnd,ADDR rect
        invoke SelectObject,hDC, hMemDC
        invoke BitBlt,hDC,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
        invoke EndPaint,hWnd,addr ps
        invoke DeleteDC,hInnerDC
        invoke DeleteObject,hBitmap
        ret

       
    .ELSEIF uMsg==WM_CREATE
        invoke GetSystemMetrics, SM_CXSCREEN
        mov maxX, eax
        invoke GetSystemMetrics, SM_CYSCREEN
        mov maxY, eax
        invoke GetDC,hWnd
        mov hDC, eax
        invoke CreateCompatibleDC, hDC
        mov hMemDC, eax
        invoke CreateCompatibleBitmap, hDC, maxX, maxY
        mov Bitmap, eax
        invoke SelectObject, hMemDC, Bitmap
        invoke PatBlt, hMemDC, 0, 0, maxX, maxY, PATCOPY
        mov startpoint.x, 0
        mov startpoint.y, 0
        invoke LoadImage, hInstance,ADDR ImageName1, IMAGE_BITMAP, 100, 100,

LR_LOADFROMFILE
        mov hBitmap,eax
        invoke InvalidateRect,hWnd,NULL,TRUE
        ret
       
     .ELSE
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
     .ENDIF
        xor eax,eax
        ret
        WndProc endp

end start


Cheers.

jj2007

Stefan,

Your code won't run properly, and it's not your fault, it's your teacher who is distributing crappy code. Read this recent thread carefully, adapt your code accordingly, and then come back.

BTW the best way to get help is to zip the source including necessary image files, preferably with folder names, and to attach the zip file to your post.

stefan.velicu

Ok, I've found out an example in the masm32 directory and managed to load the image that I want to rotate. Now, how could I rotate that image to let's say 90 degrees, or 180?

jj2007

Good. Now go to forum search (more in the old forum) and look for GetDIBits

TWell

Quote from: stefan.velicu on March 30, 2014, 10:00:28 PM
Ok, I've found out an example in the masm32 directory and managed to load the image that I want to rotate. Now, how could I rotate that image to let's say 90 degrees, or 180?
PlgBlt?

stefan.velicu

Thanks, TWell, but I have to do this in assembly.

stefan.velicu

Quote from: jj2007 on March 30, 2014, 10:12:28 PM
Good. Now go to forum search (more in the old forum) and look for GetDIBits

Thank you, I'll check it out. So far I couldn't find anything to work :D

jj2007

You need to get your pixels into a memory buffer so that you can work directly on them. That requires GetDiBits with an appropriate buffer created by HeapAlloc. The Masm32 macro alloc() is also fine:
include \masm32\include\masm32rt.inc

.code
start:   mov esi, alloc(1024*1024)
   print LastError$()
   ;... your code ...
   free esi
   print LastError$()
   exit

end start

stefan.velicu

I've found this, but I don't know who are the arguments  :icon_eek:

invoke GetDIBits,hdc,hbmp,0,bmHeight,pBits,OFFSET bi,DIB_RGB_COLORS

stefan.velicu

Quote from: jj2007 on March 30, 2014, 10:58:01 PM
You need to get your pixels into a memory buffer so that you can work directly on them. That requires GetDiBits with an appropriate buffer created by HeapAlloc. The Masm32 macro alloc() is also fine:
include \masm32\include\masm32rt.inc

.code
start:   mov esi, alloc(1024*1024)
   print LastError$()
   ;... your code ...
   free esi
   print LastError$()
   exit

end start
Thank you, but I've got this error:
Quoteundefined symbol : alloc

GoneFishing

Just add one line to your includes:
Quote
include \masm32\macros\macros.asm