package Savage.ShipsMilitary.PatrolCraftNavalAcademyBrazil;
/*
Copyright (c) 1995-2019 held by the author(s). All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of the Web3D Consortium (http://www.web3D.org)
nor the names of its contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
import java.util.*;
import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EnvironmentalEffects.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Geometry3D.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Interpolation.*;
import org.web3d.x3d.jsail.Navigation.*;
import org.web3d.x3d.jsail.Networking.*;
import org.web3d.x3d.jsail.PointingDeviceSensor.*;
import org.web3d.x3d.jsail.Scripting.*;
import org.web3d.x3d.jsail.Shape.*;
import org.web3d.x3d.jsail.Sound.*;
import org.web3d.x3d.jsail.Time.*;
// Javadoc annotations follow, see below for source.
/**
*
Brazilian Naval Academy Training Ship making a manoverboard manouver.
Related links: Butakov.java source, Butakov catalog page, X3D Resources, X3D Scene Authoring Hints, and X3D Tooltips.
This program uses the
X3D Java Scene Access Interface Library (X3DJSAIL).
It has been produced using the
X3dToJava.xslt
stylesheet to create Java source code from an .x3d
model.
* @author Claudio Coreixas
*/
public class Butakov
{
/** Default constructor to create this object. */
public Butakov ()
{
initialize();
}
/** Create and initialize the X3D model for this object. */
public final void initialize()
{
x3dModel = new X3DObject().setProfile(X3DObject.PROFILE_IMMERSIVE).setVersion(X3DObject.VERSION_3_2)
.setHead(new headObject()
.addMeta(new metaObject().setName(metaObject.NAME_TITLE ).setContent("Butakov.x3d"))
.addMeta(new metaObject().setName(metaObject.NAME_DESCRIPTION).setContent("Brazilian Naval Academy Training Ship making a manoverboard manouver"))
.addMeta(new metaObject().setName(metaObject.NAME_CREATOR ).setContent("Claudio Coreixas"))
.addMeta(new metaObject().setName(metaObject.NAME_CREATED ).setContent("20 October 2009"))
.addMeta(new metaObject().setName(metaObject.NAME_MODIFIED ).setContent("14 January 2014"))
.addMeta(new metaObject().setName(metaObject.NAME_REFERENCE ).setContent("http://www.en.mar.mil.br"))
.addMeta(new metaObject().setName(metaObject.NAME_SUBJECT ).setContent("ships manouvering"))
.addMeta(new metaObject().setName(metaObject.NAME_IDENTIFIER ).setContent("https://savage.nps.edu/Savage/ShipsMilitary/PatrolCraft-NavalAcademy-Brazil/Butakov.x3d"))
.addMeta(new metaObject().setName(metaObject.NAME_GENERATOR ).setContent("X3D-Edit, https://savage.nps.edu/X3D-Edit"))
.addMeta(new metaObject().setName(metaObject.NAME_LICENSE ).setContent("../../license.html")))
.setScene(new SceneObject()
.addChild(new SoundObject().setMaxBack(100f).setMaxFront(100f)
.setSource(new AudioClipObject("boat").setDescription("ambient sound").setLoop(true).setUrl(new String[] {"boatSound.wav","https://savage.nps.edu/Savage/ShipsMilitary/PatrolCraft-NavalAcademy-Brazil/boatSound.wav"})))
.addChild(new NavigationInfoObject().setType(new String[] {"EXAMINE"}))
.addChild(new WorldInfoObject().setInfo(new String[] {"an Butakov MOB scene"}).setTitle("Butakov"))
.addChild(new BackgroundObject().setSkyAngle(new float[] {0.7f,0.0f}).setSkyColor(new MFColorObject(new float[] {0.478431f,0.160784f,1.0f,0.701961f,0.776471f,1.0f,0.380392f,0.384314f,1.0f})))
.addChild(new ViewpointObject().setDescription("top").setOrientation(1.0f,0.0f,0.0f,-1.57f).setPosition(1.8f,10.0f,1.4f))
.addChild(new TimeSensorObject("MovementTimer").setCycleInterval(20).setLoop(true))
.addChild(new TimeSensorObject("spintTimer").setCycleInterval(4).setLoop(true))
.addChild(new PositionInterpolatorObject("MovetheShip").setKey(new float[] {0.025f,0.05f,0.075f,0.1f,0.125f,0.15f,0.175f,0.2f,0.225f,0.25f,0.275f,0.3f,0.325f,0.35f,0.375f,0.4f,0.425f,0.45f,0.475f,0.5f,0.525f,0.55f,0.575f,0.6f,0.625f,0.65f,0.675f,0.7f,0.725f,0.75f,0.775f,0.8f,0.825f,0.85f,0.875f,0.9f,0.925f,0.95f,0.975f,1.0f}).setKeyValue(new MFVec3fObject(new float[] {-3.0f,0.0f,0.0f,-2.5f,0.0f,0.0f,-2.0f,0.0f,0.0f,-1.5f,0.0f,0.0f,-1.0f,0.0f,0.0f,-0.5f,0.0f,0.0f,0.0f,0.0f,0.0f,0.48f,0.0f,0.1f,0.95f,0.0f,0.28f,1.35f,0.0f,0.55f,1.65f,0.0f,0.95f,1.88f,0.0f,1.4f,1.96f,0.0f,1.9f,2.05f,0.0f,2.45f,2.25f,0.0f,2.9f,2.5f,0.0f,3.3f,2.9f,0.0f,3.68f,3.3f,0.0f,3.9f,3.8f,0.0f,4.0f,4.3f,0.0f,4.0f,4.8f,0.0f,3.9f,5.2f,0.0f,3.65f,5.6f,0.0f,3.3f,5.85f,0.0f,2.9f,6.02f,0.0f,2.4f,6.08f,0.0f,1.9f,5.95f,0.0f,1.4f,5.78f,0.0f,0.95f,5.42f,0.0f,0.55f,5.0f,0.0f,0.25f,4.55f,0.0f,0.05f,4.0f,0.0f,0.0f,3.5f,0.0f,0.0f,3.0f,0.0f,0.0f,2.5f,0.0f,0.0f,2.0f,0.0f,0.0f,1.5f,0.0f,0.0f,1.0f,0.0f,0.0f,0.5f,0.0f,0.0f,0.0f,0.0f,0.0f})))
.addChild(new ROUTEObject().setFromNode("MovementTimer").setFromField("fraction_changed").setToNode("MovetheShip").setToField("set_fraction"))
.addChild(new OrientationInterpolatorObject("SpinTheShip").setKey(new float[] {0.0f,0.083333f,0.166667f,0.25f,0.333333f,0.416667f,0.5f,0.583333f,0.666667f,0.75f,0.833333f,0.916667f,1.0f}).setKeyValue(new MFRotationObject(new float[] {1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,-0.25f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.25f,1.0f,0.0f,0.0f,0.3f,1.0f,0.0f,0.0f,0.35f,1.0f,0.0f,0.0f,0.3f,1.0f,0.0f,0.0f,0.25f,1.0f,0.0f,0.0f,0.0f,1.0f,1.0f,0.0f,0.0f,1.0f,1.0f,0.0f,0.0f})))
.addChild(new ROUTEObject().setFromNode("MovementTimer").setFromField("fraction_changed").setToNode("SpinTheShip").setToField("set_fraction"))
.addChild(new OrientationInterpolatorObject("SpinTheShip2").setKey(new float[] {0.0f,0.166667f,0.333333f,0.5f,0.666667f,0.833333f,1.0f}).setKeyValue(new MFRotationObject(new float[] {0.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,-1.57f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,1.57f,0.0f,1.0f,0.0f,3.14f,0.0f,1.0f,0.0f,3.14f})))
.addChild(new ROUTEObject().setFromNode("MovementTimer").setFromField("fraction_changed").setToNode("SpinTheShip2").setToField("set_fraction"))
.addChild(new OrientationInterpolatorObject("SpinTheShip3").setKey(new float[] {0.0f,0.5f,1.0f}).setKeyValue(new MFRotationObject(new float[] {0.0f,0.0f,1.0f,-0.05f,0.0f,0.0f,1.0f,0.05f,0.0f,0.0f,1.0f,-0.05f})))
.addChild(new ROUTEObject().setFromNode("spintTimer").setFromField("fraction_changed").setToNode("SpinTheShip3").setToField("set_fraction"))
.addChild(new TransformObject("Ship3")
.addChild(new ROUTEObject().setFromNode("MovetheShip").setFromField("value_changed").setToNode("Ship3").setToField("translation"))
.addChild(new ViewpointObject().setDescription("topMoving").setOrientation(1.0f,0.0f,0.0f,-1.57079f).setPosition(0.0f,3.0f,0.0f))
.addChild(new TransformObject("Ship2")
.addChild(new ROUTEObject().setFromNode("SpinTheShip2").setFromField("value_changed").setToNode("Ship2").setToField("rotation"))
.addChild(new ViewpointObject().setDescription("Stern").setOrientation(0.0f,1.0f,0.0f,-1.57f).setPosition(-3.0f,0.5f,0.0f))
.addChild(new ViewpointObject().setDescription("bow").setOrientation(0.0f,1.0f,0.0f,1.57f).setPosition(3.0f,0.5f,0.0f))
.addChild(new ViewpointObject().setDescription("bow Close").setOrientation(0.0f,1.0f,0.0f,1.57f).setPosition(1.0f,0.3f,0.0f))
.addChild(new ViewpointObject().setDescription("stb Bow").setOrientation(-0.3162f,0.9487f,0.0f,0.8117f).setPosition(1.0f,0.5f,1.0f))
.addChild(new ViewpointObject().setDescription("stb Bridge Outside").setOrientation(0.0f,0.6247f,0.0f,0.8179f).setPosition(0.5f,0.2f,0.6f))
.addChild(new ViewpointObject().setDescription("port Bow").setOrientation(0.0f,0.9487f,0.0f,2.3299f).setPosition(1.5f,0.5f,-1.5f))
.addChild(new ViewpointObject().setDescription("stb Quarter").setOrientation(-0.3162f,-0.9487f,0.0f,0.8117f).setPosition(-1.5f,0.25f,1.5f))
.addChild(new ViewpointObject().setDescription("port Quarter").setOrientation(0.0f,-0.9487f,0.0f,2.3299f).setPosition(-1.5f,0.25f,-1.5f))
.addChild(new TransformObject("Ship")
.addChild(new ROUTEObject().setFromNode("SpinTheShip").setFromField("value_changed").setToNode("Ship").setToField("rotation"))
.addChild(new ViewpointObject().setDescription("StbRudder").setOrientation(0.0f,1.0f,0.0f,-1.57f).setPosition(-0.9f,-0.1f,0.14f))
.addChild(new TransformObject("Ship4")
.addChild(new ViewpointObject().setDescription(".50cal").setOrientation(0.0f,1.0f,0.0f,1.57f).setPosition(-0.05f,0.28f,0.0f))
.addChild(new ViewpointObject().setDescription("Bridge").setFieldOfView(0.43f).setOrientation(0.0f,-0.9935f,0.0f,1.57079f).setPosition(0.14f,0.27f,0.0f))
.addChild(new ViewpointObject().setDescription("Radar").setFieldOfView(0.45f).setOrientation(-0.1888f,-0.982f,0.0f,1.57079f).setPosition(-0.6f,0.5f,0.0f))
.addChild(new ROUTEObject().setFromNode("SpinTheShip3").setFromField("value_changed").setToNode("Ship4").setToField("rotation"))
.addChild(new TransformObject().setScale(0.15f,0.15f,0.15f)
.addChild(new InlineObject().setUrl(new String[] {"U11.x3d","https://savage.nps.edu/Savage/ShipsMilitary/PatrolCraft-NavalAcademy-Brazil/U11.x3d"})))))))
.addChild(new TransformObject().setTranslation(0.0f,-5.0f,0.0f)
.addChild(new ShapeObject("ocean")
.setAppearance(new AppearanceObject()
.setMaterial(new MaterialObject().setAmbientIntensity(1f).setDiffuseColor(0.0f,0.219608f,0.419608f).setShininess(1f).setTransparency(0.16f)))
.setGeometry(new BoxObject().setSize(200.0f,10.0f,100.0f).setSolid(false))))
.addChild(new TransformObject()
.addChild(new ShapeObject("path")
.setGeometry(new ExtrusionObject().setCrossSection(new MFVec2fObject(new float[] {0.0f,0.0f,0.01f,0.0f,0.0f,-0.01f,0.0f,0.01f,-0.01f,0.0f,0.01f,0.01f,0.0f,0.0f})).setSpine(new MFVec3fObject(new float[] {-3.0f,0.0f,0.0f,-2.5f,0.0f,0.0f,-2.0f,0.0f,0.0f,-1.5f,0.0f,0.0f,-1.0f,0.0f,0.0f,-0.5f,0.0f,0.0f,0.0f,0.0f,0.0f,0.48f,0.0f,0.1f,0.95f,0.0f,0.28f,1.35f,0.0f,0.55f,1.65f,0.0f,0.95f,1.88f,0.0f,1.4f,1.96f,0.0f,1.9f,2.05f,0.0f,2.45f,2.25f,0.0f,2.9f,2.5f,0.0f,3.3f,2.9f,0.0f,3.68f,3.3f,0.0f,3.9f,3.8f,0.0f,4.0f,4.3f,0.0f,4.0f,4.8f,0.0f,3.9f,5.2f,0.0f,3.65f,5.6f,0.0f,3.3f,5.85f,0.0f,2.9f,6.02f,0.0f,2.4f,6.08f,0.0f,1.9f,5.95f,0.0f,1.4f,5.78f,0.0f,0.95f,5.42f,0.0f,0.55f,5.0f,0.0f,0.25f,4.55f,0.0f,0.05f,4.0f,0.0f,0.0f,3.5f,0.0f,0.0f,3.0f,0.0f,0.0f,2.5f,0.0f,0.0f,2.0f,0.0f,0.0f,1.5f,0.0f,0.0f,1.0f,0.0f,0.0f,0.5f,0.0f,0.0f,0.0f,0.0f,0.0f,-0.5f,0.0f,0.0f})))
.setAppearance(new AppearanceObject()
.setMaterial(new MaterialObject().setAmbientIntensity(1f).setDiffuseColor(0.858824f,0.568627f,0.0f).setShininess(0.56f).setTransparency(0.36f)))))
.addChild(new TransformObject().setTranslation(1.0f,0.0f,1.0f)
.addChild(new ShapeObject("accel")
.setGeometry(new BoxObject().setSize(0.1f,0.1f,0.1f))
.setAppearance(new AppearanceObject()
.setMaterial(new MaterialObject().setAmbientIntensity(1f).setDiffuseColor(1.0f,1.0f,0.980392f).setShininess(0.56f).setTransparency(0.36f))))
.addChild(new TouchSensorObject("acceleratorSensor").setDescription("Touch to change ships speed")))
.addChild(new ScriptObject("ControlScript").setSourceCode("\n" +
" " + "\n" +
"ecmascript:" + "\n" +
"// Filename: acceleratorScript.js" + "\n" +
"// Author: Claudio Coreixas" + "\n" +
"// Created: 7 October 2009" + "\n" +
"\n" +
"\n" +
"function buttonMotionDone (value)" + "\n" +
"{" + "\n" +
" if (value == false)" + "\n" +
" {" + "\n" +
" buttonPushCount ++;" + "\n" +
" if (buttonPushCount > 3)" + "\n" +
" {" + "\n" +
" buttonPushCount = 0;" + "\n" +
" }" + "\n" +
"\n" +
" if (buttonPushCount == 0)" + "\n" +
" {" + "\n" +
"\n" +
" speed = new SFTime (20);" + "\n" +
" }" + "\n" +
" else if (buttonPushCount == 1)" + "\n" +
" {" + "\n" +
"\n" +
" speed = new SFTime (10);" + "\n" +
" }" + "\n" +
" else if (buttonPushCount == 2)" + "\n" +
" {" + "\n" +
"\n" +
" speed = new SFTime (20);" + "\n" +
" }" + "\n" +
" else if (buttonPushCount == 3)" + "\n" +
" {" + "\n" +
"\n" +
" speed = new SFTime (10);" + "\n" +
" }" + "\n" +
" startTimeReset = new SFTime (buttonPushTime + 5);" + "\n" +
"\n" +
" }" + "\n" +
"}" + "\n")
.addField(new fieldObject().setName("buttonMotionDone").setType(fieldObject.TYPE_SFBOOL).setAccessType(fieldObject.ACCESSTYPE_INPUTONLY))
.addField(new fieldObject().setName("buttonPushCount").setType(fieldObject.TYPE_SFINT32).setAccessType(fieldObject.ACCESSTYPE_INITIALIZEONLY).setValue(0))
.addField(new fieldObject().setName("speed").setType(fieldObject.TYPE_SFTIME).setAccessType(fieldObject.ACCESSTYPE_OUTPUTONLY))
.addField(new fieldObject().setName("buttonPushTime").setType(fieldObject.TYPE_SFTIME).setAccessType(fieldObject.ACCESSTYPE_INPUTONLY))
.addField(new fieldObject().setName("startTimeReset").setType(fieldObject.TYPE_SFTIME).setAccessType(fieldObject.ACCESSTYPE_OUTPUTONLY)))
.addChild(new ROUTEObject().setFromNode("acceleratorSensor").setFromField("isActive").setToNode("ControlScript").setToField("buttonMotionDone"))
.addChild(new ROUTEObject().setFromNode("ControlScript").setFromField("speed").setToNode("MovementTimer").setToField("cycleInterval"))
.addChild(new ROUTEObject().setFromNode("acceleratorSensor").setFromField("touchTime").setToNode("MovementTimer").setToField("pauseTime"))
.addChild(new ROUTEObject().setFromNode("acceleratorSensor").setFromField("touchTime").setToNode("ControlScript").setToField("buttonPushTime"))
.addChild(new ROUTEObject().setFromNode("acceleratorSensor").setFromField("touchTime").setToNode("MovementTimer").setToField("pauseTime"))
.addChild(new ROUTEObject().setFromNode("ControlScript").setFromField("startTimeReset").setToNode("MovementTimer").setToField("resumeTime")));
}
// end of initialize() method
/** The initialized model object, created within initialize() method. */
private X3DObject x3dModel;
/** Provide a
* shallow copy
* of the X3D model.
* @see X3DObject
* @return Butakov model
*/
public X3DObject getX3dModel()
{
return x3dModel;
}
/** Default main() method provided for test purposes, uses CommandLine to set global ConfigurationProperties for this object.
* @param args array of input parameters, provided as arguments
* @see X3DObject.handleArguments(args)
* @see X3DObject.validationReport()
* @see CommandLine
* @see CommandLine.USAGE
* @see ConfigurationProperties
*/
public static void main(String args[])
{
X3DObject thisExampleX3dObject = new Butakov().getX3dModel();
boolean hasArguments = (args != null) && (args.length > 0);
boolean validate = true; // default
boolean argumentsLoadNewModel = false;
String fileName = new String();
if (args != null)
{
for (String arg : args)
{
if (arg.toLowerCase().startsWith("-v") || arg.toLowerCase().contains("validate"))
{
validate = true; // making sure
}
if (arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_X3D) ||
arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_CLASSICVRML) ||
arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_X3DB) ||
arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_VRML97) ||
arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_EXI) ||
arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_GZIP) ||
arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_ZIP) ||
arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_HTML) ||
arg.toLowerCase().endsWith(X3DObject.FILE_EXTENSION_XHTML))
{
argumentsLoadNewModel = true;
fileName = arg;
}
}
}
if (argumentsLoadNewModel)
System.out.println("WARNING: \"Butakov\" model invocation is attempting to load file \"" + fileName + "\" instead of simply validating itself... file loading ignored.");
else if (hasArguments) // if no arguments provided, this method produces usage warning
thisExampleX3dObject.handleArguments(args);
if (validate)
{
System.out.print("Java program \"Butakov\" self-validation test results: ");
String validationResults = thisExampleX3dObject.validationReport();
System.out.println(validationResults);
}
}
}