Commit dac78b62 authored by Tibaos's avatar Tibaos
Browse files

Verfahren und Prefab für Pflanzen geändert, 2D nun möglich

parent 42b09321
fileFormatVersion: 2
guid: 2506237d355edc44cb2906477f3f9d23
folderAsset: yes
timeCreated: 1490801944
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e2916fefd7ae49c41bb3364ff29af11c
timeCreated: 1490801956
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -16,6 +16,7 @@ public class InputSystem : MonoBehaviour {
if(Input.GetMouseButtonDown(0))
{
generator.makeSentence();
generator.makeTree();
}
}
}
......@@ -8,13 +8,25 @@ public class LSystemGenerator : MonoBehaviour {
Rule m_testTree = new Rule();
public int m_maxGeneration;
//Turtle
public GameObject turtle;
Transform turtleTrans;
//Objects
public GameObject cylinder;
//generations modifikator
float len = 1;
float scale = 1;
// Use this for initialization
void Start () {
m_testTree.setAxiom('A');
m_testTree.setAxiom('F');
Dictionary<char, string> temp_rules = new Dictionary<char, string>();
temp_rules.Add('A', "AB");
temp_rules.Add('B', "A");
temp_rules.Add('F', "FF+[+F-F-F]-[-F+F+F]");
m_testTree.setDictionary(temp_rules);
turtleTrans = turtle.GetComponent<Transform>();
}
// Update is called once per frame
......@@ -47,12 +59,68 @@ public class LSystemGenerator : MonoBehaviour {
m_sentence = next_Sentence;
}
}
public void makeTree()
{
Vector3 start = new Vector3(0, 0, 0);
float rot = 0f;
float len = 0.5f;
public void makeTree()
Vector3[] startSave = new Vector3[10];
float[] rotSave = new float[10];
float[] lenSave = new float[10];
int saveCounter = 0;
Vector3 xAxis = new Vector3(1, 0, 0);
Vector3 zAxis = new Vector3(0, 0, 1);
for(int i = 0; i < m_sentence.Length; i++)
{
}
char current = m_sentence[i];
if (current == 'F')
{
GameObject treePart = Instantiate(cylinder);
Transform treeTrans = treePart.GetComponent<Transform>();
treeTrans.RotateAround(start, xAxis, rot);
treeTrans.localScale = new Vector3(len, len, len);
treeTrans.position = start;
turtleTrans.position = start;
turtleTrans.rotation = Quaternion.Euler(new Vector3(rot, 0, 0));
turtleTrans.Translate(new Vector3(0, len, 0));
start = turtleTrans.position;
Debug.Log(m_sentence);
len *= 0.95f;
}
else if (current == '+')
{
rot += 30;
}
else if (current == '-')
{
rot -= 30;
}
else if (current == '[')
{
startSave[saveCounter] = start;
rotSave[saveCounter] = rot;
lenSave[saveCounter] = len;
saveCounter++;
}
else if (current == ']')
{
saveCounter--;
start = startSave[saveCounter];
rot = rotSave[saveCounter];
len = lenSave[saveCounter];
}
}
}
}
......@@ -10,14 +10,7 @@ public class Rule{
public char getAxiom()
{
if (m_axiom != null)
{
return m_axiom;
}
else
{
return 'A';
}
return m_axiom;
}
public void setAxiom(char p_axiom)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment