001package scene;
002
003import java.util.List;
004import java.util.LinkedList;
005import java.awt.Color;
006
007/**
008   A Model data structure represents a distinct geometric object in a Scene.
009   A Model data structure is mainly a list of LineSegment objects. Each
010   LineSegment object contains two Vertex objects with coordinates in the
011   camera coordinate system.
012
013   The line segments represent the geometric object as a "wire-frame", that is,
014   the geometric object is drawn as a collection of "edges". This is a fairly
015   simplistic way of doing 3D graphics and we will improve this in later renderers.
016
017   See
018      http://en.wikipedia.org/wiki/Wire-frame_model
019   or
020      https://www.google.com/search?q=graphics+wireframe&tbm=isch
021*/
022public class Model
023{
024   public List<LineSegment> lineSegmentList = new LinkedList<LineSegment>();
025
026   /**
027      Construct an empty model.
028   */
029   public Model()
030   {
031   }
032
033
034   /**
035      Add a LineSegment (or LineSegments) to this model's list of line segments.
036
037      @param lsArray array of LineSegments to add to this Model
038   */
039   public void addLineSegment(LineSegment... lsArray)
040   {
041      for (LineSegment ls : lsArray)
042      {
043         this.lineSegmentList.add(ls);
044      }
045   }
046
047
048   /**
049      Set all the line segments in this model to the same color.
050
051      @param c Color for all of this model's LineSegments
052   */
053   public void setColor(Color c)
054   {
055      for (LineSegment ls : this.lineSegmentList)
056      {
057         ls.setColor(c);
058      }
059   }
060
061   /**
062      Set all the line segments in this model to the same random color.
063   */
064   public void setColorRandom()
065   {
066      lineSegmentList.get(0).setColorRandom();
067      Color c = lineSegmentList.get(0).v[0].getColor();
068      for (LineSegment ls : this.lineSegmentList)
069      {
070         ls.setColor(c);
071      }
072   }
073
074   /**
075      Set all the line segments in this model to random colors.
076   */
077   public void setRandomColors()
078   {
079      for (LineSegment ls : this.lineSegmentList)
080      {
081         ls.setColorRandom();
082      }
083   }
084
085
086   /**
087      For debugging.
088
089      @return String representation of this Model object
090   */
091   public String toString()
092   {
093      String result = "";
094      result += "This Model has " + lineSegmentList.size() + " line segments\n";
095      //result = "Printing out this Model's " + lineSegmentList.size() + " Line segments:\n";
096      for (LineSegment ls : this.lineSegmentList)
097      {
098         result += ls.toString();
099      }
100      //result += "Done printing out Model\n";
101      return result;
102   }
103}