0

directX メッシュに問題があります。4 ~ 5 個を超えるメッシュを描画すると (私は球体を使用します)、メッシュを初期化する行に Direct3dX 例外が表示されます。また、その場合、私はクレイジーな遅れがあります。私はC#を使用しています。

それは私の球体の描画関数です:

    public void draw(Device device)
    {
        device.Transform.World =Matrix.Translation(v3CurMeshPos);            
        device.Material = m;
        device.RenderState.Ambient = color;
        mesh = Mesh.Sphere(device, radius, 100, 100); // problem line
        mesh.DrawSubset(0);
    }

これが、directX を使用した初期化と描画です。

    private void devicePanel1_OnCreateDevice(object sender, DirectxGraph.DeviceEventArgs e)
    {
        device = e.Device;
        device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, devicePanel1.Width / devicePanel1.Height, 1f, 1000f);

        device.RenderState.Lighting = true;
        device.RenderState.CullMode = Cull.None;
        device.Lights[0].Type = LightType.Directional;
        device.Lights[0].Position = new Vector3(10, 10, 0);
        device.Lights[0].Direction = new Vector3(1, -3, -1);
        device.Lights[0].Enabled = true;
    }

    private void updateCamera()
    {
        v3CamPos = new Vector3(0, 0, Util.distance);
        v3CamLookAt = new Vector3(0, 0, 0);
        device.Transform.View = Matrix.RotationYawPitchRoll(Util.rotX, Util.rotY, Util.rotZ) * Matrix.LookAtLH(v3CamPos, v3CamLookAt, new Vector3(0, 1, 0));

    }

    private void devicePanel1_OnRender(object sender, DirectxGraph.DeviceEventArgs e)
    {
        Draw(device);
    }

    private void Draw(Device device)
    {
        if (rotate_forward)
        {
            if (radioButton1.Checked)
            {
                Util.rotX += 0.005f;
            }
            else if (radioButton2.Checked)
            {
                Util.rotY += 0.005f;
            }
            else if (radioButton3.Checked)
            {
                Util.rotZ += 0.005f;
            }
        }
        else if (rotate_backward)
        {
            if (radioButton1.Checked)
            {
                Util.rotX -= 0.005f;
            }
            else if (radioButton2.Checked)
            {
                Util.rotY -= 0.005f;
            }
            else if (radioButton3.Checked)
            {
                Util.rotZ -= 0.005f;
            }
        }
        updateCamera();
        if (!graph.isEmpty())
        {
            foreach (Node node in graph.nodes)
            {
                node.shape.draw(device);
            }
        }

    }
4

1 に答える 1

2

これ

mesh = Mesh.Sphere(device, radius, 100, 100); // problem line

フレームごとに新しいメッシュを作成します。もちろん、これはメモリの大きな浪費であり、おそらく例外につながります。

代わりに、アプリケーションの開始前に一度メッシュを作成し、それを再利用する必要があります。必要に応じて、ワールド マトリックスで変換できます。したがって、必要な半径ごとに球を作成する必要はありません。

于 2013-06-03T10:23:20.807 に答える