Jump to content
  • Advertisement
Sign in to follow this  
Svalorzen

Procedural drawing language

This topic is 2335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody, I'm here to ask help for solving a problem of mine, because I've been stuck for quite a while and I don't know how to proceed to solve it.

I'm premitting that this is not for a game, rather, for a ( possible ) part of a game. A proof of concept for a mechanic. I'm also not sure if this is the appropriate forum, if it's not I'll move the question where you think it belongs.
Now, onto my actual problem.

I have some runes I want to draw on a 2d plane. They are structurally arranged as a tree.

More specifically, the user creates a finite number of rune classes, which have a finite number of children which are rune classes themselves. The program I'm making then instantiates a rune tree "instance" by having the user answer some questions ( that the user pre-defined ). This program instantiates a rune, then its children, and so on until there's nothing more to do.

The thing that I want to do is to give the user the ability to specify how they want to draw an instantiated rune tree, how it should look, where each rune should be positioned and how the connections between the runes are drawn based on those answers. The user should be able to write, for each rune class, some kind of "program" that would then procedurally draw the rune itself plus its children when instantiated, be it by using pre-existing images or drawing lines, dots, whatever. The more freedom is given to the user to draw anything they want, the more I'm happy.

I have absolutely no experience in doing something like this, and after a ton of work, in which I've made some observations about absolute/relative coordinates on the screen based on previous/existing runes plus some other things, I realized that I had no method and that I was going nowhere. I've been revising the things I did over and over and I was not going anywhere.

If you know something I could read to help me out or you have an idea yourself let me know! Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Sounds like you want a scripting engine. I've heard Lua is very popular. The first result from a google search for "C++ incorporate Lua" returns this, which looks pretty straightforward.

Share this post


Link to post
Share on other sites

Sounds like you want a scripting engine. I've heard Lua is very popular. The first result from a google search for "C++ incorporate Lua" returns this, which looks pretty straightforward.


Lua is one of my options, however my problem is mostly teorical at the moment. I've really no idea of what functions I should provide to the user. As in, what ( abstract ) graphical functions are necessary to be able to draw procedural "shapes"? I could simply give access to standard 2d library functions, but I think it would be pretty difficult for an average/semi-expert user to draw arbitrary shapes, and programs made in this way would be pretty long.

Should I just do this or are there some "shortcuts" or at least more complex functions I can implement myself and then give to the user already done?

Share this post


Link to post
Share on other sites
For inspiration, you could look at these blog posts at Procedural World:

http://procworld.blogspot.com/2012/03/building-rooms.html
http://procworld.blogspot.ca/2012/04/room-with-angle.html

Granted, they deal with procedural construction of geometry, but the idea is the same. The author of that blog constructed for himself a grammar, or language, to describe the generation of architecture.

The idea of it is pretty simple. You have a number of primitives, or commands, that describe certain aspects of the rune tree or structure. Some commands actually generate a primitive, some deal with positioning and orientation, etc...

For example, say you have the basic primitive line. The line extends from the current position to the position (current.x+1, current.y). Now, the line can also have a pair of modifiers: scale and spin. Scale, of course, scales the length of the line segment, and spin will rotate it around its origin point. This, then, suggests a very simple grammar for drawing connected sequences of lines:


line { spin 30, scale 1}
line { spin 10, scale 3}


The evaluation of such a grammar would require storing some state (the current position) and stepping through the "program" described by the grammar. In the above, you start at (0,0) and call line() with spin=30, scale=1. line() will calculate the requisite end-point, draw a line between the current and endpoint, then set current=endpoint before returning. The next call to line() will use the previous endpoint to draw another line relative to the first. And so forth.

Grammars can get pretty complex, but their expression in a language such as Lua is relatively straightforward.

Share this post


Link to post
Share on other sites

I could simply give access to standard 2d library functions, but I think it would be pretty difficult for an average/semi-expert user to draw arbitrary shapes, and programs made in this way would be pretty long.

Should I just do this or are there some "shortcuts" or at least more complex functions I can implement myself and then give to the user already done?

You do both.
Create a set of low-level building blocks and then use those to make higher-level easier-to-use functions.
Expose both to users.


L. Spiro

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!