Latest UploadsKing SalmonPakzSnookerJayenkaiYou've ... o have youJayenkaiMerry XmasJayenkaiRCT Classic on iOSJayenkaiOopsJayenkai

### Image rotation?

UserMessage
Posted : Tuesday, 30 November 2010, 10:57 | Permalink
spinal

 I am trying to rotate an image (yes I know there is a rotate image function, I'm not going to use it). Anyway, the simple way is to do the following -- ; Rotate image... Graphics 640,480,0,2 pic = CreateImage(120,12) SetBuffer ImageBuffer(pic) Color 255,0,0 Rect 0,0,120,12,1 Color 0,0,255 Text 0,0,"OOOOOOOOOOOOOOOOOOOOOOOOOO" angle = 0 While Not KeyHit(1) SetBuffer FrontBuffer() Cls angle=angle+1 For x=-60 To 60 For y = -6 To 6 SetBuffer ImageBuffer(pic) GetColor(x+60,y+6) rx = x * Cos(angle) - y * Sin(angle) ry = x * Sin(angle) + y * Cos(angle) SetBuffer FrontBuffer() Plot rx + 200, ry + 200 Next Next Wend End --> However, it does leave gaps in the output image. I read somewhere that image rotation should be done backwards, as in, cycle through the output image and work out which pixel should be there, or something like that. But I have yet to find any info on how to do this. Does anyone know how this is done?-----Download "Don't Flip Out!" Directly to your OUYA! (Click Here).
Posted : Wednesday, 01 December 2010, 02:46 | Permalink
Jayenkai

WW Entries : 106
 It's quite awkward to think of this backwards, when you're working with pixels of a rotated rectangle. Instead, simplify it. You need to fill surrounding pixels of each pixel, so just do that. Find each rx/ry, then go backwards for each pixel that's around it. ; Rotate image... Graphics 1024,768,0,2 Graphics 320,240,0,3 SetBuffer BackBuffer() pic = CreateImage(120,12) SetBuffer ImageBuffer(pic) Color 255,0,0 Rect 0,0,120,12,1 Color 0,0,255 Text 0,0,"ABCDEFGHIJKLMNOPQRSTUVWXYZ" angle = 0 While Not KeyHit(1) SetBuffer BackBuffer() Cls angle=angle+1 For x=-60 To 60 For y = -6 To 6 rx = x * Cos(angle) - y * Sin(angle) ry = x * Sin(angle) + y * Cos(angle) ; For each pixel, find neighbour pixels of rotated version, then work back to find original pixels in roughly those points.. For ex=rx-1 To rx+1 For ey=ry-1 To ry+1 ; Unrotate unrotatex=Float(ex) * Cos(-angle) - Float(ey) * Sin(-angle) unrotatey=Float(ex) * Sin(-angle) + Float(ey) * Cos(-angle) ; Find colour at that point SetBuffer ImageBuffer(pic) GetColor(unrotatex+60,unrotatey+6) SetBuffer BackBuffer() ; Slap it back in.. Plot ex + 100, ey + 100 Next Next Next Next Flip Wend End --> -----"Load, Next List!"
Posted : Wednesday, 01 December 2010, 09:22 | Permalink
Andy_A

 A quick and dirty way to fill in the gaps is to plot a 2x2 rect instead of a single pixel. The drawback is that your image may be slightly distorted due to the way the rects overlap. ; Rotate image... Graphics 640,480,0,2 pic = CreateImage(120,12) SetBuffer ImageBuffer(pic) Color 255,0,0 Rect 0,0,120,12,1 Color 0,0,255 Text 0,0,"OOOOOOOOOOOOOOOOOOOOOOOOOO" angle = 0 While Not KeyHit(1) SetBuffer FrontBuffer() Cls angle=angle+1 For x=-60 To 60 For y = -6 To 6 SetBuffer ImageBuffer(pic) GetColor(x+60,y+6) rx = x * Cos(angle) - y * Sin(angle) ry = x * Sin(angle) + y * Cos(angle) SetBuffer FrontBuffer() Rect rx + 200, ry + 200, 2, 2, True ;will cause some distortion in final image Next Next Wend End -->
Posted : Wednesday, 01 December 2010, 12:34 | Permalink
spinal

 OK, I tweaked Jay's code a little, removed the initial rotation and instead worked completely backwards. I assume though, that there is a simple way to find the min and max x and y values from checking the rotation of the image corners first though, I just guessed Graphics 640,480,0,2 Graphics 320,240,0,3 SetBuffer BackBuffer() pic = CreateImage(120,12) SetBuffer ImageBuffer(pic) Color 255,0,0 Rect 0,0,120,12,1 Color 0,0,255 Text 0,0,"ABCDEFGHIJKLMNO" angle = 0 While Not KeyHit(1) SetBuffer BackBuffer() Cls angle=angle+1 If angle > 360 Then angle = angle - 360 Color 255,255,255 Rect 40,40, 120, 120,0 For ex = 41 To 158 For ey = 41 To 158 ; Unrotate unrotatex=(ex-100) * Cos(-angle) - (ey-100) * Sin(-angle) unrotatey=(ex-100) * Sin(-angle) + (ey-100) * Cos(-angle) If unrotatex > -60 And unrotatex < 60 And unrotatey > -6 And unrotatey < 6 Then ; Find colour at that point SetBuffer ImageBuffer(pic) GetColor(unrotatex+60,unrotatey+6) SetBuffer BackBuffer() ; Slap it back in.. Plot ex, ey End If Next Next Flip Wend End --> -----Download "Don't Flip Out!" Directly to your OUYA! (Click Here).
Posted : Wednesday, 15 December 2010, 16:51 | Permalink
Teasy

Posted : Saturday, 18 December 2010, 13:39 | Permalink
dna

 Jay, In your code you use : Graphics 1024,768,0,2 Graphics 320,240,0,3 What does that do? Why is that in there twice? @Teasy: That's real smoothe. I can see where BB is slow when doing this. Does BMax make a difference as far as the speed of the rot? -----DNA
Posted : Saturday, 18 December 2010, 15:06 | Permalink
Jayenkai

WW Entries : 106
 ,2 says "Make the window THIS big" ,3 says "Make this a scalable window." With a scalable window, you can Maximise it if you wish, but everything ends up looking a bit blurry and stretchy. It's a nice thing to have, but ,2 will always be clearer. However.. ,3 doesn't set the window's default size. So, by setting a LARGE ,2 (and making the window be 1024x768) and THEN setting a smaller ,3, you end up with the 320x240 graphics being rescaled up to the 1024x768 size. Basically, whereas we're drawing things to only a 320x240 area, they're actually being displayed 3 times bigger on the screen. Otherwise, you'd be looking at a teensy tiny window!-----"Load, Next List!"
Posted : Saturday, 18 December 2010, 16:03 | Permalink
CodersRule

 I never knew you could do that. I always wondered how to make a resizable window that big by default.
Posted : Saturday, 25 December 2010, 06:31 | Permalink
Teasy

 dna: if you optimize the code way more, it should be smooth and superfast in blitz2d even i still have some of blitzcoder's code laying around from optimization/math wizards ^^ which does exactly that! i am not familiar with blitzmax' graphics interface/library (opengl) benchmarks, but i imagine that it usually depends on (the wishes of) the coder whether something is fast or not taking into account that blitzmax is more capable, flexible and faster in itself, it may be fairly easy to get fast results in it jayenkai: that's a nice trick i usually use some dll calls to pull that off ^^ ( with userlibs it's a snap really ) codersrule: particularly the functions from the user32.dll can make the entire blitz window: - stretch to overlap the entire screen, - remove the caption and borders, - and stay on top. so basically a 'fake fullscreen' here's the code i use to do that: GraphicsWindow 640,480 , 0,4 --> and here's the "library" (interface) i'm using: ;------------------------------------------------------------------------------- ; * Window Handling ;------------------------------------------------------------------------------- ; Created by Teasy ; With divine help from EPS, Yan and Rufus Serano ;------------------------------------------------------------------------------- ; Use Windows' native system functions to change a window's properties, ; such as its dimensions, state and visual make-up. ;------------------------------------------------------------------------------- ; 22 Dec 2010 ; - Changed layout of code ; - Added GraphicsWindowWidth and GraphicsWindowHeight ; - Uses "AppHWND" for safer window access ; - Added GraphicsWindow() which wraps Graphics() with a new mode (4) ; - Mode 4 turns the window into a fake fullscreen (scaled) ;------------------------------------------------------------------------------- ;, ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,,, , , ;;;,d%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&b. ;,d&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%b. ;&%&%&%&' ;%&%&%&% Window state ;&%&%&%&, ;'V&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%P` ;;;'V%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&P` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::·· · · ;' Const SW_HIDE = 0 Const SW_SHOWNORMAL = 1 Const SW_NORMAL = 1 Const SW_SHOWMINIMIZED = 2 Const SW_SHOWMAXIMIZED = 3 Const SW_MAXIMIZE = 3 Const SW_SHOWNOACTIVATE = 4 Const SW_SHOW = 5 Const SW_MINIMIZE = 6 Const SW_SHOWMINNOACTIVE = 7 Const SW_SHOWNA = 8 Const SW_RESTORE = 9 Const SW_SHOWDEFAULT = 10 Const SW_MAX = 11 ;------------------------------------------------------------------------------- ; Change the active window, e.g. Blitz Function ShowWindow( message = SW_NORMAL ) Local window_handle = api_GetActiveWindow() api_ShowWindow( window_handle , message ) End Function Function ShowWindow_Demo() Graphics 512,384 , 0,3 Print "untouched" : WaitKey : Cls ShowWindow SW_MAXIMIZE Print "maximized" : WaitKey : Cls ShowWindow SW_RESTORE Print "restored" : WaitKey : Cls End End Function ;------------------------------------------------------------------------------- ; * Active window functions ;------------------------------------------------------------------------------- ; User32.decls: ; .lib "USER32.DLL" ; API_ShowWindow( hWnd% , nCmdShow% ) : "ShowWindow" ; API_GetActiveWindow%() : "GetActiveWindow" ;------------------------------------------------------------------------------- Function MaximizeActiveWindow() api_ShowWindow api_GetActiveWindow() , 3 End Function Function MinimizeActiveWindow() api_ShowWindow api_GetActiveWindow() , 6 End Function Function RestoreActiveWindow() api_ShowWindow api_GetActiveWindow() , 9 End Function ;, ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,,, , , ;;;,d%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&b. ;,d&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%b. ;&%&%&%&' ;%&%&%&% Window dimensions ;&%&%&%&, ;'V&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%P` ;;;'V%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&P` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::·· · · ;' Type struct_RECT Field Left Field Top Field Right Field Bottom End Type Global struct_RECT.struct_RECT = New struct_RECT ;------------------------------------------------------------------------------- ; userlibs: ; user32.decls ; .lib "user32.dll" ; api_GetDesktopWindow%() : "GetDesktopWindow" ; api_GetWindowRect%( hwnd% , lpRect* ) : "GetWindowRect" ;------------------------------------------------------------------------------- Function ActiveWindowWidth() api_GetWindowRect api_GetActiveWindow() , struct_RECT Return struct_RECT\Right - struct_RECT\Left End Function Function ActiveWindowHeight() api_GetWindowRect api_GetActiveWindow() , struct_RECT Return struct_RECT\Bottom - struct_RECT\Top End Function Function DesktopWidth() api_GetWindowRect api_GetDesktopWindow() , struct_RECT Return struct_RECT\Right - struct_RECT\Left End Function Function DesktopHeight() api_GetWindowRect api_GetDesktopWindow() , struct_RECT Return struct_RECT\Bottom - struct_RECT\Top End Function Function GraphicsWindowWidth() api_GetWindowRect SystemProperty( "AppHWND" ) , struct_RECT Return struct_RECT\Right - struct_RECT\Left End Function Function GraphicsWindowHeight() api_GetWindowRect SystemProperty( "AppHWND" ) , struct_RECT Return struct_RECT\Bottom - struct_RECT\Top End Function ;------------------------------------------------------------------------------- ; * Older code (low level hacks) by EPS ;------------------------------------------------------------------------------- ;Function DesktopWidth() ; by EPS ;;======================================== ;; Ermittle Windows Desktopbreite ;;======================================== ; Local struct_rect% = CreateBank(16) ; ; api_GetWindowRect(api_GetDesktopWindow(),struct_rect) ; Local res = PeekInt(struct_rect,8) ; FreeBank struct_rect ; ; Return res ;End Function ; ; ;Function DesktopHeight() ; by EPS ;;======================================== ;; Ermittle Windows Desktophöhe ;;======================================== ; Local struct_rect% = CreateBank(16) ; ; api_GetWindowRect(api_GetDesktopWindow(),struct_rect) ; Local res = PeekInt(struct_rect,12) ; FreeBank struct_rect ; ; Return res ;End Function ;------------------------------------------------------------------------------- Function WindowDimensions_Demo() Graphics 160,120 , 0,3 SetBuffer BackBuffer() Repeat Cls Text 0,0 , "Canvas: "+GraphicsWidth()+"x"+GraphicsHeight() Text 0,10 , "Window: "+ActiveWindowWidth()+"x"+ActiveWindowHeight() Text 0,20 , "Desktop: "+DesktopWidth()+"x"+DesktopHeight() Flip Until KeyHit( 1 ) End End Function ;, ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,,, , , ;;;,d%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&b. ;,d&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%b. ;&%&%&%&' ;%&%&%&% Fake full-screen ;&%&%&%&, ;'V&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%P` ;;;'V%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&P` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::·· · · ;' ;------------------------------------------------------------------------------- ; GraphicsWindow( pixel_width , pixel_height , color_depth , window_mode ) ; - pixel_width, pixel_height, color_depth: same as Graphics ; - window_mode: same as Graphics, except mode 4; which is 'fake fullscreen'. ;------------------------------------------------------------------------------- ; File: api.User32.decls ; .lib "USER32.DLL" ; api_GetClientRect( hwnd% , lprect* ) : "GetClientRect" ; api_GetWindowLong% ( hwnd% , index% ) : "GetWindowLongA" ; api_SetWindowLong% ( hwnd% , index% , info% ) : "SetWindowLongA" ; api_SetWindowPos% ( hWnd% , Depth% , x1%,y1%,x2%,y2% , Actions% ) : "SetWindowPos" ;------------------------------------------------------------------------------- Const GraphicsWindow_SilentMode = False Type GraphicsWindow_Rect Field x1,y1 Field x2,y2 End Type Function GraphicsWindow( width,height , depth=32,mode=4 ) If width <= 0 Or height <= 0 GraphicsWindow_Error "Screen dimensions out of range: "+width+"x"+height End If Select depth Case 0,8,16,24,32 Default GraphicsWindow_Error "Invalid color depth: "+depth Return False End Select Select mode Case 0,1,2,3 ; 0: auto, 1: full, 2: window, 3: scaled window Graphics width,height , depth,mode Case 4 GraphicsWindow_FakeFullscreen width,height , depth Default GraphicsWindow_Error "Undefined window mode: "+mode Return False End Select Return True End Function Function GraphicsWindow_FakeFullscreen( w,h , d ) ; setup blitz graphics Graphics w,h , d,3 ; change window properties Local hwin = SystemProperty( "AppHWND" ) ; QueryObject( win , 1 ) ; blitzplus ; assume window has caption and frame -> toggle them off Local style = api_GetWindowLong( hwin , -16 ) Xor (\$C00000+\$40000) api_SetWindowLong hwin , -16 , style ; change window dimensions Local deskrect.GraphicsWindow_Rect = New GraphicsWindow_Rect api_GetClientRect api_GetDesktopWindow() , deskrect api_SetWindowPos hwin,0 , 0,0,deskrect\x2,deskrect\y2 , 4 Delete deskrect ;api_ShowWindow hwin , 3 ; maximize End Function Function GraphicsWindow_Error( message\$ ) If GraphicsWindow_SilentMode DebugLog "() GraphicsWindow - "+message Else RuntimeError "() GraphicsWindow:"+Chr(13)+message End If End Function --> WindowHandling.BB (25 Dec 2010)
