Browse Source

GUI Corrected

sarl
zephyr 3 years ago
parent
commit
5ced960a4f
5 changed files with 27 additions and 20 deletions
  1. +8
    -8
      gui/GraphicalMap.java
  2. +11
    -4
      simulator/environment/Environment.java
  3. +2
    -3
      simulator/environment/movingManager/MovingManager.java
  4. +5
    -4
      simulator/environment/worldObject/MovableObject.java
  5. +1
    -1
      simulator/environment/worldObject/WorldObject.java

+ 8
- 8
gui/GraphicalMap.java View File

@@ -20,8 +20,8 @@ public class GraphicalMap extends JPanel{
private QuadTree tree;
private Rectangle2f fieldOfView;
private Point2f centre;
private float scale = 20;
private Point2f center;
private float scale = 5;
private ArrayList <DrawingObject> listObj;
@@ -30,7 +30,7 @@ public class GraphicalMap extends JPanel{
this.tree = tree;
this.listObj = new ArrayList<DrawingObject>();
this.fieldOfView = new Rectangle2f(-(float)(this.getWidth())/(float)(2*scale), -(float)(this.getHeight())/(float)(2*scale), (float)(this.getWidth())/(float)(2*scale), (float)(this.getHeight())/(float)(2*scale));
this.centre = new Point2f(0, 0);
this.center = new Point2f(0, 0);
}
public void paintComponent(Graphics g){
g.setColor(Color.BLACK);
@@ -39,7 +39,7 @@ public class GraphicalMap extends JPanel{
g.setColor(Color.GREEN);

for(DrawingObject tempObject : this.listObj){
g.fillOval(tempObject.getCentreX(), tempObject.getCentreY(),tempObject.getWidth(),tempObject.getHeight());
g.fillOval(tempObject.getCentreX() - tempObject.getWidth()/2, tempObject.getCentreY() - tempObject.getHeight()/2,tempObject.getWidth(),tempObject.getHeight());
}
}
@@ -47,15 +47,15 @@ public class GraphicalMap extends JPanel{
ArrayList <WorldObject> tempList;
this.fieldOfView = new Rectangle2f(-(float)(this.getWidth())/(float)(2*scale), -(float)(this.getHeight())/(float)(2*scale), (float)(this.getWidth())/(float)(2*scale), (float)(this.getHeight())/(float)(2*scale));
this.fieldOfView.translate(new Vector2f(this.centre));
this.fieldOfView = this.fieldOfView.translate(new Vector2f(this.center));
if(this.tree != null){
this.listObj.clear();
tempList = this.tree.getObjectInShape(this.fieldOfView);
int x,y,size;
for(WorldObject tempObject : tempList){
x = (int) ((tempObject.getPosition().getX() - this.fieldOfView.getCenter().getX()) * this.scale) + this.getWidth()/2;
y = (int) (-(tempObject.getPosition().getY() - this.fieldOfView.getCenter().getY()) * this.scale) + this.getHeight()/2;
size = (int) (tempObject.getShape().getRadius() * this.scale);
x = (int) ((tempObject.getPosition().getX() - this.center.getX()) * this.scale) + this.getWidth()/2;
y = (int) (-(tempObject.getPosition().getY() - this.center.getY()) * this.scale) + this.getHeight()/2;
size = (int) (tempObject.getShape().getRadius() * this.scale*2);
this.listObj.add(new DrawingObject(x,y,size,size));
}
}

+ 11
- 4
simulator/environment/Environment.java View File

@@ -15,15 +15,16 @@ public class Environment {
private ArrayList<AgentBody> bodies;
private MovingManager movingManager = new MovingManager();
MovableObject mo;
MovableObject mo2;
public Environment (float width, float height){
tree = new QuadTree(width,height);
MovableObject mo = new MovableObject(new Point2f(-5, 0), 2, 5);
mo = new MovableObject(new Point2f(-5, 0), 2, 5);
mo.setVelocity(new Vector2f(2,0));
tree.insertObject(mo);
movingManager.add(mo);
MovableObject mo2 = new MovableObject(new Point2f(0, 5), 3, 5);
mo2.setVelocity(new Vector2f(0,-2));
mo2 = new MovableObject(new Point2f(0, 5), 4, 5);
mo2.setVelocity(new Vector2f(0,-1));
tree.insertObject(mo2);
movingManager.add(mo2);
bodies = new ArrayList<AgentBody> ();
@@ -32,6 +33,12 @@ public class Environment {
//TODO
public void live(float Dt){
this.movingManager.moveAll(this.tree,Dt);
if(mo.getShape().intersects(mo2.getShape())){
System.out.println("SUCCESS");
}
else{
System.out.println("0000000");
}
}
public void perceive (){
for(AgentBody b : bodies){

+ 2
- 3
simulator/environment/movingManager/MovingManager.java View File

@@ -43,10 +43,9 @@ public class MovingManager {
}
}
for(MovableObject mo : this.movingObject){
System.out.println(mo.getVelocity().toString());
if(dt!=null){
if(dt <= 1 && dt > 0){
mo.Translate(mo.getVelocity().operator_multiply(dt*deltaT));
if(dt <= deltaT && dt > 0){
mo.Translate(mo.getVelocity().operator_multiply(deltaT));
mo.getNode().removeObject(mo);
tree.insertObject(mo);

+ 5
- 4
simulator/environment/worldObject/MovableObject.java View File

@@ -33,7 +33,7 @@ public class MovableObject extends WorldObject{
* all object have cicrle box
* 3 possibility : no collision, 1 dt, 2dt
*/
float a,b,c,discriminant;
float r,a,b,c,discriminant;
Vector2f v,d;
if(obstacle instanceof MovableObject)
v = (this.velocity.operator_minus(((MovableObject)obstacle).velocity));
@@ -43,10 +43,11 @@ public class MovableObject extends WorldObject{
return null;
v = v.operator_multiply(deltaT);
d = this.getPosition().operator_minus(obstacle.getPosition());
r = this.getShape().getRadius() + obstacle.getShape().getRadius();
a = v.lengthSquared();
b = 2*(v.dot(d));
c = d.lengthSquared() - ((this.getShape().getRadius() + obstacle.getShape().getRadius()));
c = d.lengthSquared() - r*r;
System.out.println("a = " + a + " b = " + b + " c = " + c + " v = " + v.toString());
discriminant = b*b - 4*(a*c);
@@ -54,8 +55,8 @@ public class MovableObject extends WorldObject{
return null;
}
else if(discriminant > 0){
float dt1 = (float) ((-b + Math.sqrt(discriminant))/(2*a));
float dt2 = (float) ((-b - Math.sqrt(discriminant))/(2*a));
float dt1 = (-b + (float)(Math.sqrt(discriminant)))/(2*a);
float dt2 = (-b - (float) (Math.sqrt(discriminant)))/(2*a);
return new Float(Math.min(dt1, dt2));
}
else{

+ 1
- 1
simulator/environment/worldObject/WorldObject.java View File

@@ -26,7 +26,7 @@ public class WorldObject {
}
public synchronized void Translate(Vector2f v) {
this.position = this.position.operator_plus(v);
this.shape.translate(v);
this.shape = this.shape.translate(v);
// changer dans quel node il se trouve TODO
}
public synchronized Circle2f getShape() {

Loading…
Cancel
Save