Package eas.users.demos.physics2DA

Source Code of eas.users.demos.physics2DA.PhysicsMaster

/*
* Datei:        PhysicsMaster.java
* Autor(en):    Lukas König
* Java-Version: 6.0
* Erstellt:     ??.07.2010
*
* (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.physics2DA;

import java.util.List;

import eas.math.geometry.Vector2D;
import eas.plugins.PluginProperties;
import eas.plugins.masterScheduler.AbstractDefaultMaster;
import eas.simulation.Wink;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.BruteCollisionStrategy;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.ForceSource;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.Vector2f;
import eas.simulation.spatial.sim2D.physicalSimulation.standardAgents.PhysicalObstacle;
import eas.simulation.spatial.sim2D.physicalSimulation.standardAgents.PhysicsAgent2D;
import eas.simulation.spatial.sim2D.physicalSimulation.standardAgents.PhysicsAgentCircle;
import eas.simulation.spatial.sim2D.physicalSimulation.standardAgents.StaticBody;
import eas.simulation.spatial.sim2D.physicalSimulation.standardEnvironments.PhysicsEnvironment2D;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;

/**
* @author Lukas König
*
*/
@PluginProperties(pluginIsHidden = false)
public class PhysicsMaster extends AbstractDefaultMaster<PhysicsEnvironment2D<PhysicsAgent2D<?>>> {

    /**
     *
     */
    private static final long serialVersionUID = 6432638200757692132L;

    @SuppressWarnings("unchecked")
    @Override
    public PhysicsEnvironment2D<PhysicsAgent2D<?>>[] generateRunnables(ParCollection params) {
        PhysicsEnvironment2D<PhysicsAgent2D<?>>[] envs = new PhysicsEnvironment2D[1];
        PhysicsEnvironment2D<PhysicsAgent2D<?>> env = new PhysicsEnvironment2D<PhysicsAgent2D<?>>(
                "Physics-Environment",
                0,
                null,
                params,
                new Vector2f(0, 50),
                500,
                new BruteCollisionStrategy());
       
        envs[0] = env;
        env.addAgent(new PhysicalObstacle(0, env, params, 10), new Vector2D(13, -150), 26);
        env.addCollidingAgent(new PhysicalObstacle(1, env, params, 10), new Vector2D(55, -100), 45);
        env.addCollidingAgent(new PhysicalObstacle(2, env, params, 10), new Vector2D(51, -70), 77);
        env.addCollidingAgent(new PhysicalObstacle(6, env, params, 10), new Vector2D(0, -50), 73);
        env.addCollidingAgent(new PhysicalObstacle(7, env, params, 10), new Vector2D(140, -50), 0);
        env.addCollidingAgent(new PhysicalObstacle(8, env, params, 10), new Vector2D(140, -150), 0);
        env.addCollidingAgent(new StaticBody(3, env, params), new Vector2D(-10, -50), 0);
        env.addCollidingAgent(new StaticBody(13, env, params), new Vector2D(-85, -30), 90);
        env.addCollidingAgent(new StaticBody(4, env, params), new Vector2D(16, 0), 4);
        env.addCollidingAgent(new StaticBody(5, env, params), new Vector2D(175, 20), 7);
        env.addCollidingAgent(new StaticBody(10, env, params), new Vector2D(275, 99), -16);
        env.addCollidingAgent(new PhysicsAgent2(9, env, 5, params), new Vector2D(155, -80), 95);
        env.addCollidingAgent(new PhysicsAgent2(11, env, 5, params), new Vector2D(275, 0), 47);
        env.addAgent(new PhysicsAgentCircle(12, env, 70, params), new Vector2D(-84, -120), 7);
        env.addCollidingAgent(new StaticBody(15, env, params), new Vector2D(135, 199), -6);
        env.addCollidingAgent(new StaticBody(16, env, params), new Vector2D(75, 266), 5);
//        env.addCollidingAgent(new StaticBody(17, env), new Vector2D(350, 200), -3);
        env.addCollidingAgent(new StaticBody(18, env, params), new Vector2D(248, 190), 25);
       
        return envs;
    }

    @Override
    public String id() {
        return eas.simulation.ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-physics";
    }

    ForceSource<PhysicsAgent2D<?>> f = new ForceSource<PhysicsAgent2D<?>>() {
        private static final long serialVersionUID = 7704974706762245272L;

        @Override
        public void apply(PhysicsAgent2D<?> body, float dt) {
            if (body.id() == 12) {
                body.adjustVelocity(new Vector2f(1.1f, 0));
            }
        }
    };
   
    @Override
    public void runDuringSimulation(
            PhysicsEnvironment2D<PhysicsAgent2D<?>> umg,
            Wink simZyk,
            ParCollection params) {
        super.runDuringSimulation(umg, simZyk, params);
        if (simZyk.getLastTick() == 500) {
            umg.remove(f);
        }
        if (simZyk.getLastTick() == 425) {
            umg.add(f);
        }
    }

    @Override
    public List<SingleParameter> getParameters() {
        List<SingleParameter> list = super.getParameters();
        return list;
    }
}
TOP

Related Classes of eas.users.demos.physics2DA.PhysicsMaster

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.