提示画像のように実行したときにカメラに黒い三角形が表示されてしまいます。テクスチャをオン、オフしましたが黒色が灰色になるだけで画面から決めません。これはなぜでしょうか?何度も実行し直すと時々消えたりして意図した動作になります、文字数の関係で消していますが正方形も頂点描画していますがコメントにしてるのでそれは関係ないと思います。また、紙の上に正方形を書いたりして頂点座標をイメージしたりインデックス配列等がサイズからあふれているのではないかと思い.hppを確認しましたが正しい大きさでした。テクスチャサイズは正方形です。
提示コードの.cppの最下部の関数
#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)); v->x /= magnitude; v->y /= magnitude; v->z /= magnitude; } void Game::normalize(VECTOR* v) { float magnitude = sqrt(Vector::dot(*v, *v)); v->x /= magnitude; v->y /= magnitude; v->z /= magnitude; } /*コンストラクタ 初期化*/ Game::Game() { /*操作切替*/ mc = ModeChange::rotate; cameraPos.x = 0.0f; cameraPos.y = 20.0f; cameraPos.z = -40.0f; targetV.x = 0; targetV.y = 5; targetV.z = 12.5; SetLightEnable(false);//標準ライトを有効にするかどうか? SetUseLighting(false);// handle = LoadGraph("assets/resource/texturePos.png", false); SetUseZBuffer3D(true); SetWriteZBuffer3D(true); #define GROUND_X 200 #define GROUND_Y -10 #define GROUND_Z 200 /*地面 ポリゴン*/ Ground_Vertex[0].pos = VGet(-GROUND_X, GROUND_Y, GROUND_Z); Ground_Vertex[0].norm = VGet(0.0f, 0.0f, -1.0f); Ground_Vertex[0].dif = color_dif; Ground_Vertex[0].spc = color_spc; Ground_Vertex[0].u = 0.0f; Ground_Vertex[0].v = 0.0f; Ground_Vertex[1].pos = VGet(GROUND_X , GROUND_Y, GROUND_Z); Ground_Vertex[1].norm = VGet(0.0f, 0.0f, -1.0f); Ground_Vertex[1].dif = color_dif; Ground_Vertex[1].spc = color_spc; Ground_Vertex[1].u = 1.0f; Ground_Vertex[1].v = 0.0f; Ground_Vertex[2].pos = VGet(-GROUND_X, GROUND_Y, -GROUND_Z); Ground_Vertex[2].norm = VGet(0.0f, 0.0f, -1.0f); Ground_Vertex[2].dif = color_dif; Ground_Vertex[2].spc = color_spc; Ground_Vertex[2].u = 0.0f; Ground_Vertex[2].v = 1.0f; Ground_Vertex[3].pos = VGet(GROUND_X , GROUND_Y, -GROUND_Z); Ground_Vertex[3].norm = VGet(0.0f, 0.0f, -1.0f); Ground_Vertex[3].dif = color_dif; Ground_Vertex[3].spc = color_spc; Ground_Vertex[3].u = 1.0f; Ground_Vertex[3].v = 1.0f; /*地面インデックス*/ Ground_Index[0] = 0; Ground_Index[1] = 1; Ground_Index[2] = 3; Ground_Index[3] = 0; Ground_Index[4] = 2; Ground_Index[5] = 3; } /*軸方向回転*/ Vector Game::get_axis(Vector camera, Vector target, Vector y) { Vector rel = Vector( camera.x - target.x, camera.y - target.y, camera.z - target.z ); Vector n = Vector::cross(y, rel); normalize(&n);//単位化 return n; } void Game::Update() { change(); Vertex_Norm(); // SetCameraPositionAndAngle(VGet(cameraPos.x, cameraPos.y, cameraPos.z), r, 0, 0); } /*確認用 描画*/ void Game::Debug_Draw() { } void Game::DrawUpdate() { Debug_Draw();//確認用 SetCameraPositionAndTarget_UpVecY(VGet(cameraPos.x, cameraPos.y, cameraPos.z), VGet(targetV.x, targetV.y, targetV.z)); /*ライティング*/ SetLightEnableHandle(LightHandle, true); /*ライトの座標*/ // DrawSphere3D(VGet(LightPos.x, LightPos.y, LightPos.z), 4, 100, GetColor(0, 100, 0), GetColor(225, 225, 225), true); //MV1SetPosition(modelHandle, VGet(0, 20, 220.5)); // MV1SetPosition(modelHandle, VGet(0,10,12.5)); // MV1DrawModel(modelHandle); // color_dif.r += -1; switch( mc ) { case ModeChange::rotate:{ 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; } DrawFormatString(0, 0, GetColor(255, 255, 255), "カメラ 座標 x: %.2f , y: %.2f , z:%.2f ", cameraPos.x, cameraPos.y, cameraPos.z); DrawFormatString(0, 32, GetColor(255, 255, 255), "注視点 座標 x: %.2f , y: %.2f , z:%.2f ", targetV.x, targetV.y, targetV.z); /*-------------------------------------------------------------------------------------------------------------*/ /*平面描画*/ // DrawPolygonIndexed3D(Ground_Vertex, 4, Ground_Index, 6, DX_NONE_GRAPH, false); DrawPolygonIndexed3D(Ground_Vertex,4,Ground_Index,6,handle,false); /*-------------------------------------------------------------------------------------------------------------*/ }
.hpp
#ifndef ___GAME_H___ #define ___GAME_H___ #include "DxLib.h" #include "Vector.hpp" #include <fstream> #include <iostream> using namespace std; class Game { private: enum class ModeChange { /*色編集*/ color_dif, color_spc, rotate,//頂点回転 move,//頂点移動 }; int handle; float r = 0; int modelHandle; Vector cameraPos; Vector LightPos; Vector targetV; float y = -10; const float ROTATE_SPEED = DX_PI_F / 90;//回転スピード COLOR_U8 color_dif = GetColorU8(255, 255, 255, 0); COLOR_U8 color_spc = GetColorU8(255, 255, 255, 0); /*----------------------------*/ VERTEX3D Vertex[8]; VERTEX3D Ground_Vertex[4]; WORD Index[ 6 ][ 6 ]; WORD Ground_Index[ 6 ]; /*----------------------------*/ int LightHandle; /*操作系 モード切替用*/ bool SetColor_flag; bool TextureMode; bool Color_Control; ModeChange mc; void change(); Vector Vertex_rotateX(Vector movePos, const float ang, const Vector* tergetPos); Vector Vertex_rotateY(Vector movePos, const float ang, const Vector* tergetPos); void rotate(Vector *pos, const float ang, const Vector targetV, const Vector axis); void Debug_Draw();//デバッグ用 VECTOR Surface_normal(VERTEX3D result, const VERTEX3D v1, const VERTEX3D v2, const bool n); Vector get_axis(Vector camera, Vector target, Vector y); /*単位化する関数*/ void normalize(Vector* v); void normalize(VECTOR* v); void Vertex_Norm();//頂点法線を設定する public: Game(); void Update(); void DrawUpdate(); }; #endif
回答1件
あなたの回答
tips
プレビュー