<?xml version="1.0" encoding="UTF-8" ?>
<sector name="Ballistics" >
    <vGravity> {0,-9.8,0} </vGravity>
	<vEye> {-1.0, 0.0, 2.0} </vEye>
	<vTarget> {0.0, 0.0, 0.0} </vTarget>
	<fHeading> 0.0 </fHeading> <!-- degrees -->
	<fPitch> 45.0 </fPitch> <!-- degrees -->
	<fZoom> 3.0 </fZoom>
	
	<fPitchIncrement> 5.0 </fPitchIncrement>
	<fHeadingIncrement> 5.0 </fHeadingIncrement>
	<fZoomIncrement> 0.25 </fZoomIncrement>
	<vViewport> {0.0, 0.0, 640.0, 480.0} </vViewport>
	<vUp> {0.0, 1.0, 0.0} </vUp>
	<fFOV> 90.0 </fFOV> <!-- horizontal -->
	<fClipNear> 0.1 </fClipNear>
	<fClipFar> 10000.0 </fClipFar>
	<tRenderInit prototype="Entity">
		<Init>
			<tInitOrbitCam prototype="ActionSetOrbitCamera">
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rHeading> fHeading </rHeading>
				<rPitch> fPitch </rPitch>
				<rZoom> fZoom </rZoom>
			</tInitOrbitCam>
			<tInitCameras prototype="ActionSetCamera">
				<rViewport> vViewport </rViewport>
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rUp>vUp </rUp>
				<rFOV> fFOV </rFOV> <!-- horizontal -->
				<rClipNear> fClipNear </rClipNear>
				<rClipFar> fClipFar </rClipFar>
			</tInitCameras>
		</Init>
	</tRenderInit>
	
	<iSimulationHasBegun> 0 </iSimulationHasBegun>
    <vForce> {0 0 0 0} </vForce>        <!--Newtons-->
	<tObjectAttachedToSpring prototype="Entity">
	    <!--Graphics related-->
		<pVertexBuffer>NULL</pVertexBuffer>
		<pXFormedVertexBuffer>NULL</pXFormedVertexBuffer>
		<pIndexBuffer>NULL</pIndexBuffer>
		<sFilename>teapot.obj</sFilename>
		<iNumVertices>0</iNumVertices>
		<iNumFaces>0</iNumFaces>
		<iUseIndexBuffer>true</iUseIndexBuffer>
		<vScale> {1.0, 1.0, 1.0} </vScale>
		<vRotate> {0.0, 0.0, 1.0, 0.0} </vRotate>
		<vTranslate> {0.0, 0.0, 0.0} </vTranslate> <!--meters-->
		<!--Physics related-->
    <vVelocity> {0 0 0 0} </vVelocity>  <!--m/s-->  <!--calculated output value-->
    <!-- <vForce> {0 0 0 0} </vForce> -->
    <vMomentum> {0 0 0 0} </vMomentum>  <!--N*s-->
    <fMass>1</fMass>                    <!--kg-->  <!--init will use this to calculate fMassInverse-->
    <!-- aerodynamic properties -->
    <!-- since this is a particle, cross sectional area is 0 -->
    <!-- for the sake of simulation, however, we will say it is a sphere -->
    <fRadius> 1.0 </fRadius>
    <fCoeffDrag> 0.001 </fCoeffDrag>
    <fCrossSectionalArea></fCrossSectionalArea>
		<Init>
			<tCreateGeometry prototype="ActionCreateGeometryBuffers">
				<rVertexBuffer>pVertexBuffer</rVertexBuffer>	
				<rXFormedVertexBuffer>pXFormedVertexBuffer</rXFormedVertexBuffer>
				<rIndexBuffer>pIndexBuffer</rIndexBuffer>
				<rFilename>sFilename</rFilename>
				<rNumVertices>iNumVertices</rNumVertices>
				<rNumFaces>iNumFaces</rNumFaces>
				<rUseIndexBuffer>iUseIndexBuffer</rUseIndexBuffer>
			</tCreateGeometry>
			<expr index="1"> fCrossSectionalArea = 3.14159 * fRadius * fRadius </expr>
		</Init>
		<Update>
		    <tUpdateDynamics prototype="ActionUpdateDynamics">
                <rPosition>vTranslate</rPosition>
                <rVelocity>vVelocity</rVelocity>
                <rForce>vForce</rForce>
                <rMomentum>vMomentum</rMomentum>
                <rMass>fMass</rMass>
            </tUpdateDynamics>
            <if>
                <rCondition> iSimulationHasBegun </rCondition>
                <then>
                    <!-- Update Force -->
                    <fMagVelocity></fMagVelocity>
                    <expr> fMagVelocity = sqrt ( vVelocity * vVelocity ) </expr>
                    <!-- Fdrag = -v*|v|*A*c -->
                    <expr index="1" > vForce = - 1 * vVelocity * fMagVelocity * fCrossSectionalArea * fCoeffDrag </expr>
                    <expr index="2" > vForce += vGravity </expr>
                </then>
            </if>
		</Update>
		<Render>
			<tRenderGeometry prototype="ActionRenderGeometry">
				<rVertexBuffer>pVertexBuffer</rVertexBuffer>
				<rXFormedVertexBuffer>pXFormedVertexBuffer</rXFormedVertexBuffer>
				<rIndexBuffer>pIndexBuffer</rIndexBuffer>
				<rFilename>sFilename</rFilename>
				<rNumVertices>iNumVertices</rNumVertices>
				<rNumFaces>iNumFaces</rNumFaces>
				<rUseIndexBuffer>iUseIndexBuffer</rUseIndexBuffer>
				<rScale>vScale</rScale>
				<rRotate>vRotate</rRotate>
				<rTranslate>vTranslate</rTranslate>
			</tRenderGeometry>
			<!-- On-screen text -->
			<tTextRendering prototype ="ActionList">
        <sText> Force: </sText>
        <sText index="1"> null </sText>
        <vColor> {1,1,1,1} </vColor>
        <sFont> Courier New </sFont>
        <iSize> 20 </iSize>
        <expr> sText [ 1 ] = vForce </expr>
        <tForceRender prototype="ActionRenderText">
          <vPosition> {0,0,0,0} </vPosition>
          <rText> sText </rText>
          <rPosition> vPosition </rPosition>
          <rColor> vColor </rColor>
          <rFont> sFont </rFont>
          <rSize> iSize </rSize>
        </tForceRender>
      </tTextRendering>      
		</Render>
	</tObjectAttachedToSpring>
	
	<!-- Input Reactions -->
	<!-- Camera Controls -->
	<tReactionUp prototype="ReactionInput">
		<iSoughtInputs>btup</iSoughtInputs>
		<iMask>-1</iMask>
		
		<tUpdateCamera prototype="ActionList">
			<expr> fPitch = fPitch + fPitchIncrement </expr>
			<tRefreshOrbitCam prototype="ActionSetOrbitCamera">
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rHeading> fHeading </rHeading>
				<rPitch> fPitch </rPitch>
				<rZoom> fZoom </rZoom>
			</tRefreshOrbitCam>
			<tRefreshCamera prototype="ActionSetCamera">
				<rViewport> vViewport </rViewport>
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rUp>vUp </rUp>
				<rFOV> fFOV </rFOV>
				<rClipNear> fClipNear </rClipNear>
				<rClipFar> fClipFar </rClipFar>
			</tRefreshCamera>
		</tUpdateCamera>
	</tReactionUp>
	
	<tReactionDown prototype="ReactionInput">
		<iSoughtInputs>btdn</iSoughtInputs>
		<iMask>-1</iMask>
		
		<tUpdateCamera prototype="ActionList">
			<expr> fPitch = fPitch - fPitchIncrement </expr>
			<tRefreshOrbitCam prototype="ActionSetOrbitCamera">
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rHeading> fHeading </rHeading>
				<rPitch> fPitch </rPitch>
				<rZoom> fZoom </rZoom>
			</tRefreshOrbitCam>
			<tRefreshCamera prototype="ActionSetCamera">
				<rViewport> vViewport </rViewport>
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rUp>vUp </rUp>
				<rFOV> fFOV </rFOV>
				<rClipNear> fClipNear </rClipNear>
				<rClipFar> fClipFar </rClipFar>
			</tRefreshCamera>
		</tUpdateCamera>
	</tReactionDown>
	
	<tReactionLeft prototype="ReactionInput">
		<iSoughtInputs>btlt</iSoughtInputs>
		<iMask>-1</iMask>
		
		<tUpdateCamera prototype="ActionList">
			<expr> fHeading = fHeading + fHeadingIncrement </expr>
			<tRefreshOrbitCam prototype="ActionSetOrbitCamera">
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rHeading> fHeading </rHeading>
				<rPitch> fPitch </rPitch>
				<rZoom> fZoom </rZoom>
			</tRefreshOrbitCam>
			<tRefreshCamera prototype="ActionSetCamera">
				<rViewport> vViewport </rViewport>
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rUp>vUp </rUp>
				<rFOV> fFOV </rFOV>
				<rClipNear> fClipNear </rClipNear>
				<rClipFar> fClipFar </rClipFar>
			</tRefreshCamera>
		</tUpdateCamera>
	</tReactionLeft>
	
	<tReactionF1 prototype="ReactionInput">
		<iSoughtInputs>btf1</iSoughtInputs>
		<iMask>-1</iMask>
		
		<tUpdateCamera prototype="ActionList">
			<expr> fZoom -= fZoomIncrement </expr>
			<tRefreshOrbitCam prototype="ActionSetOrbitCamera">
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rHeading> fHeading </rHeading>
				<rPitch> fPitch </rPitch>
				<rZoom> fZoom </rZoom>
			</tRefreshOrbitCam>
			<tRefreshCamera prototype="ActionSetCamera">
				<rViewport> vViewport </rViewport>
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rUp>vUp </rUp>
				<rFOV> fFOV </rFOV>
				<rClipNear> fClipNear </rClipNear>
				<rClipFar> fClipFar </rClipFar>
			</tRefreshCamera>
		</tUpdateCamera>
	</tReactionF1>
	
	<tReactionF2 prototype="ReactionInput">
		<iSoughtInputs>btf2</iSoughtInputs>
		<iMask>-1</iMask>
		
		<tUpdateCamera prototype="ActionList">
			<expr> fZoom += fZoomIncrement </expr>
			<tRefreshOrbitCam prototype="ActionSetOrbitCamera">
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rHeading> fHeading </rHeading>
				<rPitch> fPitch </rPitch>
				<rZoom> fZoom </rZoom>
			</tRefreshOrbitCam>
			<tRefreshCamera prototype="ActionSetCamera">
				<rViewport> vViewport </rViewport>
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rUp>vUp </rUp>
				<rFOV> fFOV </rFOV>
				<rClipNear> fClipNear </rClipNear>
				<rClipFar> fClipFar </rClipFar>
			</tRefreshCamera>
		</tUpdateCamera>
	</tReactionF2>
	
	<tReactionRight prototype="ReactionInput">
		<iSoughtInputs>btrt</iSoughtInputs>
		<iMask>-1</iMask>
		
		<tUpdateCamera prototype="ActionList">
			<expr> fHeading = fHeading - fHeadingIncrement </expr>
			<tRefreshOrbitCam prototype="ActionSetOrbitCamera">
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rHeading> fHeading </rHeading>
				<rPitch> fPitch </rPitch>
				<rZoom> fZoom </rZoom>
			</tRefreshOrbitCam>
			<tRefreshCamera prototype="ActionSetCamera">
				<rViewport> vViewport </rViewport>
				<rEye> vEye </rEye>
				<rTarget> vTarget </rTarget>
				<rUp>vUp </rUp>
				<rFOV> fFOV </rFOV>
				<rClipNear> fClipNear </rClipNear>
				<rClipFar> fClipFar </rClipFar>
			</tRefreshCamera>
		</tUpdateCamera>
	</tReactionRight>
	
	<!-- Physics controls -->
	<tReactionEnter prototype="ReactionInput">
		<iSoughtInputs>spce</iSoughtInputs>
		<iMask>-1</iMask>
		<tApplyForceToObject prototype="ActionList">
			<expr> vForce = {500,500,0,0} </expr>
			<expr index="1"> iSimulationHasBegun = 1 </expr>
		</tApplyForceToObject>
	</tReactionEnter>
	
	<!-- Go to Dynamics demo. -->
	<tReactionSpace prototype="ReactionInput">
		<iSoughtInputs>entr</iSoughtInputs>
		<iMask>-1</iMask>
		<tUnload prototype="ActionUnloadSector">
            <sSectorName>Ballistics</sSectorName>
        </tUnload>
		<tLoad prototype="ActionLoad">
            <sFilename>Dynamics.xml</sFilename>
            <iSynch>0</iSynch>
        </tLoad>
	</tReactionSpace>
</sector>