Class Model
- java.lang.Object
-
- renderer.scene.Model
-
- Direct Known Subclasses:
Axes2D
,Axes3D
,BarycentricTriangle
,Box
,Circle
,CircleSector
,Cone
,ConeFrustum
,ConeSector
,Cube
,Cube2
,Cube4
,Cylinder
,CylinderSector
,Disk
,DiskSector
,Dodecahedron
,GRSModel
,Icosahedron
,Icosidodecahedron
,ObjSimpleModel
,Octahedron
,PanelXY
,PanelXZ
,PanelYZ
,ParametricCurve
,ParametricSurface
,Pyramid
,PyramidFrustum
,Ring
,RingSector
,Sphere
,SphereSector
,SphereSubdivided
,Square
,SquareGrid
,Tetrahedron
,Torus
,TorusSector
,TriangularPrism
,TriangularPyramid
,ViewFrustumModel
public class Model extends Object
AModel
object represents a distinct geometric object in aScene
. AModel
data structure is mainly aList
ofVertex
objects, aList
ofPrimitive
objects, and a list ofColor
objects.Each
Vertex
object contains the xyz-coordinates, in theModel
's own coordinate system, for one point from theModel
.Each
Color
object represents a color associated to one (or more)Vertex
objects.The
Vertex
objects represents points from the geometric object that we are modeling. In the real world, a geometric object has an infinite number of points. In 3D graphics, we "approximate" a geometric object by listing just enough points to adequately describe the object. For example, in the real world, a rectangle contains an infinite number of points, but it can be adequately modeled by just its four corner points. (Think about a circle. How many points does it take to adequately model a circle? Look at theCircle
model.)Each
Primitive
object is either aLineSegment
or aPoint
.Each
LineSegment
object contains four integers, two integers that are the indices of twoVertex
objects from theModel
's vertex list, and two integers that are indices of twoColor
objects from theModel
's color list. The two vertices are the line segment's two endpoints, and each of the two colors is associated with one of the two endpoints.Each
Point
object contains two integers, one integer index of aVertex
from theModel
's vertex list, and one integer index of aColor
from theModel
's color list.We use
LineSegment
objects to represent the space between the model's vertices. For example, while a rectangle can be approximated by its four corner points, those same four points could also represent two parallel line segments, or they could represent two lines that cross each other. By using four line segments that connect around the four points, we get a good, unambiguous representation of a rectangle.If we modeled a circle using just points, we would probably need to use hundreds of points. But if we connect every two adjacent points with a short line segment, we can get a good model of a circle with just a few dozen points.
Our
Model
's represent geometric objects as a "wire-frame" of line segments, that is, a geometric object is drawn as a collection of "edges". This is a fairly simplistic way of doing 3D graphics and we will improve this in later renderers.See
https://en.wikipedia.org/wiki/Wire-frame_model
or
https://www.google.com/search?q=computer+graphics+wireframe&tbm=isch
-
-
Constructor Summary
Constructors Constructor Description Model()
Construct an emptyModel
object.Model(String name)
Construct an emptyModel
object with the given {link String} name.Model(List<Vertex> vertexList, List<Primitive> primitiveList, List<Color> colorList, String name, boolean visible)
Construct aModel
object with all the given data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColor(Color... cArray)
void
addPrimitive(Primitive... pArray)
void
addVertex(Vertex... vArray)
Primitive
getPrimitive(int index)
String
toString()
For debugging.
-
-
-
Constructor Detail
-
Model
public Model()
Construct an emptyModel
object.
-
Model
public Model(String name)
Construct an emptyModel
object with the given {link String} name.- Parameters:
name
- a {link String} that is a name for thisModel
- Throws:
NullPointerException
- ifname
isnull
-
Model
public Model(List<Vertex> vertexList, List<Primitive> primitiveList, List<Color> colorList, String name, boolean visible)
Construct aModel
object with all the given data.- Parameters:
vertexList
- aVertex
{link List} for thisModel
primitiveList
- aPrimitive
{link List} for thisModel
colorList
- aColor
{link List} for thisModel
name
- a {link String} that is a name for thisModel
visible
- aboolean
that determines thisModel
's visibility- Throws:
NullPointerException
- ifvertexList
isnull
NullPointerException
- ifprimitiveList
isnull
NullPointerException
- ifcolorList
isnull
NullPointerException
- ifname
isnull
-
-
Method Detail
-
addVertex
public final void addVertex(Vertex... vArray)
- Parameters:
vArray
- array ofVertex
objects to add to thisModel
- Throws:
NullPointerException
- if anyVertex
isnull
-
getPrimitive
public final Primitive getPrimitive(int index)
-
addPrimitive
public final void addPrimitive(Primitive... pArray)
Add aPrimitive
(or Primitives) to thisModel
'sList
of primitives.NOTE: This method does not add any vertices to the
Model
'sVertex
list. This method assumes that the appropriate vertices have been added to theModel
'sVertex
list.- Parameters:
pArray
- array ofPrimitive
objects to add to thisModel
- Throws:
NullPointerException
- if anyPrimitive
isnull
-
addColor
public final void addColor(Color... cArray)
- Parameters:
cArray
- array ofColor
objects to add to thisModel
- Throws:
NullPointerException
- if anyColor
isnull
-
-