@Override public void draw(DrawContext dc) { _ellipsoid.draw(0,0,0,0,0,1,0,1,0,1,0,0); } @Override
private void makeUnitSphere(int m) { // Buffers for vertices of triangles used to approximate the unit sphere. // The initial octahedron has 8 triangular faces, each with 3 vertices. // Each subdivision increases the number of triangles by a factor of 4. _nv = 8*3; for (int i=0; i<m; ++i) _nv *= 4; int n = _nv*3; _xyz = new float[n]; // Compute vertices and unit normal vectors for the ellipsoid by // recursively subdividing the eight triangular faces of the // octahedron. The order of the three vertices in each triangle is // counter-clockwise as viewed from outside the ellipsoid. float xm = -1.0f, x0 = 0.0f, xp = 1.0f; float ym = -1.0f, y0 = 0.0f, yp = 1.0f; float zm = -1.0f, z0 = 0.0f, zp = 1.0f; n = 0; n = addTri(xp,y0,z0,x0,yp,z0,x0,y0,zp,m,n); n = addTri(xm,y0,z0,x0,y0,zp,x0,yp,z0,m,n); n = addTri(xp,y0,z0,x0,y0,zp,x0,ym,z0,m,n); n = addTri(xm,y0,z0,x0,ym,z0,x0,y0,zp,m,n); n = addTri(xp,y0,z0,x0,y0,zm,x0,yp,z0,m,n); n = addTri(xm,y0,z0,x0,yp,z0,x0,y0,zm,m,n); n = addTri(xp,y0,z0,x0,ym,z0,x0,y0,zm,m,n); n = addTri(xm,y0,z0,x0,y0,zm,x0,ym,z0,m,n); } private int addTri(
/** * Constructs an ellipsoid glyph with specified quality. * @param m the quality = the number of subdivisions. */ public EllipsoidGlyph(int m) { makeTransformMatrix(); makeUnitSphere(m); }
_ellipsoid = new EllipsoidGlyph(); _bs = new BoundingSphere(new BoundingBox(0,0,0,1,1,1));
public void draw(DrawContext dc) { float cx = 0.0f, cy = 0.0f, cz = 0.0f; float ux = 0.0f, uy = 0.0f, uz = _thickness; float vx = 0.0f, vy = 1.0f, vz = 0.0f; float wx = 1.0f, wy = 0.0f, wz = 0.0f; _ellipsoid.draw(cx,cy,cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); } public BoundingSphere computeBoundingSphere(boolean finite) {
/** * Draws a sphere centered at a specified point with specified radius. * @param cx x coordinate of the center point. * @param cy y coordinate of the center point. * @param cz z coordinate of the center point. * @param r radius of the sphere. */ public void draw(float cx, float cy, float cz, float r) { draw(cx,cy,cz,r,r,r); }
public void draw(DrawContext dc) { int ns = _cx.length; int nt = _cx[0].length; for (int is=0; is<ns; ++is) { for (int it=0; it<nt; ++it) { _ellipsoid.draw( _cx[is][it],_cy[is][it],_cz[is][it], _ux[is][it],_uy[is][it],_uz[is][it], _vx[is][it],_vy[is][it],_vz[is][it], _wx[is][it],_wy[is][it],_wz[is][it]); } } } public BoundingSphere computeBoundingSphere(boolean finite) {
public void draw(DrawContext dc) { float cx = 0.5f, cy = 0.5f, cz = 0.5f; float ux = 0.5f, uy = 0.0f, uz = 0.0f; float vx = 0.0f, vy = 0.1f, vz = 0.0f; float wx = 0.0f, wy = 0.0f, wz = 0.5f; _ellipsoid.draw(-cx, cy,-cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); _ellipsoid.draw( cx, cy,-cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); _ellipsoid.draw(-cx,-cy,-cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); _ellipsoid.draw( cx,-cy,-cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); _ellipsoid.draw(-cx, cy, cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); _ellipsoid.draw( cx, cy, cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); _ellipsoid.draw(-cx,-cy, cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); _ellipsoid.draw( cx,-cy, cz,ux,uy,uz,vx,vy,vz,wx,wy,wz); } public BoundingSphere computeBoundingSphere(boolean finite) {
/** * Draws an axis-aligned ellipsoid centered at a specified point. * The lengths of the specified semi-principal axes must be positive. * @param cx x coordinate of the center point. * @param cy y coordinate of the center point. * @param cz z coordinate of the center point. * @param dx semi-principal length in direction of x axis. * @param dy semi-principal length in direction of y axis. * @param dz semi-principal length in direction of z axis. */ public void draw( float cx, float cy, float cz, float dx, float dy, float dz) { glPushMatrix(); glTranslatef(cx,cy,cz); glScalef(dx,dy,dz); draw(); glPopMatrix(); }
draw(); glPopMatrix();
vx *= sv*dx; vy *= sv*dy; vz *= sv*dz; wx *= sw*dx; wy *= sw*dy; wz *= sw*dz; _eg.draw(xc,yc,zc,ux,uy,uz,vx,vy,vz,wx,wy,wz); vx *= sv*dx; vy *= sv*dy; vz *= sv*dz; wx *= sw*dx; wy *= sw*dy; wz *= sw*dz; _eg.draw(xc,yc,zc,ux,uy,uz,vx,vy,vz,wx,wy,wz); vx *= sv*dx; vy *= sv*dy; vz *= sv*dz; wx *= sw*dx; wy *= sw*dy; wz *= sw*dz; _eg.draw(xc,yc,zc,ux,uy,uz,vx,vy,vz,wx,wy,wz);