예제 #1
0
        public void RunSimulation()
        {
            CollisionSystem collision = new CollisionSystemSAP();
            JitterWorld     world     = new JitterWorld(collision);

            world.Gravity = new JVector(0, -10, -0);

            Shape     shape = new BoxShape(20.0f, 1.0f, 20.0f);
            RigidBody floor = new RigidBody(shape);

            floor.IsStatic = true;
            floor.Position = new JVector(0.0f, -15.0f, 0.0f);

            shape = new SphereShape(0.5f);
            RigidBody body = new RigidBody(shape);

            body.Position             = new JVector(0.0f, 3.0f, 0.0f);
            body.Material.Restitution = 0.8f;

            world.AddBody(floor);
            world.AddBody(body);

            for (int i = 0; i < 600; i++)
            {
                world.Step(1.0f / 30.0f, true);

                SunflowAPI sunflow = new SunflowAPI();
                SetupSunflow(sunflow);

                sunflow.geometry("sphere", "sphere");

                //Instancing the big metal sphere.
                JVector v = body.Position;
                sunflow.parameter("transform", Matrix4.translation(v.X, v.Y, v.Z).multiply(Matrix4.scale(1)));
                sunflow.parameter("shaders", "metal");
                sunflow.instance("sphere.instance", "sphere");


                sunflow.render(SunflowAPI.DEFAULT_OPTIONS, new FileDisplay("spherecube" + i + ".png"));


                // do other stuff, like drawing
            }
        }
예제 #2
0
    public void Run(string[] args)
    {
        // Use this for initialization

        LParser lparser = new LParser();

        System.String[] rules = new System.String[9];

/*
 *              rules[0] = "#define a 1";
 *              rules[1] = "#thickness 0.2";
 *              rules[2] = "#recursion 4";
 *              rules[3] = "#angle 22.5";
 *              rules[4] = @"#axiom ++++F";
 *
 * //		rules[5] = "X -> F-[[X]+X]+F[+FX]-X";
 *              rules[5] = @"F -> FF-[-F+F+F]+[+F-F-F]";
 *              rules[5] = @"F -> FF&[&F^F^F]^[^F&F&F]";
 *              rules[6] = @"Y -> F-F";
 *
 */
        rules[0] = "#define p 3.14";
        rules[1] = "#thickness 0.2";
        rules[2] = "#recursion 3";
        rules[3] = "#angle 90";
        rules[4] = "#axiom A";
        rules[5] = "A -> B-F+CFC+F-D&F^D-F+&&CFC+F+B//";
        rules[6] = "B -> A&F^CFB^F^D^^-F-D^|F^B|FC^F^A//";
        rules[7] = "C -> |D^|F^B-F+C^F^A&&FA&F^C+F+B^F^D//";
        rules[8] = "D -> |CFB-F+B|FA&F^A&&FB-F+B|FC//";



        bool statusOK = lparser.ParseStringArray(rules);

        _ruleList = lparser.RunLSystem();

        Console.WriteLine("RULES: " + Rules.RuleListToString(_ruleList, lparser.GlobalParameters));

        Parameters currentParameters = new Parameters();

        SunflowAPI sunflow = new SunflowAPI();

        //		SetupSunflow(sunflow);

        SetupSunflow(sunflow);

        currentParameters.roll          = new Vector3(1.0f, 0.0f, 0.0f);
        currentParameters.pitch         = new Vector3(0.0f, 1.0f, 0.0f);
        currentParameters.yaw           = new Vector3(0.0f, 0.0f, 1.0f);
        currentParameters.position      = new Point3(0.0f, 0.0f, 0.0f);
        currentParameters.primitiveType = "box";
        currentParameters.length        = 2.0f;
        currentParameters.angle         = (float)lparser.Angle;
        currentParameters.thickness     = (float)lparser.Thickness;
        currentParameters.localRotation = new Point3(0.0f, 0.0f, 0.0f);
        currentParameters.localScale    = new Vector3(1.0f, currentParameters.thickness, currentParameters.thickness);

        currentParameters.objectCount = 0;
        sunflow.geometry(currentParameters.primitiveType + currentParameters.objectCount++, currentParameters.primitiveType);



        //	Vector3 scale = new Vector3(currentParameters.length1f, currentParameters.thickness , currentParameters.thickness);



        currentParameters.objectCount = interpretProduction(currentParameters, _ruleList, lparser, sunflow);

        sunflow.render(SunflowAPI.DEFAULT_OPTIONS, new FileDisplay("lsystem.png"));


        return;
    }