1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
public void DessinerMesh3D2()
{
Mesh meme = Mesh.Box(this.dev, 1f * this.IndiceDeZoom, 1f * this.IndiceDeZoom, 1f * this.IndiceDeZoom);// on crée un mesh qui correspondra a une shere
Material mat = new Material();// on crée un matérial qui correspondra à ce qui va recouvrir la sphère
Graphe monGraphe = env.getGraphe();
//dessin de points
for (int i = 0; i < monGraphe.size(); i++)
{
GNode n = monGraphe.getNode(i);
this.dev.Transform.World = Matrix.Multiply(Matrix.Translation((float)(n.getX() * this.IndiceDeZoom), (float)(0 + this.y), (float)(n.getY() * this.IndiceDeZoom + this.z)), Matrix.RotationY(this.AngleX));
mat.Ambient = Color.Beige; //on affecte au material qui va recouviri la sphere la couleur de la boules concernée
mat.Diffuse = Color.Beige;// pareil pour la couleur diffuse
this.dev.Material = mat;
meme.DrawSubset(0);//on indique que l'on dessine le mesh voir le tutorial 6 du SDK pour de plus ample indication sur l'index
}
}
public void Render()
{
// On commence par tout vider et mettre du bleu en fond.
this.dev.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
this.dev.BeginScene();
this.dev.SetStreamSource(0, this.vbuf, 0);
this.dev.VertexFormat = CustomVertex.PositionColored.Format;
// On créé une matrice pour le 1er triangle,
// et on applique la transformation à cette matrice.
Matrix matrixRotationX = Matrix.Identity;
matrixRotationX = Matrix.RotationX(this.AngleY);
Matrix matrixRotationY = Matrix.Identity;
matrixRotationY = Matrix.RotationY(this.AngleX);
Matrix matrixRotation = Matrix.Identity;
matrixRotation = Matrix.Multiply(matrixRotationX, matrixRotationY);
Matrix matrixTranslation = Matrix.Identity;
matrixTranslation = Matrix.Translation(new Vector3(this.X * this.IndiceDeZoom, this.Y * this.IndiceDeZoom, this.Z * this.IndiceDeZoom));
// On dessine le triangle 1 qui commence au vertexe 0.
//this.dev.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
//this.dev.DrawPrimitives(PrimitiveType.TriangleList, 3, 1);
this.dev.DrawPrimitives(PrimitiveType.LineList, 7, 3);
//this.dev.DrawPrimitives(PrimitiveType.LineStrip, 13, 2);
// On applique la matrice de rotation à notre monde.
this.dev.Transform.World = Matrix.Multiply(matrixTranslation, matrixRotation);
DessinerMesh3D();
AjustementVue();
this.dev.EndScene(); // Fin de la définition
this.dev.Present(); // Lancer l'affichage
}
public void AjustementVue()
{
// On précise comment est-ce que la caméra (la matrice View) regarde la scène :
this.dev.Transform.View = Matrix.LookAtLH(
new Vector3(0f, 0f, -4f), // position de la caméra.
new Vector3(0f, 0f, 0f), // la direction du regard (l'origine où est centré le rectangle).
new Vector3(0f, 1f, 0f)); // le vecteur directeur du regard (en face de soi)
// Enfin, on applique une perspective à tout ca pour avoir notre rendu 2D :
this.dev.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0F, 1.0F, 1000.0F);
} |
Partager