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