@Test
  public void getHitData_WithHit_ExpectHitData() {
    // Given
    Point center = new Point(1.0, 0.0, 1.0);
    double radius = 1.0;
    UtilImpl ops = new UtilImpl();

    Vector d = new Vector(0.0, 0.0, -1.0);
    Point eye = new Point(1.0, 0.0, 4.0);
    Ray ray = new RayImpl(d, eye);

    Sphere classUnderTest = new Sphere(center, radius, null, null, null, null, ops);

    ArrayList<HitData> expectedHitData = new ArrayList<HitData>();
    HitData hit =
        new HitData(2.0, classUnderTest, new Vector(0.0, 0.0, 1.0), new Point(1.0, 0.0, 2.0));
    expectedHitData.add(hit);
    hit = new HitData(4.0, classUnderTest, new Vector(0.0, 0.0, -1.0), new Point(1.0, 0.0, 0.0));
    expectedHitData.add(hit);

    // When
    ArrayList<HitData> actual = classUnderTest.getHitData(ray);

    // Then
    TestsHelper.arrayListSubsets(expectedHitData, actual);
  }
示例#2
0
 /**
  * See the class documentation
  *
  * @param args - has no purpose
  */
 public static void main(String[] args) {
   boolean cont = true; // Whether or not the user wishes to continue
   while (cont) {
     double[] input = getInput();
     Sphere aSp = new Sphere(input[0]);
     Cylinder aCy = new Cylinder(input[0], input[1]);
     Cone aCo = new Cone(input[0], input[1]);
     System.out.println(
         "The VOLUME of a SPHERE of given specifications is: " + aSp.volume((int) input[2]));
     System.out.println(
         "The SURFACE AREA of a SPHERE of given specifications is: "
             + aSp.surfaceArea(((int) input[2])));
     System.out.println(
         "The VOLUME of a CYLINDER of given specifications is: " + aCy.volume(((int) input[2])));
     System.out.println(
         "The SURFACE AREA of a CYLINDER of given specifications is: "
             + aCy.surfaceArea(((int) input[2])));
     System.out.println(
         "The VOLUME of a CONE of given specifications is: " + aCo.volume(((int) input[2])));
     System.out.println(
         "The SURFACE AREA of a CONE of given specifications is: "
             + aCo.surfaceArea(((int) input[2])));
     try {
       Thread.sleep(1000);
     } catch (InterruptedException e) {
     }
     cont = getContinue();
   }
   sc.close();
 }
示例#3
0
文件: Blob.java 项目: vain/aoi-addons
  /**
   * Update local information from the scene. It's important that this method is synchronized
   * because we get ConcurrentModificationException's during rendering otherwise.
   *
   * <p>This method is called from sceneChanged().
   */
  protected synchronized void updateCharges(Scene theScene) {
    // Clear cached infos.
    cachedBounds = null;
    cachedWire = null;
    charges.clear();

    setPositive = null;
    setNegative = null;

    // Get all selection sets.
    Object layersObj = theScene.getMetadata("selectionsPlugin.selectionSets");

    if (layersObj == null) return;

    if (!(layersObj instanceof ArrayList)) return;

    ArrayList<ObjectSet> layers = (ArrayList<ObjectSet>) layersObj;

    // Try to find those which are of interest for us.
    for (ObjectSet set : layers) {
      if (set.getName().equals(setNamePositive)) {
        setPositive = set;
      } else if (set.getName().equals(setNameNegative)) {
        setNegative = set;
      }
    }

    // Create charges.
    if (setPositive != null) {
      for (ObjectInfo oi : setPositive.getObjects(theScene)) {
        if (oi.getObject() instanceof Sphere) {
          Sphere s = (Sphere) oi.getObject();
          double q = s.getRadii().x;
          Vec3 pos = oi.getCoords().getOrigin();

          charges.add(new SphereCharge(pos, q));
        }
      }
    }

    if (setNegative != null) {
      for (ObjectInfo oi : setNegative.getObjects(theScene)) {
        if (oi.getObject() instanceof Sphere) {
          Sphere s = (Sphere) oi.getObject();
          double q = -s.getRadii().x;
          Vec3 pos = oi.getCoords().getOrigin();

          charges.add(new SphereCharge(pos, q));
        }
      }
    }
  }
