Bonjour,


Voilà, j'essaie de générer un arbre 3D avec L-System, mais j'obtiens des formes bizarres et je n'arrive pas à mettre le doigt sur le problème. De plus, pour je ne sais quelle raison l'arbre (enfin le pseudo arbre) n'est pas droit sur l'axe des Y ...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 
using System;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
 
namespace Lsys
{
	public class draw_sys
	{
		private Quaterniond rotationQuat;
		private Vector3d position;
		private Vector3d forwardVector;
		private Vector3d upvector;
		private Vector3d rightVector;
		public List<Vector3d> vertices = new List<Vector3d>();
		public List<Vector3d> vertices2 = new List<Vector3d>();
//		float x = 0.1f;
//		float y = 0.01f;
 
		public draw_sys ()
		{
			rotationQuat = Quaterniond.Identity;
			forwardVector = new Vector3d(0.1, 0, 0);
			upvector = new Vector3d (0, 0.1, 0);
			rightVector = new Vector3d (0.01, 0, 0);//Vector3d.Cross (upvector, forwardVector);
		}
 
		public void forward(double distance, bool draw){
			Vector3d moveVector = Vector3d.Transform (forwardVector * distance, rotationQuat);
			Vector3d oldPosition = position;
			position += moveVector;
 
			if (draw) {
				vertices.Add (oldPosition);
				vertices.Add (-position);
				vertices.Add (oldPosition);
				vertices.Add (-position);
//				vertices.Add (new Vector3d (-oldPosition.Y, -oldPosition.X, 0));
//				vertices.Add (new Vector3d (-position.Y, position.X, 0));
//				vertices.Add (new Vector3d (oldPosition.Y, -oldPosition.X, 0));
//				vertices.Add (new Vector3d (position.Y, position.X, 0));
 
			} else {
				vertices2.Add (oldPosition);
				vertices2.Add (-position);
				vertices2.Add (oldPosition);
				vertices2.Add (-position);
//
//				vertices2.Add (new Vector3d (-oldPosition.X, -oldPosition.Y, oldPosition.Z));
//				vertices2.Add (new Vector3d (-position.X, position.Y, position.Z));
//				vertices2.Add (new Vector3d (oldPosition.X, -oldPosition.Y, oldPosition.Z));
//				vertices2.Add (new Vector3d (position.X, position.Y, position.Z));
			}
			//					vertices.Add (new Vector3 (-x, -y, 0.0f));//-oldPosition.X, -oldPosition.Y, oldPosition.Z));
			//					vertices.Add (new Vector3 (-x, y, 0.0f));
			//					vertices.Add (new Vector3 (x, -y, 0.0f));
			//					vertices.Add (new Vector3 (x, y, 0.0f));
			//					x += 0.1f; y += 0.2f;
		}
 
		public void Yaw(double angle){
			rotationQuat *= new Quaterniond (upvector, angle);
		}
 
		public void Pitch(double angle){
			rotationQuat *= new Quaterniond (rightVector, angle);
		}
 
		public void Roll(double angle){
			rotationQuat *= new Quaterniond (forwardVector, angle);
		}
 
		public List<Vector3d>draw_please(string lsys){
			string start = "F";
			string[] tmp = new string[10];
			tmp [0] = lsys;
			for(int n = 0; n < 3; n++)
				start = start.Replace ("F", tmp[0]);
			for (int i = 0; i < start.Length; i++) {
 
				if (start [i] == 'F') {
					forward (0.2, true);
				}
				if (start [i] == '+')
					Yaw (90);
				if (start [i] == '-')
					Yaw (-90);
				if (start [i] == '[') {
					Roll (-5);
					forward (0.2f, false);
				}
				if (start [i] == ']') {
					Pitch (5);
					for (int j = 0; j < vertices2.Count; j++) {
						vertices.Add (vertices2.ElementAt (j));
					}
					vertices2.Clear ();
				}
			}
			return vertices;
		}
	}
}


Je vous remercie d'avance pour votre aide.


EDIT : voici le résultat donné (désolé l'image est un peu grande):
Nom : Lsystem-3d.png
Affichages : 167
Taille : 216,7 Ko