; たこ自動走行 サンプル #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, 4 mapsize = 150000.0 mapdiv = 50 mapheight = 10000.0 chgdegx = 0 : chkdegy = 0 : chkdegz = 0 screenw = 640 : screenh = 480 ;screenw = 420 : screenh = 340 screen 0, screenw, screenh, 1 pointmax = 100 title "Load By New Thread" ;開発中は下の行のコメントアウトを外すことを推奨します。 ;E3DEnableDbgFile ;初期化 E3DInit 0, -1, 0, 16, 0, scid1 ;カメラの初期化 camposx = 0.0 : camposy = 2500.0 : camposz = 0.0 E3DSetCameraPos camposx, camposy, camposz camdegxz = 180.0 : camdegy = 0.0 E3DSetCameraDeg camdegxz, camdegy confflag = 0 endflag = 0 ;projectionの変更をしたいときは、以下の2行を有効にしてください。 proj_near = 100.0 : proj_far = 50000.0 : proj_fov = 60.0 E3DSetProjection proj_near, proj_far, proj_fov E3DCreateProgressBar E3DSetProgressBar 30 ; たこの読み込み pathbuf.0 = mediadir + "\\tako.sig" pathbuf.1 = mediadir + "\\tako_idling.qua" pathbuf.2 = mediadir + "\\tako_run.qua" E3DSigLoad pathbuf.0, hsid4 E3DAddMotion hsid4, pathbuf.1, mk4_idling, max4_idling E3DAddMotion hsid4, pathbuf.2, mk4_run, max4_run E3DSetMotionKind hsid4, mk4_run posx4 = 117424.0 : posy4 = 7000.0 : posz4 = 44745.0 degx4 = 0.0 : degy4 = 162.0 : degz4 = 0.0 E3DSetPos hsid4, posx4, posy4, posz4 E3DSetDir hsid4, degx4, degy4, degz4 frameno4 = 0 newmk4 = 0 curposx4 = posx4 : curposy4 = posy4 : curposz4 = posz4 E3DSetBeforePos hsid4 ;///////////////// testfps = 0 lightdirx1 = 0.0 lightdiry1 = -1.0 lightdirz1 = 2.0 lightr1 = 255 lightg1 = 255 lightb1 = 255 E3DCreateLight lid1 E3DSetDirectionalLight lid1, lightdirx1, lightdiry1, lightdirz1, lightr1, lightg1, lightb1 E3DSetLightAmbient lid1, 77, 77, 77 E3DSetLightSpecular lid1, 0, 0, 0 chkfps1 = 0 pathbuf.0 = mediadir + "\\lake.bmp" pathbuf.1 = mediadir + "\\cloud3.bmp" E3DCreateBG scid1, pathbuf.0, pathbuf.1, 0.001, 0.0, 0 E3DDestroyProgressBar pbflag = 0; result0 = 0 : result1 = 0 : result2 = 0 : result3 = 0 adjustx0 = 0.0 : adjusty0 = 0.0 : adjustz0 = 0.0 adjustx1 = 0.0 : adjusty1 = 0.0 : adjustz1 = 0.0 adjustx2 = 0.0 : adjusty2 = 0.0 : adjustz2 = 0.0 adjustx3 = 0.0 : adjusty3 = 0.0 : adjustz3 = 0.0 befposx = posx4 : befposy = posy4 : befposz = posz4 ccw = 0 newdeg = 0.0 nx1 = 0.0 : ny1 = 0.0 : nz1 = 0.0 dot1 = 0.0 : dot2 = 0.0 : dot = 0.0 dim arfps, 50 maxfps = 60 befshiftF = 0 curshiftF = 0 turboflag = 0 targetpid4 = 0 movestep = 200.0 E3DCreateFont 20, 0, 400, 0, 0, 0, "MS ゴシック", fontid1 /////////////////////////////// /////////////////////////////// E3DGetPos hsid4, saveposx4, saveposy4, saveposz4 E3DPosForward hsid4, -2500.0 E3DGetPos hsid4, backposx, backposy, backposz E3DSetPos hsid4, saveposx4, saveposy4, saveposz4 E3DSetCameraPos backposx, backposy, backposz E3DSetCameraTarget saveposx4, saveposy4 + 800, saveposz4, 0, 1, 0 sdim strmes0, 1024 strmes0 = "ただいま読み込み中(20秒から1分くらい)\n読み込み中でも、絵が動く!!\nいつもより、多く読み込み中!!" pathbuf.0 = mediadir + "\\poo\\poo.sig" sdim buf0, 450000 bload pathbuf.0, buf0 bufsize0 = strsize ; 新しいスレッドでのロード pathbuf.0 = mediadir + "\\test_course_manypolly.mqo" E3DLoadMQOFileAsGroundThread pathbuf.0, 100.0, 0, threadid0 pathbuf.0 = mediadir + "\\hayame.sig" E3DSigLoadThread pathbuf.0, 0, 1.0, threadid1 pathbuf.0 = mediadir + "\\poo\\" E3DSigLoadFromBufThread pathbuf.0, buf0, bufsize0, 0, 1.0, threadid2 if( (threadid < 0) | (threadid1 < 0) | (threadid2 < 0) ){ E3DDbgOut "script threadid error \r\n" dialog "エラーが生じたので、終了します", 0, "エラー" goto *bye } working0 = 1 working1 = 1 working2 = 1 while ( (working0 != 0) | (working1 != 0) | (working2 != 0) ) E3DChkThreadWorking threadid0, working0, hsid0, returnval2 E3DChkThreadWorking threadid1, working1, hsid1, returnval2 E3DChkThreadWorking threadid2, working2, hsid2, returnval2 E3DRotateY hsid4, 1 E3DSetNewPose hsid4, frameno4 E3DBeginScene scid1 E3DChkInView scid1, hsid4 E3DRender scid1, hsid4, 0, frameno4, 0 E3DDrawTextByFontID scid1, fontid1, 10, 20, strmes0, 255, 255, 255, 255 sdim strmes1, 1024 strmes1 = "working0 " + working0 + " working1 " + working1 + " working2 " + working2 E3DDrawTextByFontID scid1, fontid1, 10, 200, strmes1, 255, 255, 255, 255 E3DEndScene E3DPresent scid1 waitbyfps 30, chkfps1 wend if( (hsid0 < 0) | (hsid1 < 0) | (hsid2 < 0) ){ E3DDbgOut "script hsid error \r\n" dialog "エラーが生じたので、終了します", 0, "エラー" goto *bye } E3DFreeThread threadid0 E3DFreeThread threadid1 E3DFreeThread threadid2 E3DSetPos hsid0, 0.0, 0.0, 0.0 frameno0 = 0 posx1 = 116190.0 posy1 = 5000.0 posz1 = 46320.0 E3DSetPos hsid1, posx1, posy1, posz1 frameno1 = 0 posx2 = 119020.0 posy2 = 5000.0 posz2 = 45950.0 E3DSetPos hsid2, posx2, posy2, posz2 frameno2 = 0 //モーション読み込みは、必ず、モデル読み込みが、完了してから行う。 pathbuf.0 = mediadir + "\\hayame_boot.qua" E3DAddMotionThread hsid1, pathbuf.0, threadid3 pathbuf.0 = mediadir + "\\hayame_crouch.qua" E3DAddMotionThread hsid1, pathbuf.0, threadid4 pathbuf.0 = mediadir + "\\hayame_kick.qua" E3DAddMotionThread hsid1, pathbuf.0, threadid5 pathbuf.0 = mediadir + "\\hayame_punch.qua" E3DAddMotionThread hsid1, pathbuf.0, threadid6 working3 = 1 working4 = 1 working5 = 1 working6 = 1 while ( (working3 != 0) | (working4 != 0) | (working5 != 0) | (working6 != 0) ) E3DChkThreadWorking threadid3, working3, motid3, maxframe3 E3DChkThreadWorking threadid4, working4, motid4, maxframe4 E3DChkThreadWorking threadid5, working5, motid5, maxframe5 E3DChkThreadWorking threadid6, working6, motid6, maxframe6 E3DRotateY hsid4, 1 E3DSetNewPose hsid4, frameno4 E3DBeginScene scid1 E3DChkInView scid1, hsid4 E3DRender scid1, hsid4, 0, frameno4, 0 E3DDrawTextByFontID scid1, fontid1, 10, 20, strmes0, 255, 255, 255, 255 sdim strmes2, 1024 strmes2 = "working2 " + working2 + " working3 " + working3 + " working4 " + working4 + " working5 " + working5 E3DDrawTextByFontID scid1, fontid1, 10, 200, strmes2, 255, 255, 255, 255 E3DEndScene E3DPresent scid1 waitbyfps 30, chkfps1 wend if( (motid3 < 0) | (motid4 < 0) | (motid5 < 0) | (motid6 < 0) ){ E3DDbgOut "script motid error \r\n" dialog "エラーが生じたので、終了します", 0, "エラー" goto *bye } E3DFreeThread threadid3 E3DFreeThread threadid4 E3DFreeThread threadid5 E3DFreeThread threadid6 E3DSetMotionKind hsid1, motid3 *main ; keybuf変数は、メインループの外で、dim keybuf, 256 として、確保しておいてください。 E3DGetKeyboardState keybuf if keybuf.VK_ESCAPE = 1 : goto *bye ; [ESC]で終了 gosub *MoveCamera2 E3DSetNewPose hsid1, frameno1 E3DSetNewPose hsid4, frameno4 E3DBeginScene scid1 E3DChkInView scid1, hsid0 E3DChkInView scid1, hsid1 E3DChkInView scid1, hsid2 E3DChkInView scid1, hsid4 gosub *ChkConf ; !!! E3DChkInViewより後で呼んでください。 ;不透明部分の描画をする E3DRender scid1, hsid0, 0, frameno0, 0 E3DRender scid1, hsid1, 0, frameno1, 0 E3DRender scid1, hsid2, 0, frameno2, 0 E3DRender scid1, hsid4, 0, frameno4, 0 ;半透明部分の描画をする E3DRender scid1, hsid0, 1, frameno0, 0 E3DRender scid1, hsid1, 1, frameno1, 0 E3DRender scid1, hsid2, 1, frameno2, 0 E3DRender scid1, hsid4, 1, frameno4, 0 gosub *DrawText E3DEndScene E3DPresent scid1 waitbyfps maxfps, chkfps1 arno = 0 repeat 49 befno = 48 - arno aftno = 49 - arno arfps.aftno = arfps.befno arno++ loop arfps.0 = chkfps1 E3DGetPos hsid4, posx4, posy4, posz4 E3DSetBeforePos hsid4 befposx = posx4 : befposy = posy4 : befposz = posz4 goto *main *bye E3DBye end return *ChkConf result0 = 0 ; 地面その1と、キャラクタのあたり判定 E3DChkConfGround hsid4, hsid0, 1, 200.0, -100.0, result0, adjustx0, adjusty0, adjustz0, nx0, ny0, nz0 if ( result0 != 0 ) { posx4 = adjustx0 : posy4 = adjusty0 : posz4 = adjustz0 E3DSetPos hsid4, posx4, posy4, posz4 } return *MoveCamera2 E3DGetPos hsid4, saveposx4, saveposy4, saveposz4 E3DGetDirQ hsid4, saveqx4, saveqy4, saveqz4, saveqw4 E3DRotateInit hsid4 E3DRotateY hsid4, 180.0 E3DPosForward hsid4, -2500.0 E3DGetPos hsid4, backposx, backposy, backposz E3DSetPos hsid4, saveposx4, saveposy4, saveposz4 E3DSetDirQ hsid4, saveqx4, saveqy4, saveqz4, saveqw4 E3DChkConfGround2 backposx, mapheight, backposz, backposx, -100.0, backposz, hsid0, 0, 200.0, 0, resultc, adjustxc, adjustyc, adjustzc, nxc, nyc, nzc if ( resultc = 0 ) { backposy = 1500.0 } else { backposy = adjustyc + 1500.0 } E3DSetCameraPos backposx, backposy, backposz E3DSetCameraTarget saveposx4, saveposy4 + 800.0, saveposz4, 0.0, 1.0, 0.0 return *DrawText textr = 0 : textg = 255 : textb = 0 textscale = 1 lcnt = 0 avfps = 0 repeat 50 avfps += arfps.lcnt lcnt++ loop avfps = avfps / 50 textposx = 10 : textposy = 20 strchk2 = "avfps " + avfps E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk2 sdim strmes1, 1024 strmes1 = "読み込みが終了しました。" E3DDrawTextByFontID scid1, fontid1, 10, 40, strmes1, 255, 255, 255, 255 return