<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Virtual Earth 3D team blog : Math</title><link>http://blogs.msdn.com/virtualearth3d/archive/tags/Math/default.aspx</link><description>Tags: Math</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Camera Control</title><link>http://blogs.msdn.com/virtualearth3d/archive/2008/10/22/camera-control.aspx</link><pubDate>Wed, 22 Oct 2008 20:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9011369</guid><dc:creator>NikolaiF</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/virtualearth3d/comments/9011369.aspx</comments><wfw:commentRss>http://blogs.msdn.com/virtualearth3d/commentrss.aspx?PostID=9011369</wfw:commentRss><description>&lt;P&gt;In this sample, we create a plug-in to move the camera to a random location in the world every time a HTML button is pressed.&amp;nbsp; It demonstrates basic plug-in loading, writing and using a CameraController, and communicating between a plug-in and the hosting web page via Events.&lt;/P&gt;
&lt;P&gt;&lt;A class="" title="Camera Control" href="http://www.veteam.members.winisp.net/Spaceland/Samples/Camera/TestPage.htm" target=_blank mce_href="http://www.veteam.members.winisp.net/Spaceland/Samples/Camera/TestPage.htm"&gt;See it in action.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Camera controllers&amp;nbsp;are important because it provides a single and consistent way of updating the camera.&amp;nbsp; Consistency is important because the camera needs to be in one position throughout an entire frame -- otherwise one part of the code may think the camera is in one place while another thinks it's elsewhere.&amp;nbsp; This is why you normally read the camera through its Snapshot in the SceneState object, and can only set it via a controller, of which there may only be one active at a time.&lt;/P&gt;
&lt;P&gt;Normally you position the camera with two properties, the position and the orientation.&amp;nbsp; Either can be set in terms of global or local coordinates.&amp;nbsp; Global essentially means relative to the center of the earth, while local means relative to your current location on the globe.&amp;nbsp; For position, global coordinates are in terms of Vector3D, local in terms of latitude, longitude, and altitude.&amp;nbsp; For orientation, you would normally set it globally in terms of lookat and lookup, Vector3Ds, and locally in terms of roll, pitch, and yaw.&amp;nbsp; See the &lt;A class="" title="Basic Math" href="http://blogs.msdn.com/virtualearth3d/archive/2008/05/06/basic-math.aspx" mce_href="http://blogs.msdn.com/virtualearth3d/archive/2008/05/06/basic-math.aspx"&gt;Basic Math&lt;/A&gt; entry for more.&lt;/P&gt;
&lt;P&gt;When this plug-in is Activated, it creates a new JumpController and begins listening to an event from CommunicationManager, but otherwise doesn't do anything.&amp;nbsp; The script on TestPage.htm is then able to raise that event, which causes JumpHandler to be fired.&amp;nbsp; A new random position is generated and given to the JumpController.&amp;nbsp; The JumpController is then set to be the current CameraController.&amp;nbsp; The next time the render thread calls the CameraStep, the JumpController will be called instead of the Default controller.&amp;nbsp; The JumpController's Activate function is called first, and it indicates that HasArrived&lt;BR&gt;is false, which means it still has work to do.&amp;nbsp; The MoveCamera is called, and the JumpController is allowed to modify its Camera property.&amp;nbsp; The CameraStep will use these values to set up the next scene and frame for rendering.&amp;nbsp; In addition, the JumpController sets HasArrived to true, indicating it has&lt;BR&gt;completed its work.&amp;nbsp; This causes the system to automatically swap JumpController's Next controller to be the Current one, in this case simply restoring control to the Default.&lt;/P&gt;
&lt;P&gt;If we wanted to animate to the location, we would adjust the current position a little at a time over a series of calls to MoveCamera, and only when we are down would we set HasArrived to true.&amp;nbsp; We could also take over completely, using Bindings to detect user input and making changes to Camera as needed,&lt;BR&gt;and only setting HasArrived when we want to return control to the Default.&lt;/P&gt;
&lt;P&gt;Note, at this time we only support one camera and one viewpoint at a time.&lt;/P&gt;
&lt;P&gt;&lt;A class="" title="Code samples" href="http://blogs.msdn.com/virtualearth3d/archive/2008/09/25/current-samples.aspx" mce_href="http://blogs.msdn.com/virtualearth3d/archive/2008/09/25/current-samples.aspx"&gt;Get the code!&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9011369" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/VE3D/default.aspx">VE3D</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Plug-In/default.aspx">Plug-In</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Math/default.aspx">Math</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Camera/default.aspx">Camera</category></item><item><title>Basic Math</title><link>http://blogs.msdn.com/virtualearth3d/archive/2008/05/06/basic-math.aspx</link><pubDate>Tue, 06 May 2008 19:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8463463</guid><dc:creator>Heptazane</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/virtualearth3d/comments/8463463.aspx</comments><wfw:commentRss>http://blogs.msdn.com/virtualearth3d/commentrss.aspx?PostID=8463463</wfw:commentRss><description>&lt;P&gt;When working with things that exist on the globe, there is a fair bit of basic math that complicates your life.&amp;nbsp; Let's start of with a mesh that you want to add to the Earth.&amp;nbsp; We recommend that you orient your mesh so that it is facing along the Y axis, Z is up, and X is to the right, as shown with this car.&amp;nbsp;&amp;nbsp;While you can do your own thing, this will simplify using RollPitchYaw later, which is the most common way&amp;nbsp;that we orient things locally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;IMG title="Recommended local coordinates." style="WIDTH: 155px; HEIGHT: 181px" height=181 alt="Recommended local coordinates." src="http://www.veteam.members.winisp.net/Images/RollPitchYaw.png" width=155 mce_src="http://www.veteam.members.winisp.net/Images/RollPitchYaw.png"&gt;&lt;/P&gt;
&lt;P&gt;Now the object needs to be placed on the Earth which involves transforming it from it's local space, onto the globe.&amp;nbsp; The globe is a &lt;A href="http://en.wikipedia.org/wiki/WGS84" mce_href="http://en.wikipedia.org/wiki/WGS84"&gt;WGS84&lt;/A&gt; ellipsoid that is laid out as shown in this image.&amp;nbsp; Note that the Z axis points up through the North Pole, and the X axis points out through latitude\longitude 0,0 (just south of Ghana in the Atlantic).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;IMG title="Structure of the globe" style="WIDTH: 289px; HEIGHT: 353px" height=353 alt="Structure of the globe" src="http://www.veteam.members.winisp.net/Images/StructureOfTheGlobe.png" width=289 mce_src="http://www.veteam.members.winisp.net/Images/StructureOfTheGlobe.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Arial','sans-serif'"&gt;So if your object is placed on this globe and&amp;nbsp;it has a local yaw of 0, it will be facing North.&amp;nbsp; If it has a local pitch of 0, it will be looking horizontally... approximately at the horizon.&amp;nbsp; If your local orientation remains the same, but the position of the object changes on the surface of the globe, the&amp;nbsp;&lt;I&gt;&lt;SPAN style="FONT-FAMILY: 'Arial','sans-serif'"&gt;global&lt;/SPAN&gt;&lt;/I&gt; orientation of the object will change.&amp;nbsp; To assist in the manipulation of position, local orientation, and global orientation, we provide the Microsoft.MapPoint.Rendering3D.Cameras.GeodeticViewpoint class.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This class automatically handles the conversions, for example:&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;// Set up the viewpoint with a position and local orientation.&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;GeodeticViewpoint&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; viewpoint = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;GeodeticViewpoint&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;();&lt;BR&gt;viewpoint.Position.Location = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;LatLonAlt.CreateUsingDegrees&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;(33, -97, 10000); &lt;FONT color=#008000&gt;// Someplace over Dallas&lt;/FONT&gt;&lt;BR&gt;viewpoint.LocalOrientation.RollPitchYaw = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;RollPitchYaw&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;(0, 0, 90.0 * &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Constants&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.RadiansPerDegree);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;// Ask for the global orientation.&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;LookAtLookUp&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; globalOrientation = viewpoint.Orientation.LookAtLookUp;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size=2&gt;Note that the local yaw is set to 90 degrees which will face West.&amp;nbsp; The reason is that RollPitchYaw represents a rotation around the Y, X, and Z axes respectively.&amp;nbsp; So a Yaw rotation is&amp;nbsp;the left most diagram below.&amp;nbsp; This diagram holds for any use of Matrix4x4D.RotationX, Y, or Z, and can be useful in mentally visualizing how you're rotating in our coordinate space.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;IMG title=Rotation style="WIDTH: 407px; HEIGHT: 165px" height=165 alt=Rotation src="http://www.veteam.members.winisp.net/Images/Rotation.png" width=407 mce_src="http://www.veteam.members.winisp.net/Images/Rotation.png"&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;The GeodeticViewpoint class has a bunch of helper properties on it, for example you can adjust just the altitude on the viewpoint, and anything that depends on that change will cascade out:&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;viewpoint.Position.Altitude = 500;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Also, one of the things that using the viewpoint also saves you is that calculating the exact X,Y,Z coordinate from the latitude/longitude/altitude that you provided which is quite tricky since we use WGS84.&amp;nbsp; However GeodeticViewpoint makes that easy:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT color=#2b91af size=2&gt;&lt;FONT color=#2b91af size=2&gt;Vector3D&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; coordinate = viewpoint.Position.Vector;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;
&lt;P&gt;I've shown a lot of random tidbits above, and included diagrams from bits of "cheat sheet" that I made up for developers here.&amp;nbsp; If there are parts that don't make sense, feel free to comment.&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8463463" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Code/default.aspx">Code</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Virtual+Earth+3D/default.aspx">Virtual Earth 3D</category><category domain="http://blogs.msdn.com/virtualearth3d/archive/tags/Math/default.aspx">Math</category></item></channel></rss>