Use a parametric surface factory

From JReality Wiki
Jump to: navigation, search

Source file: ParametricSurfaceExample

JavaDoc: ParametricSurfaceFactory


Run as Java webstart


This tutorial assumes that you know how to display a geometry.


Suppose we want to display the parametrized surface <math>(u,v)\mapsto (u-v^2, uv, u^2-4uv^2)</math> (a so called swallowtail singularity).


For this task jReality provides the factory de.jreality.geometry.ParametricSurfaceFactory.


To make our formula available to the ParametricSurfaceFactory we implement the interface ParametricSurfaceFactory.Immersion


public class Swallowtail implements Immersion {
	public void evaluate(double u, double v, double[] xyz, int index) {
		xyz[index]=(u-v*v);
		xyz[index+1]=u*v;
		xyz[index+2]=(u*u-4*u*v*v);
	}
	public int getDimensionOfAmbientSpace() { return 3;	}
	public boolean isImmutable() { return true; }
}


Then we instantiate a ParametricSurfaceFactory with this immersion,


ParametricSurfaceFactory psf = new ParametricSurfaceFactory(new Swallowtail());


set some parameters,


psf.setUMin(-.3);psf.setUMax(.3);psf.setVMin(-.4);psf.setVMax(.4);
psf.setULineCount(20);psf.setVLineCount(20); 
psf.setGenerateEdgesFromFaces(true);
psf.setGenerateVertexNormals(true);


and tell the ParametricSurfaceFactory to update the geometry,


psf.update();


which we may access through ParametricSurfaceFactor.getIndexedFaceSet().


Changing parameters of the ParametricSurfaceFactory and updating the geometry through ParametricSurfaceFactory.update() changes the object provided by ParametricSurfaceFactor.getIndexedFaceSet() rather than creating a new one. In particular, the image in the viewer will change immediately.


Screenshot, showing the example run with the useViewerVR flag set to true.


Swallowtail.png


Previous: Use a quad mesh factory Developer Tutorial: Contents Next: Use a tube factory