Package org.nlogo.api

Examples of org.nlogo.api.Agent


    gl.glLoadIdentity();

    synchronized (world) {
      Perspective perspective = world.observer().perspective();
      Agent targetAgent = world.observer().targetAgent();

      worldRenderer.observePerspective(gl);

      worldRenderer.renderCrossHairs(gl);

      lightManager.applyLighting();

      // Uncomment the code below to show the positions and directions of all the lights
      // in the world (only works in NetLogo 3D, not the 3D view in 2D).
      /*
      if (world instanceof World3D)
      {
        double observerDistance = Math.sqrt(world.observer().oxcor() * world.observer().oxcor()
              + world.observer().oycor() * world.observer().oycor()
              + world.observer().ozcor() * world.observer().ozcor());
        lightManager.showLights(glu, (World3D)world, WORLD_SCALE, observerDistance, shapeRenderer);
      }
      */

      renderWorld(gl, world);

      setClippingPlanes(gl);

      // Calculate the line scale to use for rendering outlined turtles and links,
      // as well as link stamps.
      double lineScale = calculateLineScale();

      boolean sortingNeeded = world.mayHavePartiallyTransparentObjects();

      if (!sortingNeeded) {
        worldRenderer.renderPatchShapes
            (gl, outlineAgent, renderer.fontSize(), renderer.patchSize());

        linkRenderer.renderLinks(gl, glu, renderer.fontSize(), renderer.patchSize(), outlineAgent);

        turtleRenderer.renderTurtles(gl, glu, renderer.fontSize(), renderer.patchSize(), outlineAgent);

        // Render stamps and trails
        //
        // Note: in the 3D view in 2D, stamps and trails appear as bitmaps
        // on the drawing layer, which already got rendered in renderWorld().
        //
        // In the true 3D version, we skipped the call to renderDrawing()
        // because there's the possibility that stamps and trails might be
        // transparent, and so they need to get sorted along with the rest
        // of the objects in the scene.
        //
        // However, since we've determined that no sorting is needed in this
        // block, we can safely render the drawing layer now.

        if (world instanceof World3D) {
          worldRenderer.renderDrawing(gl);
        }
      } else {
        // Make sure everything needed for transparency is enabled.
        gl.glEnable(GL.GL_BLEND);
        gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

        opaqueAgents.clear();
        transparentAgents.clear();

        for (Agent agent : world.turtles().agents()) {
          if (agentIsVisible(agent)) {
            if (agent.isPartiallyTransparent()) {
              transparentAgents.add(agent);
            } else {
              opaqueAgents.add(agent);
            }
          }
        }

        for (Agent agent : world.patches().agents()) {
          if (agentIsVisible(agent)) {
            if (agent.isPartiallyTransparent()) {
              transparentAgents.add(agent);
            } else {
              opaqueAgents.add(agent);
            }
          }
        }

        for (Agent agent : world.links().agents()) {
          if (agentIsVisible(agent)) {
            if (agent.isPartiallyTransparent()) {
              transparentAgents.add(agent);
            } else {
              opaqueAgents.add(agent);
            }
          }
        }

        // Now add stamps and trails.
        //
        // Note: in the 3D view in 2D, stamps and trails appear as bitmaps
        // on the drawing layer, which already got rendered in renderWorld().
        // We only have to worry about the true 3D version.

        if (world instanceof World3D) {
          // Link stamps
          for (org.nlogo.api.Link stamp : ((Drawing3D) world.getDrawing()).linkStamps()) {
            if (agentIsVisible(stamp)) {
              if (stamp.isPartiallyTransparent()) {
                transparentAgents.add(stamp);
              } else {
                opaqueAgents.add(stamp);
              }
            }
          }

          // Turtle stamps
          for (org.nlogo.api.Turtle stamp : ((Drawing3D) world.getDrawing()).turtleStamps()) {
            if (agentIsVisible(stamp)) {
              if (stamp.isPartiallyTransparent()) {
                transparentAgents.add(stamp);
              } else {
                opaqueAgents.add(stamp);
              }
            }
          }

          // Turtle trails
          ((WorldRenderer3D) worldRenderer).renderTrails(gl);

          // Note: We are currently not supporting transparent turtle trails
          // (trails are left by the turtles when you use the pen-down command).
          // The difficulty with these is that they are not instances of Agent,
          // so we would have to reimplement our code to use Objects instead,
          // or create some sort of Renderable interface (but this would create
          // more problems because we would need to make Agent implement
          // this Renderable interface, so either we have to create a bad dependency
          // from the org.nlogo.api package to the render package, or else we
          // have to put the Renderable interface in the org.nlogo.api package).
          // There may also be a significant performance issue since the trails
          // consist of a large number of small line segments, all of which would
          // need to be sorted each frame for transparency to work properly.
          //
          // For reference:
          // for( org.nlogo.api.DrawingLine3D line : ( (Drawing3D) world.getDrawing() ).lines() )
          // {
          //     // add trail segment to the list here
          // }
        }

        //    System.out.printf( "\t\t%d opaque objects.\n" , opaqueAgents.size() ) ;
        //    System.out.printf( "\t\t%d transparent objects (sorted).\n" , transparentAgents.size() ) ;

        // Render the opaque objects first
        for (Agent agent : opaqueAgents) {
          renderAgent(gl, agent, lineScale);
        }

        // Now render the transparent agents in sorted order (back to front)
        while (!transparentAgents.isEmpty()) {
          Agent agent = transparentAgents.remove();
          renderAgent(gl, agent, lineScale);
        }

        gl.glDisable(GL.GL_BLEND);
      }
View Full Code Here


  @Override
  public Object report(final org.nlogo.nvm.Context context) {
    if (world.observer().perspective() == PerspectiveJ.OBSERVE()) {
      return org.nlogo.api.Nobody$.MODULE$;
    }
    Agent subject = world.observer().targetAgent();
    // not actually sure if the null check here is necessary - ST 6/28/05
    if (subject == null || subject.id() == -1) {
      return org.nlogo.api.Nobody$.MODULE$;
    }
    return subject;
  }
View Full Code Here

  @Override
  protected java.awt.image.BufferedImage getSpotlightImage(ViewSettings settings) {
    double xcor, ycor, spotlightSize;
    boolean wrap = false;
    Agent agent = targetAgent();

    if (agent instanceof Turtle) {
      Turtle turtle = (Turtle) agent;
      spotlightSize = turtle.size() * 2;
      xcor = turtle.xcor();
View Full Code Here

TOP

Related Classes of org.nlogo.api.Agent

Copyright © 2018 www.massapicom. 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.