Posted : Monday, 17 January 2011, 09:36 | Permalink
Teasy

-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 549|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
 Latest PostsHurricane Doris vs Shed Roof steve_ancell Wed 20:23 PIP Crap Jayenkai Wed 16:45 What Have You Done? - Feb 2017 rockford Wed 12:23 SSL Options Jayenkai Wed 11:31 AGameAWeek : 2017 - Part One Jayenkai Mon 08:35 Nintendo Switch Indies rychan Mon 02:48 UWP Languages rskgames Sun 05:05 Switchmas rockford Sun 04:24 Happy Birthday, Mrs Rockford rockford Fri 05:30 Pokemon Go Jayenkai Fri 04:46 More

 Latest Items Snippet : Wall Tracing on Random Maps (rpg)Pakz Wed 18:56 Blog : mini projectJayenkai Tue 06:23 Snippet : Path FollowingPakz Mon 16:25 Dev-Diary : PS2 to N64 Adapterspinal Mon 01:53 Snippet : Flowers (Jan 2017)Kuron Thu 01:13 Showcase : Clusters of Hextherevillsgames Mon 15:01 Article : Maths 101 - Episode 1: Basic Trigonometryshroom_monk Sun 14:07 Article : Maths 101 - Episode 5: Line Intersectionshroom_monk Sun 14:02 Dev-Diary : Normals and Dot productsPakz Sat 20:37 Pets : Molly On The CouchJayenkai Thu 04:32 Showcase : Between SpacePakz Sun 12:55 Snippet : Additive Particle FlamesPakz Fri 18:12 Snippet : Maze 2d - Recursive BacktrackerPakz Sun 07:34 Snippet : Bush fire mapsPakz Wed 09:43 Woot : My MusicJayenkai Sat 14:20More

Who's Online
steve_ancell
Wed, at 20:27
rskgames
Wed, at 20:21
Pakz
Wed, at 19:43
Jayenkai
Wed, at 18:27