Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 20. Incorporating XNA Graphics i... > Displaying a 3D XNA Model in a Hybri...

Displaying a 3D XNA Model in a Hybrid App

The example for this chapter is located in the SilverlightXnaHybrid solution in the downloadable sample code. In the sample, we use a PhoneApplicationPage to display an XNA model and integrate Silverlight elements with the XNA content.

The viewmodel for this example is called GamePageViewModel. It contains a custom ModelMetadata property, which provides the view with the information it needs to display a particular 3D model using XNA.

The ModelMetadata field is initialized in the viewmodel constructor. An XNA asset, called Spaceship, is specified, and various other properties that are used when drawing the 3D model are defined as shown:

public GamePageViewModel()
{
    modelMetadata = new ModelMetadata
    {
        Asset = "Spaceship",
        Name = "Spaceship",
        Description = "Alien spaceship model",
        World = Matrix.Identity,
        ViewMatrix = Matrix.CreateLookAt(
            new Vector3(3500, 400, 0) + new Vector3(0, 250, 0),
            new Vector3(0, 250, 0),
            Vector3.Up),
        FieldOfViewDivisor = 1f,
        AspectRatio = 1.66666663f,
        NearPlaneDistance = 10f,
        FarPlaneDistance = 20000f,
    };

    displayMessageCommand = new DelegateCommand(
                                    obj => Message = "Silverlight Message");
}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial