/** * Constructs a 3D Plane. The location of the plane is determined by <code>distance</code>, the * minimal distance of the plane from the origin. * * @param distance the distance of the plane from the origin * @param normal The (direction of the) unit normal vector */ public Plane3D(double distance, Point3D normal) { this.distance = distance; this.normal = normal.norm(); if (distance < 0.0) { throw new IllegalArgumentException("Cant work with negative distance!"); } }
private void loadAndDecode() { // LOAD 3DS FILE this.setAction(IProgressListener.ACTION_FILE_DOWNLOAD); ProgressListener pl = new ProgressListener(); IOManagerAsynch aLoader = new IOManagerAsynch(); aLoader.downloadData(this.baseURL + this.fileName, getClass(), null, pl, false); while (aLoader.running || !pl.getFinished()) { this.setProgress((50 * (pl.getProgress()) / pl.getMaximumProgress())); try { Thread.sleep(5); } catch (InterruptedException ie) { pl.setFinished(true); pl.setError(true); return; } } this.data = aLoader.getData(); if (pl.getError() || this.data == null) { this.setError(true); this.setFinished(true); return; } // DECODE 3DS FILE this.input = new ByteArrayInputStream(this.data); this.setProgress(50); this.setAction(IProgressListener.ACTION_FILE_DECOMPRESS); int offset = 0; while (offset < data.length) offset += decodeChunk(0); // CREATE SCENE FROM LOADED SCENE (INIT WITH KEYFRAME IF AVAILABLE) objets3D = new Scene3DObject[nbObjet + 1]; objets3D[0] = new Mesh3D(); objets3D[0].setName(this.fileName); double zx = 1; double zy = 1; double zz = 1; for (int nbo = 0; nbo < nbObjet; nbo++) { cObjet = tObjets3D[nbo]; objets3D[nbo + 1] = cObjet; Axis3D cAxe = cObjet.axes; Point3D o = cAxe.origine; Point3D ax = cAxe.axeX; Point3D ay = cAxe.axeY; Point3D az = cAxe.axeZ; // READ ZOOM FROM AXIS zx = ax.norm(); zy = ay.norm(); zz = az.norm(); ax.add(o); ay.add(o); az.add(o); // if(cObjet instanceof Camera3D) // System.out.println(cObjet.getPosition().toString()); // NORMALIZE AXIS cAxe.normalize(); if (cObjet instanceof Mesh3D) { Point3D vertex[] = ((Mesh3D) cObjet).vertices3D; for (int np = 0; np < vertex.length; np++) vertex[np].toLocalAxe(cAxe).zoom(1.0 / zx, 1.0 / zy, 1.0 / zz); } ax.sub(o); ay.sub(o); az.sub(o); // KEEP AXZ (TO KNOW IF ZOOM NEGATIVE) Point3D axz = new Point3D(); axz.copy(ax).cross(ay); // IF ZOOM NEGATIVE INVERT ALL AXIS AND FLIP OBJECT'S FACES NORMALS if (az.dot(axz) < 0.0) { ax.mul(-1.0); ay.mul(-1.0); az.mul(-1.0); zx = -zx; zy = -zy; zz = -zz; } ax.add(o); ay.add(o); az.add(o); // SET OBJECT ROTATION AND PIVOT FROM AXIS cObjet.axes.getPosition(cObjet.position); cObjet.axes.getRotationXZY(cObjet.rotation); // SET OBJECT ZOOM cObjet.zoom.set(zx, zy, zz); } // SET OBJECT AXIS IN WORLD SPACE WITH PIVOT,POSITION,ROTATION for (int nbo = 1; nbo < objets3D.length; nbo++) { cObjet = objets3D[nbo]; cObjet.axes.init(); cObjet.axes.set(cObjet.pivot, cObjet.position, cObjet.rotation); } // UPDATE OBJECT HIERARCHY for (int nbo = 1; nbo < objets3D.length; nbo++) { cObjet = objets3D[nbo]; if (cObjet.parent == null) cObjet.parent = objets3D[0]; cObjet.setParent(cObjet.parent); } // UPDATE OBJECT FOR HIERARCHY NEW for (int nbo = 1; nbo < objets3D.length; nbo++) { cObjet = objets3D[nbo]; // cObjet.axes.push(); IAxis3D a = DzzD.newAxis3D(); a.copy(cObjet.axes); if (cObjet.parent == null) cObjet.parent = objets3D[0]; cObjet.toLocalAxe(cObjet.parent.axes); // if(cObjet.parent instanceof ICamera3D) // cObjet.axes.pop(); cObjet.axes.copy(a); } try { // UPDATE ALL OBJECT WITH FIRST KEYFRAMER KEY if (this.isKeyFrame) { for (int nbo = 1; nbo < objets3D.length; nbo++) { cObjet = objets3D[nbo]; if (cObjet.id == -1) continue; IAxis3D a = DzzD.newAxis3D(); a.copy(cObjet.axes); // cObjet.axes.push(); Point3D rot = this.key3DRotAxe[cObjet.id]; if (rot != null) { double rota = this.key3DRotAng[cObjet.id]; cObjet.axes.init(); cObjet.axes.rotate(rota, -rot.x, -rot.y, -rot.z); cObjet.axes.getRotationXZY(cObjet.rotation); // cObjet.axes.pop(); cObjet.axes.copy(a); } Point3D trans = this.key3DTrans[cObjet.id]; if (trans != null) { cObjet.position.set(trans.x, trans.y, trans.z); if (cObjet.parent != null) cObjet.position.add(cObjet.parent.pivot); } Point3D zoom = this.key3DZoom[cObjet.id]; if (zoom != null) { cObjet.zoom.set(zoom.x, zoom.y, zoom.z); } cObjet.axes.copy(a); // cObjet.axes.pop(); } } // Add animator to object for (int nbo = 1; nbo < objets3D.length; nbo++) { cObjet = objets3D[nbo]; if (cObjet.id == -1) continue; if (this.animators[cObjet.id] != null) cObjet.setScene3DObjectAnimator(this.animators[cObjet.id]); } } catch (ArrayIndexOutOfBoundsException aioobe) { Log.log(aioobe); } catch (NullPointerException npe) { Log.log(npe); } for (int nbo = 1; nbo < objets3D.length; nbo++) { cObjet = objets3D[nbo]; Point3D zoom = cObjet.zoom; cObjet.zoom(zoom.x, zoom.y, zoom.z); } this.setFinished(true); this.setProgress(100); return; }