Example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D toArray

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D toArray

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D toArray.

Prototype

public double[] toArray() 

Source Link

Document

Get the vector coordinates as a dimension 3 array.

Usage

From source file:org.jtrfp.trcl.beh.AutoFiring.java

@Override
public void _tick(long timeMillis) {
    final WorldObject thisObject = getParent();
    final Player player = thisObject.getTr().getGame().getPlayer();
    if (player.getBehavior().probeForBehavior(Cloakable.class).isCloaked())
        return;/*from ww w. jav  a 2 s  .c o  m*/
    final double[] thisPos = thisObject.getPosition();
    final double[] playerPos = player.getPosition();
    final double dist = Vect3D.distance(thisPos, playerPos);
    if (dist < maxFiringDistance || dist > minFiringDistance) {
        final int patIndex = (int) (((timeMillis + patternOffsetMillis) % totalFiringPatternTimeMillis)
                / timePerPatternEntry);
        if (patIndex != lastIndexVisited) {//end if(lastVisited)
            if (firingPattern[patIndex]) {
                Vector3D result;
                if (smartFiring) {
                    final Vector3D playerVelocity = player.getBehavior().probeForBehavior(Velocible.class)
                            .getVelocity();
                    final double projectileSpeed = projectileFiringBehavior.getProjectileFactory().getWeapon()
                            .getSpeed() / TR.crossPlatformScalar;
                    Vector3D virtualPlayerPos = interceptOf(new Vector3D(playerPos), playerVelocity,
                            new Vector3D(thisPos), projectileSpeed);
                    if (virtualPlayerPos == null)
                        virtualPlayerPos = new Vector3D(playerPos);
                    Vect3D.subtract(virtualPlayerPos.toArray(), thisPos, firingVector);
                } else {
                    Vect3D.subtract(playerPos, thisPos, firingVector);
                }
                result = new Vector3D(Vect3D.normalize(firingVector, firingVector));
                final double[] objectHeading = thisObject.getHeadingArray();
                Vect3D.subtract(objectHeading, result.toArray(), headingDelta);
                if (Vect3D.norm(headingDelta) > maxFireVectorDeviation)
                    return;
                if (berzerk)
                    result = new Vector3D(Math.random(), Math.random(), Math.random()).normalize();
                Vector3D rand = new Vector3D((Math.random() * 2. - 1.) * aimRandomness,
                        (Math.random() * 2. - 1.) * aimRandomness, (Math.random() * 2. - 1.) * aimRandomness);
                result = result.add(rand).normalize();
                projectileFiringBehavior.requestFire(result);
            }
        }
        lastIndexVisited = patIndex;
    } //end in range
}

From source file:org.jtrfp.trcl.beh.ExplodesOnDeath.java

@Override
public synchronized void notifyDeath() {
    final WorldObject p = getParent();
    final TR tr = p.getTr();
    final Vector3D loc = p.probeForBehavior(DeathBehavior.class).getLocationOfLastDeath();
    tr.getResourceManager().getExplosionFactory().triggerExplosion(loc, type);
    String explosionSound = this.explosionSound;
    if (explosionSound != null)
        tr.soundSystem.get()/*from w  w  w. j a v  a  2s.  co m*/
                .enqueuePlaybackEvent(tr.soundSystem.get().getPlaybackFactory().create(
                        tr.getResourceManager().soundTextures.get(explosionSound), loc.toArray(),
                        tr.mainRenderer.get().getCamera(), SoundSystem.DEFAULT_SFX_VOLUME * 2));
}

From source file:org.jtrfp.trcl.beh.HorizAimAtPlayerBehavior.java

