;///////////////////////////////////////////////////////// ;// ;// ツールなどで必要となる、カメラの動きを作ってみました。 ;// 矢印キーで、注視点を周りに回転します。 ;// Shift + 矢印キーで、視点と注視点が、平行移動(画面に対して平行に)します。 ;// Z, Xキーで、注視点に接近したり、遠ざかったりします。 ;// カメラの位置のプレフィックスは、campos、 ;// 注視点のプレフィックスは、targetです。 ;// ;////////////////////////////////////////////////////////// ; e3dhsp.dll test script #include "e3dhsp3.as" #module #deffunc waitbyfps int p1, var fps E3DWaitbyFPS@ p1, fps await 0 return #global dim keybuf, 256 ;file のpath 用のバッファーの作成 pathlen = 2048 sdim mediadir, pathlen mediadir = dir_cur + "\\Media" sdim pathbuf, pathlen, 2 screenw = 640 : screenh = 480 screen 0, screenw, screenh, 1 pointmax = 100 title "Easy3D for HSP3 sample" ;開発中は下の行のコメントアウトを外すことを推奨します。 ;E3DEnableDbgFile ;初期化 E3DInit 0, -1, 0, 16, 0, scid1 ;カメラの初期化 eye_y = 1500.0 camposx = 0.0 : camposy = eye_y : camposz = -5000.0 E3DSetCameraPos camposx, camposy, camposz camdegxz = 180.0 : camdegy = 0.0 E3DSetCameraDeg camdegxz, camdegy targetx = 0.0 targety = eye_y targetz = 0.0 cameradist = 5000.0 ;projectionの変更をしたいときは、以下の2行を有効にしてください。 proj_near = 100.0 : proj_far = 30000.0 : proj_fov = 60.0 E3DSetProjection proj_near, proj_far, proj_fov E3DCreateProgressBar E3DSetProgressBar 0 ;地面データのロード pathbuf.0 = mediadir + "\\ground.mqo" E3DLoadMQOFileAsGround pathbuf.0, 10.0, hsid0 posx0 = 0.0 : posy0 = 0.0 : posz0 = 0.0 degx0 = 0.0 : degy0 = 0.0 : degz0 = 0.0 E3DSetPos hsid0, posx0, posy0, posz0 E3DSetDir hsid0, degx0, degy0, degz0 frameno0 = 0 // pathbuf.0 = mediadir + "\\bbs_bone1_red2.sig" pathbuf.0 = mediadir + "\\saru_bone.sig" // pathbuf.0 = mediadir + "\\tiyu.sig" E3DSigLoad pathbuf.0, hsid1 E3DSetPos hsid1, 0.0, 0.0, 0.0 lightdirx1 = 0.0 lightdiry1 = 0.0 lightdirz1 = 1.0 lightr1 = 255 lightg1 = 255 lightb1 = 255 E3DCreateLight lid1 E3DSetDirectionalLight lid1, lightdirx1, lightdiry1, lightdirz1, lightr1, lightg1, lightb1 /////////////////////// E3DCreateQ camq E3DCreateQ invcamq chkfps1 = 0 E3DDestroyProgressBar *main ; keybuf変数は、メインループの外で、dim keybuf, 256 として、確保しておいてください。 E3DGetKeyboardState keybuf if keybuf.VK_ESCAPE = 1 : goto *bye ; [ESC]で終了 gosub *MoveCamera E3DBeginScene scid1 E3DChkInView scid1, hsid0 E3DChkInView scid1, hsid1 ;不透明部分の描画をする E3DRender scid1, hsid0, 0, frameno0, 0 E3DRender scid1, hsid1, 0, frameno0, 0 gosub *DrawText E3DEndScene E3DPresent scid1 waitbyfps 100, chkfps1 goto *main *bye E3DBye end *MoveCamera ; VK_ が頭につく、定数の詳細は、e3dhsp_vk.as をご覧ください。 ; keybuf は、GetKeyboardState 命令で、セットされます。 k=0 if keybuf.VK_LEFT = 1 : k+=1 ; 矢印左 if keybuf.VK_UP = 1 : k+=2 ; 矢印上 if keybuf.VK_RIGHT = 1 : k+=4 ; 矢印右 if keybuf.VK_DOWN = 1 : k+=8 ; 矢印下 if keybuf.VK_SHIFT = 1 : k+= 16 shift = 20.0 deg = 2.0 if ( k&16 ) { if( k&1 ){ //左平行移動 deg = camdegxz + 90.0 E3DSin deg, shiftx E3DCos deg, shiftz targetx += shiftx * shift targetz -= shiftz * shift } if( k&4 ){ //右平行移動 deg = camdegxz - 90.0 E3DSin deg, shiftx E3DCos deg, shiftz targetx += shiftx * shift targetz -= shiftz * shift } if( k&2 ){ //上平行移動 E3DGetCameraQ camq E3DInvQ camq, invcamq E3DMultQVec invcamq, 0.0, shift, 0.0, shiftx, shifty, shiftz targetx += shiftx targety += shifty targetz += shiftz eye_y = targety } if( k&8 ){ //下平行移動 E3DGetCameraQ camq E3DInvQ camq, invcamq E3DMultQVec invcamq, 0.0, -shift, 0.0, shiftx, shifty, shiftz targetx += shiftx targety += shifty targetz += shiftz eye_y = targety } } else { //左右回転 if k&1 : camdegxz += deg if k&4 : camdegxz -= deg if( camdegxz > 360.0 ){ camdegxz -= 360.0 } if( camdegxz < 0.0 ) { camdegxz += 360.0 } //上下回転 if k&2 : camdegy += deg if k&8 : camdegy -= deg if( camdegy >= 90.0 ){ camdegy = 89.0 } if( camdegy <= -90.0 ){ camdegy = -89.0 } } if( keybuf.'Z' == 1 ){ cameradist -= 100.0 if( cameradist < 500.0 ){ cameradist = 500.0 } } if( keybuf.'X' == 1 ){ cameradist += 100.0 } //targetの場所と角度から、カメラの位置を計算する E3DSin camdegxz, sinxz E3DCos camdegxz, cosxz E3DSin camdegy, siny E3DCos camdegy, cosy camposx = sinxz * cosy * cameradist + targetx camposy = eye_y + siny * cameradist camposz = -cosxz * cosy * cameradist + targetz E3DSetCameraPos camposx, camposy, camposz E3DSetCameraTarget targetx, targety, targetz, 0.0, 1.0, 0.0 return *DrawText textr = 255 : textg = 255 : textb = 255 textscale = 1 textposx = 10 : textposy = 60 strchk7 = "chkfps1 " + chkfps1 E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk7 textposy += 20 strchk7 = "camdegxz " + camdegxz + " camdegy " + camdegy E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk7 textposy += 20 strchk7 = "camposx " + camposx + " camposy " + camposy + " camposz " + camposz E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk7 textposy += 20 strchk7 = "targetx " + targetx + " targety " + targety + " targetz " + targetz E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk7 return