Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 带有DirectX 11的球体_C++_Math_3d_Directx 11 - Fatal编程技术网

C++ 带有DirectX 11的球体

C++ 带有DirectX 11的球体,c++,math,3d,directx-11,C++,Math,3d,Directx 11,我尝试用DirectX 11创建一个基本球体。请参阅下面的代码。但有些点的z值不正确。我在代码末尾手动更正它们 我宁愿不手动更正它们,而是让数学正确运行。我看不出有什么不对。其他人能看到吗 void CreateSphere(std::vector<EJM_DGE::Vertex_Color>& Vertex_Color_Vector_Out, std::vector<unsigned short>& us_Indices_Vector_Out) {

我尝试用DirectX 11创建一个基本球体。请参阅下面的代码。但有些点的z值不正确。我在代码末尾手动更正它们

我宁愿不手动更正它们,而是让数学正确运行。我看不出有什么不对。其他人能看到吗

void CreateSphere(std::vector<EJM_DGE::Vertex_Color>& Vertex_Color_Vector_Out, std::vector<unsigned short>& us_Indices_Vector_Out)
{
    int int_Factor = 10;
    float flt_Radius = 10.0f;
    float flt_XT1, flt_YT1, flt_ZT1, flt_XT2, flt_YT2, flt_ZT2;
    int iPos = 0;
    UINT ui_ShapeCount = int_Factor * int_Factor * 2;
    Vertex_Color_Vector_Out.clear();
    us_Indices_Vector_Out.clear();
    std::vector<float> flt_Vector_PosX;
    std::vector<float> flt_Vector_PosY;
    std::vector<float> flt_Vector_PosZ;
    for (int i = 0; i < int_Factor * int_Factor; i++)
    {
        flt_Vector_PosX.push_back(0.0f);
        flt_Vector_PosY.push_back(0.0f);
        flt_Vector_PosZ.push_back(0.0f);
    }
    for (DWORD j = 0; j < int_Factor; j++)
    {
        FLOAT theta = (DirectX::XM_PI * j) / (int_Factor);

        for (DWORD i = 0; i < int_Factor; i++)
        {
            iPos = j * int_Factor + i;
            FLOAT phi = (2 * DirectX::XM_PI * i) / (int_Factor);
            flt_Vector_PosX[iPos] = ((float)(sin(theta) * cos(phi))) * flt_Radius;
            flt_Vector_PosY[iPos] = ((float)(sin(theta) * sin(phi))) * flt_Radius;
            flt_Vector_PosZ[iPos] = ((float)(cos(theta))) * flt_Radius;
        }
    }
    int iNext = 0;
    for (DWORD j = 0; j < int_Factor; j++)
    {

        for (DWORD i = 0; i < int_Factor; i++)
        {
            if (i == int_Factor - 1)
                iNext = 0;
            else iNext = i + 1;

            iPos = (j * int_Factor * 6) + (i * 6);

            Vertex_Color_Vector_Out.push_back(EJM_DGE::Vertex_Color{ flt_Vector_PosX[j * int_Factor + i], flt_Vector_PosY[j * int_Factor + i], flt_Vector_PosZ[j * int_Factor + i],
                0.0f, 0.0f, 0.0f, 1.0f }); // = color.
            us_Indices_Vector_Out.push_back(iPos);

            flt_XT1 = flt_Vector_PosX[j * int_Factor + iNext];
            flt_YT1 = flt_Vector_PosY[j * int_Factor + iNext];
            flt_ZT1 = flt_Vector_PosZ[j * int_Factor + iNext];
            Vertex_Color_Vector_Out.push_back(EJM_DGE::Vertex_Color{ flt_XT1, flt_YT1, flt_ZT1,
                0.0f, 0.0f, 0.0f, 1.0f }); // = color.
            us_Indices_Vector_Out.push_back(iPos + 1);

            if (j != int_Factor - 1)
            {
                flt_XT2 = flt_Vector_PosX[((j + 1) * int_Factor) + i];
                flt_YT2 = flt_Vector_PosY[((j + 1) * int_Factor) + i];
                flt_ZT2 = flt_Vector_PosZ[((j + 1) * int_Factor) + i];
            }
            else
            {
                flt_XT2 = 0;
                flt_YT2 = 0;
                flt_ZT2 = -1;
            }
            Vertex_Color_Vector_Out.push_back(EJM_DGE::Vertex_Color{ flt_XT2, flt_YT2, flt_ZT2,
                0.0f, 0.0f, 0.0f, 1.0f }); // = color.
            us_Indices_Vector_Out.push_back(iPos + 2);

            Vertex_Color_Vector_Out.push_back(EJM_DGE::Vertex_Color{ flt_XT2, flt_YT2, flt_ZT2,
                0.0f, 0.0f, 0.0f, 1.0f }); // = color.
            us_Indices_Vector_Out.push_back(iPos + 3);

            Vertex_Color_Vector_Out.push_back(EJM_DGE::Vertex_Color{ flt_XT1, flt_YT1, flt_ZT1,
                0.0f, 0.0f, 0.0f, 1.0f }); // = color.
            us_Indices_Vector_Out.push_back(iPos + 4);

            if (j != int_Factor - 1)
            {
                Vertex_Color_Vector_Out.push_back(EJM_DGE::Vertex_Color{ flt_Vector_PosX[((j + 1) * int_Factor) + iNext], flt_Vector_PosY[((j + 1) * int_Factor) + iNext], flt_Vector_PosZ[((j + 1) * int_Factor) + iNext],
                    0.0f, 0.0f, 0.0f, 1.0f }); // = color.
                us_Indices_Vector_Out.push_back(iPos + 5);
            }
            else
            {
                Vertex_Color_Vector_Out.push_back(EJM_DGE::Vertex_Color{ 0, 0, -1,
                    0.0f, 0.0f, 0.0f, 1.0f }); // = color.
                us_Indices_Vector_Out.push_back(iPos + 5);
            }
        }
    }
    // Some z values are incorrect. They are near the origin.
    for (int i = 542; i <= 599; i += 3)
    {
        Vertex_Color_Vector_Out.at(i).z = -flt_Radius;
    }
    for (int i = 543; i <= 599; i += 6)
    {
        Vertex_Color_Vector_Out.at(i).z = -flt_Radius;
        Vertex_Color_Vector_Out.at(i).z = -flt_Radius;
        Vertex_Color_Vector_Out.at(i).z = -flt_Radius;
    }
}
void CreateSphere(std::vector&Vertex\u Color\u vector\u Out,std::vector&us\u index\u vector\u Out)
{
int_系数=10;
浮动flt_半径=10.0f;
浮球浮球XT1、浮球YT1、浮球ZT1、浮球XT2、浮球YT2、浮球ZT2;
int iPos=0;
UINT ui_ShapeCount=int_因子*int_因子*2;
顶点颜色向量清除();
us_index_Vector_Out.clear();
std::向量flt_向量PosX;
std::向量flt_向量位置;
std::向量flt_向量PosZ;
对于(int i=0;i对于(int i=542;i)来说,如果没有渲染代码,就很难知道问题到底是什么。也就是说,您应该查看中的
geometricsprimitive
。好的,我会检查它。