@Override
public void _tick(long timeInMillis) {
    if (chaseTarget != null) {
        WorldObject thisObject = getParent();
        final Player player = thisObject.getTr().getGame().getPlayer();
        if (player.getBehavior().probeForBehavior(Cloakable.class).isCloaked())
            return;
        final RotationalMomentumBehavior rmb = thisObject.getBehavior()
                .probeForBehavior(RotationalMomentumBehavior.class);

        assert !Vect3D.isAnyEqual(chaseTarget.getPosition(), Double.POSITIVE_INFINITY);
        assert !Vect3D.isAnyEqual(thisObject.getPosition(), Double.NEGATIVE_INFINITY);
        TR.twosComplimentSubtract(chaseTarget.getPosition(), thisObject.getPosition(), vectorToTargetVar);
        assert !Vect3D.isAnyNaN(vectorToTargetVar);
        assert !Vect3D.isAnyEqual(vectorToTargetVar, Double.POSITIVE_INFINITY);
        assert !Vect3D.isAnyEqual(vectorToTargetVar, Double.NEGATIVE_INFINITY);
        vectorToTargetVar[1] = 0;//from  ww  w . ja v a 2s.  c  o m
        Vect3D.normalize(vectorToTargetVar, vectorToTargetVar);
        final Vector3D thisHeading = new Vector3D(thisObject.getHeading().getX(), 0,
                thisObject.getHeading().getZ()).normalize();
        Vect3D.subtract(thisHeading.toArray(), vectorToTargetVar, headingVarianceDelta);
        if (Math.sqrt(headingVarianceDelta[2] * headingVarianceDelta[2]
                + headingVarianceDelta[0] * headingVarianceDelta[0]) < hysteresis)
            return;
        if (!reverse)
            Vect3D.negate(vectorToTargetVar);
        Rotation rot = new Rotation(new Vector3D(vectorToTargetVar), thisHeading);
        final Vector3D deltaVector = rot.applyTo(Vector3D.PLUS_K);
        if ((deltaVector.getZ() > 0 || deltaVector.getX() < 0) == leftHanded) {
            rmb.accellerateEquatorialMomentum(-equatorialAccelleration);
        } else {
            rmb.accellerateEquatorialMomentum(equatorialAccelleration);
        }
    } //end if(target!null)
}

From source file:org.jtrfp.trcl.beh.ProjectileFiringBehavior.java

@Override
public void _tick(long tickTimeMillis) {
    if (tickTimeMillis > timeWhenNextFiringPermittedMillis && pendingFiring) {
        if (takeAmmo()) {
            final WorldObject p = getParent();
            Vector3D heading = this.firingHeading;
            if (this.firingHeading == null)
                heading = p.getHeading();
            for (int mi = 0; mi < multiplexLevel; mi++) {
                final Vector3D firingPosition = new Rotation(Vector3D.PLUS_K, Vector3D.PLUS_J, heading,
                        p.getTop()).applyTo(getNextFiringPosition());
                resetFiringTimer();/*from  w w w . ja v a 2  s .  c om*/
                projectileFactory.fire(
                        Vect3D.add(p.getPositionWithOffset(), firingPosition.toArray(), new double[3]), heading,
                        getParent());
            } //for(multiplex)
            heading = p.getHeading();
        } //end if(ammo)
        pendingFiring = false;
    } //end timeWhenNextfiringPermitted
}

From source file:org.jtrfp.trcl.obj.Debris.java

public void reset(Vector3D pos, Vector3D newVelocity) {
    getBehavior().probeForBehavior(LimitedLifeSpan.class).reset(lifespan());
    setHeading(newVelocity.normalize());
    setPosition(pos.toArray());
    setVisible(true);/*w ww .j ava 2  s . co  m*/
    setActive(true);
    getBehavior().probeForBehavior(RotationalMomentumBehavior.class).setEquatorialMomentum(.2 * Math.random())
            .setLateralMomentum(.2 * Math.random()).setPolarMomentum(.2 * Math.random());
    getBehavior().probeForBehavior(Velocible.class).setVelocity(newVelocity);
    getBehavior().probeForBehavior(DeathBehavior.class).reset();
}

From source file:org.jtrfp.trcl.obj.SmokeSystem.java

public Smoke triggerSmoke(Vector3D pos, SmokeType type) {
    if (!isNewSmokeFeasible(pos, type))
        return null;
    indices[type.ordinal()]++;/*from www. j  a v  a 2s  .  c o m*/
    indices[type.ordinal()] %= MAX_SMOKE_PER_POOL;
    Smoke result = allSmokes[type.ordinal()][indices[type.ordinal()]];
    result.destroy();
    result.reset();
    result.setPosition(pos.toArray());
    add(result);
    return result;
}

From source file:org.jtrfp.trcl.Tunnel.java

private Vector3D buildTunnel(TDFFile.Tunnel _tun, Vector3D groundVector, boolean entrance)
        throws IllegalAccessException, UnrecognizedFormatException, FileNotFoundException, FileLoadException,
        IOException {/*  w  w w .ja va2s. c  o m*/
    // Entrance uses only a stub. Player is warped to TUNNEL_POS facing
    // TUNNEL_START_DIRECTION
    ResourceManager rm = tr.getResourceManager();
    LVLFile tlvl = rm.getLVL(_tun.getTunnelLVLFile());
    final ColorPaletteVectorList tunnelColorPalette = new ColorPaletteVectorList(
            tr.getResourceManager().getPalette(lvl.getGlobalPaletteFile()));
    TextureDescription[] tunnelTexturePalette = rm.getTextures(tlvl.getLevelTextureListFile(), paletteVL,
            ESTuTvPalette, true);
    TNLFile tun = tr.getResourceManager().getTNLData(tlvl.getHeightMapOrTunnelFile());

    final double segLen = 65536;
    final double bendiness = 18;
    List<Segment> segs = tun.getSegments();
    final LoadingProgressReporter[] reporters = tunnelAssemblyReporter.generateSubReporters(segs.size());
    // Vector3D tunnelEnd = TUNNEL_START_POS;
    Rotation rotation = entrance ? new Rotation(new Vector3D(0, 0, 1), groundVector)
            : new Rotation(new Vector3D(0, 0, 1), new Vector3D(1, 0, 0));
    Vector3D startPoint = TUNNEL_START_POS;

    Vector3D segPos = Vector3D.ZERO;

    final Vector3D top = rotation.applyTo(new Vector3D(0, 1, 0));
    /*
    if (entrance) {
        // Entrance is just a stub so we only need a few of the segments
        List<Segment> newSegs = new ArrayList<Segment>();
        for (int i = 0; i < 10; i++) {
       newSegs.add(segs.get(i));
        }
        segs = newSegs;
    }*/
    // CONSTRUCT AND INSTALL SEGMENTS
    int segIndex = 0;
    Vector3D finalPos = TUNNEL_START_POS;
    for (Segment s : segs) {
        reporters[segIndex].complete();
        tr.getReporter().report(
                "org.jtrfp.trcl.Tunnel." + _tun.getTunnelLVLFile() + ".segment" + (segIndex++) + "",
                s.getObstacle().name());
        // Figure out the space the segment will take
        Vector3D positionDelta = new Vector3D((double) (s.getEndX() - s.getStartX()) * bendiness * -1,
                (double) (s.getEndY() - s.getStartY()) * bendiness, segLen);
        // Create the segment
        Vector3D position = startPoint.add(rotation.applyTo(segPos));
        TunnelSegment ts = new TunnelSegment(tr, s, tunnelTexturePalette, segLen, positionDelta.getX(),
                positionDelta.getY());
        ts.setPosition(position.toArray());
        ts.setHeading(entrance ? groundVector : Vector3D.PLUS_I);
        ts.setTop(entrance ? top : Vector3D.PLUS_J);
        // Install the segment
        add(ts);
        installObstacles(s, tunnelColorPalette, ESTuTvPalette, tunnelTexturePalette,
                entrance ? groundVector : Vector3D.PLUS_I, entrance ? top : Vector3D.PLUS_J, position,
                TR.legacy2Modern(s.getStartWidth() * TunnelSegment.TUNNEL_DIA_SCALAR),
                TR.legacy2Modern(s.getStartWidth() * TunnelSegment.TUNNEL_DIA_SCALAR), tr);
        // Move origin to next segment
        segPos = segPos.add(positionDelta);
        finalPos = position;
    } // end for(segments)
    return finalPos;
}

From source file:org.jtrfp.trcl.Tunnel.java

/**
 * Tunnel items: FANBODY.BIN - fan IRIS.BIN - animated iris BEAM.BIN /
 * PIPE.BIN JAW1.BIN (right) JAW2.BIN (left) - jaws ELECTRI[0-3].RAW - force
 * field TP1.RAW - good enough for blastable door?
 * /*ww w .  j a v a 2s .c o  m*/
 * @throws IOException
 * @throws FileLoadException
 * 
 * 
 */

private void installObstacles(Segment s, ColorPaletteVectorList tunnelColorPalette,
        ColorPaletteVectorList ESTuTvPalette, TextureDescription[] tunnelTexturePalette, Vector3D heading,
        Vector3D top, Vector3D wPos, double width, double height, TR tr)
        throws IllegalAccessException, FileLoadException, IOException {
    final ColorPaletteVectorList palette = tr.getGlobalPaletteVL();
    Obstacle obs = s.getObstacle();
    WorldObject wo;
    Model m;
    switch (obs) {
    case none0:
        break;
    case doorway: {
        m = Model.buildCube(tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 1, 1, tr);
        wo = new WorldObject(tr, m);
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        add(wo);
        break;
    }
    case closedDoor: {
        BarrierCube bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 0, 1, false);
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.addBehavior(new DamageableBehavior().setHealth(4096));
        bc.addBehavior(new ExplodesOnDeath(ExplosionType.Blast));
        bc.addBehavior(new DeathBehavior());
        bc.addBehavior(new DebrisOnDeathBehavior());
        bc.addBehavior(new DestructibleWallBehavior());
        bc.setTop(top);
        add(bc);
        break;
    }
    case blownOpenDoor://TODO: This is not displaying alpha
        BarrierCube bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, .5, .5, 1, 1, true);
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        add(bc);
        break;
    case movingWallLeft: {
        Vector3D endPos = wPos.add(heading.crossProduct(top).scalarMultiply(tunnelDia));
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case movingWallRight: {
        Vector3D endPos = wPos.subtract(heading.crossProduct(top).scalarMultiply(tunnelDia));
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos));
        bc.addBehavior(new CubeCollisionBehavior(bc));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case movingWallDown: {
        Vector3D endPos = wPos.subtract(top.scalarMultiply(tunnelDia));
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case movingWallUp: {
        Vector3D endPos = wPos.add(top.scalarMultiply(tunnelDia));
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.addBehavior(new ShiftingObjectBehavior(3000, wPos, endPos));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case wallLeftSTUB:
    case wallLeft:
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0., tunnelDia / 2., 0 },
                false);
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    case wallRightSTUB:
    case wallRight:
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia, tunnelDia / 2., 0 }, false);
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    case wallDownSTUB:
    case wallDown:
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.setPosition((wPos.subtract(top.scalarMultiply(tunnelDia / 2))).toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    case wallUpSTUB:
    case wallUp:
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()],
                new double[] { tunnelDia / 2., tunnelDia / 2., 0 }, false);
        bc.setPosition((wPos.add(top.scalarMultiply(tunnelDia / 2))).toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    case rotatingHalfWall: {
        final double rotPeriod = 32768. / (double) s.getRotationSpeed();
        final boolean rotate = !Double.isInfinite(rotPeriod);

        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 0 },
                false);
        if (rotate) {
            bc.addBehavior(new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.), 0));
            bc.setTop(top);
        } else
            bc.setTop(new Rotation(heading, Math.PI + Math.PI / 2).applyTo(top));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.setTop(top);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case rotating34Wall: {
        final double rotPeriod = 32768. / (double) s.getRotationSpeed();
        final boolean rotate = !Double.isInfinite(rotPeriod);
        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 10 },
                false);
        if (rotate) {
            bc.addBehavior(
                    new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.), Math.PI));
            bc.setTop(top);
        } else
            bc.setTop(new Rotation(heading, Math.PI + Math.PI / 2).applyTo(top));
        bc.setPosition(wPos.toArray());
        bc.setHeading(heading);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);

        bc = new BarrierCube(tr, tunnelDia, tunnelDia, wallThickness,
                tunnelTexturePalette[s.getObstacleTextureIndex()], new double[] { 0, tunnelDia / 2., 0 },
                false);
        if (rotate) {
            bc.addBehavior(new RotatingObjectBehavior(heading, heading, top, (int) (rotPeriod * 1000.),
                    Math.PI + Math.PI / 2));
            bc.setTop(top);
        } else
            bc.setTop(new Rotation(heading, Math.PI * 2).applyTo(top));

        bc.setPosition((wPos.add(new Vector3D(100, 0, 0))).toArray());
        bc.setHeading(heading);
        bc.addBehavior(new CubeCollisionBehavior(bc));
        add(bc);
        break;
    }
    case fan:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BLADE.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 28, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        wo.addBehavior(new RotatingObjectBehavior(heading, heading, top, 6000, Math.random() * 2 * Math.PI));
        add(wo);
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("FANBODY.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 28, false, palette, null));//No ESTuTv for fan for now.
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case jawsVertical:
        // Up jaw
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW2.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.addBehavior(new ShiftingObjectBehavior(3000, wPos, wPos.add(top.scalarMultiply(tunnelDia / 2))));
        wo.addBehavior(new CubeCollisionBehavior(wo));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(heading.crossProduct(top).negate());
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        // Down jaw
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW1.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.addBehavior(
                new ShiftingObjectBehavior(3000, wPos, wPos.subtract(top.scalarMultiply(tunnelDia / 2))));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(heading.crossProduct(top).negate());
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case jawsHorizontal:
        // Left jaw
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW2.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.addBehavior(new ShiftingObjectBehavior(3000, wPos,
                wPos.add(heading.crossProduct(top).scalarMultiply(tunnelDia / 2))));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        // Right jaw
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("JAW1.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.addBehavior(new ShiftingObjectBehavior(3000, wPos,
                wPos.subtract(heading.crossProduct(top).scalarMultiply(tunnelDia / 2))));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case metalBeamUp:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.add(new Vector3D(0, tunnelDia / 6, 0)).toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case metalBeamDown:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.add(new Vector3D(0, -tunnelDia / 6, 0)).toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case metalBeamLeft:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.add(new Vector3D(-tunnelDia / 6, 0, 0)).toArray());
        wo.setHeading(heading);
        wo.setTop(top.crossProduct(heading));
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case metalBeamRight:
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("BEAM.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 8, false, palette, ESTuTvPalette));
        wo.setPosition(wPos.add(new Vector3D(tunnelDia / 6, 0, 0)).toArray());
        wo.setHeading(heading);
        wo.setTop(top.crossProduct(heading));
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    case forceField: {
        //ELECTRI[0-3].RAW 
        final ForceField ff = new ForceField(tr, (int) tunnelDia, (int) wallThickness);
        ff.setPosition(wPos.toArray());
        ff.setHeading(heading);
        ff.setTop(top);
        add(ff);
        break;
    }
    // Invisible walls, as far as I know, are never used.
    // This makes sense: There is nothing fun about trying to get through a
    // tunnel and crashing into invisible walls.
    case invisibleWallUp:// TODO
        break;
    case invisibleWallDown:// TODO
        break;
    case invisibleWallLeft:// TODO
        break;
    case invisibleWallRight:// TODO
        break;
    case iris: {
        wo = new WorldObject(tr, tr.getResourceManager().getBINModel("IRIS.BIN",
                tunnelTexturePalette[s.getObstacleTextureIndex()], 4 * 256, false, palette, ESTuTvPalette));
        final Model mod = wo.getModel();
        wo.addBehavior(new IrisBehavior(new Sequencer(mod.getFrameDelayInMillis(), 2, true), width));
        wo.setPosition(wPos.toArray());
        wo.setHeading(heading);
        wo.setTop(top);
        wo.addBehavior(new CubeCollisionBehavior(wo));
        add(wo);
        break;
    }
    }// end switch(obstruction)
}

