List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D PLUS_I
Vector3D PLUS_I
To view the source code for org.apache.commons.math3.geometry.euclidean.threed Vector3D PLUS_I.
Click Source Link
From source file:nova.core.render.model.TechneModelProvider.java
@Override public void load(InputStream stream) { try {//ww w . j ava 2 s . c o m Map<String, byte[]> zipContents = new HashMap<>(); ZipInputStream zipInput = new ZipInputStream(stream); ZipEntry entry; while ((entry = zipInput.getNextEntry()) != null) { byte[] data = new byte[(int) entry.getSize()]; // For some reason, using read(byte[]) makes reading stall upon reaching a 0x1E byte int i = 0; while (zipInput.available() > 0 && i < data.length) { data[i++] = (byte) zipInput.read(); } zipContents.put(entry.getName(), data); } byte[] modelXml = zipContents.get("model.xml"); if (modelXml == null) { throw new RenderException("Model " + name + " contains no model.xml file"); } DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(new ByteArrayInputStream(modelXml)); NodeList nodeListTechne = document.getElementsByTagName("Techne"); if (nodeListTechne.getLength() < 1) { throw new RenderException("Model " + name + " contains no Techne tag"); } NodeList nodeListModel = document.getElementsByTagName("Model"); if (nodeListModel.getLength() < 1) { throw new RenderException("Model " + name + " contains no Model tag"); } NamedNodeMap modelAttributes = nodeListModel.item(0).getAttributes(); if (modelAttributes == null) { throw new RenderException("Model " + name + " contains a Model tag with no attributes"); } NodeList textureSize = document.getElementsByTagName("TextureSize"); if (textureSize.getLength() == 0) throw new RenderException("Model has no texture size"); String[] textureDimensions = textureSize.item(0).getTextContent().split(","); double textureWidth = Integer.parseInt(textureDimensions[0]); double textureHeight = Integer.parseInt(textureDimensions[1]); NodeList shapes = document.getElementsByTagName("Shape"); for (int i = 0; i < shapes.getLength(); i++) { Node shape = shapes.item(i); NamedNodeMap shapeAttributes = shape.getAttributes(); if (shapeAttributes == null) { throw new RenderException("Shape #" + (i + 1) + " in " + name + " has no attributes"); } Node name = shapeAttributes.getNamedItem("name"); String shapeName = null; if (name != null) { shapeName = name.getNodeValue(); } if (shapeName == null) { shapeName = "Shape #" + (i + 1); } String shapeType = null; Node type = shapeAttributes.getNamedItem("type"); if (type != null) { shapeType = type.getNodeValue(); } if (shapeType != null && !cubeIDs.contains(shapeType)) { System.out.println( "Model shape [" + shapeName + "] in " + this.name + " is not a cube, ignoring"); continue; } boolean mirrored = false; String[] offset = new String[3]; String[] position = new String[3]; String[] rotation = new String[3]; String[] size = new String[3]; String[] textureOffset = new String[2]; NodeList shapeChildren = shape.getChildNodes(); for (int j = 0; j < shapeChildren.getLength(); j++) { Node shapeChild = shapeChildren.item(j); String shapeChildName = shapeChild.getNodeName(); String shapeChildValue = shapeChild.getTextContent(); if (shapeChildValue != null) { shapeChildValue = shapeChildValue.trim(); switch (shapeChildName) { case "IsMirrored": mirrored = !shapeChildValue.equals("False"); break; case "Offset": offset = shapeChildValue.split(","); break; case "Position": position = shapeChildValue.split(","); break; case "Rotation": rotation = shapeChildValue.split(","); break; case "Size": size = shapeChildValue.split(","); break; case "TextureOffset": textureOffset = shapeChildValue.split(","); break; } } } /* Generate new models Models in Techne are based on cubes. Each cube is, by default, skewed to the side. They are not centered. Everything is scaled by a factor of 16. The y coordinate is inversed, y = 24 is the surface The z coordinate is inverted, too. */ double positionX = Double.parseDouble(position[0]) / 16d; double positionY = (16 - Double.parseDouble(position[1])) / 16d; double positionZ = -Double.parseDouble(position[2]) / 16d; double sizeX = Double.parseDouble(size[0]) / 16d; double sizeY = Double.parseDouble(size[1]) / 16d; double sizeZ = Double.parseDouble(size[2]) / 16d; double offsetX = Double.parseDouble(offset[0]) / 16d; double offsetY = -Double.parseDouble(offset[1]) / 16d; double offsetZ = -Double.parseDouble(offset[2]) / 16d; double angleX = -Math.toRadians(Double.parseDouble(rotation[0])); double angleY = Math.toRadians(Double.parseDouble(rotation[1])); double angleZ = Math.toRadians(Double.parseDouble(rotation[2])); double textureOffsetU = Double.parseDouble(textureOffset[0]); double textureOffsetV = Double.parseDouble(textureOffset[1]); CubeTextureCoordinates textureCoordinates = new TechneCubeTextureCoordinates(textureWidth, textureHeight, textureOffsetU, textureOffsetV, sizeX, sizeY, sizeZ); final String modelName = shapeName; MeshModel modelPart = new MeshModel(modelName); BlockRenderPipeline.drawCube(modelPart, offsetX, offsetY - sizeY, offsetZ - sizeZ, offsetX + sizeX, offsetY, offsetZ, textureCoordinates); MatrixStack ms = new MatrixStack(); ms.translate(positionX, positionY, positionZ); ms.rotate(Vector3D.PLUS_J, angleY); ms.rotate(Vector3D.PLUS_I, angleX); ms.rotate(Vector3D.PLUS_K, angleZ); modelPart.matrix = ms; modelPart.textureOffset = new Vector2D(Integer.parseInt(textureOffset[0]), Integer.parseInt(textureOffset[1])); if (model.children.stream().anyMatch(m -> m.name.equals(modelName))) { throw new RenderException( "Model contained duplicate part name: '" + shapeName + "' node #" + i); } model.children.add(modelPart); } } catch (ZipException e) { throw new RenderException("Model " + name + " is not a valid zip file"); } catch (IOException e) { throw new RenderException("Model " + name + " could not be read", e); } catch (SAXException e) { throw new RenderException("Model " + name + " contains invalid XML", e); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jtrfp.trcl.beh.phy.BouncesOffSurfaces.java
@Override public void collidedWithSurface(WorldObject wo, double[] surfaceNormal) { final WorldObject parent = getParent(); final Vector3D oldHeading = parent.getHeading(); final Vector3D oldTop = parent.getTop(); final Vector3D _surfaceNormal = new Vector3D(surfaceNormal); if (oldHeading == null) throw new NullPointerException("Parent heading is null."); if (surfaceNormal == null) throw new NullPointerException("Surface normal is null."); if (reflectHeading && new Rotation(oldHeading, _surfaceNormal).getAngle() > Math.PI / 2.) { Vector3D newHeading = (_surfaceNormal.scalarMultiply(_surfaceNormal.dotProduct(oldHeading) * -2) .add(oldHeading));//from ww w. j ava 2 s. c o m parent.setHeading(newHeading); final Rotation resultingRotation = new Rotation(oldHeading, newHeading); Vector3D newTop = resultingRotation.applyTo(oldTop); //if(newTop.getY()<0)newTop=newTop.negate(); parent.setTop(newTop); } //end if(should reflect) //if(parent instanceof Velocible){ final Velocible velocible = (Velocible) parent.probeForBehavior(Velocible.class); Vector3D oldVelocity = velocible.getVelocity(); if (oldVelocity.getNorm() == 0) oldVelocity = Vector3D.PLUS_I; if (new Rotation(oldVelocity.normalize(), _surfaceNormal).getAngle() > Math.PI / 2.) { velocible.setVelocity( (_surfaceNormal.scalarMultiply(_surfaceNormal.dotProduct(oldVelocity) * -2).add(oldVelocity)) .scalarMultiply(velocityRetainmentCoefficient)); //Nudge parent.setPosition( new Vector3D(parent.getPosition()).add(_surfaceNormal.scalarMultiply(1000.)).toArray()); } //end if(should bounce) //}//end if(Velocible) }
From source file:org.jtrfp.trcl.flow.GameShell.java
public void applyGFXState() { final Renderer renderer = tr.mainRenderer.get(); final Camera camera = renderer.getCamera(); camera.probeForBehavior(SkyCubeCloudModeUpdateBehavior.class).setEnable(false); renderer.getSkyCube().setSkyCubeGen(DEFAULT_GRADIENT); camera.setHeading(Vector3D.PLUS_I); camera.setTop(Vector3D.PLUS_J); }
From source file:org.jtrfp.trcl.flow.Mission.java
public Result go() { setMissionMode(new Mission.LoadingMode()); synchronized (missionLock) { synchronized (missionEnd) { if (missionEnd[0] != null) return missionEnd[0]; }// w w w. j a va2 s .c o m tr.getThreadManager().setPaused(true); for (ProjectileFactory pf : tr.getResourceManager().getProjectileFactories()) for (Projectile proj : pf.getProjectiles()) proj.destroy(); System.out.println("Starting GampeplayLevel loading sequence..."); final LoadingProgressReporter rootProgress = LoadingProgressReporter.Impl .createRoot(new UpdateHandler() { @Override public void update(double unitProgress) { game.getLevelLoadingScreen().setLoadingProgress(unitProgress); } }); final LoadingProgressReporter[] progressStages = rootProgress .generateSubReporters(LoadingStages.values().length); final Renderer renderer = tr.mainRenderer.get(); renderer.getCamera().probeForBehavior(SkyCubeCloudModeUpdateBehavior.class).setEnable(false); renderer.getSkyCube().setSkyCubeGen(GameShell.DEFAULT_GRADIENT); final Camera camera = renderer.getCamera(); camera.setHeading(Vector3D.PLUS_I); camera.setTop(Vector3D.PLUS_J); game.setDisplayMode(game.levelLoadingMode); game.getUpfrontDisplay().submitPersistentMessage(levelName); try { final ResourceManager rm = tr.getResourceManager(); final Player player = tr.getGame().getPlayer(); final World world = tr.getWorld(); final TDFFile tdf = rm.getTDFData(lvl.getTunnelDefinitionFile()); player.setActive(false); // Abort check synchronized (missionEnd) { if (missionEnd[0] != null) return missionEnd[0]; } overworldSystem = new OverworldSystem(tr, progressStages[LoadingStages.overworld.ordinal()]); getOverworldSystem().loadLevel(lvl, tdf); System.out.println("\t...Done."); // Install NAVs final NAVSystem navSystem = tr.getGame().getNavSystem(); navSubObjects = rm.getNAVData(lvl.getNavigationFile()).getNavObjects(); START s = (START) navSubObjects.get(0); Location3D l3d = s.getLocationOnMap(); playerStartPosition[0] = TR.legacy2Modern(l3d.getZ()); playerStartPosition[2] = TR.legacy2Modern(l3d.getX()); final double HEIGHT_PADDING = 10000; playerStartPosition[1] = Math.max( HEIGHT_PADDING + (world.sizeY / 2) * getOverworldSystem().getAltitudeMap() .heightAt(TR.legacy2MapSquare(l3d.getZ()), TR.legacy2MapSquare(l3d.getX())), TR.legacy2Modern(l3d.getY())); playerStartDirection = new ObjectDirection(s.getRoll(), s.getPitch(), s.getYaw()); // ////// INITIAL HEADING player.setPosition(getPlayerStartPosition()); player.setDirection(getPlayerStartDirection()); player.setHeading(player.getHeading().negate());// Kludge to fix // incorrect heading ///////// STATE final Propelled propelled = player.probeForBehavior(Propelled.class); propelled.setPropulsion(propelled.getMinPropulsion()); installTunnels(tdf, progressStages[LoadingStages.tunnels.ordinal()]); Factory f = new NAVObjective.Factory(tr); final LoadingProgressReporter[] navProgress = progressStages[LoadingStages.navs.ordinal()] .generateSubReporters(navSubObjects.size()); for (int i = 0; i < navSubObjects.size(); i++) { final NAVSubObject obj = navSubObjects.get(i); f.create(tr, obj, navs); navProgress[i].complete(); } // end for(navSubObjects) navSystem.updateNAVState(); player.resetVelocityRotMomentum(); final String startX = System.getProperty("org.jtrfp.trcl.startX"); final String startY = System.getProperty("org.jtrfp.trcl.startY"); final String startZ = System.getProperty("org.jtrfp.trcl.startZ"); final double[] playerPos = player.getPosition(); if (startX != null && startY != null && startZ != null) { System.out.println("Using user-specified start point"); final int sX = Integer.parseInt(startX); final int sY = Integer.parseInt(startY); final int sZ = Integer.parseInt(startZ); playerPos[0] = sX; playerPos[1] = sY; playerPos[2] = sZ; player.notifyPositionChange(); } // end if(user start point) System.out.println("Start position set to " + player.getPosition()[0] + " " + player.getPosition()[1] + " " + player.getPosition()[2]); System.out.println("Setting sun vector"); final AbstractTriplet sunVector = lvl.getSunlightDirectionVector(); tr.getThreadManager().submitToGL(new Callable<Void>() { @Override public Void call() throws Exception { tr.mainRenderer.get().setSunVector( new Vector3D(sunVector.getX(), sunVector.getY(), sunVector.getZ()).normalize()); return null; } }).get(); System.out.println("\t...Done."); } catch (Exception e) { e.printStackTrace(); } if (System.getProperties().containsKey("org.jtrfp.trcl.flow.Mission.skipNavs")) { try { final int skips = Integer.parseInt(System.getProperty("org.jtrfp.trcl.flow.Mission.skipNavs")); System.out.println("Skipping " + skips + " navs."); for (int i = 0; i < skips; i++) { removeNAVObjective(currentNAVObjective()); } // end for(skips) } catch (NumberFormatException e) { System.err.println( "Invalid format for property \"org.jtrfp.trcl.flow.Mission.skipNavs\". Must be integer."); } } // end if(containsKey) //System.out.println("Invoking JVM's garbage collector..."); //TR.nuclearGC(); //System.out.println("Mission.go() complete."); // Transition to gameplay mode. // Abort check synchronized (missionEnd) { if (missionEnd[0] != null) return missionEnd[0]; } //end sync(missionEnd) tr.getThreadManager().submitToThreadPool(new Callable<Void>() { @Override public Void call() throws Exception { final SoundSystem ss = Mission.this.tr.soundSystem.get(); MusicPlaybackEvent evt; Mission.this.tr.soundSystem.get().enqueuePlaybackEvent(evt = ss.getMusicFactory().create( new GPUResidentMOD(tr, tr.getResourceManager().getMOD(lvl.getBackgroundMusicFile())), true)); synchronized (Mission.this) { if (bgMusic != null) return null; bgMusic = evt; bgMusic.play(); } //end sync(Mission.this) return null; }// end call() }); game.getUpfrontDisplay().removePersistentMessage(); tr.getThreadManager().setPaused(false); if (showIntro) { setMissionMode(new Mission.IntroMode()); game.getBriefingScreen().briefingSequence(lvl); } setMissionMode(new Mission.AboveGroundMode()); getOverworldSystem().activate(); final SkySystem skySystem = getOverworldSystem().getSkySystem(); tr.mainRenderer.get().getCamera().probeForBehavior(SkyCubeCloudModeUpdateBehavior.class) .setEnable(true); renderer.getSkyCube().setSkyCubeGen(skySystem.getBelowCloudsSkyCubeGen()); renderer.setAmbientLight(skySystem.getSuggestedAmbientLight()); renderer.setSunColor(skySystem.getSuggestedSunColor()); game.getNavSystem().activate(); game.setDisplayMode(game.gameplayMode); game.getPlayer().setActive(true); tr.getGame().setPaused(false); //Wait for mission end synchronized (missionEnd) { while (missionEnd[0] == null) { try { missionEnd.wait(); } catch (InterruptedException e) { break; } } } //Completion summary if (missionEnd[0] != null) if (!missionEnd[0].isAbort()) { setMissionMode(new Mission.MissionSummaryMode()); game.getBriefingScreen().missionCompleteSummary(lvl, missionEnd[0]); } //end if(proper ending) tr.getThreadManager().submitToThreadPool(new Callable<Void>() { @Override public Void call() throws Exception { bgMusic.stop(); return null; }// end call() }); cleanup(); return missionEnd[0]; } //end sync }
From source file:org.jtrfp.trcl.gpu.Model.java
public static Model buildCube(double w, double h, double d, TextureDescription tunnelTexturePalette, double[] origin, double u0, double v0, double u1, double v1, boolean hasAlpha, boolean hasNorm, TR tr) { Model m = new Model(false, tr); // Front// www .ja v a 2s .c o m m.addTriangles(Triangle.quad2Triangles( new double[] { 0 - origin[0], w - origin[0], w - origin[0], 0 - origin[0] }, new double[] { h - origin[1], h - origin[1], 0 - origin[1], 0 - origin[1] }, new double[] { 0 - origin[2], 0 - origin[2], 0 - origin[2], 0 - origin[2] }, new double[] { u0, u1, u1, u0 }, new double[] { v1, v1, v0, v0 }, tunnelTexturePalette, RenderMode.STATIC, hasAlpha, hasNorm ? Vector3D.MINUS_K : Vector3D.ZERO, "Model.buildCube.front")); // Left m.addTriangles(Triangle.quad2Triangles( new double[] { 0 - origin[0], 0 - origin[0], 0 - origin[0], 0 - origin[0] }, new double[] { h - origin[1], h - origin[1], 0 - origin[1], 0 - origin[1] }, new double[] { 0 - origin[2], d - origin[2], d - origin[2], 0 - origin[2] }, new double[] { u0, u1, u1, u0 }, new double[] { v1, v1, v0, v0 }, tunnelTexturePalette, RenderMode.STATIC, hasAlpha, hasNorm ? Vector3D.MINUS_I : Vector3D.ZERO, "Model.buildCube.left")); // Right m.addTriangles(Triangle.quad2Triangles( new double[] { w - origin[0], w - origin[0], w - origin[0], w - origin[0] }, new double[] { h - origin[1], h - origin[1], 0 - origin[1], 0 - origin[1] }, new double[] { 0 - origin[2], d - origin[2], d - origin[2], 0 - origin[2] }, new double[] { u0, u1, u1, u0 }, new double[] { v1, v1, v0, v0 }, tunnelTexturePalette, RenderMode.STATIC, hasAlpha, hasNorm ? Vector3D.PLUS_I : Vector3D.ZERO, "Model.buildCube.right")); // Back m.addTriangles(Triangle.quad2Triangles( new double[] { 0 - origin[0], w - origin[0], w - origin[0], 0 - origin[0] }, new double[] { 0 - origin[1], 0 - origin[1], h - origin[1], h - origin[1] }, new double[] { d - origin[2], d - origin[2], d - origin[2], d - origin[2] }, new double[] { u0, u1, u1, u0 }, new double[] { v0, v0, v1, v1 }, tunnelTexturePalette, RenderMode.STATIC, hasAlpha, hasNorm ? Vector3D.PLUS_K : Vector3D.ZERO, "Model.buildCube.back")); return m; }
From source file:org.jtrfp.trcl.obj.ObjectDirection.java
public ObjectDirection(int legacyRoll, int legacyPitch, int legacyYaw) { Vector3D headingAccumulator, topAccumulator; Rotation rot;//from www. j a v a 2 s . co m yaw = ((double) legacyYaw / 65535.) * 2 * Math.PI; roll = ((double) legacyRoll / 65535.) * 2 * Math.PI; tilt = ((double) legacyPitch / 65535.) * 2 * Math.PI; /* * Rotation hRot = new Rotation(//yaw only. new Vector3D(0,1,0), new * Vector3D(0,0,1), new Vector3D(0,1,0), new * Vector3D(Math.cos(yaw),0.,Math.sin(yaw))); heading = * hRot.applyTo(heading); */ topAccumulator = new Vector3D(0, 1, 0); /* * Rotation tRot = new Rotation(//Pitch and roll new Vector3D(0,1,0), * new Vector3D(0,1,0), new Vector3D(Math.sin(roll),1,Math.cos(roll)), * new Vector3D(0.,Math.cos(tilt),Math.cos(tilt))); */ headingAccumulator = Vector3D.PLUS_K; rot = new Rotation(Vector3D.PLUS_I, tilt); headingAccumulator = rot.applyTo(headingAccumulator); topAccumulator = rot.applyTo(topAccumulator); rot = new Rotation(Vector3D.PLUS_J, yaw + 1.5 * Math.PI); headingAccumulator = rot.applyTo(headingAccumulator); topAccumulator = rot.applyTo(topAccumulator); // Commit the values heading = headingAccumulator; top = topAccumulator; }
From source file:org.jtrfp.trcl.obj.ProjectileObject3D.java
@Override public void reset(double[] newPos, Vector3D newVelocity, WorldObject objectOfOrigin) { this.objectOfOrigin = new WeakReference<WorldObject>(objectOfOrigin); if (newVelocity.getNorm() != 0) setHeading(newVelocity.normalize()); else {//from w w w.ja v a2s. c o m setHeading(Vector3D.PLUS_I); newVelocity = Vector3D.PLUS_I; } //meh. assert !Vect3D.isAnyNaN(newPos); setPosition(newPos[0], newPos[1], newPos[2]); getBehavior().probeForBehavior(Velocible.class).setVelocity(newVelocity); getBehavior().probeForBehavior(ProjectileBehavior.class).reset(newVelocity.normalize(), newVelocity.getNorm()); setActive(true); setVisible(true); }
From source file:org.jtrfp.trcl.obj.TunnelExitObject.java
public TunnelExitObject(TR tr, Tunnel tun) { super(tr);/* w w w . j a v a2 s.c o m*/ addBehavior(new TunnelExitBehavior()); final DirectionVector v = tun.getSourceTunnel().getExit(); final double EXIT_Y_NUDGE = 0; final InterpolatingAltitudeMap map = tr.getGame().getCurrentMission().getOverworldSystem().getAltitudeMap(); final double exitY = map.heightAt(TR.legacy2Modern(v.getZ()), TR.legacy2Modern(v.getX())) + EXIT_Y_NUDGE; this.exitLocation = new Vector3D(TR.legacy2Modern(v.getZ()), exitY, TR.legacy2Modern(v.getX())); this.tun = tun; exitHeading = map.normalAt(exitLocation.getZ() / TR.mapSquareSize, exitLocation.getX() / TR.mapSquareSize); Vector3D horiz = exitHeading.crossProduct(Vector3D.MINUS_J); if (horiz.getNorm() == 0) { horiz = Vector3D.PLUS_I; } else horiz = horiz.normalize(); exitTop = exitHeading.crossProduct(horiz.negate()).normalize().negate(); exitLocation = exitLocation.add(exitHeading.scalarMultiply(10000)); this.tr = tr; setVisible(false); try { Model m = tr.getResourceManager().getBINModel("SHIP.BIN", tr.getGlobalPaletteVL(), null, tr.gpu.get().getGl()); setModel(m); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jtrfp.trcl.Tunnel.java
private Vector3D buildTunnel(TDFFile.Tunnel _tun, Vector3D groundVector, boolean entrance) throws IllegalAccessException, UnrecognizedFormatException, FileNotFoundException, FileLoadException, IOException {//from w ww . j av a2 s . co 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.orekit.attitudes.AttitudeTest.java
@Test public void testShift() throws OrekitException { double rate = 2 * FastMath.PI / (12 * 60); Attitude attitude = new Attitude(AbsoluteDate.J2000_EPOCH, FramesFactory.getEME2000(), Rotation.IDENTITY, new Vector3D(rate, Vector3D.PLUS_K), Vector3D.ZERO); Assert.assertEquals(rate, attitude.getSpin().getNorm(), 1.0e-10); double dt = 10.0; double alpha = rate * dt; Attitude shifted = attitude.shiftedBy(dt); Assert.assertEquals(rate, shifted.getSpin().getNorm(), 1.0e-10); Assert.assertEquals(alpha, Rotation.distance(attitude.getRotation(), shifted.getRotation()), 1.0e-10); Vector3D xSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_I); Assert.assertEquals(0.0, xSat.subtract(new Vector3D(FastMath.cos(alpha), FastMath.sin(alpha), 0)).getNorm(), 1.0e-10);/* w w w .j a v a 2 s. c o m*/ Vector3D ySat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_J); Assert.assertEquals(0.0, ySat.subtract(new Vector3D(-FastMath.sin(alpha), FastMath.cos(alpha), 0)).getNorm(), 1.0e-10); Vector3D zSat = shifted.getRotation().applyInverseTo(Vector3D.PLUS_K); Assert.assertEquals(0.0, zSat.subtract(Vector3D.PLUS_K).getNorm(), 1.0e-10); }