All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neuronrobotics.addons.driving.virtual.VirtualWorld Maven / Gradle / Ivy

The newest version!
package com.neuronrobotics.addons.driving.virtual;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import javax.swing.JFrame;

import com.neuronrobotics.addons.driving.AbstractRobotDrive;
import com.neuronrobotics.addons.driving.NrMap;
import com.neuronrobotics.sdk.ui.ConnectionImageIconFactory;

// TODO: Auto-generated Javadoc
/**
 * The Class VirtualWorld.
 */
public class VirtualWorld extends NrMap{
	
	/** long. */
	
	private static final long serialVersionUID = 3437012102714959690L;
	
	/** The bots. */
	private ArrayList bots = new ArrayList();
	
	/** The frame. */
	private JFrame frame;

	/**
	 * Instantiates a new virtual world.
	 */
	public VirtualWorld() {
		System.out.println("Starting new Virtual World");
		BufferedImage d = new BufferedImage(getWidth(), getHeight(),BufferedImage.TYPE_INT_RGB);
		Graphics2D g =  d.createGraphics();
		//Backdrop is blue
		g.setColor(Color.blue);
		g.fillRect(0,0, getWidth(),getHeight());
		
		//White Oval tack
		g.setColor(Color.white);
		int rad =20;
		g.fillRoundRect(30,50, 720,300, rad ,rad );
		g.fillRoundRect(450,50,150,500, rad ,rad );
		g.fillRoundRect(450,450,300,120, rad ,rad );
		g.setColor(Color.orange);
		g.fillOval(720, 460, 20, 20);
		//g.fillOval(30,10, (int)(width-50 ),(int)( hight-80 ));
		
		//Draw Line Follow Track
		g.setColor(Color.black);
		g.setStroke(new BasicStroke(10));
		//g.drawOval(80,50, (int)(width-160 ),(int)( hight-160 ));
		
		//Straight Sections
		int lSx = (int)(width/2-120 );
		int ly=(int)( height/2+60 );
		int lEx=(int)(width/2+120 );
		
		int sSx=(int)(width/2-50 );
		int sy=(int)( height/2-60 );
		int sEx= (int)(width/2+50 );
		
		g.drawLine(lSx, ly, lEx, ly);
		g.drawLine(sSx, sy, sEx, sy);
		
		int h = (int)(width/2 );
		g.drawLine(h, ly-20, h, ly+20);
		
		//End Archs
		int ar = 200;
		g.drawArc(lSx-(ar/2), ly-ar, ar, ar, 90, 180);
		g.drawArc(lEx-(ar/2), ly-ar, ar, ar, -90, 180);
		
		//Connect the ends
		g.drawLine(sEx, sy, lEx, ly-ar);
		g.drawLine(sSx, sy, lSx, ly-ar);
		setDisplay(d);
		initGui();
	}
	
	/**
	 * Instantiates a new virtual world.
	 *
	 * @param b the b
	 */
	public VirtualWorld(BufferedImage b) {
		super(b);
		setDisplay(b);
		initGui();
	}

	/* (non-Javadoc)
	 * @see com.neuronrobotics.addons.driving.NrMap#initGui()
	 */
	public void initGui(){
		super.initGui();
		
		
        getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBackground(Color.black);
        getFrame().add(this);
        getFrame().setSize((int)width+200,(int)height+200);
        getFrame().setLocationRelativeTo(null);
        getFrame().setVisible(true);
        getFrame().setIconImage( ConnectionImageIconFactory.getIcon("images/hat.png").getImage());
        //frame.addMouseListener(this);
        //frame.addMouseMotionListener(this);
	}
	
	/* (non-Javadoc)
	 * @see com.neuronrobotics.addons.driving.NrMap#updateMap()
	 */
	public void updateMap() {
		//System.out.println("Updating Map");
		BufferedImage display = getMap();
		
		Graphics2D g =  display.createGraphics();
		if(bots != null){
			for(DrivingRobotUI b:bots) {
				b.drawRobot(g);
			}
		}
		setFinalDisplayImage(display);
		getFrame().setVisible(true);
		getFrame().repaint();
	}
	
	/**
	 * Adds the robot.
	 *
	 * @param robot the robot
	 * @param botStartX the bot start x
	 * @param botStartY the bot start y
	 */
	public void addRobot(AbstractRobotDrive robot,int botStartX ,int botStartY) {
		if(!bots.contains(robot))
			bots.add(new DrivingRobotUI(this,robot,botStartX ,botStartY));
		updateMap();
	}
	
	/**
	 * Adds the sensor display dot.
	 *
	 * @param platform the platform
	 * @param deltLateral the delt lateral
	 * @param deltForward the delt forward
	 * @param c the c
	 */
	public synchronized void addSensorDisplayDot(AbstractRobotDrive platform, double deltLateral, double deltForward, Color c){
		for( int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy