Skip to main content

setCoordinates for QuadArray throwing NullPointer

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
8 replies [Last post]
okelly4408
Offline
Joined: 2012-08-12

When I attempt to set coordinates with my quadarray with a point3f[] array with the following: quad.setCoordinates(0,array); a nullpointerexception is returned. When I add the following arguments quad.setCoordinates(0,array,0,array.length); a nullpointer is still returned and when I change that to array.length-1 it works. Here is the code for the class where .setCoordinates is used, if any more code is required please ask. Thanks for any help!

import javax.media.j3d.Appearance;
import javax.media.j3d.GeometryArray;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.QuadArray;
import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.Stripifier;


public class Landscape extends Shape3D {

private  QuadArray plane;
public Landscape( Point3f[] pointarray, Color3f cols){

  
int vert = pointarray.length;
System.out.println(vert+"+");
    plane = new QuadArray(vert, GeometryArray.COORDINATES| GeometryArray.COLOR_3);
    plane.setCoordinates(0,pointarray,0,pointarray.length-1);
//plane.setColors(0,cols);
GeometryInfo geo = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
geo.setCoordinates(pointarray);
    Stripifier triangler = new Stripifier();
    triangler.stripify(geo);
    setGeometry(plane);
    appearance();
}
private  void appearance(){
PolygonAttributes pa = new PolygonAttributes();
Appearance app = new Appearance();
pa.setCullFace(PolygonAttributes.CULL_NONE);
pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
app.setPolygonAttributes(pa);

}

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
interactivemesh
Offline
Joined: 2006-06-07

The printed NPE's stack trace would be helpful.
Is pointarray[ pointarray.length-1 ] != null ?
The Stripifier 'triangle' doesn't seem to have an effect on the QuadArray 'pane'.

August

okelly4408
Offline
Joined: 2012-08-12

Well I fixed it so that setCoordinates(0, array) does not throw any errors and I applied the stripifier class to the quadarray but now when I run it instead of a nicely wire mesh drawn landscape being displayed an abstract-like picture of floating square and rectangles is shown. Any ideas as to why this is happening? Picture of what it looks like:

interactivemesh
Offline
Joined: 2006-06-07

If GeometryInfo is used then your QuadArray is unnecessary.
Supposed your 'pointarray' represents a landscape correctly following code should create a wire mesh:

GeometryInfo geo = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
geo.setCoordinates(pointarray);
Stripifier triangler = new Stripifier();
triangler.stripify(geo);
setGeometry(geo.getGeometryArray());
// or
// setGeometry(geo.getIndexedGeometryArray(false, false, false, true, false));

Add a ColoringAttributes with the desired color to your Appearance for unlit coloring of your wire mesh.

okelly4408
Offline
Joined: 2012-08-12

Everything is fixed now...Forgot to setAppearance (facepalm) thank you very much for your help:
Looks bad but more fiddling will hopefully yield a nicer land

okelly4408
Offline
Joined: 2012-08-12

OK! After looking at that array code I noticed I was being stupid and adjusted it so that each vertice on the quad had it's own y coordinates like so (if you are interested):

float y1 = nf.Fractal((xD * seed), ((zD * seed)));
float y2 = nf.Fractal((xD+1 * seed), ((zD * seed)));
float y3 = nf.Fractal((xD+1 * seed), ((zD+1 * seed)));
float y4 = nf.Fractal((xD * seed), ((zD+1 * seed)));
p1 = new Point3f(x,y1,z);
p2 = new Point3f(x+1,y2,z);
p3 = new Point3f(x+1,y3,z+1);
p4 = new Point3f(x,y4,z+1);

and this gave me...: This
So now my problem is that the polygon attribute line setting is not being applied for some reason. Which is sort of bad because until I get my lighting set up I won't really be able to see anything... So why could this be?

okelly4408
Offline
Joined: 2012-08-12

OK! After looking at that array code I noticed I was being stupid and adjusted it so that each vertice on the quad had it's own y coordinates like so (if you are interested):

float y1 = nf.Fractal((xD * seed), ((zD * seed)));
float y2 = nf.Fractal((xD+1 * seed), ((zD * seed)));
float y3 = nf.Fractal((xD+1 * seed), ((zD+1 * seed)));
float y4 = nf.Fractal((xD * seed), ((zD+1 * seed)));
p1 = new Point3f(x,y1,z);
p2 = new Point3f(x+1,y2,z);
p3 = new Point3f(x+1,y3,z+1);
p4 = new Point3f(x,y4,z+1);

and this gave me...: This
So now my problem is that the polygon attribute line setting is not being applied for some reason. Which is sort of bad because until I get my lighting set up I won't really be able to see anything... So why could this be?

okelly4408
Offline
Joined: 2012-08-12

Following the above code gives me the same image that I showed you above. I don't understand why the quads are not connected to each other...Could this have something to do with the way the array is constructed? This is the code that actually sets up the array (minus the algorithm which generates the y values but I think that is irrelevant)

ArrayList<Point3f> array = new ArrayList<Point3f>();
Point3f p1;
Point3f p2;
Point3f p3;
Point3f p4;
for(int i = 0; i<length; i++){
for(int ii = 0; ii<length; ii++){
float x = (float)i;
float z = (float)ii;
double xD = (double)x;
double zD = (double)z;
float y = nf.Fractal((xD * seed), ((zD * seed)));
p1 = new Point3f(x,y,z);
p2 = new Point3f(x+1,y,z);
p3 = new Point3f(x+1,y,z+1);
p4 = new Point3f(x,y,z+1);
array.add(p1);
array.add(p2);
array.add(p3);
array.add(p4);

Thanks for all your help so far

okelly4408
Offline
Joined: 2012-08-12

Sorry repeat