package Savage.CommunicationsAndSensors.TRC170;

import org.web3d.x3d.jsail.Core.*;
import org.web3d.x3d.jsail.EnvironmentalEffects.*;
import org.web3d.x3d.jsail.fields.*;
import org.web3d.x3d.jsail.Grouping.*;
import org.web3d.x3d.jsail.Navigation.*;
import org.web3d.x3d.jsail.Networking.*;
import org.web3d.x3d.jsail.Scripting.*;

// Javadoc metadata annotations follow, see below for X3DJSAIL Java source code.
/**
 * <p> A Pair of TRC-170s. A TRC-170 is a long-range SHF communication system. It operates in 3 modes. 1)Direct point-to-point link (&lt; 30 miles). 2) Tropospheric shot (up to 100 or 150 miles, depending on system version). 3) Defraction shot over an a terrain feature or object in the path ( &lt; 50 miles). </p>
 <p> Related links: Catalog page <a href="../../../../CommunicationsAndSensors/TRC170/TRC170PairPrototypeIndex.html" target="_blank">TRC170PairPrototype</a>,  source <a href="../../../../CommunicationsAndSensors/TRC170/TRC170PairPrototype.java">TRC170PairPrototype.java</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dResources.html" target="_blank">X3D Resources</a>, <a href="https://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html" target="_blank">X3D Scene Authoring Hints</a>, and <a href="https://www.web3d.org/x3d/content/X3dTooltips.html" target="_blank">X3D Tooltips</a>. </p>
	<table style="color:black; border:0px solid; border-spacing:10px 0px;">
        <caption>Scene Meta Information</caption>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center; padding:10px 0px;"><i>meta tags</i></td>
			<td style="text-align:left;   padding:10px 0px;">&nbsp; Document Metadata </td>
		</tr>

		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> title </i> </td>
			<td> <a href="../../../../CommunicationsAndSensors/TRC170/TRC170PairPrototype.x3d">TRC170PairPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> description </i> </td>
			<td> A Pair of TRC-170s. A TRC-170 is a long-range SHF communication system. It operates in 3 modes. 1)Direct point-to-point link (&lt; 30 miles). 2) Tropospheric shot (up to 100 or 150 miles, depending on system version). 3) Defraction shot over an a terrain feature or object in the path ( &lt; 50 miles). </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> creator </i> </td>
			<td> Mike Hunsberger </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> created </i> </td>
			<td> 8 May 2001 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> modified </i> </td>
			<td> 12 October 2023 </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> identifier </i> </td>
			<td> <a href="https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TRC170/TRC170PairPrototype.x3d" target="_blank">https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TRC170/TRC170PairPrototype.x3d</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> generator </i> </td>
			<td> X3D-Edit 4.0, <a href="https://www.web3d.org/x3d/tools/X3D-Edit" target="_blank">https://www.web3d.org/x3d/tools/X3D-Edit</a> </td>
		</tr>
		<tr>
			<td style="text-align:right; vertical-align: text-top;"> <i> license </i> </td>
			<td> <a href="../../../../CommunicationsAndSensors/TRC170/../../license.html">../../license.html</a> </td>
		</tr>
		<tr style="background-color:silver; border-color:silver;">
			<td style="text-align:center;" colspan="2">  &nbsp; </td>
		</tr>
	</table>

	<p>
		This program uses the
		<a href="https://www.web3d.org/specifications/java/X3DJSAIL.html" target="_blank">X3D Java Scene Access Interface Library (X3DJSAIL)</a>.
		It has been produced using the 
		<a href="https://www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">X3dToJava.xslt</a>
		stylesheet
	       (<a href="https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/stylesheets/X3dToJava.xslt" target="_blank">version control</a>)
                which is used to create Java source code from an original <code>.x3d</code> model.
	</p>

	* @author Mike Hunsberger
 */

public class TRC170PairPrototype
{
	/** Default constructor to create this object. */
	public TRC170PairPrototype ()
	{
	  initialize();
	}

