opengl - Clipping a sphere -
had asked question here: drawing portion of hemisphere airspace
probably more gis have moved more basic , specific implementation in opengl desired output.
i have overridden/copied functions drawing hemisphere , altering gl part insert clipping. able draw hemisphere centred @ location (latitude,longitude) , radius may 2000. when cut using plane nothing happens. please check equation of plane(its plane parallel surface of globe @ height may 1000, (0,0,+1,1000))
the base class has drawunitsphere might causing problems trying use gl's glusphere(). can't see sphere on globe. used translate shift location(lat/lon) still can't see it. might issues lat/lon , cartesian coordinates, or placing of clipping code. please check.
here code:
@override public void drawsphere(drawcontext dc) { double[] altitudes = this.getaltitudes(dc.getverticalexaggeration()); boolean[] terrainconformant = this.isterrainconforming(); int subdivisions = this.getsubdivisions(); if (this.isenablelevelofdetail()) { detaillevel level = this.computedetaillevel(dc); object o = level.getvalue(subdivisions); if (o != null && o instanceof integer) subdivisions = (integer) o; } vec4 centerpoint = this.computepointfromposition(dc, this.location.getlatitude(), this.location.getlongitude(), altitudes[0], terrainconformant[0]); matrix modelview = dc.getview().getmodelviewmatrix(); modelview = modelview.multiply(matrix.fromtranslation(centerpoint)); modelview = modelview.multiply(matrix.fromscale(this.getradius())); double[] matrixarray = new double[16]; modelview.toarray(matrixarray, 0, false); this.setexpirytime(-1l); // sphere geometry never expires. gl gl = dc.getgl(); // gl initialization checks gl2 compatibility. gl.glpushattrib(gl.gl_polygon_bit | gl.gl_transform_bit); try { gl.glenable(gl.gl_cull_face); gl.glfrontface(gl.gl_ccw); // applying scale transform on modelview matrix, normal vectors must re-normalized // before lighting computed. in case we're scaling constant factor, gl_rescale_normal // sufficient , potentially less expensive gl_normalize (or computing unique normal vectors // each value of radius). gl_rescale_normal introduced in opengl version 1.2. gl.glenable(gl.gl_rescale_normal); gl.glmatrixmode(gl.gl_modelview); gl.glpushmatrix(); //clipping doublebuffer eqn1 = bufferutils.createdoublebuffer(8).put(new double[] {0, 0, 1, 100}); eqn1.flip(); gl.glclipplane(gl.gl_clip_plane0, eqn1); gl.glenable(gl.gl_clip_plane0); try { gl.glloadmatrixd(matrixarray, 0); //this.drawunitsphere(dc, subdivisions); gl.glloadidentity(); gl.gltranslatef(75.2f, 32.5f, 0.0f); gl.glcolor3f(1.0f, 0.0f, 0.0f); glu glu = dc.getglu(); gluquadric qd=glu.glunewquadric(); glu.glusphere(qd,3.0f,20,20); } { gl.glpopmatrix(); } } { gl.glpopattrib(); } } @override public void drawunitsphere(drawcontext dc, int subdivisions) { object cachekey = new geometry.cachekey(this.getclass(), "sphere", subdivisions); geometry geom = (geometry) this.getgeometrycache().getobject(cachekey); if (geom == null || this.isexpired(dc, geom)) { if (geom == null) geom = new geometry(); this.makesphere(1.0, subdivisions, geom); this.updateexpirycriteria(dc, geom); this.getgeometrycache().add(cachekey, geom); } this.getrenderer().drawgeometry(dc, geom); } @override public void makesphere(double radius, int subdivisions, geometry dest) { geometrybuilder gb = this.getgeometrybuilder(); gb.setorientation(geometrybuilder.outside); geometrybuilder.indexedtrianglearray ita = gb.tessellatesphere((float) radius, subdivisions); float[] normalarray = new float[3 * ita.getvertexcount()]; gb.makeindexedtrianglearraynormals(ita, normalarray); dest.setelementdata(gl.gl_triangles, ita.getindexcount(), ita.getindices()); dest.setvertexdata(ita.getvertexcount(), ita.getvertices()); dest.setnormaldata(ita.getvertexcount(), normalarray); }
Comments
Post a Comment