Package eas.users.demos.helloWorld3D

Source Code of eas.users.demos.helloWorld3D.Scheduler3D

/*
* File name:        DemoScheduler1.java (package eas.simulation.users.students.fabianRigoll.sim3D.physicalSimulation.Demo1)
* Author(s):        Lukas König
* Java version:     6.0
* Generation date:  17.05.2011
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
*   author or licensor (but not in any way that suggests that they endorse
*   you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
*   distribute the resulting work only under the same or a similar license to
*   this one.
*
* + Detailed license conditions (Germany):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/

package eas.users.demos.helloWorld3D;

import java.util.Random;

import javax.vecmath.Vector3f;

import com.bulletphysics.collision.shapes.BoxShape;
import com.bulletphysics.collision.shapes.CollisionShape;
import com.bulletphysics.collision.shapes.SphereShape;

import eas.plugins.PluginProperties;
import eas.plugins.masterScheduler.AbstractDefaultMaster;
import eas.simulation.ConstantsSimulation;
import eas.simulation.Wink;
import eas.startSetup.ParCollection;

/**
* @author Lukas König
*
*/
@PluginProperties(pluginIsHidden = true)
public class Scheduler3D extends AbstractDefaultMaster<Env3D> {

    /**
     *
     */
    private static final long serialVersionUID = -1226350930987546385L;

    @Override
    public Env3D[] generateRunnables(ParCollection params) {

        Env3D env = new Env3D(0, params);

        CollisionShape box2 = new BoxShape(new Vector3f(100f, 10f, 100f));
        env.getCollisionShapes().add(box2);
        CollisionShape box3 = new BoxShape(new Vector3f(30f, 30f, 5f));
        env.getCollisionShapes().add(box2);
        CollisionShape box4 = new BoxShape(new Vector3f(30f, 30f, 5f));
        env.getCollisionShapes().add(box2);
        CollisionShape box5 = new BoxShape(new Vector3f(5f, 30f, 30f));
        env.getCollisionShapes().add(box2);
        CollisionShape box6 = new BoxShape(new Vector3f(5f, 30f, 30f));
        env.getCollisionShapes().add(box2);
        env.addAgent(new Agent3D(0, env, box2, new Vector3f(0f, -51f, 0f), 0f));
        env.addAgent(new Agent3D(1, env, box3, new Vector3f(0f, 0f, 45f), 0f));
        env.addAgent(new Agent3D(2, env, box4, new Vector3f(0f, 0f, -45f), 0f));
        env.addAgent(new Agent3D(3, env, box5, new Vector3f(45f, 0f, 0f), 0f));
        env.addAgent(new Agent3D(4, env, box6, new Vector3f(-45f, 0f, 0f), 0f));

        return new Env3D[] { env };
    }

    @Override
    public String id() {
        return ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-lukes3Dtest";
    }
   
    private int i = 10;
    private int j = 10;
    private Random rand = new Random();
   
    @Override
    public synchronized void runDuringSimulation(Env3D env, Wink simZyk,
            ParCollection params) {
        super.runDuringSimulation(env, simZyk, params);
       
        // Add dynamic agents (mass != 0).
        if (rand.nextDouble() < 1 && i < 1000) {
            float kantenLaenge = 1 + ((float) (i)) / 50 + (float) rand.nextGaussian();
            CollisionShape box1;
            if (rand.nextDouble() < 0.9) {
                box1 = new BoxShape(new Vector3f(kantenLaenge, kantenLaenge, kantenLaenge));
            } else {
                box1 = new SphereShape(kantenLaenge);
            }
            env.getCollisionShapes().add(box1);
            env.addAgent(new Agent3D(
                    i,
                    env,
                    box1,
                    new Vector3f(
                            0f,
                            30 * i,
                            0f),
                    (float) Math.pow(kantenLaenge, 3)));
            i++;
        }
       
        if (rand.nextDouble() < 0.1 && simZyk.getLastTick() > 1000 && j < i) {
            env.removeAgent(j);
        }
    }
}
TOP

Related Classes of eas.users.demos.helloWorld3D.Scheduler3D

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.