grotateのガタガタを逆に利用できないか改

grotate のガタガタを逆に利用できないか試してみるの記事では微妙な結果に終わってしまったものの。今度は、カーソルキーで拡大率と角度を変更できるようにしてみたり。あと、ソースもデバッグ用のコードが残っていたりとかしてたので。

#include "hspmath.as"

#const WINDOW_ID_MAIN 0
#const WINDOW_ID_PICTURE 1
#const WINDOW_ID_WORK 2

#module
#deffunc getGrotateSize int copyWidth, int copyHeight, double rotate, double scale, \
    var sizeX, var sizeY, \
    local sinRotate, local cosRotate, local x, local y, local xx, \
    local minX, local minY, local maxX, local maxY
    sinRotate = sin( rotate )
    cosRotate = 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 *= scale
        y *= scale
        xx = cosRotate * x - sinRotate * y
        y  = sinRotate * x + cosRotate * y
        x = xx

        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
    sizeX = maxX - minX + 1
    sizeY = maxY - minY + 1
    return
#global

    // バッファに画像読み込み
    buffer WINDOW_ID_PICTURE
    picload dir_exe + "\\sample\\demo\\jp6girl.bmp"
    copyWidth   = ginfo_winx
    copyHeight  = ginfo_winy
    rotate      = 0.0 // 角度
    scale       = 1.0 // 拡大率

    screen WINDOW_ID_MAIN, copyWidth, copyHeight
    onkey gosub *labelOnKey
    gosub *draw
    stop

*draw
    getGrotateSize copyWidth, copyHeight, rotate, scale, workWidth, workHeight

    buffer WINDOW_ID_WORK, workWidth, workHeight

    pos workWidth / 2, workHeight / 2
    gmode GMODE_GDI, copyWidth, copyHeight
    grotate WINDOW_ID_PICTURE, 0, 0, rotate, scale * copyWidth, scale * copyHeight

    gsel WINDOW_ID_MAIN
    redraw 0
    pos copyWidth / 2, copyHeight / 2
    gmode GMODE_GDI, workWidth, workHeight
    grotate WINDOW_ID_WORK, 0, 0, -rotate, workWidth / scale, workHeight / scale
    redraw 1
    title strf( "角度:%.2f", rotate ) + " " + strf( "拡大率:%.2f", scale )
    return

*labelOnKey
    switch wParam
        case 37 // カーソルキー[←]
            rotate -= M_PI / 180
            if rotate < ( -M_PI ) : rotate += M_PI * 2
            gosub *draw
            swbreak
        case 39 // カーソルキー[→]
            rotate += M_PI / 180
            if rotate > ( M_PI ) : rotate -= M_PI * 2
            gosub *draw
            swbreak
        case 38 // カーソルキー[↑]
            scale *= 1.1
            scale = limitf( scale, 0.01, 10.0 )
            gosub *draw
            swbreak
        case 40 // カーソルキー[↓]
            scale /= 1.1
            scale = limitf( scale, 0.01, 10.0 )
            gosub *draw
            swbreak
    swend
    return

拡大率をあげると重くなるので注意!

インフォメーション

公開日時
2007年9月26日 午後1時23分14秒
最終更新日時
2007年9月26日 午後1時23分19秒
カテゴリ
HSP