示例#4
0
 public void drawSphere(int scaleX, int scaleY, int scaleZ, int posX, int posY, int posZ) {
   Vector3f axe = new Vector3f(0, 0, 0);
   axe.x = posX;
   axe.y = posY;
   axe.z = posZ;
   Sphere.drawSphere(false, 0, scaleX, scaleY, scaleZ, axe);
 }
示例#5
0
 public void fillSphere(
     int texture, int scaleX, int scaleY, int scaleZ, int posX, int posY, int posZ) {
   Vector3f axe = new Vector3f(0, 0, 0);
   axe.x = posX;
   axe.y = posY;
   axe.z = posZ;
   Sphere.drawSphere(true, texture, scaleX, scaleY, scaleZ, axe);
 }
示例#6
0
 /* draw the character and the tail */
 public void Draw(GL10 gl) {
   gl.glPushMatrix();
   gl.glTranslatef(x_pos, y_pos, z_pos);
   m_sphere.draw(gl);
   gl.glPopMatrix();
   gl.glPushMatrix();
   m_tail.draw(gl);
   gl.glPopMatrix();
 }
  @Test
  public void getHitData_MissLeft_ExpectNoHits() {
    // Given
    Point center = new Point(0.0, 0.0, 0.0);
    double radius = 1.0;
    UtilImpl ops = new UtilImpl();

    Vector d = new Vector(0.0, 1.0, -1.0);
    Point eye = new Point(0.0, 0.0, 4.0);
    Ray ray = new RayImpl(d, eye);

    Sphere classUnderTest = new Sphere(center, radius, null, null, null, null, ops);

    // When
    ArrayList<HitData> list = classUnderTest.getHitData(ray);

    // Then
    Assert.assertEquals(0, list.size());
  }
示例#8
0
文件: Blob.java 项目: vain/aoi-addons
  @Override
  public WireframeMesh getWireframeMesh() {
    if (cachedWire != null) return cachedWire;

    // This is a dirty hack.
    // TODO: Remove it!

    Vec3 vert[] = new Vec3[0];
    int[] from = new int[0];
    int[] to = new int[0];

    if (charges.size() <= 0) {
      cachedWire = new NullObject().getWireframeMesh();
      return cachedWire;
    }

    for (Charge c : charges) {
      double rad = c.w;
      Sphere s = new Sphere(rad, rad, rad);
      WireframeMesh wfm = s.getWireframeMesh();

      Vec3[] vert2 = new Vec3[vert.length + wfm.vert.length];
      int i;
      for (i = 0; i < vert.length; i++) vert2[i] = vert[i];
      for (Vec3 v : wfm.vert) vert2[i++] = v.plus(new Vec3(c.x, c.y, c.z));

      int[] from2 = new int[from.length + wfm.from.length];
      for (i = 0; i < from.length; i++) from2[i] = from[i];
      for (int foreign = 0; foreign < wfm.from.length; foreign++)
        from2[i++] = wfm.from[foreign] + vert.length;
      from = from2;

      int[] to2 = new int[to.length + wfm.to.length];
      for (i = 0; i < to.length; i++) to2[i] = to[i];
      for (int foreign = 0; foreign < wfm.to.length; foreign++)
        to2[i++] = wfm.to[foreign] + vert.length;
      to = to2;

      vert = vert2;
    }

    return (cachedWire = new WireframeMesh(vert, from, to));
  }
 public void display() {
   pushMatrix();
   translate(location.x, location.y, -boxSize);
   rotateY(theta);
   theta += 0.01f;
   fill(120);
   box(boxSize);
   sphere.display();
   popMatrix();
 }
  public static void main(String args[]) {
    // Declare variables
    double aRadius;
    double aVolume;

    // Declare objects
    MainWindow mWindow;
    InputBox iBox;
    OutputBox oBox;

    Sphere aSphere;

    // Create objects
    mWindow = new MainWindow();
    iBox = new InputBox(mWindow);
    oBox = new OutputBox(mWindow);

    aSphere = new Sphere();

    // Use objects
    mWindow.show();

    // get Input
    aRadius = iBox.getDouble("Please enter the radius of the sphere: ");
    aSphere.setTheRadius(aRadius);

    // debug code
    System.out.println("value input:" + aRadius);
    System.out.println("the radius value in the sphere object:" + aSphere.getTheRadius());

    // Process
    aSphere.computeVolume();
    aVolume = aSphere.getTheVolume();

    // Output
    oBox.show();
    oBox.print(" The volume of a sphere with a radius of  " + aRadius + " is " + aVolume);
  }
