⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pickcherriesdemo.java

📁 一款机器人仿真软件,功能上与microsoft robotics studio有些相似,但基于Java平台.突出特点是给出了传感器仿真,如声纳,激光等.
💻 JAVA
字号:
/* * Created on 31 mars 2005 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */package simbad.demo;import javax.vecmath.Color3f;import javax.vecmath.Vector3d;import javax.vecmath.Vector3f;import simbad.sim.Agent;import simbad.sim.CherryAgent;import simbad.sim.Box;import simbad.sim.SimpleAgent;/** * This demo show a robot picking cherries. When touched, the cherries are either removed or repaint. */public class PickCherriesDemo extends Demo {    /** The robot used in the demo.*/    public class Robot extends Agent {              Color3f yellow = new Color3f(0.9f,0.7f,0.1f);        public Robot(Vector3d position, String name) {            super(position, name);                 }        /** Initialize Agent's Behavior */        public void initBehavior() {            setTranslationalVelocity(0.5);        }              /** Perform one step of Agent's Behavior */        public void performBehavior() {            if (collisionDetected())                moveToStartPosition();            if ((getCounter() % 80) == 0) {                setRotationalVelocity(Math.PI / 2 * (0.5 - Math.random()));                setTranslationalVelocity(0.5);            }            // Test if there is an agent near . */            if (anOtherAgentIsVeryNear()){                SimpleAgent agent = getVeryNearAgent();                                if (agent instanceof CherryAgent){                    // detach it from te scene graph so it is no more visible.                    agent.detach();                    System.out.println("cherry picked !");                }                // or  change the color of the agent.                //   ((CherryAgent) agent).setColor(yellow);                            }        }    }    public  PickCherriesDemo() {        showAxis(false);        setWorldSize(12);        boxColor = new Color3f(0.6f,0.5f,.3f);        // add the four walls         add(new Box(new Vector3d(-5,0,0),new Vector3f(0.1f,1,10),this,new Color3f(.8f,0.2f,0.2f)));		add(new Box(new Vector3d(0,0,-5),new Vector3f(10,1,0.1f),this,new Color3f(0.2f,0.8f,0.2f)));		add(new Box(new Vector3d(5,0,0),new Vector3f(0.1f,1,10),this,new Color3f(0f,0.2f,0.8f)));		add(new Box(new Vector3d(0,0,5),new Vector3f(10,1,0.1f),this,new Color3f(0.2f,0.2f,0.8f)));				// add the robot        add(new Robot(new Vector3d(0, 0, 0), "R1"));                // add cherries randomly .        for( int n =0; n < 30;n++){            double x =( Math.random()*10 - 5);            double z = (Math.random()*10 - 5);            add(new CherryAgent(new Vector3d(x, 0, z), "cherry", 0.15f));        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -