質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

3DCG

コンピュータの演算により、3次元空間の仮想物体を、2次元平面上で表現する手法である。

DirectX

DirectX(ダイレクトエックス)は、 マイクロソフトが開発したゲーム・マルチメディア処理用のAPIの集合です。

DXライブラリ

DXライブラリとは、DirectXを使ったWindowsソフトの開発に必ず付いて回るDirectXやWindows関連のプログラムを使い易くまとめた形で利用できるようにしたC++言語用のゲームライブラリです。

Q&A

解決済

1回答

1761閲覧

地面として描画した正方形ポリゴンになぞの黒い三角形が描画させる原因が知りたい。DxLib

退会済みユーザー

退会済みユーザー

総合スコア0

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

3DCG

コンピュータの演算により、3次元空間の仮想物体を、2次元平面上で表現する手法である。

DirectX

DirectX(ダイレクトエックス)は、 マイクロソフトが開発したゲーム・マルチメディア処理用のAPIの集合です。

DXライブラリ

DXライブラリとは、DirectXを使ったWindowsソフトの開発に必ず付いて回るDirectXやWindows関連のプログラムを使い易くまとめた形で利用できるようにしたC++言語用のゲームライブラリです。

0グッド

0クリップ

投稿2020/05/01 06:03

提示画像のように実行したときにカメラに黒い三角形が表示されてしまいます。テクスチャをオン、オフしましたが黒色が灰色になるだけで画面から決めません。これはなぜでしょうか?何度も実行し直すと時々消えたりして意図した動作になります、文字数の関係で消していますが正方形も頂点描画していますがコメントにしてるのでそれは関係ないと思います。また、紙の上に正方形を書いたりして頂点座標をイメージしたりインデックス配列等がサイズからあふれているのではないかと思い.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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2020/05/01 07:04

Ground_Index[2] = 3; を Ground_Index[2] = 2; に変えてみては。
退会済みユーザー

退会済みユーザー

2020/05/01 08:58

試しましたが違いました。そこは3であってるみたいです。
guest

回答1

0

ベストアンサー

DrawPolygonIndexed3D(Ground_Vertex,4,Ground_Index,6,handle,false);

これの第4引数に渡す値って,6で合ってますか?
(2ではなく?)

投稿2020/05/01 07:36

fana

総合スコア11654

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問