• Sábado 21 de Diciembre de 2024, 14:50

Autor Tema:  Como Usar Los Indices En C# Con Directx 9  (Leído 2133 veces)

yeisondx

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Como Usar Los Indices En C# Con Directx 9
« en: Martes 7 de Febrero de 2006, 02:25 »
0
Estoy aprendiendo a utilizar directX en C# y al usar los indices me muestra un error.

El codigo de la aplicacion es el sgte.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
 
namespace DirectX_Tutorial
{
 
   public class WinForm : System.Windows.Forms.Form
   {
      private Device device;
      private float angle = 0f;
      private CustomVertex.PositionColored[] vertices;
      private VertexBuffer vb;
      private int[] indices;
      private IndexBuffer ib;
      private System.ComponentModel.Container components = null;
      
      public WinForm()
      {
         InitializeComponent();
         this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
      }
 
      public void InitializeDevice()
      {
         PresentParameters presentParams = new PresentParameters();
         presentParams.Windowed = true;
         presentParams.SwapEffect = SwapEffect.Discard;
         device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
         device.RenderState.CullMode = Cull.None;
         device.RenderState.FillMode = FillMode.WireFrame;
      }

      private void CameraPositioning()
      {
         device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, this.Width/this.Height, 1f, 50f);
         device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-30), new Vector3(0,0,0), new Vector3(0,1,0));
         device.RenderState.Lighting = false;
      }

      private void VertexDeclaration()
      {
         vb = new VertexBuffer(typeof(CustomVertex.PositionColored), 5, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
 
         vertices = new CustomVertex.PositionColored[5];
         vertices[0].SetPosition(new Vector3(0f, 0f, 0f));
         vertices[0].Color = Color.White.ToArgb();
         vertices[1].SetPosition(new Vector3(5f, 0f, 0f));
         vertices[1].Color = Color.White.ToArgb();
         vertices[2].SetPosition(new Vector3(10f, 0f, 0f));
         vertices[2].Color = Color.White.ToArgb();
         vertices[3].SetPosition(new Vector3(5f, 5f, 0f));
         vertices[3].Color = Color.White.ToArgb();
         vertices[4].SetPosition(new Vector3(10f, 5f, 0f));
         vertices[4].Color = Color.White.ToArgb();

         vb.SetData(vertices, 0 ,LockFlags.None);
      }


      private void IndicesDeclaration()
      {
         ib = new IndexBuffer(typeof(int), 6, device, Usage.WriteOnly, Pool.Default);
         indices = new int[6];
 
         indices[0]=3;
         indices[1]=1;
         indices[2]=0;
         indices[3]=0;
         indices[4]=0;
         indices[5]=0;
 
         ib.SetData(indices, 0, LockFlags.None);
      }
 
      protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
      {
         device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);
 
         device.BeginScene();
         device.VertexFormat = CustomVertex.PositionColored.Format;
         //device.Transform.World = Matrix.Translation(-5,-10*1/3,0)*Matrix.RotationAxis(new Vector3(angle*4,angle*3,angle*2),angle);

         device.SetStreamSource(0,vb,0);
         device.Indices = ib;
         //device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);

         //device.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,5,0,2);
         
         device.EndScene();
 
         device.Present();
 
         this.Invalidate();
         angle += .05f;
      }
 
      protected override void Dispose (bool disposing)
      {
         if (disposing)
         {
            if (components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose(disposing);
      }
 
      private void InitializeComponent()
      {
         this.components = new System.ComponentModel.Container();
         this.Size = new System.Drawing.Size(500,500);
         this.Text = "DirectX Tutorial";
      }
     
      static void Main()
      {
         using (WinForm dx = new WinForm())
         {
            dx.InitializeDevice();
            dx.CameraPositioning();
            dx.VertexDeclaration();
            dx.IndicesDeclaration();
            Application.Run(dx);
         }
      }
   }
}

JuanK

  • Miembro de ORO
  • ******
  • Mensajes: 5393
  • Nacionalidad: co
    • Ver Perfil
    • http://juank.io
Re: Como Usar Los Indices En C# Con Directx 9
« Respuesta #1 en: Martes 7 de Febrero de 2006, 14:50 »
0
tu error debe ser muy sencillo de corregir, y ya me imagino cual es, sin ambargo seria mejor si noa ayudaras con esto:

1- Formatea el codigo ( colocalo dentro de los tags [ code ] codigo[/ code ])
2- coloca cual es el error que te arroja
[size=109]Juan Carlos Ruiz Pacheco
[/size]
Microsoft Technical Evangelist
@JuanKRuiz
http://juank.io