Window3D Class Documentation
| Window3D is an extension of Canvas that allows the user to draw wireframe models and view them from different orientations. The above picture is "live", try rotating the figure by dragging your mouse around... |
DOWNLOAD David Eberle's source...
HOW TO INFORMATION
1. How do I instantiate a Window3D object in my application?
If you are creating an applet, have Window3D be a class member.
public Window3D w3d;
In the init()
function of your applet class call the following functions:
w3d=new Window3D();//create instance w3d.init();//initialize w3d.setSize(300,300);//set width and height w3d.setVisible(true);//Make it visible this.add(w3d);//Add w3d to the applet w3d.makeDoubleBuffer(w3d);//Create double buffering rendering context
Note: You must add the Window3D object before
calling makeDoubleBuffer( )!
See test.java in the downloaded zip file for an example.
Note: In a standalone application things are very different.
Look at Input.java in the zip file for an example.
2. How do I get Window3D to draw my geometry?
Window3D uses the class Draw_Object
to organize and store the geometry that is
going to be displayed. If you are creating a standalone application, you
can create an instance of Draw_Object and then pass it to the
Window3D object using the
addActor(Draw_Object variable)
method.
You can create a new Draw_Object in the Window3D class itself by using
createObject()
method. This will be needed if you are not creating a
standalone application.This method returns an integer index
that identifies the object.
Note: If you want to make changes to this object or make it actually draw anything, you will need this index.
3. How do I describe the geometry via Draw_Object or Window3D?
If you used the
createObject()
method of Window3D you must also describe
the geometry using Window3D methods. The methods are described below:
addVertex(int index, double x,double y,double z);
Index is the integer that was returned when
createObject()
was called.
This identifies which object in the window you
want to add the vertex to. The other variables are the x,y,and z components
of the vertex.
Note: When adding vertices it is vital that you remember the order in which they were added!
This becomes crtical when you are creating lines and polygons.
addEdge(int index, int v1,int v2);
Again index is the integer that identifies the object you are adding the
edge to. The other two variables are the indices
of the vertices in the Draw_Object.
addPolygon(int index,Vector indices);
Index is the integer that identifies the object. Indices is a Vector of Integers. You cannot fill a Vector with variables of type int or just a number, they must be Integer objects.
setDrawMode(int index,int mode);
Index identifies the object and mode describes how to draw the object.
The options for mode are:
Describing geometry using Draw_Object
If you are passing an instance of Draw_Object
to a window, you have more options available.
The methods are listed below. All of the methods for Window3D are available
in Draw_Object.
The difference in these methods is that you don`t need to provide an index
to identify the object.
For example: To add a vertex to a Draw_Object called Mesh
Mesh.addVertex(x,y,z);
How to set the color of the geometry
Draw_Object has a Color member that can be set using the
setColor(float r,float g,float b) method.
This will cause all entities within the Draw_Object
to have this color. Draw_Object has
a public boolean member called USECOLOR.
If you set this to false then
individual edges,points,or
polygons can have individual colors. The default color for all of these
entities is red.
How to set the color of geometric entities
There is another way to create geometry with a Draw_Object
if you are in a standalone application.
Point3D, Line3D, and Poly3D
are the classes for vertices,edges, and polygons.
You can create instances
of these outside of Draw_Object and then add them with the following methods:
Point3D, Line3D, and Poly3D all have the method setColor(float r,float g,float b) . Using this you can define colors for individual geometric entities.
addVertex(Point3D v)//Add a Vertex/Point3D Object addEdge(Line3D e)//Add an Edge/Line3D object addPolygon(Poly3D new_poly)//Add an Polygon/Poly3D object
4. How can I pan and zoom the camera?
The default mode for Window3D is to do rotations when the mouse
is dragged inside the canvas.
To change modes, use the
setMode(int mode)
functon of w3d. To get the current mode of Window3D, use
getMode()
| Action | Value>
| Rotation | 1
| Pan | 2
| Zoom | 3
| |
5. How can I turn the grid and the axis on or off?
There is a coordinate axis that can be turned on or off. To control this, use the
setAxis(boolean tf)
function of Window3D. To get the current axis state, use
getAxis()
method.
6. How can I pick a vertex and move it with the mouse?
The ability to select a vertex using the mouse is availble. To do this, pick_mode needs to be set to true. Use the
setPick(boolean tf)
method to enable or disable this option.
The current status of pick_mode can be obtained by
getPick()
7. How can I create an input file of a model and have Window3D read in the geometry?
To have Window3D read a file, use the Load(String filename) function of Window3D. This assumes the file is in the current directory.
You can name the file anything
you want, but you must follow the file specification below.
Omit all comments in your actual file.
| O 1 | //O says create a new Draw_Object and the |
| //number indicates the draw_mode...in this case Wireframe | |
| v 1.2 1.3 1.4 | //Says create a vertex with the coordinates (1.2,1.3,1.4) and |
| //add it to the Draw_Object O | |
| v ... | //Enter all vertices for this object |
| e 0 1 | //Create an edge with vertex indices 0 and 1... |
| //and add it to the Draw_Object | |
| ... | |
| O 2 | //Create another draw_object with Filled_Polygon draw mode |
| v 1 2 3 | |
| ... | |
| p 0 1 2 3 ...n | //create and add polygon with indices 0 to n |
| O | //This is needed at the end of the file to |
| // indicate that the last object should be | |
| // added to the list of items to be drawn. |
The file Object.dat is in the zip file. Please refer to this if you have trouble. Be careful not to use commas and make sure each line ends with a new line.