![]() |
|
Spaces home Heptazane's StumpPhotosProfileFriendsMore ![]() | ![]() |
|
Heptazane's StumpManipulating Virtual Earth 3D in C#... and other thoughts
April 19 The Awesome Loading ScreenI just posted an article on the Virtual Earth 3D team blog about creating a Windows Application with the new GoliatH release, then felt bad about my poor blog not getting any love. So I decided to post something of no worth to C# programming, but of somewhat interesting historical value: the VE3D control "Circle of Hope".
When we were first getting started with VE3D, I had set up a very basic framework with an empty sphere in it that people could start attaching substantial things to. At that point I had dropped in some text in that intermittent span between the control being created and the DX subsystem being initialized, but it was dull and unsatisfying. I think I was in my morning shower (where all the good ideas happen) and was thinking about this span of time and decided that it need to look cooler. I've always liked eclipses, and the loading time was a period when we didn't have the Earth yet, but it was coming. So I had this idea an eclipse-like graphic emerging. I confess that in my head it looked a little more like the Heros logo, but as I began playing with colors, it became clear that it wouldn't mesh with the colors that had been picked for the Live Maps website. So I ended up borrowing some out of there. I assumed that eventually our design team would throw it out and replace it with something more boring, but I was having fun so I dropped it in. It turned out that the 3D control itself ended up with pretty much one designer: Rick... a man who gets props from me for not only leaving my loading screen in, but for getting me my WoW Figure Print. He decided to leave it alone and, I believe, coined the name "Circle of Hope" since during initial development you frequently had to hope that it would load. Anyhow, I'm happy with it since it is pretty much the only piece of my mind-blowing artistic creativity that remains... April 14 New MSDN blogFrom now on, meaningful VE3D C# samples and discussion will take place at http://blogs.msdn.com/VirtualEarth3D/, so go there and check it out. Also, I was made aware of the new 3D blog at http://ve3d.spaces.live.com/.
April 12 GoliatH Release LiveJust in case you missed it, the latest version of Live Maps including a new 3D control went live on the 10th. This means that all your programs are most likely broken. As always, check out http://virtualearth.spaces.live.com/ for features and whatnot. We hope to have some new samples up shortly, so stay tuned. January 10 FigurePrintsWell, my wife got in her FigurePrint for Christmas. They hardly need any free advertising from me because of their awesomeness, but check out http://figureprints.com/ if you've been living under a rock and haven't been there.
December 04 Kristoffer's BlogI was just informed that my comrade-in-arms in the evil empire: Kristoffer has a blog on doing cool things with VE3D. Check it out at http://blogs.msdn.com/kristoffer/default.aspx or we'll send the Borg Cube to land on your house. Seriously though, I've had people pull up to me while I was walking down the road and ask me where "the Microsoft building" is. Well, we have tools for letting you view buildings, and in this view, pretty much every building comprises main and west campus. That doesn't include the countless other campuses both in the area and world wide. While I think it would be sweet to just have a giant Borg Cube from which we all operate off of the hive mind, reality, as usual, takes its own path. November 30 Using the WiimoteI just had this sent to me about how to code a plug-in for VE3D to support the Wiimote:
I haven't tried it since I don't have any Wii peripherals, but it gave me a great deal of satisfaction to see it extended this way using the plug-in and bindings system that I (and others) have worked so hard on. Makes me just a little teary-eyed. November 12 Embedding the Gemini release in WinFormsWell, I got a few free moments yesterday to sit down and see if the control still works as a WinForms control. The answer is no and yes. Unfortunately no one had the time to polish off the drop-on-a-form-from-the-toolbox scenario, so if you try to do that, you'll get an exception. As a reminder, this is all unsupported, so the fact that it is crufty is the way it is. However, it does provide a way to get all of the references in place, so here's what I did:
(1/1/08) Note that the trick I used no longer works, so the original trick is in grey, with new steps in black.
this.globeControl = new GlobeControl(); this.SuspendLayout(); this.globeControl.Location = new System.Drawing.Point(0, 0); this.globeControl.Name = "globeControl"; this.globeControl.Size = this.ClientSize; this.globeControl.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; this.globeControl.TabIndex = 0; this.globeControl.Host.DataSources.Add(new DataSourceLayerData("Elevation", "Elevation", @"http://sc1.maps.live.com//Manifests/HD.xml", DataSourceUsage.ElevationMap)); this.globeControl.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"http://sc1.maps.live.com//Manifests/HT.xml", DataSourceUsage.TextureMap)); this.globeControl.Host.DataSources.Add(new DataSourceLayerData("Models", "Models", @"http://sc1.maps.live.com//Manifests/MO.xml", DataSourceUsage.Model)); this.globeControl.Host.WorldEngine.ShowBuildingTextures = true; this.globeControl.Host.CameraControllers.Camera.Viewpoint.Position.Location = new LatLonAlt(0.830766834501557, -2.13516921856724, 299.907466547564); this.globeControl.Host.CameraControllers.Camera.Viewpoint.LocalOrientation.RollPitchYaw = new RollPitchYaw(0, -0.391886060767613, 0); this.Controls.Add(this.globeControl); this.ResumeLayout(false); You'll have to add a "GlobeControl globeControl;" local variable and resolve any missing using clauses (just right click on the unknown type and select Resolve->using Xyz), but that should drop you in downtown Seattle. October 25 Bird's Eye in 3DI was thinking about writing a few nuggets about my experiences with Bird’s Eye in 3D, so here it is. I’ll warn you that I’m listening to JoCo, so I might get a little silly. Also, I’ll include people’s names if I can find plenty of references to them on the internet anyhow… the rest will remain anonymous.
I think one misconception of development at Microsoft is that every feature has a massive team of people that make it happen, well the BE3D client module had a relatively large team for our group: one Program Manager (Gene Vaatveit of MS Flight Simulator fame), one Dev Lead (Tommer Leyvand), me (to write all the code), and two excellent testers to keep me honest. However, the client does hook into a large chunk of existing infrastructure for the photos and photo metadata and it is installed, called by the shell, and so on… if I started naming names there I wouldn’t have any space left. Another misconception is that BE3D uses Photosynth technology (http://labs.live.com/photosynth/). Now don’t get me wrong, we have nothing but love for our homies in Photosyth, and we had all used it quite a bit, but we took nothing from them other than ideas. That isn’t to say that we won’t in the future, but the reconstruction that they do is not necessary for Bird’s Eye images since they are all geotagged by the Microsoft Ultracam as the plane flies overhead (yes, the camera does transform into a killer robot, so watch the skies). Bird’s Eye images are also huge which introduces certain technical challenges, and we have very specific types of navigation that we need to deal with. So it was really quicker to start from scratch on this one. When we started out the plan was to allow you to select a photo and then drop a billboard in space that you could navigate around. This turned out to be pretty pointless and confusing, so the only time you see a floating billboard is when you first turn on the BE layer, and if you hit Escape/wheel out to get out of a photo. However, these billboards immediately disappear when you do anything other than re-select them. I was really having fun with the billboards, sticking frustums on them and having them turn into flares when you zoom out, but Gene and Tommer reeled me back to Earth… and I grudgingly agree with them now. I guess I’ll wrap up with some things that I think are cool about BE3D. First, it is a standalone plug-in. We ultimately want a plug-in model that really rocks, and I’m happy that BE3D can be a proof of concept for this. Next, I like the fact that you can find an interesting place in 3D, turn on the BE3D layer and simply click on the place and have it show you the picture. Unfortunately we currently zoom in and out more than I’d like, but maybe next version. Finally I really like the way rotation looks. I didn’t have a good picture in my head for how it would turn out, but the final result looks great… at least I think so. October 16 Ships AhoyThe new Gemini release of Live Search Maps went live yesterday. Head on over to http://maps.live.com/ and check it out. October 14 PortalNot VE3D related, so stop reading if you're all work and no play. I just got through the game Portal by Valve which is really the commercial release of Narbacular Drop out of Digipen, but with Valve behind it. I'm a heavy gamer, and let me just say that the game is pure genius. The mechanics of it are fun, as Narbacular Drop was, but the environment and humor just blew me away. And, not to give anything away, but the game ends with a song which is truely icing on the cake... especially when I found out it was written by Jonathan Coulton. My hat is off to the team that worked on it... if I wore a hat.
The cake is a lie... October 12 New VersionVery shortly there will be a new version of the website and control. Lots of new features are packed into it, but in the spirit of blogging isolationism, I'll just talk about myself. I haven't been adding new entries lately because I've been heads down, and I'm never sure what I can and can't talk about, so I leave it up to our excellent VE Team blogger (http://virtualearth.spaces.live.com/) to keep all of you entertained. With this release ready, I find myself with some free time, although the future always calls... and when it isn't calling, I'm playing Half Life 2: Episode 2, Halo 3, WoW, or whatever captures my fancy... busy busy.
One sad piece of news that I should get out of the way first off so that we can focus on happier things is that this release will not see the VE3D SDK going public. There was too much that took priority over it, but I am told by more than one source that it will be high prio for next release, and as always I'll try to get some samples up or point you at people that have them. Since the existing release's SDK wasn't public, the new release has no upgrade story, so anything you've done so far will have to be reworked.
Okay, onto happier things. I finished this release working on the Bird's Eye Photos in 3D feature. It struck me as an odd feature when I started, but once you get into it is surprisingly useful. If you're in 3D you go to a city that has Bird's Eye imagery and hit the Bird's Eye button (just like you would for 2D), and you can then navigate the images, but with a 3D flair (incidentally it also used to have a 3D flare, but the PM made take it out... so I sent him to China... just kidding G).
I mention Bird's Eye Photos in 3D before the work that I did at the beginning of the release since I've been so focused on it that I can barely remember what I did then, however, I did spend a significant time at the beginning assisting in the redesign of the API. Plug-ins and the rendering internals now make quite a bit more sense, and the new structure lends itself to some scenarios that were before impossible. For example, with the new structure I was able to write a movie making sample that another developer was able to take and turn into a movie maker feature that is built into the new release... but I don't want to spoil the surprise too much. It's days away, I'll say that much.
July 03 Hill Shading in 2DEven though I'm primarily focused on 3D, I have to congratulate the Live Search Maps 2D team for rolling out hill shading in the road style. It was a lot of work to get it just right, and it looks awesome. Keep it LegalI've had questions lately about how to access the underlying file streams that we expose with VE3D (or should I say Live Search Maps 3D). I don't give legal advice, so read http://www.microsoft.com/virtualearth/control/terms.mspx, especially 5.3. May 30 New York City!A few nights ago we went live with buildings for New York city (and a load of other stuff). New York is of particular interest since it just has so many buildings... well, and hey... it's New York. April 04 Falcon ReleaseLast night the new Falcon release of the VE3D control was released (along with changes to the website). Some of the changes include an improved setup program, performance improvements, and support for the Space Navigator. However, I've warned before of the non-released status of the API, and with this release all of my samples are broken. I will post the fixed samples here as they become available:
Ghosts
The change was very minor for Ghosts. To show that it works, I added a photo of ghosts bursting out of my secret lair on Mt. Rainier... also known as Skullcrusher Mountain. After considering it a while, though, I decided that if I were an evil genius I'd pick Koko Crater for my lair since everyone needs a little sun, sand, and a Jamba Juice every now and then.
TopDown
This required no code changes, just a rebuild, so you can get the source below.
March 29 New DataI haven't posted here for a while since I've been pounding away at vNext, but there is new data available! We now have new/updated city models for: Portland, OR; SanDiego, CA; Chulavista, CA; East LA, CA; Long Beach, CA; Compton, CA; Glendale, CA; Paradise, NV; Spring Valley NV; Seattle, WA; San Francisco, CA; LAX, CA; Malibu, CA; Roseville, MN; Plymouth, GBR; Cardiff, GBR; Bristol, GBR; Gloucester, GBR; Wolverhampton, GBR. There is also new ortho and oblique imagery in a bunch of places. December 30 SpaceNavigatorThe guys at 3Dconnexion recently sent me a SpaceNavigator which enables motion through 3D space. I must confess that I was skeptical at first, but once I got it integrated into Virtual Earth 3D (with some help), my mind was changed. It is a really great way to move your view, is relatively cheap, and can be used with your left hand... so you can continue to use your right with your mouse. Below are instructions on how to install a sample that enables navigation of Virtual Earth 3D in a standalone application with the SpaceNavigator.
I included the source code for how to accomplish this which illustrates the creation of an EventSource. The SpaceNavigator provides simply an XYZ movement delta and a rotational XYZ delta, so the BindingsSpaceNavigator.xml file defines how these axis map to actions. Since we have no Roll action, one of the rotation axis is unused. December 28 Love what you doI’m sitting at home, after Christmas, having spent time with family and relaxed. A few hours ago my daughter’s hamster unexpectedly died and my idling brain has been slowly turning the outcome over and over. I generally have very little use for pets, but I loved the little furball because I love my family... and they loved her.
As 16 year veteran of professional development, it becomes increasingly clear that this idea extends to programming also. Love what you do because through it you love people. Loving a program is both different and the same as loving anything. It means fighting to do it right, while listening and learning to determine what “right” means. It means acknowledging your own skills and limitations; sometimes picking up extra work, sometimes giving work away if you’re not the best person for it or don't have the energy. And sometimes it means feeling frustrated because external forces do unexpected things. But sometimes hamsters die… and that doesn’t mean they aren’t worth having. People who don’t care make it harder for everyone, but they hurt mostly themselves because they are not nurturing that which is good in them.
A program needs to be helpful to someone. Helpful can mean a lot of things… but if it is not; if it is just frustrating or pointless, or just a good idea sitting on a hard drive somewhere out of reach, then its only benefit was the lessons the author learned. December 20 ChristmasI hope everyone reading this has a great Christmas and new year. The windstorm on the night of the 14th & 15th solidly knocked out power to the entire East-Side. Microsoft campus was back up in a few days, but rural Woodinville where I live still does not have power. Right now it is looking like it will be a miracle if we get it before Christmas. Dispite going on a week without heat/hot water/computers, we thank God for the many things that went very right for us: no lives or property hit by falling trees, our wood supply is holding out and keeping us fairly comfortable, though the electrical riser on our house was pulled off by trees on the power line we were able to get electricians in to fix it before the rush, we had gassed up our cars before the stations all ran out of power.
As work on v2 of Spaceland begins to ramp up, my chance to write v1 samples will significantly decrease. However, I would love to know if anyone out there writes cool stuff, has problems using what we've got, etc. Please continue to comment here and I'll monitor it. December 01 SettingsVirtual Earth 3D has several files that it needs in order to operate, and knowing where these files are may be useful to you.
Settings and Cache: This includes the Bindings.xml file (which controls mappings how input devices are mapped to actions in the program), any custom Bindings*.xml files that you add, the data.cmf file which is the local cache for data coming from the server, the manifest files, and the user.config.
On XP these are in:
"C:\Documents and Settings\{User Alias}\Application Data\Microsoft\Virtual Earth 3D"
On Vista, if you are running the control in IE, these are in the non-roaming, low integrity settings folder:
"C:\User\{User Alias}\AppData\LocalLow\Microsoft\Virtual Earth 3D"
If you are running as a full-trust managed application, these are in:
"C:\User\{User Alias}\AppData\Roaming\Microsoft\Virtual Earth 3D" Managed Assemblies: All of the managed assemblies are kept only in the GAC.
Miscellaneous Data: Various bits of miscellaneous data that is not embedded in the assemblies are stored in Program Files... more specifically something like
"C:\Program Files\Virtual Earth 3D". November 28 New Camera ControllerThe camera controller is the thing responsible for moving the camera around in Virtual Earth 3D. Generally the website uses the ActionCameraController for everything, but it occassionally dips into others when flying from one point to another, for example. I've been wanting to do a complete camera controller replacement sample, but have been too preoccupied. Then, last night we got slammed by loads of snow.
For some reason people always complain that drivers where they're at are the worst. But I'd have to say that east-side drivers are competant, and generally very polite. However, in heavy snow and ice, I'd rather be the only person slipping and sliding around, so I stayed in my cozy little office until late, kept my eye on east-side traffic info, and worked on the TopDown sample.
Basically what it does is toss out the regular camera controller and sticks in the TopDownCameraController. This controller is locked to one local orientation and supports two actions: ForwardBackward, and SideToSide. When you run the sample, it starts in San Francisco and all you can do us move laterally using the up/down/left/right arrows. I had thought about sticking a little UFO model in the middle that you were controlling... hey wouldn't it be even cooler to rescue people off rooftops... well maybe someday.
There are a few quick steps to getting it going:
Updates
On Nov 28, 3:45PM PST I updated the sample that is linked to above to correctly set the position of the predicted camera to smooth things out a little.
On Nov 29, 11:13AM PST I updated the sample to force building textures on inside TopDownCameraController.Activate. November 13 More about bindingsWhen you first run Virtual Earth 3D, it looks for Bindings.xml (as described previously). Since you just installed it, it won't find it, so it will extract it from its resources and plunk it in place. From this point on you can tweak it. For example, if you want the "Y" key to move you forward (rather than the "Up" key), find the line:
<Bind Source="Key" Name="Up" Action="Move" Factor="22" />
...and change "Up" to "Y". This associates the specified key with the Move action; executing it whenever the key is pressed or released. The Factor specifies a value that, in the case of Move, adjusts the speed with which you move forward or backward. You may have noticed that the same Action (Move) is associated with the left thumbstick of the XBox 360 (GamePad) controller.
<Bind Source="GamePad" Name="LeftThumbY" Action="Move" Factor="0.000025" />
LeftThumbY is an axis value meaning that it changes without "releasing", and the value Move ultimately processes is a combination of PositionOnTheAxis * Factor. They keyboard keys simply recieve 1 or -1 instead of an axis position, so its value is 1 * Factor for press and then -1 * Factor for release.
If you were to write code that you wanted to execute your own action, you must implement a method with the following signature:
public void Move(EventData cause, EventSource eventSource)
The cause value is the event that caused the action, and eventSource is the event source that is passed in from the bindings. This is either the event source that caused the event (KeyboardEventSource or GamePadEventSource in the above examples), or it is possible to override the event source using a somewhat clunky form in the Action tag:
Action="MyAction:Mouse"
Once you have the method, you have to register it from a GlobeControl reference like so:
globeControl.BindingsManager.ActionSystem.ActionManager.RegisterAction("MyAction", new Action(MyActionMethod));
Now you can add your own binding... something like:
<Bind Source="Key" Name="Q" Action="MyAction" />
Note that by leaving out Factor, it defaults to 1.
Also note that your action will execute in the Rendering thread. Virtual Earth 3D has a UI thread (that it either gets from WinForms or IE if running there), a Rendering thread that handles building render queues and calling DirectX, and then various other data loading threads. So if you need to do something on the UI thread like muck with your form or change the cursor, you can invoke back to it like so:
globeControl.BeginInvoke((MethodInvoker)delegate { globeControl.SetCursor(myCursor); } ); November 08 L33t FPS pwnage - and now for something completely differentIn navigating around in Virtual Earth 3D, one mode that is somewhat hidden is mouse look mode. Just hit Ctrl-Q, and when you move your mouse, your "head" moves (hit Escape to back out). When you're in this mode, you can also use the WASD keys to move around laterally like you would if you were playing Half-Life 2 (or most other FPSs). You can use Space to go up and C to go down... perhaps more reminiscent of the later Dooms and UT. These are all customizable by tracking down your Bindings.xml file (see Settings entry above for its location), loading it up in notepad and then tinkering with it.
But since I specialize in the down-and-dirty, half-baked pieces of VE3D, let me take you a little ways into the guts of bindings. When the control starts, it scans the directory mentioned above for Bindings.xml and loads it. It then scans for Bindings*.xml and loads all of them. So if you want to have your own custom bindings without screwing up Bindings.xml, create a file BindingsExtra.xml. In this case populate it with the following XML:
<?xml version="1.0" encoding="utf-8" ?>
<BindingData> <Controller Name="Action"> <Bindings Name="default" Cursor="Drag"> <Bind Source="Key" Name="Insert" Action="AdjustSpeedMultiplier" Factor="0.005" /> <Bind Source="Key" Name="Delete" Action="AdjustSpeedMultiplier" Factor="-0.005" /> <Bind Source="Key" Name="OemOpenBrackets" Action="SetGravity" Factor="-25" /> <Bind Source="Key" Name="OemCloseBrackets" Action="SetGravity" Factor="0" /> </Bindings> </Controller> </BindingData> This exposes two functions that we don't expose by default. The first allows you to adjust the global speed multiplier, and the second lets you turn on some really cheesy gravity.
Restart Virtual Earth 3D, and now when you press Insert, movement with the arrow keys (or WASD) will go a little faster, and Delete will do the opposite. So if you zoom in really close to street level on a city with buildings, and hit Delete a bunch of times, you'll eventually get to a speed muliplier of 0 and won't be able to move at all. Then hit Insert once and you'll be at super slow speed... perfect for walking around. Then hit the [ key and you'll descend to the ground. Now hit Ctrl-Q and you can walk around at street level.
Okay, I know this is a lot of work, but we all need something to occupy our time on Tuesdays when they're patching our WoW server.
As a follow-up note, the easier way to do something similar to the steps described above is just to by an XBox 360 controller (either wired or wireless for the PC) and just hold down the right trigger to go down and then navigate around with the left and right joystick. | |||||||||||||||||||||||||||||||