   L-System Drawing
  Hey Gamedev folks,I have bee trying ti build a basic L-System program.I have the string building working but i was wondering ifanyone here has got the drawing working with it because mydrawing algorithm goes wacky.Has anyone got a decent algorithm or OpenGL code to draw these things?I will keep trying but it is doing my head in because i haven't workedwith drawing code for over a year =-[Edited by - Deftoned on June 17, 2009 12:49:39 AM]
  You would need to describe what kind of data you have at hand to draw. I am not that familiar with L-systems.   ;  Well for example i have the string-F--F--FF "move forward"- "rotate Pi/3"so assuming the first direction is straight up we loop through the string and use a switch case to decide what to doIn the end we end up with a Triangle. But they get more advanced when you get to things likeF-[[X]+X]+F[+FX]-XF "Move Forward"- "-25 degrees"+ "+25 degrees"[ "Push current state on stack:] "Pop state from stack"This is just the first iteration, the strings become a lot longer then you start substitution letters ie. (X → F-[[X]+X]+F[+FX]-X), (F → FF)So second iteration would beFF-[[F-[[X]+X]+F[+FX]-X]+F-[[X]+X]+F[+FX]-X]+FF[+FFF-[[X]+X]+F[+FX]-X]-XAs you can see these strings get larger and larger, and it builds a fractal.For more info on the exciting world of L-Systems visit http://en.wikipedia.org/wiki/L-system   ;  A dynamic drawing approach would then be too slow. For a start you should just parse a line of this L-System and create a line list from the instructions. So start with a point (0, 0, 0). Then create a vector along the initial direction with the default stepping length. Upon rotation just rotate this vector and insert another point to your list by adding this vector to the last point. Upon moving forward just add the current vector to the last point in the list.Vec3d dir(0, 0, 1); // default directionvector<Vec3d> points;points.push_back(Vec3d(0,0,0)); // start positionfor (all entries of L-System){   switch (L-System command)   { case FORWARD: {    points.push_back(points.back() + dir);    break; } case ROTATION: {    dir = Rotate(dir, angle);    break; }   }}This creates you a linestrip you can render as LINE_STRIP primitive. I think you get the idea from that and come up with the details about how to create static render data from this list or how to create other primitives such as a LINE_LIST if you need those.   ;  Thank you for your help. Works now.