示例#11
0
 public void drawColorSphere(
     int texture,
     int scaleX,
     int scaleY,
     int scaleZ,
     int posX,
     int posY,
     int posZ,
     float r,
     float g,
     float b) {
   Vector3f axe = new Vector3f(0, 0, 0);
   axe.x = posX;
   axe.y = posY;
   axe.z = posZ;
   Sphere.drawColorSphere(true, texture, scaleX, scaleY, scaleZ, axe, r, g, b);
 }
示例#12
0
 @SuppressWarnings("unchecked")
 public void readSphereList(File filename, Server server) {
   // Read from disk using FileInputStream
   try {
     thisspheres.clear();
     FileInputStream f_in;
     f_in = new FileInputStream(filename);
     // Read object using ObjectInputStream
     ObjectInputStream obj_in = new ObjectInputStream(f_in);
     // Read an object
     Object obj = obj_in.readObject();
     if (obj instanceof List<?>) {
       thisspheres = (List<Sphere>) obj;
     }
     for (Sphere s : thisspheres) {
       s.setV(new Vector(s.getX(), s.getY(), s.getZ()));
     }
   } catch (Exception e) {
     System.out.print("First run. Let's generate the spheres.");
     thisspheres.clear();
     // Now test if we make a new
     {
       try {
         /*Sphere ns = new Sphere();
         ns.setSize(SphereWorldConfig.maxradius);
         // set the Spawn.
                        Move this to post world generation?
         server.getWorld(SphereWorldConfig.world).loadChunk(0,0);
         server.getWorld(SphereWorldConfig.world).setSpawnLocation(0,server.getWorld(SphereWorldConfig.world).getHighestBlockYAt(0,0),0);
         ns.setV(server.getWorld(SphereWorldConfig.world).getSpawnLocation().toVector());
         ns.setWorld(SphereWorldConfig.world);
         ns.setX(server.getWorld(SphereWorldConfig.world).getSpawnLocation().getX());
         ns.setY(server.getWorld(SphereWorldConfig.world).getSpawnLocation().getY());
         ns.setZ(server.getWorld(SphereWorldConfig.world).getSpawnLocation().getZ());
         System.out.println("Spawnlocation on world is:"+
          " x"+server.getWorld(SphereWorldConfig.world).getSpawnLocation().getX()+
          " y"+server.getWorld(SphereWorldConfig.world).getSpawnLocation().getY()+
          " z"+server.getWorld(SphereWorldConfig.world).getSpawnLocation().getZ());
                       */
         System.out.println("Creating new Spheres... First run");
         System.out.print("working.. please wait.. this may take several minutes");
         // thisspheres.add(ns);
       } catch (Exception e1) {
         // Well seems like world is not default world.. so we cannot
         // get spawnpoint.
         // System.out.print("World does not exist... This is not Good. Should not happen");
         return;
       }
     }
     // Add this for start
     for (int x = -SphereWorldConfig.worldsize; x < SphereWorldConfig.worldsize; x = x + 20) {
       for (int y = -SphereWorldConfig.worldsize; y < SphereWorldConfig.worldsize; y = y + 20) {
         Boolean makenew = true;
         Location loc =
             new Location(
                 null,
                 x + r.nextInt(20),
                 r.nextInt(SphereWorldConfig.maxheight - SphereWorldConfig.minheight)
                     + SphereWorldConfig.minheight,
                 y + r.nextInt(20));
         for (Sphere s : thisspheres) {
           if (s.getV().distance(loc.toVector()) < SphereWorldConfig.mindist) makenew = false;
         }
         if (r.nextInt(100) > SphereWorldConfig.spherechance) makenew = false;
         if (makenew) {
           // distance ok make sphere
           Sphere ns = new Sphere();
           ns.setSize(
               r.nextInt(SphereWorldConfig.maxradius - SphereWorldConfig.minradius)
                   + SphereWorldConfig.minradius);
           ns.setV(new Vector(loc.getX(), loc.getY(), loc.getZ()));
           ns.setWorld(SphereWorldConfig.world);
           ns.setX(loc.getX());
           ns.setY(loc.getY());
           ns.setZ(loc.getZ());
           thisspheres.add(ns);
           ns = null;
         }
       }
     }
     writeSphereList(filename);
   }
   System.out.println("Created / Loaded Spheres: " + thisspheres.size());
 }
