; 回転を考慮した当たり判定を実現するためのスクリプト ; 0度で上下反転しているのは要(VC++上でもそうなるのか)確認(しなくてもいいかも) ; 2004/12/28 計算が間違っていたのを密かに修正 #include"hspext.as" screen 0,640,480,1 emath 8 dim x,4 dim y,4 dim xd,4 dim yd,4 ; 相対座標で x=-160<<8, 160<<8, 160<<8,-160<<8 y=-120<<8,-120<<8, 120<<8, 120<<8 rotx=0 roty=0 rotz=0 *main redraw 2 palcolor 0 boxf 0,0,640,480 rotx=rotx+1\256 roty=roty+3\256 rotz=rotz+5\256 repeat 4 ; A=cosY ; B=cosXsinZ= (Sp-Sm)>>1 ; C=sinXcosZ= (Sp+Sm)>>1 ; D=sinY ; E=cosXcosZ= (Cp+Cm)>>1 ; F=sinXsinZ=-(Cp-Cm)>>1 ; ; Cm=cos(X-Z) ; Cp=cos(X+Z) ; Sm=sin(X-Z) ; Sp=sin(X+Z) ; ; x'=x* A*cosZ + y*(B+C*D) // + z*(F-D*E) ((*)今回の場合、zの算出は不要なので省略) ; y'=x*-A*sinZ + y*(E-D*F) // + z*(C+B*D) ; ; 参考:MEGADEMO mod otaku ; http://web.archive.org/web/20010521062059/www.and.or.jp/~ikeuchi/ emcos cm,rotx-rotz emcos cp,rotx+rotz emsin sm,rotx-rotz emsin sp,rotx+rotz emcos a,roty b=(sp-sm)>>1 c=(sp+sm)>>1 emsin d,roty e=(cp+cm)>>1 f=-(cp-cm)>>1 emcos cz,rotz emsin sz,rotz xd.cnt=( (x.cnt*( a*cz>>8)>>8) + (y.cnt*(b+(c*d>>8))>>8) )>>8+320; + (z*(f-(d*e>>8))>>8) )>>8+320 yd.cnt=( (x.cnt*(-a*sz>>8)>>8) + (y.cnt*(e-(d*f>>8))>>8) )>>8+240; + (z*(c+(b*d>>8))>>8) )>>8+240 pos xd.cnt-8,yd.cnt-8 palcolor 255-cnt mes"●" loop pos 0,0 palcolor 255 repeat 4 mes ""+xd.cnt+","+yd.cnt loop pos xd.3,yd.3 repeat 4 line xd.cnt,yd.cnt loop redraw 1 await 33 goto *main