DirectX: нарисовать несколько объектов - C#

Узнай цену своей работы

Формулировка задачи:

Как мне тут несколько объектов нарисовать кроме чайника? подскажите куда компать
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        static void Main()
        {
            Form1 form = new Form1();
            form.Text = "test";
            form.Width = 400;
            form.Height = 300;
            form.InitD3D();
            form.Show();
            while (form.Created)
            {
                form.Render();
                Application.DoEvents();
            }
        }
 
        Device device;
        Mesh teapot;
 
        public void InitD3D()
        {
            PresentParameters parameters = new PresentParameters();
            parameters.Windowed = true;
            parameters.SwapEffect = SwapEffect.Discard;
 
            device = new Device(0, DeviceType.Hardware, this,
              CreateFlags.SoftwareVertexProcessing, parameters);
            teapot = Mesh.Teapot(device);
        }
 
        public void Render()
        {
            device.Clear(ClearFlags.Target,
              System.Drawing.Color.Blue, 1.0f, 0);
            device.BeginScene();
            try
            {
                device.RenderState.Lighting = true;
                device.Lights[0].Type = LightType.Directional;
                device.Lights[0].Direction = new Vector3(7, -2, 1);
                device.Lights[0].Diffuse = System.Drawing.Color.Yellow;
                device.Lights[0].Enabled = true;
 
                Material material = new Material();
                material.Ambient = System.Drawing.Color.White;
                material.Diffuse = System.Drawing.Color.White;
                material.Specular = System.Drawing.Color.White;
                device.Material = material;
 
                Matrix matrix = new Matrix();
                matrix.Scale(0.7f, 0.7f, 0.7f);
                matrix *= Matrix.RotationY(
                  System.Environment.TickCount / 300.0f);
                float move = (float)Math.Sin(
                  System.Environment.TickCount / 2000.0f) * 4 + 6;
                matrix.M43 = move;
                Text = move.ToString("##.##");
                device.RenderState.Clipping = false;
                device.Transform.World = matrix;
                device.Transform.Projection = Matrix.PerspectiveFovLH(
                  (float)Math.PI / 10, 1.0f, 0.1f, 20.0f);
                device.RenderState.CullMode = Cull.Clockwise;
                teapot.DrawSubset(0);
            }
            finally
            {
                device.EndScene();
            }
            device.Present();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
    } 
}

Решение задачи: «DirectX: нарисовать несколько объектов»

textual
Листинг программы
class GreenCube
{
   public int health;
   public Texture2D Texture;//вообще-то так делать нельзя. Класс не должен предоставлять прямой  доступ к своим объектам, но для наглядности сойдет. 
}
 
//....
 
GreenCube[] green_cubes = new GreenCube[128]; 
 protected override void LoadContent() 
 { 
 for (int i = 0; i <= 127; i++) 
 { 
 green_cubes.Texture = Content.Load<Texture2D>("textures/green"); 
 green_cubes.health = i;
} 
}
 
int health = green_cubes[5].health;

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 4.182 из 5
Похожие ответы