示例#13
0
  public Sphere getBoundingSphere(Sphere optionalTarget) {
    optionalTarget.setCenter(this.center());
    optionalTarget.setRadius(this.size(_v1).length() * 0.5);

    return optionalTarget;
  }
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // RayTracing Variables
    int h = 600;
    int w = 800;
    double[] planeDim = {1., 0, 0, -100};
    double[] eyeDim = {100.5, 0, 0};
    double[] topDim = {100.0, 0.1, 0};
    // Normal Variables
    CameraPlane pl = new CameraPlane(planeDim);
    Point pt = new Point(eyeDim);
    // Create Camera
    cam = new Camera(pl, pt, w, h);
    // Set Camera Frame
    cam.setTopDir(topDim, .001);
    // CreateObjects
    // Sphere
    double[] sDim1 = {0, 0, 0, 400};
    Sphere s1 = new Sphere(sDim1);
    s1.setColor(sphere1);
    s1.setKA(0.1);
    s1.setKD(0.9);
    s1.setKS(1);
    s1.setN(2000);
    double[] sDim2 = {10, 10, -10, 100};
    Sphere s2 = new Sphere(sDim2);
    s2.setColor(sphere2);
    s2.setKA(0.1);
    s2.setKD(0.9);
    s2.setKS(1);
    s2.setN(2000);
    // Plane
    double[] pDim1 = {0, 1, 0, 40};
    Plane p1 = new Plane(pDim1);
    p1.setColor(plane);
    p1.setKA(0.1);
    p1.setKD(0.9);
    p1.setKS(1);
    p1.setN(1000);
    // Lighting
    double[] l1Dim = {200, 200, 200};
    Light l1 = new Light(l1Dim);

    // Main Render Loop
    for (int yR = 0; yR < h; yR++) {
      for (int xR = 0; xR < w; xR++) {
        Ray primary = cam.createRay(xR, yR);
        cam.img.setRGB(xR, yR, trace(primary).getRGB());
      }
    }

    // Output Image
    try {
      File outputfile = new File("saved.png");
      ImageIO.write(cam.img, "png", outputfile);
    } catch (IOException e) {
    }
  }
示例#15
0
文件: Box.java 项目: RMMJR/g3m
 public final boolean fullContainedInSphere(Sphere that) {
   return that.contains(_lower) && that.contains(_upper);
 }
示例#16
0
文件: Box.java 项目: RMMJR/g3m
 public final BoundingVolume mergedWithSphere(Sphere that) {
   return that.mergedWithBox(this);
 }
示例#17
0
文件: Box.java 项目: RMMJR/g3m
 public final boolean touchesSphere(Sphere that) {
   return that.touchesBox(this);
 }