|
Flight Club |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--flightclub.framework3d.Obj3d
This class implements a 3d object made up of polygons. We have a list of points (x, y, z) in model space and a second list of the those points after they have been mapped into screen space (x_, y_, z_). The x_ coord is handy for fogging and sorting; it represents the 'depth' of the projected point. (y_, z_) is the location of the point in screen space.
The mapping from model space to screen space is as follows: 1. A translation such that the camera focus becomes the origin. 2. A rotation such that the camera eye is on the +ve x_ axis. 3. Forshorten y_ and z_ by one over x_, the depth of the point. 4. Scale y_ and z_ according to the height of the display area in pixels. We use a flat array to store the coords as follows: (x0, y0, z0, x1, y1, z1, x2, ...). If npoints * 3 exceeds the array size then we double the array size and do a System.copyarray(). I got the flat array idea from the WireFrame demo applet.
| Field Summary | |
static int |
CONCAVE
|
static int |
CONVEX
|
protected ModelViewer |
modelViewer
|
| Constructor Summary | |
Obj3d(ModelViewer modelViewer,
int npolygons)
Creates an Obj3d and registers it with the 3d object manager. |
|
Obj3d(ModelViewer modelViewer,
int npolygons,
boolean register)
|
|
Obj3d(Obj3d from,
boolean register)
Creates a copy of obj. |
|
Obj3d(java.io.StreamTokenizer st,
ModelViewer modelViewer,
boolean register)
Parses a text file and creates an Obj3d. |
|
| Method Summary | |
int |
addPolygon(float[][] vs)
Adds a single sided gray polygon. |
int |
addPolygon(float[][] vs,
java.awt.Color c)
Adds a polygon with one side visible. |
int |
addPolygon(float[][] vs,
java.awt.Color c,
boolean doubleSided)
Adds a polygon. |
int |
addPolygon2(float[][] vs)
Adds a gray polygon that is visible from both sides. |
int |
addPolygon2(float[][] vs,
java.awt.Color c)
Adds a polygon that is visible from both sides. |
void |
addPolygonBent(float[][] ps,
java.awt.Color color,
int concaveFlag)
Adds a bent polygon (made out of two triangles). |
void |
destroyMe()
|
void |
draw(java.awt.Graphics g)
Draws a 2d representation of the object onto the screen. |
float |
getDepthMax()
|
float |
getDepthMin()
|
float[] |
getEye()
|
float[] |
getFocus()
|
int |
getPointIndex(int poly,
int vertex)
Gets the index of a point on a polygon. |
static Obj3d |
makeCube(ModelViewer modelViewer)
Creates a unit cube whose centre of mass lies at the origin. |
static Obj3d |
parseFile(java.io.InputStream is,
ModelViewer modelViewer,
boolean register)
This method is a hack. |
void |
scaleBy(float s)
|
void |
setBB()
Creates unit axes at the origin. |
void |
setColor(java.awt.Color c)
Gives all polygons the specifed color. |
void |
setNormals()
Loops thru' surfaces setting their dirtyNormal flags so that the surface normals will be computed again. |
void |
setPoint(int index,
float x,
float y,
float z)
Sets the co-ords of a point. |
java.lang.String |
toString()
Dumps the data of this 3d shape. |
void |
transform()
Uses the camera to map all points from model space, (x, y, z) to screen space (x_, y_, z_). |
void |
translateBy(float dx,
float dy,
float dz)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected ModelViewer modelViewer
public static final int CONCAVE
public static final int CONVEX
| Constructor Detail |
public Obj3d(ModelViewer modelViewer,
int npolygons,
boolean register)
public Obj3d(ModelViewer modelViewer,
int npolygons)
public Obj3d(Obj3d from,
boolean register)
obj.
public Obj3d(java.io.StreamTokenizer st,
ModelViewer modelViewer,
boolean register)
throws java.io.IOException,
FileFormatException
# a simple kite made of two triangular polygons
# by foo bar, 27 Aug 2002
2
f CC99FF 12.1 2.4 3.5, 12.4 2.2 3.5, 3.2 5 7.4,
t 336699 9.7 0 3.5, 2.2 2.2 3.5, 3.2 5 7.3,
The above represents an Obj3d with two polygons, the second of
which is double sided; each is a differnt color; each is made
up of 3 points.
| Method Detail |
public static Obj3d parseFile(java.io.InputStream is,
ModelViewer modelViewer,
boolean register)
throws java.io.IOException,
FileFormatException
java.io.IOException
FileFormatExceptionpublic void destroyMe()
public void draw(java.awt.Graphics g)
ModelCanvas.paintModel()public void transform()
CameraMan
public void translateBy(float dx,
float dy,
float dz)
public void scaleBy(float s)
public void setColor(java.awt.Color c)
public int addPolygon(float[][] vs,
java.awt.Color c,
boolean doubleSided)
public int addPolygon(float[][] vs,
java.awt.Color c)
public int addPolygon(float[][] vs)
public int addPolygon2(float[][] vs,
java.awt.Color c)
public int addPolygon2(float[][] vs)
public void addPolygonBent(float[][] ps,
java.awt.Color color,
int concaveFlag)
p3 .-------. p2
| / |
| / |
| / |
p0 .-------. p1
public static Obj3d makeCube(ModelViewer modelViewer)
public void setBB()
public float[] getEye()
getEye in interface CameraSubjectpublic float[] getFocus()
getFocus in interface CameraSubject
public int getPointIndex(int poly,
int vertex)
public void setPoint(int index,
float x,
float y,
float z)
public final float getDepthMin()
public final float getDepthMax()
public java.lang.String toString()
toString in class java.lang.Objectpublic void setNormals()
Obj3dDir.updateRotated
|
Dan Burton <danb@dircon.co.uk> | latest update: 20 Sep 2002; | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||