; マウスのクリックに応じて、テクスチャーを切り替えるサンプルです。 ; ; クリックするたびに、1,2,3の数字の書かれたテクスチャーが、 ; 順番にセットされます。 ; ; テクスチャーの変更は、ChangeTexutreで行っています。 ; ; 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 ;カメラの初期化 camposx = 0.0 : camposy = 0.0 : camposz = -2500.0 E3DSetCameraPos camposx, camposy, camposz camdegxz = 180.0 : camdegy = 0.0 E3DSetCameraDeg camdegxz, camdegy ;projectionの変更をしたいときは、以下の2行を有効にしてください。 proj_near = 100.0 : proj_far = 30000.0 : proj_fov = 60.0 E3DSetProjection proj_near, proj_far, proj_fov 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 /////////// ;板データのロード pathbuf.0 = mediadir + "\\plane.sig" E3DSigLoad pathbuf.0, hsid0 E3DGetMaterialNoByName hsid0, "obj1_mat0", matid 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 ; 数字のテクスチャーを3枚読み込む pathbuf.0 = mediadir + "\\Num1.jpg" E3DCreateTexture pathbuf.0, D3DPOOL_DEFAULT, 0, texid1 pathbuf.0 = mediadir + "\\Num2.jpg" E3DCreateTexture pathbuf.0, D3DPOOL_DEFAULT, 0, texid2 pathbuf.0 = mediadir + "\\Num3.jpg" E3DCreateTexture pathbuf.0, D3DPOOL_DEFAULT, 0, texid3 E3DSetTextureToMaterial hsid0, matid, texid1 ; テクスチャーのIDの表(texindex)を作る ; displaytexnoを0から2までの間で変化させ(クリックする毎に変化)、 ; displaytexnoに対応するtexidを、配列、texindex.displaytexno に格納します。 displaytexno = 0 dim texindex, 3 texindex.0 = texid1 texindex.1 = texid2 texindex.2 = texid3 chkfps1 = 0 ////////////// onclick gosub *ChangeTexture *main ; keybuf変数は、メインループの外で、dim keybuf, 256 として、確保しておいてください。 E3DGetKeyboardState keybuf if keybuf.VK_ESCAPE = 1 : goto *bye ; [ESC]で終了 E3DRotateZ hsid0, 1 E3DBeginScene scid1 E3DChkInView scid1, hsid0 ;不透明部分の描画をする E3DRender scid1, hsid0, 0, frameno0, 0 ;半透明部分の描画をする E3DRender scid1, hsid0, 1, frameno1, 0 gosub *DrawText E3DEndScene E3DPresent scid1 waitbyfps 100, chkfps1 goto *main *bye E3DBye end *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 = "Click Mouse --> Change Texture" E3DDrawText textposx, textposy, textscale, textr, textg, textb, strchk7 return *ChangeTexture displaytexno++ if( displaytexno >= 3 ){ displaytexno = 0 } ;テクスチャーを、表示オブジェクトに設定する。 E3DSetTextureToMaterial hsid0, matid, texindex.displaytexno return