Package eas.users.students.fabian.cloth

Source Code of eas.users.students.fabian.cloth.ClothEnv

/*
* File name:        ClothEnv.java (package eas.users.fabian.cloth)
* Author(s):        Fabian
* Java version:     6.0
* Generation date:  15.02.2012 (16:31:21)
*
* (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.students.fabian.cloth;

import org.lwjgl.input.Keyboard;
import org.ode4j.ode.DBody;
import org.ode4j.ode.DGeom;
import org.ode4j.ode.DMass;
import org.ode4j.ode.OdeHelper;

import eas.simulation.spatial.sim3D.physicalSimulation.standardAgents.AbstractAgentODE3D;
import eas.simulation.spatial.sim3D.physicalSimulation.standardEnvironments.AbstractEnvironmentODE3D;
import eas.startSetup.ParCollection;

/**
* @author Fabian
*
*/
public class ClothEnv extends AbstractEnvironmentODE3D<AbstractAgentODE3D<?>> {

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

    public ClothEnv(int id, ParCollection params) {
    super(id, params);
    DBody blockbody = OdeHelper.createBody(getWorld());
    DGeom blockgeom = OdeHelper.createSphere(1);
    DMass blockmass = OdeHelper.createMass();
    blockbody.setPosition(0, 0, 1.1);
    blockmass.setSphere(1, 1);
    blockgeom.setBody(blockbody);
    blockbody.setMass(blockmass);
    getSpace().add(blockgeom);
   
  }
 
  @Override
  public void handleKeyboard(char key) {
        final double MAXSTEER = 20;
    final double MAXTURN = 1;
    final double MAXTHRUST = 1000;
    final double BOTTOM = -1.5;
    final double SIDE = .5;
    super.handleKeyboard(key);
   
    if (key == Keyboard.KEY_UP) {
      getAgent(0).getBody(250).addForce(0, 0, 0.01);
    }

    else if (key == Keyboard.KEY_DOWN) {
      getAgent(0).getBody(0).addRelForceAtRelPos(0, 0, MAXSTEER, -SIDE, 0, BOTTOM);
    }

    else if (key == Keyboard.KEY_RIGHT) {
      getAgent(0).getBody(0).addRelForceAtRelPos(0, 0, MAXSTEER, 0, SIDE, BOTTOM);
    }

    else if (key == Keyboard.KEY_LEFT) {
      getAgent(0).getBody(0).addRelForceAtRelPos(0, 0, MAXSTEER, 0, -SIDE, BOTTOM);
    }

    else if (key == Keyboard.KEY_SPACE) {
      getAgent(0).getBody(0).addRelForceAtRelPos(0, 0, MAXTHRUST, 0, 0, BOTTOM);
    }
    else if (key == Keyboard.KEY_D) {
      getAgent(0).getBody(0).addRelForceAtRelPos(MAXTURN, 0, 0, 0, -SIDE, BOTTOM);
      getAgent(0).getBody(0).addRelForceAtRelPos(-MAXTURN, 0, 0, 0, +SIDE, BOTTOM);
    }
    else if (key == Keyboard.KEY_A) {
      getAgent(0).getBody(0).addRelForceAtRelPos(-MAXTURN, 0, 0, 0, -SIDE, BOTTOM);
      getAgent(0).getBody(0).addRelForceAtRelPos(MAXTURN, 0, 0, 0, +SIDE, BOTTOM);
    }
  }
 
}
TOP

Related Classes of eas.users.students.fabian.cloth.ClothEnv

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.