MV1SetTextureGraphHandle();のコメント部////部で囲ってあるのif文の一行です。公式リファレンスを見たのですがテクスチャの貼り方が
わかりません、一番それらしい関数を実装してみましたが違うみたいです。どうすればテクスチャを設定できるのでしょうか?
公式リファレンス: https://dxlib.xsrv.jp/function/dxfunc_3d.html
※モデルはブレンダーで新規作成した四角いキューブです。モデルの読み込みには成功しています。
#include "DxLib.h" #include "Game.hpp" #include "Input.hpp" #include "Frame.hpp" #include "Vector.hpp" const char* filename = "Log.txt"; std::ofstream ofs(filename); void Game::normalize(VECTOR* v) { float magnitude = sqrt(Vector::dot(*v, *v)); // ofs<<"magnitude: "<<magnitude<<std::endl; v->x /= magnitude; v->y /= magnitude; v->z /= magnitude; if (isnan(v->x) == true) { v->x = 0; } if (isnan(v->y) == true) { v->y = 0; } if (isnan(v->z) == true) { v->z = 0; } } /*コンストラクタ 初期化*/ Game::Game() { int gu = GetUseDirect3DVersion(); if(gu == DX_DIRECT3D_11) { ofs << "Direct3D Version 11" << std::endl; } gu = GetValidShaderVersion(); ofs << "Shader Version " << gu / 100 <<std::endl; modelHandle = MV1LoadModel("assets/resource/model.mv1"); if(modelHandle == -1) { exit(1); } /*操作切替*/ mc = ModeChange::rotate; /*ライト設定*/ LightHandle = CreateDirLightHandle(VGet(0, -1, 0)); if(LightHandle == -1) { exit(1); } SetLightEnable(false); //標準ライトを有効にするかどうか? SetUseLighting(false); SetUseZBuffer3D(true); SetWriteZBuffer3D(true); handle = LoadGraph("assets/resource/texturePos.png"); cameraPos.x = 34; cameraPos.y = 174; cameraPos.z = -676; targetV.x = 0; targetV.y = 0; targetV.z = 0; /*マテリアル関係*/ materialName = (char*)MV1GetMaterialName(modelHandle,0); if(materialName == NULL){ exit(1); }else{ ofs << "material name: " << materialName << std::endl; } /*テクスチャ関係*/ ofs<<"aaaa: "<<MV1GetTextureNum(modelHandle)<<std::endl; if(handle == -1) { ofs<<"画像読み込み失敗"<<std::endl; exit(1); } ///////////////////////////////////////////////////////////////////////////////////////////////// if(MV1SetTextureGraphHandle(modelHandle,0,handle,0 ) == -1) ///////////////////////////////////////////////////////////////////////////////////////////////// { ofs << " MV1SetTextureGraphHandle() error " << std::endl; exit(1); } textureName = (char*)MV1GetTextureName(modelHandle,0); if(textureName == NULL){ ofs<<" texture name error "<<std::endl; exit(1); }else{ ofs << "texture name: " << textureName << std::endl; } } void Game::Update() { change(); /*カメラ回転*/ if (Input::keyboard(KEY_INPUT_LEFT) > 0) { rotate(&cameraPos, ROTATE_SPEED, targetV, Vector(0, 1, 0)); } else if (Input::keyboard(KEY_INPUT_RIGHT) > 0) { rotate(&cameraPos, ROTATE_SPEED, targetV, Vector(0, -1, 0)); } else if (Input::keyboard(KEY_INPUT_UP) > 0) { rotate(&cameraPos,ROTATE_SPEED,targetV,get_axis(cameraPos,targetV,Vector(0,1,0))); } else if (Input::keyboard(KEY_INPUT_DOWN) > 0) { rotate(&cameraPos,ROTATE_SPEED,targetV,get_axis(cameraPos,targetV,Vector(0,-1,0))); } /*編集*/ switch( mc ){ case ModeChange::rotate: { if (Input::keyboard(KEY_INPUT_W) > 0) { for (int i = 0; i < 8; i++) { Vector tv = Vertex_rotateX(Vector(Vertex[i].pos.x, Vertex[i].pos.y, Vertex[i].pos.z),ROTATE_SPEED, &Vector(targetV.x, targetV.y, targetV.z)); Vertex[i].pos.x = tv.x; Vertex[i].pos.y = tv.y; Vertex[i].pos.z = tv.z; } } else if (Input::keyboard(KEY_INPUT_S) > 0) { for (int i = 0; i < 8; i++) { Vector tv = Vertex_rotateX(Vector(Vertex[i].pos.x, Vertex[i].pos.y, Vertex[i].pos.z), -ROTATE_SPEED, &Vector(targetV.x, targetV.y, targetV.z)); Vertex[i].pos.x = tv.x; Vertex[i].pos.y = tv.y; Vertex[i].pos.z = tv.z; } } else if (Input::keyboard(KEY_INPUT_A) > 0) { for (int i = 0; i < 8; i++) { Vector tv = Vertex_rotateY(Vector(Vertex[i].pos.x, Vertex[i].pos.y, Vertex[i].pos.z), -ROTATE_SPEED, &Vector(targetV.x, targetV.y, targetV.z)); Vertex[i].pos.x = tv.x; Vertex[i].pos.y = tv.y; Vertex[i].pos.z = tv.z; } } else if (Input::keyboard(KEY_INPUT_D) > 0) { for (int i = 0; i < 8; i++) { Vector tv = Vertex_rotateY(Vector(Vertex[i].pos.x, Vertex[i].pos.y, Vertex[i].pos.z), ROTATE_SPEED, &Vector(targetV.x, targetV.y, targetV.z)); Vertex[i].pos.x = tv.x; Vertex[i].pos.y = tv.y; Vertex[i].pos.z = tv.z; } } } break; case ModeChange::move: if (Input::keyboard(KEY_INPUT_W) > 0) { for (int i = 0; i < 8; i++) { Vertex[i].pos.z += 1; } } else if (Input::keyboard(KEY_INPUT_S) > 0) { for (int i = 0; i < 8; i++) { Vertex[i].pos.z += -1; } } else if (Input::keyboard(KEY_INPUT_A) > 0) { for (int i = 0; i < 8; i++) { Vertex[i].pos.x += -1; } } else if (Input::keyboard(KEY_INPUT_D) > 0) { for (int i = 0; i < 8; i++) { Vertex[i].pos.x += 1; } } break; /*スペキュラーカラーを変更*/ case ModeChange::color_spc: if (Input::keyboard(KEY_INPUT_W) > 0) { } else if (Input::keyboard(KEY_INPUT_S) > 0) { } else if (Input::keyboard(KEY_INPUT_A) > 0) { color_spc.r += -1; color_spc.g += -1; color_spc.b += -1; for (int i = 0; i < 8; i++) { Vertex[i].spc = color_spc; } for (int i = 0; i < 4; i++) { Ground_Vertex[i].spc = color_spc; } } else if (Input::keyboard(KEY_INPUT_D) > 0) { color_spc.r += +1; color_spc.g += +1; color_spc.b += +1; for (int i = 0; i < 8; i++) { Vertex[i].spc = color_spc; } for (int i = 0; i < 4; i++) { Ground_Vertex[i].spc = color_spc; } } break; /*ディフューズカラーを変更*/ case ModeChange::color_dif: if (Input::keyboard(KEY_INPUT_W) > 0) { } else if (Input::keyboard(KEY_INPUT_S) > 0) { } else if (Input::keyboard(KEY_INPUT_A) > 0) { color_dif.r += -1; color_dif.g += -1; color_dif.b += -1; for(int i = 0 ;i < 8; i++) { Vertex[i].dif = color_dif; } for (int i = 0; i < 4; i++) { Ground_Vertex[i].dif = color_dif; } } else if (Input::keyboard(KEY_INPUT_D) > 0) { color_dif.r += +1; color_dif.g += +1; color_dif.b += +1; for (int i = 0; i < 8; i++) { Vertex[i].dif = color_dif; } for (int i = 0; i < 4; i++) { Ground_Vertex[i].dif = color_dif; } } break; } // Vertex_Norm(); } /*確認用 描画*/ void Game::Debug_Draw() { DrawFormatString(0, 0, GetColor(255, 255, 255), "カメラ 座標 x: %.2f , y: %.2f , z:%.2f ", cameraPos.x, cameraPos.y, cameraPos.z); DrawFormatString(0, 32 * 1, GetColor(255, 255, 255), "注視点 座標 x: %.2f , y: %.2f , z:%.2f ", targetV.x, targetV.y, targetV.z); switch ( mc ) { case ModeChange::rotate: { // ofs<<"rotate"<<std::endl; DrawFormatString(0, 32 * 2, GetColor(255, 255, 255), "-------------- Rotate --------------"); } break; case ModeChange::move: { DrawFormatString(0, 32 * 2, GetColor(255, 255, 255), "-------------- Move --------------"); } break; case ModeChange::color_dif: { DrawFormatString(0, 32 * 2, GetColor(255, 255, 255), "-------------- Color_dif --------------"); DrawFormatString(0, 32 * 3, GetColor(255, 255, 255), "R: %d", color_dif.r); DrawFormatString(0, 32 * 4, GetColor(255, 255, 255), "G: %d", color_dif.g); DrawFormatString(0, 32 * 5, GetColor(255, 255, 255), "B: %d", color_dif.b); } break; case ModeChange::color_spc: { DrawFormatString(0, 32 * 2, GetColor(255, 255, 255), "-------------- Color_spc --------------"); DrawFormatString(0, 32 * 3, GetColor(255, 255, 255), "R: %d", color_spc.r); DrawFormatString(0, 32 * 4, GetColor(255, 255, 255), "G: %d", color_spc.g); DrawFormatString(0, 32 * 5, GetColor(255, 255, 255), "B: %d", color_spc.b); } break; } VECTOR p = MV1GetPosition(modelHandle); DrawFormatString(0,32 * 10,GetColor(255,255,255),"%f , %f , %f",p.x,p.y,p.z); } void Game::DrawUpdate() { // DrawFormatString(0, 32 * 3, GetColor(255, 255, 255), "chqnge();"); SetCameraPositionAndTarget_UpVecY(VGet(cameraPos.x, cameraPos.y, cameraPos.z), VGet(targetV.x, targetV.y, targetV.z)); VECTOR v; /* v.x = cameraPos.x; v.x = cameraPos.y; v.x = cameraPos.z + 100; */ v.x = 0; v.y = 0; v.z = 0; if (MV1DrawModel(modelHandle) == -1) { exit(1); } if (MV1SetPosition(modelHandle,v) == -1 ){ exit(1); } /*ライト*/ SetLightEnableHandle(LightHandle,true); Debug_Draw(); }

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/05/22 01:41