; 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, 4 mapsize = 60000.0 mapdiv = 60.0 mapheight = 5500.0 chgdegx = 0.0 : chkdegy = 0.0 : chkdegz = 0.0 screenw = 640 : screenh = 480 screen 0, screenw, screenh, 1 pointmax = 100 title "Easy3D for HSP3 sample" ;開発中は下の行のコメントアウトを外すことを推奨します。 ;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 0 pathbuf.0 = mediadir + "\\g_6_20_1.bmp" pathbuf.1 = mediadir + "\\g_road_6_20_1.bmp" pathbuf.2 = mediadir + "\\g_river_6_20_1.bmp" pathbuf.3 = mediadir + "\\BG43.bmp" E3DLoadGroundBMP pathbuf.0, pathbuf.1, pathbuf.2, pathbuf.3, mapsize, mapsize, mapdiv, mapdiv, mapheight, 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 25 E3DLoadGroundBMP pathbuf.0, pathbuf.1, pathbuf.2, pathbuf.3, mapsize, mapsize, mapdiv, mapdiv, mapheight, hsid1 posx1 = 0.0 : posy1 = 0.0 : posz1 = mapsize degx1 = 0.0 : degy1 = 0.0 : degz1 = 0.0 E3DSetPos hsid1, posx1, posy1, posz1 E3DSetDir hsid1, degx1, degy1, degz1 frameno1 = 0 E3DSetProgressBar 50 E3DLoadGroundBMP pathbuf.0, pathbuf.1, pathbuf.2, pathbuf.3, mapsize, mapsize, mapdiv, mapdiv, mapheight, hsid2 posx2 = mapsize : posy2 = 0.0 : posz2 = 0.0 degx2 = 0.0 : degy2 = 0.0 : degz2 = 0.0 E3DSetPos hsid2, posx2, posy2, posz2 E3DSetDir hsid2, degx2, degy2, degz2 frameno2 = 0 E3DSetProgressBar 70 E3DLoadGroundBMP pathbuf.0, pathbuf.1, pathbuf.2, pathbuf.3, mapsize, mapsize, mapdiv, mapdiv, mapheight, hsid3 posx3 = mapsize : posy3 = 0.0 : posz3 = mapsize degx3 = 0.0 : degy3 = 0.0 : degz3 = 0.0 E3DSetPos hsid3, posx3, posy3, posz3 E3DSetDir hsid3, degx3, degy3, degz3 frameno2 = 0 pathbuf.0 = mediadir + "\\morob_6_26_r3.sig" pathbuf.1 = mediadir + "\\morob_6_26_r3.qua" E3DSigLoad pathbuf.0, hsid4 E3DAddMotion hsid4, pathbuf.1, mk4_idling, max4_idling E3DSetMotionKind hsid4, mk4_idling posx4 = 39690.0 : posy4 = 3000.0 : posz4 = 42115.0 degx4 = 0.0 : degy4 = 180.0 : degz4 = 0.0 E3DSetPos hsid4, posx4, posy4, posz4 E3DSetDir hsid4, degx4, degy4, degz4 frameno4 = 0 newmk4 = 0 E3DSetBeforePos hsid4 ;!!!!!!!!!!!!!!!!!!!!! ; PosOnGround 命令を使うために、ChkInViewを、あらかじめ、呼んでおく必要があります。 ;!!!!!!!!!!!!!!!!!!!!! E3DChkInView scid1, hsid0 E3DChkInView scid1, hsid1 E3DChkInView scid1, hsid2 E3DChkInView scid1, hsid3 ;////////billboard E3DSeed 321 bbnum = 50 ;/////////////////////////// ; 地面(hsid0)に木をはやす dim bbid0, bbnum ;billboard id sdim texstr0, 1024, 1 bbno = 0 repeat bbnum E3DRand 3, texkind if ( texkind = 0 ) { pathbuf.0 = mediadir + "\\tree01S.tga" } else { if( texkind = 1 ) { pathbuf.0 = mediadir + "\\tree02S.tga" } else { pathbuf.0 = mediadir + "\\tree35S.tga" } } E3DCreateBillboard pathbuf.0, 2000.0, 3200.0, 0, bbid0.bbno divsize = int(mapsize) E3DRand divsize, rand1 E3DRand divsize, rand2 randx = double(rand1) * 2.0 randz = double(rand2) * 2.0 E3DSetBillboardOnGround bbid0.bbno, hsid0, mapheight, -100.0, randx, randz bbno++; loop ;/////////////////////////// ; 地面(hsid1)に木をはやす dim bbid1, bbnum ;billboard id bbno = 0 repeat bbnum E3DRand 3, texkind if ( texkind = 0 ) { pathbuf.0 = mediadir + "\\tree01S.tga" } else { if( texkind = 1 ) { pathbuf.0 = mediadir + "\\tree02S.tga" } else { pathbuf.0 = mediadir + "\\tree35S.tga" } } E3DCreateBillboard pathbuf.0, 2000.0, 3200.0, 0, bbid1.bbno divsize = int(mapsize) / 2 E3DRand divsize, rand1 E3DRand divsize, rand2 randx = double(rand1) * 2.0 randz = double(rand2) * 2.0 E3DSetBillboardOnGround bbid1.bbno, hsid1, mapheight, -100.0, randx, randz + mapsize bbno++; loop E3DSetProgressBar 80 ;/////////////////////////// ; 地面(hsid2)に木をはやす dim bbid2, bbnum ;billboard id bbno = 0 repeat bbnum E3DRand 3, texkind if ( texkind = 0 ) { pathbuf.0 = mediadir + "\\tree01S.tga" } else { if( texkind = 1 ) { pathbuf.0 = mediadir + "\\tree02S.tga" } else { pathbuf.0 = mediadir + "\\tree35S.tga" } } E3DCreateBillboard pathbuf.0, 2000, 3200, 0, bbid2.bbno divsize = int(mapsize) / 2 E3DRand divsize, rand1 E3DRand divsize, rand2 randx = double(rand1) * 2.0 randz = double(rand2) * 2.0 E3DSetBillboardOnGround bbid2.bbno, hsid2, mapheight, -100.0, randx + mapsize, randz bbno++; loop E3DSetProgressBar 90 ;/////////////////////////// ; 地面(hsid3)に木をはやす dim bbid3, bbnum ;billboard id bbno = 0 repeat bbnum E3DRand 3, texkind if ( texkind = 0 ) { pathbuf.0 = mediadir + "\\tree01S.tga" } else { if( texkind = 1 ) { pathbuf.0 = mediadir + "\\tree02S.tga" } else { pathbuf.0 = mediadir + "\\tree35S.tga" } } E3DCreateBillboard pathbuf.0, 2000, 3200, 0, bbid3.bbno divsize = int(mapsize) / 2 E3DRand divsize, rand1 E3DRand divsize, rand2 randx = double(rand1) * 2.0 randz = double(rand2) * 2.0 E3DSetBillboardOnGround bbid3.bbno, hsid3, mapheight, -100.0, randx + mapsize, randz + mapsize bbno++; loop ;///////////////// testfps = 0 lightdirx1 = 0.0 lightdiry1 = -1.0 lightdirz1 = 1.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 ;mqo file 出力のテスト ;pathbuf.0 = mediadir + "\\wtest_e3dhsp.mqo" ;E3DSaveMQOFile hsid0, pathbuf.0 E3DSetLinearFogParams 1, 0, 0, 255, 1000.0, proj_far dim arfps, 50 *main ; keybuf変数は、メインループの外で、dim keybuf, 256 として、確保しておいてください。 E3DGetKeyboardState keybuf if keybuf.VK_ESCAPE = 1 : goto *bye ; [ESC]で終了 gosub *MoveChara gosub *MoveCamera E3DSetNewPose hsid4, frameno4 E3DBeginScene scid1 E3DChkInView scid1, hsid0 E3DChkInView scid1, hsid1 E3DChkInView scid1, hsid2 E3DChkInView scid1, hsid3 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, hsid3, 0, frameno3, 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, hsid3, 1, frameno3, 0 E3DRender scid1, hsid4, 1, frameno4, 0 E3DRenderBillboard scid1 gosub *DrawText E3DEndScene E3DPresent scid1 waitbyfps 60, 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 *MoveChara forwardstep = 100.0 backstep = -100.0 degstep = 5.0 mdegstep = -degstep posstep = 100.0 ; VK_ が頭につく、定数の詳細は、e3dhsp_vk.as をご覧ください。 ; keybuf は、GetKeyboardState 命令で、セットされます。 if keybuf.VK_UP = 1 : E3DPosForward hsid4, forwardstep ;矢印上 if keybuf.VK_DOWN = 1 : E3DPosForward hsid4, backstep ;矢印下 if keybuf.VK_LEFT = 1 : E3DRotateY hsid4, mdegstep ;矢印左 if keybuf.VK_RIGHT = 1 : E3DRotateY hsid4, degstep ;矢印右 ; a が 押されたときに、前進したいときは、下の様に記述します。 ;;;if keybuf.'A' = 1 : E3DPosForward hsid4, forwardstep return *ChkConf result0 = 0 result1 = 0 result2 = 0 result3 = 0 resultbillboard = 0 ; ビルボードと、キャラクタのあたり判定 dim confbbid, 10 E3DChkConfBillboard hsid4, 0.1, resultbillboard, confbbid, 10, confbbnum if ( resultbillboard ) : posx4 = befposx : posy4 = befposy : posz4 = befposz : E3DSetPos hsid4, posx4, posy4, posz4 ; 地面その1と、キャラクタのあたり判定 E3DChkConfGround hsid4, hsid0, 1, 200.0, -100.0, result0, adjustx0, adjusty0, adjustz0, nx0, ny0, nz0 ; 自分で、移動前後の座標を管理すれば、E3DChkConfGround2も使用できます。 ;下のコメント化された命令を参照。 ;E3DGetPos hsid4, posx4, posy4, posz4 ;E3DChkConfGround2 befposx, befposy, befposz, posx4, posy4, posz4, hsid0, 1, 200, 0, result0, adjustx0, adjusty0, adjustz0, nx0, ny0, nz0 if ( result0 != 0 ) : E3DSetPos hsid4, adjustx0, adjusty0, adjustz0 ; 地面その2と、キャラクタのあたり判定 E3DChkConfGround hsid4, hsid1, 1, 200.0, -100.0, result1, adjustx1, adjusty1, adjustz1, nx1, ny1, nz1 if ( result1 != 0 ) : E3DSetPos hsid4, adjustx1, adjusty1, adjustz1 ; 地面その3と、キャラクタのあたり判定 E3DChkConfGround hsid4, hsid2, 1, 200.0, -100.0, result2, adjustx2, adjusty2, adjustz2, nx2, ny2, nz2 if ( result2 != 0 ) : E3DSetPos hsid4, adjustx2, adjusty2, adjustz2 ; 地面その4と、キャラクタのあたり判定 E3DChkConfGround hsid4, hsid3, 1, 200.0, -100.0, result3, adjustx3, adjusty3, adjustz3, nx3, ny3, nz3 if ( result3 != 0 ) : E3DSetPos hsid4, adjustx3, adjusty3, adjustz3 return *MoveCamera E3DGetPos hsid4, saveposx4, saveposy4, saveposz4 E3DPosForward hsid4, -2500.0 E3DGetPos hsid4, backposx, backposy, backposz E3DSetPos hsid4, saveposx4, saveposy4, saveposz4 E3DSetCameraPos backposx, backposy + 1500.0, backposz E3DSetCameraTarget saveposx4, saveposy4 + 800.0, saveposz4, 0, 1, 0 return *DrawText textr = 255 : textg = 0 : textb = 255 textscale = 1 ;textposx = 10 : textposy = 60 ;strchk1 = "chkFPS1 " + chkfps1 ;E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk1 lcnt = 0 avfps = 0 repeat 50 avfps += arfps.lcnt lcnt++ loop avfps = avfps / 50 textposx = 10 : textposy = 80 strchk2 = "avfps " + avfps E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk2 ;textposx = 10 : textposy = 100 ;strchk2 = "camdegxz " + camdegxz + " campos X " + camposx + " campos Y " + camposy + " campos Z " + camposz ;E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk2 E3DGetPos hsid4, chkposx, chkposy, chkposz textposx = 10 : textposy = 140 strchk3 = "chara position X : " + chkposx + " Y : " + chkposy + " Z : " + chkposz E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk3 textposx = 10 : textposy = 180 strchk4 = "confGround result, result0 " + result0 + " result1 " + result1 + " result2 " + result2 + " result3 " + result3 E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk4 textposx = 10 : textposy = 220 if ( result0 != 0 ){ strchk5 = "adjustx0 " + adjustx0 + " adjusty0 " + adjusty0 + " adjustz0 " + adjustz0 E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk5 } textposx = 10 : textposy = 260 if ( result1 != 0 ){ strchk6 = "adjustx1 " + adjustx1 + " adjusty1 " + adjusty1 + " adjustz1 " + adjustz1 E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk6 } textposx = 10 : textposy = 300 if ( result2 != 0 ){ strchk7 = "adjustx2 " + adjustx2 + " adjusty2 " + adjusty2 + " adjustz2 " + adjustz2 E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk7 } textposx = 10 : textposy = 340 if ( result3 != 0 ){ strchk8 = "adjustx3 " + adjustx3 + " adjusty3 " + adjusty3 + " adjustz3 " + adjustz3 E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk8 } repeat confbbnum textposy += 20 strchk8 = "conf billboard id : " + confbbid.cnt E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk8 loop return