sample\sample_devmotion\
sample10_devmotion.hsp
#include "hsp3dish.as" #include "ezlocal-dish-js.hsp" ezLocalJS #include "mod_dish-js-devmotion.hsp" ; ============================== ; HSP3.7β10 から一部のデバイスモーション値は標準で取得できるようになりました。 ; jsdevm_accel_x, jsdevm_accel_y, jsdevm_accel_z ; jsdevm_orient_alpha, jsdevm_orient_beta, jsdevm_orient_gamma ; これらは『センサーを使用する』をチェックすることでHSP3のシステム変数から同じ値を取得することができます。 ; ; 他のセンサー値も使用したい場合は mod_dish-js-devmotion.hsp を利用してください。 ; このモジュールを利用する場合は『センサーを使用する』にチェックをしないでください。処理が重複してしまいます。 ; ============================== // デバイスモーション値の取得開始 JsdevmStart ; - iOSの場合は、ユーザーに画面をタップして貰ってデバイスモーションのアクセス許可(パーミッション)を取得する必要があります。 ; - jsdevm_allowed で既に許可済みか確認できますが、#include直後はまだ判定できず jsdevm_allowed に値が反映されません。 ; iOS向けに「画面をタップしてください」等の注記を書く場合は、jsdevm_allowed が「1」になったら消してください。 #if 0 // mesなしFPS確認用 #undef mes #define mes(%1="",%2=0) logmes "" celload "fps.png",1 : celdiv 1, 8, 8 #define mesfps(%1) fpslen=strlen(str.int(%1)):repeat 4:celput 1,10+cnt:loop:repeat fpslen,1:celput 1,(%1/(int.powf(10,fpslen-cnt)))\10:loop gmode 3,,,256 #else #define mesfps(%1) mes "FPS : "+(%1) #endif // 履歴 ddim ax, 100 : ddim ay, 100 : ddim az, 100 ddim gx, 100 : ddim gy, 100 : ddim gz, 100 ddim ra, 100 : ddim rb, 100 : ddim rg, 100 dim oa, 100 : dim ob, 100 : dim og, 100 *main redraw 0 : color : pos 0,0 mes "加速度(X,Y,Z) : " mes strf(" (% .02f, % .02f, % .02f) m/s^2",jsdevm_accel_x,jsdevm_accel_y,jsdevm_accel_z) ax(i) = jsdevm_accel_x : ay(i) = jsdevm_accel_y : az(i) = jsdevm_accel_z yy = ginfo_cy + 50 color 200,200,200 : line 10, yy, 410, yy color 255,0,0 : pos 410, yy+int(ax((i-cnt+100)\100)*5) : repeat 100 : line 410-cnt*4, yy+int(ax((i-cnt+100)\100)*5) : loop color 0,255,0 : pos 410, yy+int(ay((i-cnt+100)\100)*5) : repeat 100 : line 410-cnt*4, yy+int(ay((i-cnt+100)\100)*5) : loop color 0,0,255 : pos 410, yy+int(az((i-cnt+100)\100)*5) : repeat 100 : line 410-cnt*4, yy+int(az((i-cnt+100)\100)*5) : loop pos 0, yy + 50 : color mes "加速度(X,Y,Z) [重力込み] : " mes strf(" (% .02f, % .02f, % .02f) m/s^2",jsdevm_accel_gx,jsdevm_accel_gy,jsdevm_accel_gz) gx(i) = jsdevm_accel_gx : gy(i) = jsdevm_accel_gy : gz(i) = jsdevm_accel_gz yy = ginfo_cy + 50 color 200,200,200 : line 10, yy, 410, yy color 255,0,0 : pos 410, yy-int(gx((i-cnt+100)\100)*5) : repeat 100 : line 410-cnt*4, yy-int(gx((i-cnt+100)\100)*5) : loop color 0,255,0 : pos 410, yy-int(gy((i-cnt+100)\100)*5) : repeat 100 : line 410-cnt*4, yy-int(gy((i-cnt+100)\100)*5) : loop color 0,0,255 : pos 410, yy-int(gz((i-cnt+100)\100)*5) : repeat 100 : line 410-cnt*4, yy-int(gz((i-cnt+100)\100)*5) : loop pos 0, yy + 50 : color mes "端末向きの変化速度(alpha,beta,gamma) : " mes strf(" (% .02f, % .02f, % .02f) deg/s",jsdevm_rotate_alpha,jsdevm_rotate_beta,jsdevm_rotate_gamma) ra(i) = jsdevm_rotate_alpha : rb(i) = jsdevm_rotate_beta : rg(i) = jsdevm_rotate_gamma yy = ginfo_cy + 50 color 200,200,200 : line 10, yy, 410, yy color 255,0,0 : pos 410, yy-int(ra((i-cnt+100)\100)*0.3) : repeat 100 : line 410-cnt*4, yy-int(ra((i-cnt+100)\100)*0.3) : loop color 0,255,0 : pos 410, yy-int(rb((i-cnt+100)\100)*0.3) : repeat 100 : line 410-cnt*4, yy-int(rb((i-cnt+100)\100)*0.3) : loop color 0,0,255 : pos 410, yy-int(rg((i-cnt+100)\100)*0.3) : repeat 100 : line 410-cnt*4, yy-int(rg((i-cnt+100)\100)*0.3) : loop pos 0, yy + 50 : color mes "端末の回転量(alpha,beta,gamma) : " mes strf(" (% 04d, % 04d, % 04d) deg",jsdevm_orient_alpha,jsdevm_orient_beta,jsdevm_orient_gamma) oa(i) = jsdevm_orient_alpha : ob(i) = jsdevm_orient_beta : og(i) = jsdevm_orient_gamma yy = ginfo_cy + 50 color 200,200,200 : line 10, yy, 410, yy color 255,0,0 : pos 410, yy-int(oa((i-cnt+100)\100)/4) : repeat 100 : line 410-cnt*4, yy-int(oa((i-cnt+100)\100)/4) : loop color 0,255,0 : pos 410, yy-int(ob((i-cnt+100)\100)/3) : repeat 100 : line 410-cnt*4, yy-int(ob((i-cnt+100)\100)/3) : loop color 0,0,255 : pos 410, yy-int(og((i-cnt+100)\100)/2) : repeat 100 : line 410-cnt*4, yy-int(og((i-cnt+100)\100)/2) : loop mes "" if jsdevm_allowed == 0 { pos 5, yy + 50 : color 200,0,0 mes "iOS : ", 1 mes "画面をタップして" mes "デバイスモーションのアクセス許可をしてください" ; - iOSで一度許可するとページ更新しても許可済みになります。 ; 何度か確認したいときはブラウザのプライベートモードを活用してください。 }else { // FPS表示 getreq t2, SYSREQ_TIMER t3 = t2 - t1 if t3 >= 1000 : t1 = t2 : fps = count : count = 0 count++ pos 5, yy + 50 : color mesfps fps } redraw 1 await (1000 / 60) _i++ : i = (_i \ 300) / 3 ; 記録間隔調整 goto *main