; e3dhsp.dll test script #include "e3dhsp3.as" ;///////////////////////////////////////////////////////// ;///////////////////////////////////////////////////////// ;キーに応じて、リアルタイムで、ボーン変形します ;1から6キーでboneno1の回転を制御 ;Q,W,E,R,T,Yキーでboneno2の回転を制御 ;A,S,D,F,G,Hキーでboneno3の回転を制御 ;Z,X,C,V,B,Nキーでboneno4の回転を制御 ;7,8キーでboneno5の 移動を制御 ;9,0キーで、boneno4の拡大縮小を制御 ; shiftキーを、押しながら操作すると、ローカル座標軸に関する回転が出来ます。 ;///////////////////////////////////////////////////////// ;///////////////////////////////////////////////////////// #module #deffunc waitbyfps int p1, var fps E3DWaitbyFPS@ p1, fps await 0 return #deffunc BoneRotate tempinfo@.MPI_QUA = curqid@ E3DGetMPInfo@ hsid1@, motid1@, curboneno@, curmpid@, tempinfo@ if( curaxis@ == 0 ) { ;X軸回転 if ( curlocalflag@ == 0 ) { if curcalc@ == 0 : E3DRotateQX@ tempinfo@.MPI_QUA, 1 ; 正方向回転 if curcalc@ == 1 : E3DRotateQX@ tempinfo@.MPI_QUA, -1 ; 負方向回転 } else { if curcalc@ == 0 : E3DRotateQLocalX@ tempinfo@.MPI_QUA, 1 ; 正方向回転 if curcalc@ == 1 : E3DRotateQLocalX@ tempinfo@.MPI_QUA, -1 ; 負方向回転 } } if( curaxis@ == 1 ) { ;Y軸回転 if ( curlocalflag@ == 0 ) { if curcalc@ == 0 : E3DRotateQY@ tempinfo@.MPI_QUA, 1 ; 正方向回転 if curcalc@ == 1 : E3DRotateQY@ tempinfo@.MPI_QUA, -1 ; 負方向回転 } else { if curcalc@ == 0 : E3DRotateQLocalY@ tempinfo@.MPI_QUA, 1 ; 正方向回転 if curcalc@ == 1 : E3DRotateQLocalY@ tempinfo@.MPI_QUA, -1 ; 負方向回転 } } if( curaxis@ == 2 ) { ;Z軸回転 if ( curlocalflag@ == 0 ) { if curcalc@ == 0 : E3DRotateQZ@ tempinfo@.MPI_QUA, 1 ; 正方向回転 if curcalc@ == 1 : E3DRotateQZ@ tempinfo@.MPI_QUA, -1 ; 負方向回転 } else { if curcalc@ == 0 : E3DRotateQLocalZ@ tempinfo@.MPI_QUA, 1 ; 正方向回転 if curcalc@ == 1 : E3DRotateQLocalZ@ tempinfo@.MPI_QUA, -1 ; 負方向回転 } } mpinfoflag@.MPI_QUA = 1 ; <--- クォータニオンだけをセットするため、ここだけ1にする。 mpinfoflag@.MPI_TRAX = 0 mpinfoflag@.MPI_TRAY = 0 mpinfoflag@.MPI_TRAZ = 0 mpinfoflag@.MPI_FRAMENO = 0 mpinfoflag@.MPI_DISPSWITCH = 0 mpinfoflag@.MPI_INTERP = 0 mpinfoflag@.MPI_SCALEX = 0 mpinfoflag@.MPI_SCALEY = 0 mpinfoflag@.MPI_SCALEZ = 0 mpinfoflag@.MPI_USERINT1 = 0 mpinfoflag@.MPI_SCALEDIV = 0 E3DSetMPInfo@ hsid1@, motid1@, curboneno@, curmpid@, tempinfo@, mpinfoflag@ updateflag@ = 1 return #deffunc BoneTranslate tempinfo@.MPI_QUA = curqid@ E3DGetMPInfo@ hsid1@, motid1@, curboneno@, curmpid@, tempinfo@ if( curaxis@ == 0 ) { ;X軸移動 if curcalc@ == 0 : tempinfo@.MPI_TRAX += 10 ;正方向移動 if curcalc@ == 1 : tempinfo@.MPI_TRAX -= 10 ;負方向移動 } if( curaxis@ == 1 ) { ;Y軸移動 if curcalc@ == 0 : tempinfo@.MPI_TRAY += 10 ;正方向移動 if curcalc@ == 1 : tempinfo@.MPI_TRAY -= 10 ;負方向移動 } if( curaxis@ == 2 ) { ;Z軸移動 if curcalc@ == 0 : tempinfo@.MPI_TRAZ += 10 ;正方向移動 if curcalc@ == 1 : tempinfo@.MPI_TRAZ -= 10 ;負方向移動 } mpinfoflag@.MPI_QUA = 0 mpinfoflag@.MPI_TRAX = 1 ; <--- 移動量Xをセットするため、1にする。 mpinfoflag@.MPI_TRAY = 1 ; <--- 移動量Yをセットするため、1にする。 mpinfoflag@.MPI_TRAZ = 1 ; <--- 移動量Zをセットするため、1にする。 mpinfoflag@.MPI_FRAMENO = 0 mpinfoflag@.MPI_DISPSWITCH = 0 mpinfoflag@.MPI_INTERP = 0 mpinfoflag@.MPI_SCALEX = 0 mpinfoflag@.MPI_SCALEY = 0 mpinfoflag@.MPI_SCALEZ = 0 mpinfoflag@.MPI_USERINT1 = 0 mpinfoflag@.MPI_SCALEDIV = 0 E3DSetMPInfo@ hsid1@, motid1@, curboneno@, curmpid@, tempinfo@, mpinfoflag@ updateflag@ = 1 return #deffunc BoneScale tempinfo@.MPI_QUA = curqid@ E3DGetMPInfo@ hsid1@, motid1@, curboneno@, curmpid@, tempinfo@ if( curcalc@ == 0 ){ tempinfo@.MPI_SCALEX += 10 tempinfo@.MPI_SCALEY += 10 tempinfo@.MPI_SCALEZ += 10 } else { tempinfo@.MPI_SCALEX -= 10 if( tempinfo@.MPI_SCALEX < 0 ) : tempinfo@.MPI_SCALEX = 0 tempinfo@.MPI_SCALEY -= 10 if( tempinfo@.MPI_SCALEY < 0 ) : tempinfo@.MPI_SCALEY = 0 tempinfo@.MPI_SCALEZ -= 10 if( tempinfo@.MPI_SCALEZ < 0 ) : tempinfo@.MPI_SCALEZ = 0 } mpinfoflag@.MPI_QUA = 0 mpinfoflag@.MPI_TRAX = 0 mpinfoflag@.MPI_TRAY = 0 mpinfoflag@.MPI_TRAZ = 0 mpinfoflag@.MPI_FRAMENO = 0 mpinfoflag@.MPI_DISPSWITCH = 0 mpinfoflag@.MPI_INTERP = 0 mpinfoflag@.MPI_SCALEX = 1 ;X方向の拡大率をセットするため、1にする。 mpinfoflag@.MPI_SCALEY = 1 ;Y方向の拡大率をセットするため、1にする。 mpinfoflag@.MPI_SCALEZ = 1 ;Z方向の拡大率をセットするため、1にする。 mpinfoflag@.MPI_USERINT1 = 0 mpinfoflag@.MPI_SCALEDIV = 1 ;拡大率をセットするため1にする。 E3DSetMPInfo@ hsid1@, motid1@, curboneno@, curmpid@, tempinfo@, mpinfoflag@ updateflag@ = 1 return #global dim keybuf, 256 screenw = 640 : screenh = 480 screen 0, screenw, screenh, 1 title "Easy3D for HSP3 sample" ;開発中は下の行のコメントアウトを外すことを推奨します。 ;E3DEnableDbgFile ;初期化 E3DInit 0, -1, 0, 16, 0, scid1 ;カメラ変数の初期化 cameradist = 2700.0 cameraheight = 900.0 camdegxz = 180.0 camposx = 0.0 camposy = cameraheight camposz = 0.0 ;file のpath 用のバッファーの作成 pathlen = 2048 sdim mediadir, pathlen mediadir = dir_cur + "\\Media" sdim pathbuf, pathlen, 2 ;projectionの変更をしたいときは、以下の2行を有効にしてください。 ;proj_near = 100.0 : proj_far = 20000.0 : proj_fov = 45.0 ;E3DSetProjection proj_near, proj_far, proj_fov E3DCreateProgressBar E3DSetProgressBar 0 ;地面データのロード pathbuf.0 = mediadir + "\\groundplane1_p_small.sig" E3DSigLoad pathbuf.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 E3DSetProgressBar 50 ;takoheadデータのロード pathbuf.0 = mediadir + "\\takohead.sig" E3DSigLoad pathbuf.0, hsid1 pathbuf.0 = mediadir + "\\takohead.qua" E3DAddMotion hsid1, pathbuf.0, motid1, max1_idling ;<---- motid1を取得!! E3DSetPos hsid1, 0.0, 0.0, 0.0 E3DSetProgressBar 80 ;以下、ライトの設定 lightdirx1 = 0.0 lightdiry1 = 0.0 lightdirz1 = 1.0 lightr1 = 128 lightg1 = 128 lightb1 = 128 ;平行光源 E3DCreateLight lid1 E3DSetDirectionalLight lid1, lightdirx1, lightdiry1, lightdirz1, lightr1, lightg1, lightb1 pathbuf.0 = mediadir + "\\lake.bmp" pathbuf.1 = mediadir + "\\cloud3.bmp" E3DCreateBG scid1, pathbuf.0, pathbuf.1, 0.001, 0.0, 0 switchflag1 = 0 chkfps1 = 0 E3DDestroyProgressBar ;ボーンの番号を取得します E3DGetBoneNoByName hsid1, "胴体1", boneno1 E3DGetBoneNoByName hsid1, "胴体2", boneno2 E3DGetBoneNoByName hsid1, "胴体3", boneno3 E3DGetBoneNoByName hsid1, "胴体4", boneno4 E3DGetBoneNoByName hsid1, "頭", boneno5 ;各ボーンの、フレーム番号0のモーションポイントを取得します。 ;モーションポイントは、あらかじめ、takohead.qua中に作ってあるので、この場合は、作成しません。 E3DGetNextMP hsid1, motid1, boneno1, -1, mpid1 E3DGetNextMP hsid1, motid1, boneno2, -1, mpid2 E3DGetNextMP hsid1, motid1, boneno3, -1, mpid3 E3DGetNextMP hsid1, motid1, boneno4, -1, mpid4 E3DGetNextMP hsid1, motid1, boneno5, -1, mpid5 ;モーションポイントの情報を格納するための配列を作成 dim tempinfo, MPI_MAX dim mpinfoflag, MPI_MAX ;計算に使うクォータニオンを、あらかじめ、作成しておく。 E3DCreateQ qid1 ; mpid1 のモーションポイントのクォータニオン操作用のqid E3DCreateQ qid2 ; mpid2 のモーションポイントのクォータニオン操作用のqid E3DCreateQ qid3 ; mpid3 のモーションポイントのクォータニオン操作用のqid E3DCreateQ qid4 ; mpid4 のモーションポイントのクォータニオン操作用のqid E3DCreateQ qid5 ; mpid5 のモーションポイントのクォータニオン操作用のqid curlocalflag = 0 updateflag = 0 *main ; keybuf変数は、メインループの外で、dim keybuf, 256 として、確保しておいてください。 E3DGetKeyboardState keybuf if keybuf.VK_ESCAPE = 1 : goto *bye ; [ESC]で終了 gosub *MoveCamera gosub *MoveChara1 E3DSetMotionFrameNo hsid1, motid1, 0 ;<----- このサンプルでは、フレーム番号は常に0 E3DSetNewPose hsid1, frameno1 E3DChkInView scid1, hsid0 E3DChkInView scid1, hsid1 E3DBeginScene scid1 ;不透明部分の描画をする E3DRender scid1, hsid0, 0, frameno0, 0 E3DRender scid1, hsid1, 0, frameno1, 0 ;半透明部分の描画をする E3DRender scid1, hsid1, 1, frameno1, 0 gosub *DrawText E3DEndScene E3DPresent scid1 waitbyfps 100, chkfps1 goto *main *bye E3DBye end *MoveCamera cameraupdate = 0 if ( keybuf.VK_LEFT == 1 ) { camdegxz += 1 if camdegxz > 360.0 : camdegxz -= 360.0 cameraupdate = 1 } if ( keybuf.VK_RIGHT == 1 ) { camdegxz -= 1 if camdegxz < 0.0 : camdegxz += 360.0 cameraupdate = 1 } if ( keybuf.VK_UP == 1 ) { camposy += 10.0 cameraupdate = 1 } if ( keybuf.VK_DOWN == 1 ) { camposy -= 10.0 cameraupdate = 1 } E3DSin camdegxz, camposx E3DCos camdegxz, camposz camposx *= cameradist camposz *= cameradist E3DSetCameraPos camposx, camposy, camposz E3DSetCameraTarget 0.0, camposy, 0.0, 0.0, 1.0, 0.0 return *MoveChara1 ;hsid1のキャラクタの動作制御 updateflag = 0 if ( keybuf.VK_SHIFT == 1 ) { curlocalflag = 1 } else { curlocalflag = 0 } ; boneno1のモーションの操作 ;////X軸回転 if( keybuf.'1' == 1 ){ curboneno = boneno1 curmpid = mpid1 curqid = qid1 curaxis = 0 curcalc = 0 BoneRotate } if( keybuf.'2' == 1 ){ curboneno = boneno1 curmpid = mpid1 curqid = qid1 curaxis = 0 curcalc = 1 BoneRotate } ;////Y軸回転 if( keybuf.'3' == 1 ){ curboneno = boneno1 curmpid = mpid1 curqid = qid1 curaxis = 1 curcalc = 0 BoneRotate } if( keybuf.'4' == 1 ){ curboneno = boneno1 curmpid = mpid1 curqid = qid1 curaxis = 1 curcalc = 1 BoneRotate } ;////Z軸回転 if( keybuf.'5' == 1 ){ curboneno = boneno1 curmpid = mpid1 curqid = qid1 curaxis = 2 curcalc = 0 BoneRotate } if( keybuf.'6' == 1 ){ curboneno = boneno1 curmpid = mpid1 curqid = qid1 curaxis = 2 curcalc = 1 BoneRotate } ; boneno2のモーションの操作 ;////X軸回転 if( keybuf.'Q' == 1 ){ curboneno = boneno2 curmpid = mpid2 curqid = qid2 curaxis = 0 curcalc = 0 BoneRotate } if( keybuf.'W' == 1 ){ curboneno = boneno2 curmpid = mpid2 curqid = qid2 curaxis = 0 curcalc = 1 BoneRotate } ;////Y軸回転 if( keybuf.'E' == 1 ){ curboneno = boneno2 curmpid = mpid2 curqid = qid2 curaxis = 1 curcalc = 0 BoneRotate } if( keybuf.'R' == 1 ){ curboneno = boneno2 curmpid = mpid2 curqid = qid2 curaxis = 1 curcalc = 1 BoneRotate } ;////Z軸回転 if( keybuf.'T' == 1 ){ curboneno = boneno2 curmpid = mpid2 curqid = qid2 curaxis = 2 curcalc = 0 BoneRotate } if( keybuf.'Y' == 1 ){ curboneno = boneno2 curmpid = mpid2 curqid = qid2 curaxis = 2 curcalc = 1 BoneRotate } ; boneno3のモーションの操作 ;////X軸回転 if( keybuf.'A' == 1 ){ curboneno = boneno3 curmpid = mpid3 curqid = qid3 curaxis = 0 curcalc = 0 BoneRotate } if( keybuf.'S' == 1 ){ curboneno = boneno3 curmpid = mpid3 curqid = qid3 curaxis = 0 curcalc = 1 BoneRotate } ;////Y軸回転 if( keybuf.'D' == 1 ){ curboneno = boneno3 curmpid = mpid3 curqid = qid3 curaxis = 1 curcalc = 0 BoneRotate } if( keybuf.'F' == 1 ){ curboneno = boneno3 curmpid = mpid3 curqid = qid3 curaxis = 1 curcalc = 1 BoneRotate } ;////Z軸回転 if( keybuf.'G' == 1 ){ curboneno = boneno3 curmpid = mpid3 curqid = qid3 curaxis = 2 curcalc = 0 BoneRotate } if( keybuf.'H' == 1 ){ curboneno = boneno3 curmpid = mpid3 curqid = qid3 curaxis = 2 curcalc = 1 BoneRotate } ; boneno4のモーションの操作 ;////X軸回転 if( keybuf.'Z' == 1 ){ curboneno = boneno4 curmpid = mpid4 curqid = qid4 curaxis = 0 curcalc = 0 BoneRotate } if( keybuf.'X' == 1 ){ curboneno = boneno4 curmpid = mpid4 curqid = qid4 curaxis = 0 curcalc = 1 BoneRotate } ;////Y軸回転 if( keybuf.'C' == 1 ){ curboneno = boneno4 curmpid = mpid4 curqid = qid4 curaxis = 1 curcalc = 0 BoneRotate } if( keybuf.'V' == 1 ){ curboneno = boneno4 curmpid = mpid4 curqid = qid4 curaxis = 1 curcalc = 1 BoneRotate } ;////Z軸回転 if( keybuf.'B' == 1 ){ curboneno = boneno4 curmpid = mpid4 curqid = qid4 curaxis = 2 curcalc = 0 BoneRotate } if( keybuf.'N' == 1 ){ curboneno = boneno4 curmpid = mpid4 curqid = qid4 curaxis = 2 curcalc = 1 BoneRotate } ; boneno5のモーション操作 ;////Y軸 移動 if( keybuf.'7' == 1 ){ curboneno = boneno5 curmpid = mpid5 curqid = qid5 curaxis = 1 curcalc = 0 BoneTranslate } if( keybuf.'8' == 1 ){ curboneno = boneno5 curmpid = mpid5 curqid = qid5 curaxis = 1 curcalc = 1 BoneTranslate } ; boneno4の拡大縮小 if( keybuf.'9' == 1 ){ curboneno = boneno4 curmpid = mpid4 curqid = qid4 curaxis = 0 curcalc = 0 BoneScale } if( keybuf.'0' == 1 ){ curboneno = boneno4 curmpid = mpid4 curqid = qid4 curaxis = 0 curcalc = 1 BoneScale } ;///////////////// ; セットしたモーション情報を元に、モデルの姿勢の計算をする。 ; ここでは、フレーム0しか使わないので、startframe = 0, endframe = 0 でOK。 ; このサンプルでは、ボーン情報の変更によって、パーツが画面外に出たりすることがないので、 ; initflag = 0 で良い。 startframe = 0 endframe = 0 initflag = 0 E3DFillUpMotion hsid1, motid1, boneno1, startframe, endframe, initflag ;///////////////////////////////////////////////////////////////////////////////////////////////////////////// ;上の命令で、boneno1とその子供ボーン全ての計算が行われるため、boneno2からboneno5に対する呼び出しはしなくてよい。 ;///////////////////////////////////////////////////////////////////////////////////////////////////////////// ;E3DFillUpMotion hsid1, motid1, boneno2, startframe, endframe, initflag ;E3DFillUpMotion hsid1, motid1, boneno3, startframe, endframe, initflag ;E3DFillUpMotion hsid1, motid1, boneno4, startframe, endframe, initflag ;E3DFillUpMotion hsid1, motid1, boneno5, startframe, endframe, initflag return *DrawText textposx = 10 : textposy = 10 textr = 255 : textg = 255 : textb = 255 textscale = 1 textposx = 10 : textposy = 300 str5 = "chkfps1 " + chkfps1 E3DDrawText textposx, textposy, textscale, textr, textg, textb, str5 textposx = 10 : textposy = 320 str6 = "updateflag " + updateflag E3DDrawText textposx, textposy, textscale, textr, textg, textb, str6 return