Teraz dobrze?
vertex[0].X = 0.1f;
vertex[0].Y = 0.9f;
vertex[0].Z = 0f;
vertex[0].Tu = 0; // nie kapuję co ten parametr robi
vertex[0].Tv = 0; //tu tak samo
// następne definicje aż do vertex[3] tak samo
// Wypełnianie bufora
vertexbuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), vertex.Length, device, Usage.Dynamic, CustomVertex.PositionTextured.Format, Pool.Default); //tego też nie rozumiem
vertexbuffer.SetData(vertex, 0, LockFlags.None); // nie rozumiem do czego i jak działa LockFlags
}
private void SetLight(float time)
{
// Tego już w ogóle nie mogę zrozumieć
device.Lights[0].Enabled = true;
device.Lights[0].Type = LightType.Point;
device.Lights[0].Range = 1.5f;
device.Lights[0].Ambient = Color.Red;
device.Lights[0].Attenuation1 = 3f;
device.Lights[0].Position = new Vector3(
1f, (float)Math.Sin(time / 2000f), (float)Math.Cos(time / 2000f));
device.Lights[1].Enabled = true;
device.Lights[1].Type = LightType.Point;
device.Lights[1].Range = 1.5f;
device.Lights[1].Ambient = Color.Green;
device.Lights[1].Attenuation1 = 3f;
device.Lights[1].Position = new Vector3(
(float)Math.Sin(time / 1000f), 1f, (float)Math.Cos(time / 1000f));
device.Lights[2].Enabled = true;
device.Lights[2].Type = LightType.Point;
device.Lights[2].Range = 1.5f;
device.Lights[2].Ambient = Color.Blue;
device.Lights[2].Attenuation1 = 3f;
device.Lights[2].Position = new Vector3(
(float)Math.Sin(time / 3000f), (float)Math.Cos(time / 3000f), 1f);
}
/// <summary>
/// Wykonanie renderowania
/// </summary>
/// <param name="time">Czas działania aplikacji</param>
public void Render(float time)
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
material = new Material();
material.Ambient = Color.White;
device.Material = material;
device.BeginScene();
SetLight(time);
device.RenderState.CullMode = Cull.None;
//Miejsce na implementację renderowania konkretnych elementów sceny
// Odtąd
device.SetTexture(0, texture);
device.VertexFormat = CustomVertex.PositionTextured.Format;
device.SetStreamSource(0, vertexbuffer, 0);
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
device.VertexFormat = CustomVertex.PositionColored.Format;
device.DrawUserPrimitives(PrimitiveType.LineList, 3, vertex_axis);
device.SetTexture(0, null);
//
device.Transform.View = Matrix.LookAtLH(
new Vector3((float)Math.Cos(time / 1000f) * 5f, 1f, (float)Math.Sin(time / 1000f) * 5f),
new Vector3(0f, 0f, 0f),
new Vector3(0f, 1f, 0f));
device.Transform.Projection = Matrix.PerspectiveFovLH(
(float)Math.PI / 4f,
parent.Width / parent.Height,
1f,
100f);
device.Transform.World = Matrix.Translation(0f, 1f, 0f) * Matrix.RotationX((float)Math.PI);
//Dotąd nie mogę skapować w jaki sposób to działa
device.EndScene();
device.Present();
}
}
}
Pozdrawiam