せっかく作ったので、ほかの grotate のスクリも晒しちゃう。カーソルキーで回転させて grotate のガタガタがよく分かるサンプルと、 grotate したときの頂点を計算するスクリ。
まずは、カーソルキーで回転させて grotate のガタガタがよく分かるサンプル。 1024 x 768 のでかい画面なので、低解像度な方は適宜画面サイズ変更してください。± 1.0 、± 2.0 あたりが特にガタガタ。
#include "hspmath.as"
#const WINDOW_ID_MAIN 0
#const WINDOW_ID_PICTURE 1
#const KEYCODE_LEFT 37
#const KEYCODE_UP 38
#const KEYCODE_RIGHT 39
#const KEYCODE_DOWN 40
buffer WINDOW_ID_PICTURE
picload dir_exe + "\\sample\\demo\\jp6girl.bmp"
pictureWidth = ginfo_winx
pictureHeight = ginfo_winy
screen WINDOW_ID_MAIN, 1024, 768
rad = 0.0
onkey gosub *l_onkey
gosub *draw
stop
*draw
redraw 0
color 255, 255, 255 : boxf
pos ginfo_winx / 2, ginfo_winy / 2
gmode GMODE_GDI, pictureWidth, pictureHeight
grotate WINDOW_ID_PICTURE, 0, 0, rad, pictureWidth * 7 / 2, pictureHeight * 7 / 2
redraw 1
titleStr = strf( "角度(rad) : %.16f", rad )
title titleStr
return
*l_onkey
if ( wParam == KEYCODE_LEFT ) || ( wParam == KEYCODE_UP ) {
rad -= M_PI / 180
if rad < ( -M_PI ) : rad += M_PI * 2
} else : if ( wParam == KEYCODE_RIGHT ) || ( wParam == KEYCODE_DOWN ) {
rad += M_PI / 180
if rad > M_PI : rad -= M_PI * 2
} else {
return
}
gosub *draw
return
次に grotate したときの頂点を計算してみるスクリ。加法定理使ってます。
#include "hspmath.as"
#define gbox( %1, %2, %3, %4 ) line %3, %2, %1, %2:\
line %3, %4:\
line %1, %4:\
line %1, %2
#const WINDOW_ID_MAIN 0
#const WINDOW_ID_PICTURE 1
buffer WINDOW_ID_PICTURE
picload dir_exe + "\\sample\\demo\\jp6girl.bmp"
pictureWidth = ginfo_winx
pictureHeight = ginfo_winy
screen WINDOW_ID_MAIN
repeat
redraw 0
color 255, 255, 255 : boxf
copyLeft = 0
copyTop = 0
copyWidth = pictureWidth
copyHeight = pictureHeight
pasteX = ginfo_winx / 2
pasteY = ginfo_winy / 2
pasteWidth = int( 0.6 * copyWidth )
pasteHeight = int( 0.6 * copyHeight )
rotate = M_PI / 180 * cnt
pos pasteX, pasteY
gmode GMODE_GDI, copyWidth, copyHeight
grotate WINDOW_ID_PICTURE, copyLeft, copyTop, rotate, pasteWidth, pasteHeight
sin_rotate = sin( rotate )
cos_rotate = cos( rotate )
repeat 4
x = double(copyWidth) / 2
if ( ( cnt + 1 ) \ 4 ) <= 1 {
x *= -1
}
y = double(copyHeight) / 2
if cnt <= 1 {
y *= -1
}
x *= double( pasteWidth ) / copyWidth
y *= double( pasteHeight ) / copyHeight
xx = cos_rotate * x - sin_rotate * y
y = sin_rotate * x + cos_rotate * y
x = xx
x += pasteX
y += pasteY
if ( cnt == 0 ) || ( minX > x ) {
minX = x
}
if ( cnt == 0 ) || ( minY > y ) {
minY = y
}
if ( cnt == 0 ) || ( maxX < x ) {
maxX = x
}
if ( cnt == 0 ) || ( maxY < y ) {
maxY = y
}
loop
color
gbox minX, minY, maxX, maxY
redraw 1
await 17
loop