From source file:org.rhwlab.dispim.nucleus.NamedNucleusFile.java

License:asdf

static public void nameChildren(Nucleus nuc) {
    Nucleus last = LinkedNucleusFile.lastNucleusInCell(nuc);
    if (last.isLeaf())
        return; // no children

    Division div = divisionMap.get(last.getCellName());
    if (div != null) {
        if (R != null) {
            Nucleus c1 = last.getChild1();
            Nucleus c2 = last.getChild2();
            Vector3D direction = divisionDirection(c1, c2);
            double d0 = new Vector3D(R.operate(direction.toArray())).dotProduct(div.getV());
            double d1 = new Vector3D(R.operate(direction.scalarMultiply(-1.0).toArray()))
                    .dotProduct(div.getV());
            if (d0 < d1) {
                Nucleus parent = c1.getParent();
                parent.setDaughters(c2, c1); //swap the daughters
            }/*from  ww w. j  a  v  a  2  s .c  om*/
        }
        Nucleus.nameCellRecursive(last.getChild1(), div.child1, false);
        Nucleus.nameCellRecursive(last.getChild2(), div.child2, false);
    } else {
        Nucleus.nameCellRecursive(last.getChild1(), null, false);
        Nucleus.nameCellRecursive(last.getChild2(), null, false);
    }
    // rename nuclei in the subtrees
    nameChildren(last.getChild1());
    nameChildren(last.getChild2());

}