	/** Create and initialize the X3D model for this object. */
	public final void initialize()
	{
            try { // catch-all
  x3dModel = new X3D().setProfile(X3D.PROFILE_IMMERSIVE).setVersion(X3D.VERSION_3_0)
  .setHead(new head()
    .addMeta(new meta().setName(meta.NAME_TITLE      ).setContent("TRC170PairPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_DESCRIPTION).setContent("A Pair of TRC-170s. A TRC-170 is a long-range SHF communication system. It operates in 3 modes. 1)Direct point-to-point link (< 30 miles). 2) Tropospheric shot (up to 100 or 150 miles, depending on system version). 3) Defraction shot over an a terrain feature or object in the path ( < 50 miles)."))
    .addMeta(new meta().setName(meta.NAME_CREATOR    ).setContent("Mike Hunsberger"))
    .addMeta(new meta().setName(meta.NAME_CREATED    ).setContent("8 May 2001"))
    .addMeta(new meta().setName(meta.NAME_MODIFIED   ).setContent("12 October 2023"))
    .addMeta(new meta().setName(meta.NAME_IDENTIFIER ).setContent("https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TRC170/TRC170PairPrototype.x3d"))
    .addMeta(new meta().setName(meta.NAME_GENERATOR  ).setContent("X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit"))
    .addMeta(new meta().setName(meta.NAME_LICENSE    ).setContent("../../license.html")))
  .setScene(new Scene()
    .addChild(new ExternProtoDeclare("BeamCylinder").setName("BeamCylinder").setAppinfo("Produce wireframe or transparent beam cylinders. Typical uses include propeller/thruster water flow or line-of-sight sonar/radar/light beams. Negative range values invert base and apex at same relative location. Default: beam with apex at (0 0 0) and base of radius 1 in x-z plane at (1 0 0).").setUrl(new String[] {"../../CommunicationsAndSensors/Beam/BeamCylinderPrototype.x3d#BeamCylinder","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Beam/BeamCylinderPrototype.x3d#BeamCylinder","../../CommunicationsAndSensors/Beam/BeamCylinderPrototype.wrl#BeamCylinder","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Beam/BeamCylinderPrototype.wrl#BeamCylinder"})
      .addField(new field().setName("contact").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("(communications) is transmitted signal in contact with receiver or (sensor) is a target return detected?"))
      .addField(new field().setName("range").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("distance in meters along x axis"))
      .addField(new field().setName("defaultRange").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("distance in meters used until eventIn range sent"))
      .addField(new field().setName("wireframe").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("whether wireframe beam is drawn"))
      .addField(new field().setName("solid").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("whether solid beam is drawn"))
      .addField(new field().setName("beamHeight").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("meters across vertical y axis"))
      .addField(new field().setName("beamWidth").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("meters across horizontal z axis"))
      .addField(new field().setName("contactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("rendering color when contact=true"))
      .addField(new field().setName("noContactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("rendering color when contact=false"))
      .addField(new field().setName("transparency").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setAppinfo("1 = fully transparent wireframe only"))
      .addField(new field().setName("name").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("Assigning a name to a BeamCylinder aids tracing")))
    .addChild(new ExternProtoDeclare("BeamCone").setName("BeamCone").setAppinfo("Produce wireframe or transparent beam cones. Typical uses include propeller/thruster water flow or line-of-sight sonar/radar/light beams. Negative range values invert base and apex at same relative location. Default: beam with apex at (0 0 0) and base of radius 1 in x-z plane at (1 0 0).").setUrl(new String[] {"../../CommunicationsAndSensors/Beam/BeamConePrototype.x3d#BeamCone","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Beam/BeamConePrototype.x3d#BeamCone","../../CommunicationsAndSensors/Beam/BeamConePrototype.wrl#BeamCone","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/Beam/BeamConePrototype.wrl#BeamCone"})
      .addField(new field().setName("contact").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("(communications) is transmitted signal in contact with receiver or (sensor) is a target return detected?"))
      .addField(new field().setName("range").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTONLY).setAppinfo("distance in meters along x axis"))
      .addField(new field().setName("defaultRange").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("distance in meters used until eventIn range sent"))
      .addField(new field().setName("wireframe").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("whether wireframe beam is drawn"))
      .addField(new field().setName("solid").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("whether solid beam is drawn"))
      .addField(new field().setName("beamHeightDegrees").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("degrees across vertical y axis"))
      .addField(new field().setName("beamWidthDegrees").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("degrees across horizontal z axis"))
      .addField(new field().setName("contactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("rendering color when contact=true"))
      .addField(new field().setName("noContactColor").setType(field.TYPE_SFCOLOR).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("rendering color when contact=false"))
      .addField(new field().setName("transparency").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_INPUTOUTPUT).setAppinfo("1 = fully transparent wireframe only"))
      .addField(new field().setName("name").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("BeamCone name aids in node identification and tracing"))
      .addField(new field().setName("traceEnabled").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setAppinfo("flag to turn on Script tracing")))
    .addComments(" ExternProtoDeclare definitions must be included verbatim ")
    .addComments(" PROTO consists of two TRC170 for long range (up to 100 mile) point-to-point communication. TRC170s can be used in 3 different settings. The first is a direct link of up to 30 miles. The second is a defraction setting over an obstruction in the path. The third is a tropospheric scatter shot of up to 100 miles in which the signal is bounced off the troposphere. This PROTO allows specification for the initial placement of each TSSR. It automatically calculates the correct angle to complete the link. ")
    .addChild(new ProtoDeclare("TRC170Pair").setName("TRC170Pair")
      .setProtoInterface(new ProtoInterface()
        .addField(new field().setName("TRC1Location").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(1.0,1.0,1.0)))
        .addField(new field().setName("TRC2Location").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue(new SFVec3f(0.0,0.0,0.0)))
        .addField(new field().setName("OperatingMode").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY).setValue("DIRECT")))
      .setProtoBody(new ProtoBody()
        .addChild(new Group()
          .addChild(new Transform("HighAboveXZTranslation")
            .addChild(new Viewpoint("HighAbove").setDescription("High Above TRC170").setOrientation(1.0,0.0,0.0,-1.4).setPosition(0.0,0.0,0.0)))
          .addChild(new Viewpoint("TRC1Viewpoint").setDescription("TRC170 #1"))
          .addChild(new Viewpoint("TRC2Viewpoint").setDescription("TRC170 #2"))
          .addChild(new LOD().setRange(new double[] {200000.0})
            .addComments(" TRC 1 Two Transforms. One in the XZ plane, the second in the XY plane. Inlines for the TRC body, stand, and the dome pattern. ")
            .addChild(new Transform("TRC1_TRANSFORM").setTranslation(-2.0,0.0,0.0)
              .setIS(new IS()
                .addConnect(new connect().setNodeField("translation").setProtoField("TRC1Location")))
              .addChild(new Transform("TRC1_XY_TRANSFORM").setTranslation(1.0,5.0,0.0)
                .addChild(new Inline("TRCBody").setUrl(new String[] {"TRC170Dish.x3d","../../CommunicationsAndSensors/TRC170/TRC170Dish.x3d","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TRC170/TRC170Dish.x3d","TRC170Dish.wrl","../../CommunicationsAndSensors/TRC170/TRC170Dish.wrl","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TRC170/TRC170Dish.wrl"}))
                .addChild(new Transform("TRC1Cone").setTranslation(2.0,0.0,0.0)
                  .addChild(new Switch("BeamSwitch").setWhichChoice(0)
                    .addChild(new Group()
                      .addChild(new ProtoInstance("BeamCylinder", "TRC1_BEAMCYLINDER").setContainerField("children")
                        .addFieldValue(new fieldValue().setName("defaultRange").setValue(10))
                        .addFieldValue(new fieldValue().setName("beamHeight").setValue(1.5))
                        .addFieldValue(new fieldValue().setName("beamWidth").setValue(1.5))
                        .addFieldValue(new fieldValue().setName("transparency").setValue(0.2))
                        .addFieldValue(new fieldValue().setName("wireframe").setValue(true))
                        .addFieldValue(new fieldValue().setName("solid").setValue(true))
                        .addFieldValue(new fieldValue().setName("contactColor").setValue(new SFColor(.3,.5,.5)))
                        .addFieldValue(new fieldValue().setName("noContactColor").setValue(new SFColor(.8,.1,.1)))))
                    .addChild(new Group()
                      .addChild(new ProtoInstance("BeamCone", "TRC1_BEAMCONE").setContainerField("children")
                        .addFieldValue(new fieldValue().setName("defaultRange").setValue(10))
                        .addFieldValue(new fieldValue().setName("beamHeightDegrees").setValue(2))
                        .addFieldValue(new fieldValue().setName("beamWidthDegrees").setValue(2))
                        .addFieldValue(new fieldValue().setName("transparency").setValue(0.2))
                        .addFieldValue(new fieldValue().setName("wireframe").setValue(true))
                        .addFieldValue(new fieldValue().setName("solid").setValue(true))
                        .addFieldValue(new fieldValue().setName("noContactColor").setValue(new SFColor(.8,.1,.1)))
                        .addFieldValue(new fieldValue().setName("contactColor").setValue(new SFColor(.3,.5,.5))))))))
              .addChild(new Transform()
                .addChild(new Inline("TRCStand").setUrl(new String[] {"TRC170Tripod.x3d","../../CommunicationsAndSensors/TRC170/TRC170Tripod.x3d","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TRC170/TRC170Tripod.x3d","../../CommunicationsAndSensors/TRC170/TRC170Tripod.wrl","TRC170Tripod.wrl","https://www.web3d.org/x3d/content/examples/Savage/CommunicationsAndSensors/TRC170/TRC170Tripod.wrl"}))
                .addChild(new LOD().setRange(new double[] {500.0})
                  .addChild(new Viewpoint().setDescription("TRC170 Side View").setPosition(0.0,5.0,40.0))
                  .addChild(new WorldInfo().setInfo(new String[] {"null node for no rendering when distant"})))))
            .addChild(new WorldInfo().setInfo(new String[] {"null node for no rendering when distant"})))
          .addChild(new LOD().setRange(new double[] {200000.0})
            .addComments(" TRC 2 Two Transforms. One in the XZ plane, the second in the XY plane. Inlines for the TRC body, stand, and the dome pattern. ")
            .addChild(new Transform("TRC2_TRANSFORM").setTranslation(-2.0,0.0,0.0)
              .setIS(new IS()
                .addConnect(new connect().setNodeField("translation").setProtoField("TRC2Location")))
              .addChild(new Transform("TRC2_XY_TRANSFORM").setTranslation(1.0,5.0,0.0)
                .addChild(new Inline().setUSE("TRCBody"))
                .addChild(new Transform("TRC2Cone").setTranslation(2.0,0.0,0.0)
                  .addChild(new Switch("BeamSwitch2").setWhichChoice(0)
                    .addChild(new Group()
                      .addChild(new ProtoInstance("BeamCylinder", "TRC2_BEAMCYLINDER").setContainerField("children")
                        .addFieldValue(new fieldValue().setName("defaultRange").setValue(10))
                        .addFieldValue(new fieldValue().setName("beamHeight").setValue(1.5))
                        .addFieldValue(new fieldValue().setName("beamWidth").setValue(1.5))
                        .addFieldValue(new fieldValue().setName("transparency").setValue(0.2))
                        .addFieldValue(new fieldValue().setName("wireframe").setValue(true))
                        .addFieldValue(new fieldValue().setName("solid").setValue(true))
                        .addFieldValue(new fieldValue().setName("contactColor").setValue(new SFColor(.3,.5,.5)))
                        .addFieldValue(new fieldValue().setName("noContactColor").setValue(new SFColor(.8,.1,.1)))))
                    .addChild(new Group()
                      .addChild(new ProtoInstance("BeamCone", "TRC2_BEAMCONE").setContainerField("children")
                        .addFieldValue(new fieldValue().setName("defaultRange").setValue(10))
                        .addFieldValue(new fieldValue().setName("beamHeightDegrees").setValue(2))
                        .addFieldValue(new fieldValue().setName("beamWidthDegrees").setValue(2))
                        .addFieldValue(new fieldValue().setName("transparency").setValue(0.2))
                        .addFieldValue(new fieldValue().setName("wireframe").setValue(true))
                        .addFieldValue(new fieldValue().setName("solid").setValue(true))
                        .addFieldValue(new fieldValue().setName("noContactColor").setValue(new SFColor(.8,.1,.1)))
                        .addFieldValue(new fieldValue().setName("contactColor").setValue(new SFColor(.3,.5,.5))))))))
              .addChild(new Transform()
                .addChild(new Inline().setUSE("TRCStand"))
                .addChild(new LOD().setRange(new double[] {500.0})
                  .addChild(new Transform()
                    .addChild(new Viewpoint().setDescription("TRC170 Side View").setPosition(0.0,5.0,40.0)))
                  .addChild(new Transform()))))
            .addChild(new WorldInfo().setInfo(new String[] {"null node"})))
          .addChild(new Script("TransmitScript").setSourceCode("""
ecmascript:

function initialize ()
{
	size = new SFVec3f(100, 100, 100) ;
	Browser.println ('TransmitScript initialize() complete');
}

// function name matches eventIn variable name ('hour')
// hourValue captures the new value of the ROUTE hour event
// minutes is just the current field value

function transState (newValue, timestamp)
{
	transmitState = newValue ;
	if (transmitState == 3) {
		size = new SFVec3f(10, 10, 10) ;
	}
	else {
		size = new SFVec3f(100, 100, 100) ;
	}
	Browser.println ('size	= ' + size);
}
""")
            .addField(new field().setName("transState").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("size").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY)))
          .addChild(new Script("TransmitScript2").setSourceCode("""
ecmascript:

function initialize ()
{
	size = new SFVec3f(100, 100, 100) ;
	Browser.println ('TransmitScript initialize() complete');
}

// function name matches eventIn variable name ('hour')
// hourValue captures the new value of the ROUTE hour event
// minutes is just the current field value

function transState (newValue, timestamp)
{
	transmitState = newValue ;
	if (transmitState == 3) {
		size = new SFVec3f(10, 10, 10) ;
	}
	else {
		size = new SFVec3f(100, 100, 100) ;
	}
	Browser.println ('size	= ' + size);
}
""")
            .addField(new field().setName("transState").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_INPUTONLY))
            .addField(new field().setName("size").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY)))
          .addComments(" This script is used to calculate the corresponding rotation angles so the TSSRs will be pointed at each other ")
          .addChild(new Script("CalculateAngleScript").setSourceCode("""
ecmascript:

function initialize ()
{
	Browser.println ('TRC1	=' + TRC1Location);
	Browser.println ('TRC2	=' + TRC2Location);
	Browser.println ('TransmitScript initialize() complete');
	active = true ;
	TRC1_XZangle	= new SFRotation(0, 1, 0, 0) ;
	TRC2_XZangle	= new SFRotation(0, 1, 0, 0) ;
	TRC1_XYangle	= new SFRotation(0, 0, 1, 0) ;
	TRC2_XYangle	= new SFRotation(0, 0, 1, 0) ;
	XZangle	= new SFRotation(0, 1, 0, 0) ;
	XYangle	= new SFRotation(0, 0, 1, 0) ;
	TRC1_ViewpointAngle	= new SFRotation(0, 1, 0, 0) ;
	TRC2_ViewpointAngle	= new SFRotation(0, 1, 0, 0) ;
	HighAboveViewpointAngle	= new SFRotation(1, 0, 0, 0) ;
	HighAboveTranslationAngle	= new SFRotation(0, 1, 0, 0) ;

	beamScale	   = new SFVec3f ( ) ;
	center		   = new SFVec3f ( ) ;
	TRC1_Viewpoint	   = new SFVec3f ( ) ;
	TRC2_Viewpoint	   = new SFVec3f ( ) ;
	HighAboveViewpoint = new SFVec3f ( ) ;
	LinkEstablished	= true;
	Browser.println ('OperatingMode	=' + OperatingMode);

	compute(active) ;
}

function compute ( )
{
	if (OperatingMode == 'DIRECT') {
		WhichBeam = 0 ;
		computeDistance( ) ;
		computeXZangle( );
		computeXYangle( ) ;

	}

	if (OperatingMode == 'TROPOSCATTER') {
		WhichBeam = 1 ;
		centerX 	= (TRC2Location[0] - TRC1Location[0])/2 ;
		centerZ 	= (TRC2Location[2] - TRC1Location[2])/2 ;
		XZDistance	= Math.sqrt(centerX * centerX + centerZ * centerZ);
		center[0]	= TRC1Location[0] + centerX;
		center[1]	= 15000 ;  // vertical height of troposphere
		center[2]	= TRC1Location[2] + centerZ;
                Browser.println ('TRC1	= ' + TRC1Location);
                Browser.println ('center	= ' + center);
                Browser.println ('TRC2	= ' + TRC2Location);

		computeTropoDistance(TRC1Location, center) ;
		computeTropoXZangle( );
		computeTropoXYangle( ) ;
		TRC1_beamLength 	= tropoDistance-2;
		TRC1_XZangle		= XZangle;
		TRC1_XYangle		= XYangle;

		computeTropoDistance(TRC2Location, center) ;
		computeTropoXZangle( );
		computeTropoXYangle( ) ;
		TRC2_beamLength 	= tropoDistance-2;
		TRC2_XZangle		= XZangle;
		TRC2_XYangle		= XYangle;
	}

	TRC1_Viewpoint[0]	= TRC1Location[0] + Math.sin(TRC1_XZangle[3] - 1.57)*40;
	TRC1_Viewpoint[1]	= TRC1Location[1] + 10;
	TRC1_Viewpoint[2]	= TRC1Location[2] +Math.cos(TRC1_XZangle[3] - 1.57)*40;
	Browser.println ('TRC1_Viewpoint	'+ TRC1_Viewpoint);
	TRC1_ViewpointAngle[3]	= TRC1_XZangle[3] - 1.57 ;

	TRC2_Viewpoint[0]	= TRC2Location[0] + Math.sin(TRC2_XZangle[3] - 1.57)*40 ;
	TRC2_Viewpoint[1]	= TRC2Location[1] + 10;
	TRC2_Viewpoint[2]	= TRC2Location[2] + Math.cos(TRC2_XZangle[3] - 1.57)*40;
	TRC2_ViewpointAngle[3]	= TRC2_XZangle[3] - 1.57 ;
	Browser.println ('TRC2_Viewpoint	'+ TRC2_Viewpoint);

	HighAboveViewpoint[0]	= center[0] + Math.sin(TRC1_XZangle[3])*3000 ;
	HighAboveViewpoint[1]	= center[1]  + 5000;
	HighAboveViewpoint[2]	= center[2] + Math.cos(TRC1_XZangle[3])*3000 ;
	Browser.println ('HighAboveViewpoint	'+ HighAboveViewpoint);
//	HighAboveViewpointAngle[3]	= Math.cos(TRC1_XZangle[3]) ;
	HighAboveTranslationAngle[3]	= TRC1_XZangle[3] ;
//	Browser.println ('HighAboveTranslationle		'+ HighAboveViewpointAngle);
	Browser.println ('HighAboveXZTranslationAngle	'+HighAboveTranslationAngle);



}

function computeTropoDistance(loc1, loc2 )
{
	tropoDeltaX 	= (loc2[0] - loc1[0]) ;
	tropoDeltaY 	= (loc2[1] - loc1[1]) ;
	tropoDeltaZ 	= (loc2[2] - loc1[2]) ;
	tropoDistanceSquared	= tropoDeltaX * tropoDeltaX + tropoDeltaY * tropoDeltaY + tropoDeltaZ * tropoDeltaZ ;
	Browser.println ('Distance Squared	=' + tropoDistanceSquared);
	tropoDistance 	= Math.sqrt(tropoDistanceSquared) ;
	Browser.println ('Distance	=' + tropoDistance);

	if (XZDistance > 100/.6*1000) {
		LinkEstablished = false;
		//TRC1_beamLength = 5000 ;
		//TRC2_beamLength = 5000 ;
	}
}

function computeTropoXZangle( )
{
	if (tropoDeltaZ == 0) {
		tropoDeltaZ = .00000001 ;
	}

	angle 	= Math.atan(tropoDeltaX/tropoDeltaZ) ;
	if (tropoDeltaZ < 0) {
		XZangle[3] = angle + Math.PI/2;
	}
	else {
		XZangle[3] = angle -  Math.PI/2;
	}
	Browser.println ('Angle	=' + XZangle[3]);
//	Browser.println ('Angle2	=' + TRC2_XZangle[3]);
}


function computeTropoXYangle( )
{
	Browser.println ('tropoDeltaY	=' + tropoDeltaY);
	angle 	= Math.asin(tropoDeltaY/tropoDistance) ;
	XYangle[3] = angle ;
	//XYangle[3]  = - TRC1_XYangle[3];

	Browser.println ('AngleXY	=' +XYangle[3]);
//	Browser.println ('Angle2XY	=' + TRC2_XYangle[3]);
}

function computeDistance( )
{
	Browser.println ('TRC1	=' + TRC1Location);
	Browser.println ('TRC2	=' + TRC2Location);
	deltaX 	= (TRC2Location[0] - TRC1Location[0]) ;
	deltaY 	= (TRC2Location[1] - TRC1Location[1]) ;
	deltaZ 	= (TRC2Location[2] - TRC1Location[2]) ;
	distanceSquared	= deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ ;
	Browser.println ('Distance Squared	=' + distanceSquared);
	distance 	= Math.sqrt(distanceSquared) ;
	Browser.println ('Distance	=' + distance);

	beamScale[0] 	= distance/10;
	beamScale[1]	= 10;
	beamScale[2]	= 10;
	Browser.println ('BeamScale	=' + beamScale);
	TRC1_beamLength 	= distance -2;
	TRC2_beamLength 	= distance -2;
	if (distance > 5/.6*1000) {
		LinkEstablished = false;
		TRC1_beamLength = 5000/.6 ;
		TRC2_beamLength = 5000/.6 ;
	}
}

function computeXZangle( )
{
	if (deltaZ == 0) {
		deltaZ = .00000001 ;
	}

	angle 	= Math.atan(deltaX/deltaZ) ;
	if (deltaZ < 0) {
		TRC1_XZangle[3] = angle + Math.PI/2;
	}
	else {
		TRC1_XZangle[3] = angle -  Math.PI/2;
	}
	TRC2_XZangle[3]  = TRC1_XZangle[3] +  Math.PI;

	Browser.println ('Angle	=' + TRC1_XZangle[3]);
	Browser.println ('Angle2	=' + TRC2_XZangle[3]);
}



function computeXYangle( )
{
	angle 	= Math.asin(deltaY/distance) ;
	TRC1_XYangle[3] = angle ;
	TRC2_XYangle[3]  = - TRC1_XYangle[3];

	Browser.println ('AngleXY	=' + TRC1_XYangle[3]);
	Browser.println ('Angle2XY	=' + TRC2_XYangle[3]);
}
""")
            .addField(new field().setName("TRC1Location").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("TRC2Location").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("OperatingMode").setType(field.TYPE_SFSTRING).setAccessType(field.ACCESSTYPE_INITIALIZEONLY))
            .addField(new field().setName("TRC1_XZangle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC2_XZangle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("beamScale").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC1_beamLength").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC2_beamLength").setType(field.TYPE_SFFLOAT).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC1_XYangle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC2_XYangle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("LinkEstablished").setType(field.TYPE_SFBOOL).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC1_Viewpoint").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC2_Viewpoint").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC1_ViewpointAngle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("TRC2_ViewpointAngle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("HighAboveViewpoint").setType(field.TYPE_SFVEC3F).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("HighAboveTranslationAngle").setType(field.TYPE_SFROTATION).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .addField(new field().setName("WhichBeam").setType(field.TYPE_SFINT32).setAccessType(field.ACCESSTYPE_OUTPUTONLY))
            .setIS(new IS()
              .addConnect(new connect().setNodeField("TRC1Location").setProtoField("TRC1Location"))
              .addConnect(new connect().setNodeField("TRC2Location").setProtoField("TRC2Location"))
              .addConnect(new connect().setNodeField("OperatingMode").setProtoField("OperatingMode")))))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC1_XZangle").setToNode("TRC1_TRANSFORM").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC2_XZangle").setToNode("TRC2_TRANSFORM").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC1_beamLength").setToNode("TRC1_BEAMCYLINDER").setToField("range"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC1_beamLength").setToNode("TRC1_BEAMCONE").setToField("range"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC2_beamLength").setToNode("TRC2_BEAMCYLINDER").setToField("range"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC1_beamLength").setToNode("TRC2_BEAMCONE").setToField("range"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC1_XYangle").setToNode("TRC1_XY_TRANSFORM").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC2_XYangle").setToNode("TRC2_XY_TRANSFORM").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("LinkEstablished").setToNode("TRC1_BEAMCYLINDER").setToField("contact"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("LinkEstablished").setToNode("TRC1_BEAMCONE").setToField("contact"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("LinkEstablished").setToNode("TRC2_BEAMCYLINDER").setToField("contact"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("LinkEstablished").setToNode("TRC2_BEAMCONE").setToField("contact"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC1_Viewpoint").setToNode("TRC1Viewpoint").setToField("position"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC2_Viewpoint").setToNode("TRC2Viewpoint").setToField("position"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC1_ViewpointAngle").setToNode("TRC1Viewpoint").setToField("orientation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("TRC2_ViewpointAngle").setToNode("TRC2Viewpoint").setToField("orientation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("HighAboveViewpoint").setToNode("HighAboveXZTranslation").setToField("translation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("HighAboveTranslationAngle").setToNode("HighAboveXZTranslation").setToField("rotation"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("WhichBeam").setToNode("BeamSwitch").setToField("whichChoice"))
        .addChild(new ROUTE().setFromNode("CalculateAngleScript").setFromField("WhichBeam").setToNode("BeamSwitch2").setToField("whichChoice"))))
    .addChild(new WorldInfo().setInfo(new String[] {"Authors: Mike Hunsberger","Revised: 30 April 2001","Purpose: Pair of TSSRs","Browser: CosmoPlayer"}).setTitle("AntennaWorld"))
    .addChild(new ProtoInstance("TRC170Pair").setContainerField("children")
      .addFieldValue(new fieldValue().setName("TRC1Location").setValue(new SFVec3f(0.0,0.0,0.0)))
      .addFieldValue(new fieldValue().setName("TRC2Location").setValue(new SFVec3f(-20000.0,0.0,-20000.0)))
      .addFieldValue(new fieldValue().setName("OperatingMode").setValue("TROPOSCATTER")))
    .addChild(new Background().setGroundAngle(new double[] {1.57079}).setGroundColor(new MFColor(new double[] {1.0,0.8,0.6,0.6,0.4,0.2})).setSkyAngle(new double[] {0.2}).setSkyColor(new MFColor(new double[] {1.0,1.0,1.0,0.2,0.2,1.0}))));
            }
            catch (Exception ex)
            {       
                System.err.println ("*** Further hints on X3DJSAIL errors and exceptions at");
                System.err.println ("*** https://www.web3d.org/specifications/java/X3DJSAIL.html");
                throw (ex);
            }
	}
	// end of initialize() method

	/** The initialized model object, created within initialize() method. */
	private X3D x3dModel;

	/** 
	 * Provide a 
	 * <a href="https://dzone.com/articles/java-copy-shallow-vs-deep-in-which-you-will-swim" target="_blank">shallow copy</a>
	 * of the X3D model.
	 * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html">X3D</a>
	 * @return TRC170PairPrototype model
	 */
	public X3D 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 <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#handleArguments-java.lang.String:A-">X3D.handleArguments(args)</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/Core/X3D.html#validationReport--">X3D.validationReport()</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html">CommandLine</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/CommandLine.html#USAGE">CommandLine.USAGE</a>
     * @see <a href="https://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/ConfigurationProperties.html">ConfigurationProperties</a>
     */
    public static void main(String args[])
    {
        System.out.println("Build this X3D model, showing validation diagnostics...");
        X3D thisExampleX3dModel = new TRC170PairPrototype().getX3dModel();
//      System.out.println("X3D model construction complete.");
	
        // next handle command line arguments
        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(X3D.FILE_EXTENSION_X3D) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_CLASSICVRML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_X3DB) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_VRML97) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_EXI) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_GZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_ZIP) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_HTML) ||
                                arg.toLowerCase().endsWith(X3D.FILE_EXTENSION_XHTML))
                        {
                                argumentsLoadNewModel = true;
                                fileName = arg;
                        }
                }
        }
        if      (argumentsLoadNewModel)
                System.out.println("WARNING: \"Savage.CommunicationsAndSensors.TRC170.TRC170PairPrototype\" 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
                thisExampleX3dModel.handleArguments(args);
	
        if (validate)
        {
            //  System.out.println("--- TODO fix duplicated outputs ---"); // omit when duplicated outputs problem is solved/refactored
		String validationResults = thisExampleX3dModel.validationReport();
            //  System.out.println("-----------------------------------"); // omit when duplicated outputs problem is solved/refactored
                System.out.print("Savage.CommunicationsAndSensors.TRC170.TRC170PairPrototype self-validation test confirmation: ");
                if (!validationResults.equals("success"))
                    System.out.println();
                System.out.println(validationResults.trim());

                // experimental: test X3DJSAIL output files
                // CommunicationsAndSensors/TRC170/TRC170PairPrototype_JavaExport.* file validation is checked when building X3D Example Archives
                String filenameX3D  = "CommunicationsAndSensors/TRC170/TRC170PairPrototype_JavaExport.x3d"; 
                String filenameX3DV = "CommunicationsAndSensors/TRC170/TRC170PairPrototype_JavaExport.x3dv"; 
                String filenameJSON = "CommunicationsAndSensors/TRC170/TRC170PairPrototype_JavaExport.json";
                thisExampleX3dModel.toFileX3D        (filenameX3D);
                thisExampleX3dModel.toFileClassicVRML(filenameX3DV);
// TODO         thisExampleX3dModel.toFileJSON       (filenameJSON);
        }
    }
}
