Commit 664b5dd7 authored by Tibaos's avatar Tibaos
Browse files

3D und licht empflindlichkeit drin

parent dac78b62
fileFormatVersion: 2
guid: 9cbb7c28d4b89b74bbfc621c38067da3
timeCreated: 1490883547
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,6 +5,7 @@ using UnityEngine;
public class InputSystem : MonoBehaviour {
public LSystemGenerator generator;
public Camera cam;
// Use this for initialization
void Start () {
......@@ -15,8 +16,9 @@ public class InputSystem : MonoBehaviour {
void Update () {
if(Input.GetMouseButtonDown(0))
{
Vector3 mousepos = cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10));
generator.makeSentence();
generator.makeTree();
generator.makeTree(0.0f, 0.0f);
}
}
}
......@@ -14,17 +14,20 @@ public class LSystemGenerator : MonoBehaviour {
Transform turtleTrans;
//Objects
public GameObject cylinder;
public GameObject cylinder1;
//sun
public Collider sun;
//generations modifikator
float len = 1;
float scale = 1;
public float len;
public float lengthMultSun;
public float lengthMultNoSun;
public float angle;
// Use this for initialization
void Start () {
m_testTree.setAxiom('F');
Dictionary<char, string> temp_rules = new Dictionary<char, string>();
temp_rules.Add('F', "FF+[+F-F-F]-[-F+F+F]");
m_testTree.setDictionary(temp_rules);
initiateRules();
turtleTrans = turtle.GetComponent<Transform>();
}
......@@ -36,7 +39,7 @@ public class LSystemGenerator : MonoBehaviour {
public void makeSentence()
{
m_sentence = "" + m_testTree.getAxiom();
m_sentence = m_testTree.getAxiom();
string next_Sentence = "";
string temp;
......@@ -61,52 +64,90 @@ public class LSystemGenerator : MonoBehaviour {
}
}
public void makeTree()
public void makeTree(float x, float z)
{
Vector3 start = new Vector3(0, 0, 0);
float rot = 0f;
float len = 0.5f;
Vector3 start = new Vector3(x, 0, z);
Vector3 rotations = new Vector3(0, 0, 0);
Vector3[] startSave = new Vector3[10];
float[] rotSave = new float[10];
Vector3[] rotationsSave = new Vector3[10];
float[] lenSave = new float[10];
int saveCounter = 0;
Vector3 xAxis = new Vector3(1, 0, 0);
Vector3 zAxis = new Vector3(0, 0, 1);
Vector3 yAxis = new Vector3(0, 1, 0);
for(int i = 0; i < m_sentence.Length; i++)
{
char current = m_sentence[i];
if (current == 'F')
if (current == 'F' || current == 'E')
{
GameObject treePart = Instantiate(cylinder);
GameObject treePart = null;
if (current == 'E')
treePart = Instantiate(cylinder);
if (current == 'F')
treePart = Instantiate(cylinder1);
Transform treeTrans = treePart.GetComponent<Transform>();
treeTrans.RotateAround(start, xAxis, rot);
treeTrans.localScale = new Vector3(len, len, len);
treeTrans.position = start;
treeTrans.rotation = Quaternion.Euler(rotations);
treeTrans.localScale = new Vector3(len, len, len);
turtleTrans.position = start;
turtleTrans.rotation = Quaternion.Euler(new Vector3(rot, 0, 0));
turtleTrans.rotation = Quaternion.Euler(rotations);
turtleTrans.Translate(new Vector3(0, len, 0));
start = turtleTrans.position;
len *= 0.95f;
RaycastHit hit;
Ray ray = new Ray();
ray.origin = Vector3.Scale(start, new Vector3(1.1f, 1.1f, 1.1f));
ray.direction = new Vector3(7, 10, -10);
if(Physics.Raycast(ray, out hit))
{
if (hit.collider != sun)
{
len *= lengthMultNoSun;
}
else
{
len *= lengthMultSun;
}
}
}
else if (current == '+')
{
rot += 30;
rotations[2] += angle;
}
else if (current == '-')
{
rot -= 30;
rotations[2] -= angle;
}
else if (current == '<')
{
rotations[0] += angle;
}
else if (current == '>')
{
rotations[0] -= angle;
}
else if(current == '&')
{
rotations[1] += angle;
}
else if(current == '%')
{
rotations[1] -= angle;
}
else if (current == '[')
{
startSave[saveCounter] = start;
rotSave[saveCounter] = rot;
rotationsSave[saveCounter] = rotations;
lenSave[saveCounter] = len;
saveCounter++;
......@@ -116,11 +157,27 @@ public class LSystemGenerator : MonoBehaviour {
saveCounter--;
start = startSave[saveCounter];
rot = rotSave[saveCounter];
rotations = rotationsSave[saveCounter];
len = lenSave[saveCounter];
}
else if(current == 'f')
{
turtleTrans.position = start;
turtleTrans.rotation = Quaternion.Euler(rotations);
turtleTrans.Translate(new Vector3(0, len, 0));
start = turtleTrans.position;
}
}
}
void initiateRules()
{
m_testTree.setAxiom("F");
Dictionary<char, string> temp_rules = new Dictionary<char, string>();
temp_rules.Add('F', "EE[%-F][%%%-F][%%%%%-F][%%%%%%-F][&-F][&&&-F][&&&&&-F]");
temp_rules.Add('E', "EE[%-F][%%%-F][%%%%%-F][%%%%%%-F][&-F][&&&-F][&&&&&-F]");
m_testTree.setDictionary(temp_rules);
}
}
......@@ -5,15 +5,15 @@ using UnityEngine;
public class Rule{
Dictionary<char, string> m_rules = new Dictionary<char, string>();
char m_axiom;
string m_axiom;
public char getAxiom()
public string getAxiom()
{
return m_axiom;
}
public void setAxiom(char p_axiom)
public void setAxiom(string p_axiom)
{
m_axiom = 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