Projects

PHP Data Pivot
PHP Data Subtotals
HTML5 Graph
Java NW3D2
JS Code Formatter
HTML5 Clock
Silverlight Gauge
Java NW3D
Java Fireworks
Java Early 3D
Java Snow
Java Dogfight
Java Water Simulation
Java Bump Mapping
Java Elite Ships

NW3D - Use of lathe and path objects

This applet demonstrates the use of lathe and path objects from within the objectfactory class. Demo first, explanation afterward.

No Java Support.

The path class is used to store a series of x/y coordinates that can be joined in sequence to form a 2D outline. The lathe class takes a path and rotates it through 360 degrees around the y-axis to form a solid 3D object. Texture coordinates are calculated and a user-specified material applied. There is also a parameter to control whether multiple vertices with the same coordinates are considered to be the same, for the purposes of the shading algorithm. The torus in the above demo has this set to 'true' and as you can see this as the effect of creating a far smoother finish.

Going back a step, let's look firstly at how the cylinder was created. The instructions within the applet look like this:-

  nw3d_material col2 = new nw3d_material(0.1f,0.7f,0.4f,20);
  nw3d_path path3 = new nw3d_path(new float[] {0,3,1,3,1,-3,0,-3});
  scene.addObj(nw3d_objectfactory.LatheObject(path3, 20, col2, false));
The first line creates a new greenish material, 'col2'. The second line creates a new path object comprising the 4 x/y coordinates necessary to define the cylinder. The third line uses the path object form the previous instruction as an input to create a new geometry. A quick note on the parameters: they are the path, the number of segments, the material to use, and the flag described above that denotes smooth shading. A higher number of segments creates a more detailed model. The coordinates can be visualised as follows:-

Similarly, the spinning top is defined as follows:-

  nw3d_material col1 = new nw3d_material(0.7f,0.1f,1.0f,30);
  nw3d_path path = new nw3d_path(new float[] {0,3,0.5f,3,0.5f,2.5f,4,1.5f,4,1.4f,1,0,0,-3});
  scene.addObj(nw3d_objectfactory.LatheObject(path, 20, col1, false));
You'll notice that the main difference is additional coordinates, 7 in total, giving a spinning top shape:-

The torus (donut) object is created by firstly plotting a circular cross-section, which is then swept around the y-axis to form a solid geometry. Here's the code:-

  nw3d_path path2 = nw3d_objectfactory.CirclePath(1,40);
  path2.translate(2.7f,0);
  scene.addObj(nw3d_objectfactory.LatheObject(path2, 40, checker, true));
As with the previous examples a path is created though this time the coordinates are not user-supplied, instead a 'CirclePath' method does the work. The two parameters are the radius of the circle and number of points to divide the circle into. The path is x/y zero-centered. If we passed it to the LatheObject method as it stands we would generate a sphere. So instead, we translate it along the x-axis first.

Back to NW3D index