ThreeD.java revision 0
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved.
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * Redistribution and use in source and binary forms, with or without
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * modification, are permitted provided that the following conditions
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * - Redistributions of source code must retain the above copyright
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * notice, this list of conditions and the following disclaimer.
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * - Redistributions in binary form must reproduce the above copyright
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * notice, this list of conditions and the following disclaimer in the
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * documentation and/or other materials provided with the distribution.
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * - Neither the name of Sun Microsystems nor the names of its
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * contributors may be used to endorse or promote products derived
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * from this software without specific prior written permission.
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
65e99be301d5a19db33f25841f671756e8dbb9b5ludovicp * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
a5b9f8fb834b1b2208e59a2fa76714bd91a5f147violette * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara/* A set of classes to parse, represent and display 3D wireframe models
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara represented in Wavefront .obj format. */
class Model3D {
float vert[];
int tvert[];
int con[];
boolean transformed;
Model3D () {
scan:
break scan;
addVert((float) x, (float) y, (float) z);
start = n;
prev = n;
break scan;
int addVert(float x, float y, float z) {
int i = nvert;
if (i >= maxvert)
vert[i] = x;
return nvert++;
int i = ncon;
if (i >= maxcon)
int t = p1;
p2 = t;
void transform() {
transformed = true;
int partionElement;
++leftIndex;
--rightIndex;
++leftIndex;
--rightIndex;
private void swap(int a[], int i, int j)
void compress() {
int c[] = con;
int p1 = c[i];
c[d] = p1;
ncon = d;
transform();
int c[] = con;
int v[] = tvert;
void findBB() {
float v[] = vert;
if (x < xmin)
xmin = x;
if (x > xmax)
xmax = x;
if (y < ymin)
ymin = y;
if (y > ymax)
ymax = y;
if (z < zmin)
zmin = z;
if (z > zmax)
zmax = z;
boolean painted = true;
float xfac;
public void init() {
}catch(Exception e){};
addMouseListener(this);
addMouseMotionListener(this);
public void destroy() {
removeMouseListener(this);
removeMouseMotionListener(this);
public void run() {
md = m;
m.findBB();
m.compress();
} catch(Exception e) {
} catch(Exception e) {
repaint();
public void start() {
public void stop() {
e.consume();
int x = e.getX();
int y = e.getY();
if (painted) {
painted = false;
repaint();
prevx = x;
prevy = y;
e.consume();
setPainted();
private synchronized void setPainted() {
painted = true;
notifyAll();
return info;