1. Trang chủ
  2. » Công Nghệ Thông Tin

Microsoft press 3d programming for windows jul 2007 ISBN 0735623945

837 80 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 837
Dung lượng 4,57 MB

Nội dung

3D Programming for Windows®: ThreeDimensional Graphics Programming for the Windows Presentation Foundation by Charles Petzold Publisher: Microsoft Press Pub Date: July 25, 2007 Print ISBN-10: 0-7356-2394-5 Print ISBN-13: 978-0-7356-2394-1 Pages: 448 Table of Contents | Index Overview The Windows Presentation Foundation is a key component of NET Framework 3.0, which is a part of Windows Vista and available for Windows XP With the Windows Presentation Foundation, 3D images can be displayed regardless of the video-display hardware on the users machine Focusing on developing user interface objects or simple animations, this book builds on a readers knowledge of Windows Presentation Foundation essentials to demonstrate how to effectively create 3D graphics for Windows You get the fundamental information for using the Windows Presentation Foundation 3D application programming interface (API), as well as in-depth coverage of mesh geometries 3D Programming for Windows®: ThreeDimensional Graphics Programming for the Windows Presentation Foundation by Charles Petzold Publisher: Microsoft Press Pub Date: July 25, 2007 Print ISBN-10: 0-7356-2394-5 Print ISBN-13: 978-0-7356-2394-1 Pages: 448 Table of Contents | Index Copyright Introduction Chapter 1 Lights! Camera! Mesh Geometries! Three-Dimensional Coordinates Points in Space Introduction to Vectors Defining the 3D Figure Lights and Camera The Viewport3D and Its Constituents Variations in Code and Markup Fields of View Defining Flat Rectangles Defining "Solid" Figures Balancing Light Sources The Orthographic Projection Why Not Share the Vertices? Transparency Sorting Out the Classes Chapter 2 Transforms and Animation Animation Without Transforms Manipulating Collections The Transform3D Class The Translation Transform Shareable Models The Scale Transform Combining Translation and Scaling How to Build a Chair Chapter 3 Axis/Angle Rotation The Rotation Transform Combining Rotation and Other Transforms Introduction to Hit-Testing Animating the Axis Chapter 4 Light and Shading Lessons in Illumination Vector Mathematics DiffuseMaterial and Its Properties SpotLight and PointLight Chapter 5 Texture and Materials Gradient Brushes Tile Brushes Specular and Emissive Materials Chapter 6 Algorithmic Mesh Geometries Triangulation Basics Triangulation Resources Deriving from ModelVisual3D The Petzold.Media3D Library Chapter 7 Matrix Transforms Linear Transforms Affine Transforms and Beyond Camera Transforms Chapter 8 Quaternions The Convenience of Complex Numbers Hamilton and Quaternions Why Are Quaternions So Weird? The Quaternion Structure Quaternions and Rotation Low-Level Quaternion Rotation Quaternions and Rotation Matrices SLERP and Animation Chapter 9 Applications and Curiosa Control Templates 3D Visualization of Data Mimicking Real World Objects Interactive Mouse Tracking Printing in 3D Anaglyphs About the Author Additional Resources for Developers Visual Basic 2005 Visual C# 2005 Web Development Data Access SQL Server 2005 Other Developer Topics More Great Developer Resources Developer Step by Step Developer Reference Advanced Topics Index Copyright PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2008 by Charles Petzold All rights reserved No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher Library of Congress Control Number: 2007928771 Printed and bound in the United States of America 1 2 3 4 5 6 7 8 9 QWT 2 1 0 9 8 7 Distributed in Canada by H.B Fenn and Company Ltd A CIP catalogue record for this book is available from the British Library Microsoft Press books are available through booksellers and distributors worldwide For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329 Visit our Web site at www.microsoft.com/mspress Send comments to mspinput@microsoft.com Microsoft, Microsoft Press, DirectX, IntelliSense, Internet Explorer, Visual Studio, Win32, Windows, and Windows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries Other product and company names mentioned herein may be the trademarks of their respective owners The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred This book expresses the author's views and opinions The information contained in this book is provided without any express, statutory, or implied warranties Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book Acquisitions Editor: Ben Ryan Project Editor: Valerie Woolley Technical Editor: Technical Reviewer: Kenn Scribner; Technical Review se Content Master, a member of CM Group, Ltd Editorial and Production Services: Publishing.com Body Part No X13-82451 Introduction Microsoft Windows Vista is the first version of Windows to have built-in support for three-dimensional graphics This 3D graphics support is integrated with the Microsoft Windows Presentation Foundation (WPF), the client application programming interface (API) that was introduced in 2006 as part of the Microsoft NET Framework 3.0 Although NET 3.0 is automatically included in Windows Vista, you can also install it under Microsoft Windows XP with Service Pack 2 or Windows Server 2003 with Service Pack 1 This book shows you how to write programs targeting the 3D graphics API of the Windows Presentation Foundation—or "WPF 3D," as it is known to its friends This book is essentially a comprehensive examination of virtually all the classes and structures in the NET namespace System.Windows.Media.Media3D, with plenty of code and markup examples The Role of WPF 3D WPF 3D is not intended for graphics-intensive point-of-view games; nor is it suitable for producing the next big-screen epic featuring three-dimensional rodents or ogres Programmers who want to pursue those types of applications might be happier looking at Microsoft DirectX rather than WPF 3D WPF 3D is instead intended to give programmers the ability to integrate 3D into their client Windows applications This use of enhanced graphics might be as subtle as fashioning a control that has a 3D appearance, or using 3D to display complex information, or mimicking real-world objects (such as books) The last chapter of this book has some examples of WPF applications incorporating 3D that I hope will inspire you Although WPF 3D is not intended for complex games or movies, it is definitely built for animation WPF includes an extensive animation API and you can use that API with your 3D graphics In this book I begin demonstrating animation in Chapter 2, "Transforms and Animation," and I never let up Somewhat related to animation is data binding You can move or transform 3D figures by binding them to controls such as scrollbars— another of my favorite activities in this book Although WPF 3D runs on both Windows Vista and Windows XP with NET 3.0 installed, you don't get exactly the same features Even on Windows Vista, the quality of 3D graphics is dependent on the video board you have installed in the computer A video board with a better on-board graphics processing unit (GPU) can accomplish some feats that are too slow to be done entirely in software WPF graphics capabilities are categorized by "tiers" that are described on this Web page: http://msdn2.microsoft.com/en-us/library/ms742196.aspx In particular, only with a Tier 2 video board installed under Windows Vista do you get anti-aliasing in 3D (Anti-aliasing is the use of shades of color to minimize the stark "staircase" effect caused by using discrete pixels to represent continuous lines or surfaces.) In the grand scheme of things, anti-aliasing might not sound like an important feature, but it makes a big difference when 3D graphics are animated You might want to get a new video board for your forays into 3D graphics, but if you're writing applications for other users, you might also want to be aware of the limitations that some of your users may experience when they run your programs Your Background In writing this book, I have assumed that you already have experience programming for the Windows Presentation Foundation using the C# programming language and the Extensible Application Markup Language (XAML) that was introduced as part of NET 3.0 If you're a beginning programmer, I recommend that you learn C# first by writing console programs, which are character-mode programs that run in the Command Prompt window My book Programming in the Key of C#: A Primer for Aspiring Programmers (Microsoft Press, 2003) takes this approach If you're a programmer who has a previous background in C or C++ but has not yet learned about programming for the NET Framework with C#, you might want to begin with my short book NET Book Zero: What the C or C++ Programmer Needs to Know About C# and the NET Framework The book is free and is available for reading or downloading from the following page of my Web site: http://www.charlespetzold.com/dotnet If you're familiar with earlier manifestations of NET but haven't yet tackled NET 3.0, WPF, and XAML, my book Applications = Code + Markup: A Guide to the Microsoft Windows Presentation Foundation (Microsoft Press, 2006) is a comprehensive tutorial Several aspects of WPF programming are more crucial for 3D than others These are: XAML syntax, including data binding and resources Dependency properties Animation and storyboards Two-dimensional brushes If you are an experienced WPF programmer but you prefer to code in Microsoft Visual Basic NET or another NET-compliant language, I can only tell you that many of the programming examples in this book are in XAML rather than C# Learning at least to read C# code and mentally translate it into your preferred language has become a vital skill in NET programming Three-dimensional graphics programming necessarily involves mathematics, but I've tried to presume a minimum of background knowledge For example, I've provided refreshers on vectors, matrix algebra, and imaginary numbers, but I've assumed that you have no previous knowledge of quaternions However, I do want you to come to this book with a basic facility with trigonometry I don't need you to reel off lists of common trigonometric identities, but you should have a good working knowledge of angles, radians, sines, cosines, and tangents If you know without thinking too hard that there are π radians in 180 degrees, that the sine of 90 degrees equals 1, that the cosine of zero degrees also equals 1, and that the tangent of 45 degrees equals 1 as well, you should be in good shape Some of the WPF 3D classes are specifically intended to insulate you from heavier mathematics going on under the covers Consequently, I cover those classes early in the book Not until relatively late in the book do I get into the more mathematicsladen topics of matrix transforms and quaternions Depending on your ambitions and aspirations regarding 3D graphics programming, you might find these chapters challenging or altogether too scary Books are great for conflicts like that because: You can skip something if you don't want to bother with it just now You can come back and read something later—perhaps more than once My objective is to help you, not torture you System Requirements To compile and run the programs described in this book, you'll need: Windows Vista, Windows XP with Service Pack 2, or Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] TableForFour.cs TableForFour.xaml TableForFourApp.xaml taper transforms tessellation [See triangulation] text brushes for adding to figures TextBlock elements tiling VisualBrush class for adding TextureCoordinates property application rules DodecahedronWithRadialBrush.xaml FaceOnACube1.xaml FaceOnACuboid.xaml sphere triangulation issues tiling aspect ratios textures [See brushes, Material class] three-dimensional homogeneous coordinates [See homogeneous coordinates] ThreeRotations.xaml Tier 2 graphics rendering tile brushes alignment settings bitmap-based [See ImageBrush class] TileBrush class vector graphics based [See DrawingBrush class] ViewBox property ViewPort property visual-object based [See VisualBrush class] tiling 3DCubeBrush.xaml aligning first tiles FaceOnACuboid.xaml flipping tile orientations None option, TileMode option summary performance issues TextureCoordinates effects tiles in rectangles, number of ViewPort property ViewPortUnits options TimerOnTick event handlers Tiniest3D.xaml Title property top (side of space) transform matrices [See matrices, MatrixTransform3D class] Transform3D class 2D versus 3D transform modes affine transforms class hierarchy of classes derived from device contexts formula representation of linear transforms operation of Point4D structures with setting matrix values for standard transform types transforms defined translations [See TranslateTransform3D class] Value property of Transform3DGroup class composite rotations Matrix3D structure transform methods MatrixTransform3D replacements for multiple transforms with rotation and scaling combined TranslateTransform3D with translation and rotation combined Value property, referencing transforms 3DTransformerExperimenter.xaml algorithmic BuildChair.xaml chair building example composite rotations compound [See compound transforms] coordinate transforms inverse transforms 2nd matrix [See MatrixTransform3D class] multiple order of projection matrices projection transforms rigid body rotations rotations [See RotateTransform3D class] scale transforms [See ScaleTransform3D class] scaling with no change of position shareable models for TranslateTransform3D class BuildChair.xaml CelestialBodies.xaml chair building transform example combining with ScaleTransform3D composite rotations with defined GeometryModel3D objects, applying to MagicBox.xaml Matrix3D equivalents mouse tracking application multiple transforms with naming elements of Offset properties of 2nd PerspectiveCamera with RotateTransform3D with TargetProperty references Transform3DGroup tags TranslateTransformExperimenter.xaml ZigZag.xaml translation transforms 2D homogeneous coordinates 2D matrix mechanics 3D homogeneous coordinates affine nature of formulas for non-linear nature of shear-equivalence of [See homogeneous coordinates] view matrices, as component of transparency semi-transparent colors Transparent setting for Brush property transposes of matrices TriangleIndices property of MeshGeometry3D class arrays for setup composition of order of points, importance of purpose of rectangles in meshes, for sphere triangulation collection setup TextureCoordinates with vertex normal calculations with triangles figure definition role of Law of Cosines MeshGeometry3D representation of [See MeshGeometry3D class] TriangleIndices property vertices of triangulation mesh generation classes, defining Petzold.Media.3D.dll resource mechanics SphereMeshGenerator1.cs SphereResourceDemo.cs SphereResourceDemo.xaml spheres, of [See sphere triangulation] Triggers section of ControlTemplate TubeWithSpecularBrush.xaml Turning the Pages virtual books TwoRectangles.xaml Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] unit cubes unit vectors 2nd UpDirection property of PerspectiveCamera class 2nd upper (side of space) UprootedHouse.xaml Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] vector products [See cross products] Vector3D structures addition operators with AngleBetween method 2nd animation capability CrossProduct method 2nd DotProduct method 2nd Length property of LengthSquared property of negative operators with non-linearity of rotation Normalize method properties of scalar multiplication of vectors addition of angles between, calculating basis 2nd beginning and ending points of components of creation from basis vectors cross products defined directions of 2nd dot products Lambert's Cosine Law Law of Cosines linear transforms 2nd magnitudes of 2nd multiplication operation types non-commutative operations Normalize method normalized 2nd normals for shading notation for orthonormal quaternion rotations of quaternions, relationship to reversing direction by negative multiplication right-hand rule scalar division of scalar multiplication of structure for [See Vector3D structures] subtracting from points subtraction of points model of transforms of [See Transform3D class] unit 2nd Vector3DAnimation class Vector3DAnimationUsingKeyFrames class vertex normals ConvexSurfaceWithNormals.xaml defined FourNormals.xaml guidelines for use Normals collections WPF default calculation vertex processing vertices of triangles calculating [See triangulation] indices for [See TriangleIndices property of MeshGeometry3D class] normals at [See vertex normals] shared specifying Vertigo effect view matrices aspect ratio issue CameraInfo class, Petzold.Media3D library components of coordinate transform nature of default rotation transform component of translation transform component of view transforms view transforms ViewBox class cropping brushed images with purpose of ViewBoxUnits ViewPort class 2D operation of aligning first tiles purpose of 2nd tiles in rectangles, number of ViewPortUnits options Viewport3D class 3D to 2D conversion issues ActualHeight and ActualWidth properties BookViewport.xaml Children property class hierarchy of DockPanel for hosting Height assignment hit-testing on MaxWidth and MaxHeight properties MinWidth and MinHeight properties ModelVisual3D class in 2nd mouse coordinates, obtaining [See mouse tracking] one-camera rule OrthographicCamera class with printing contents of projection matrices purpose of ScrollViewers with shareable models with Simple3dScene.xaml example StackPanel issues structure of, typical transforms in VerticalAlignment property ViewportInfo class, Petzold.Media3D library Visual3DCollections in Width assignment Viewport3DVisual class creating from Viewport3D resources DescendantBounds property printing contents of ViewportInfo class, Petzold.Media3D library Visual3D class class hierarchy of defined Visual3DCollections VisualBrush class 3DCubeBrush.xaml AutoLayoutContent property brushes based on 3D figures CachingHint.Cache controls not functional when added Hello3D.xaml Panel objects with PaneledCube.xaml performance issues purpose of 2nd TextBlock objects with UniformGrid panels with Viewport3DVisual class 2nd Visual property of visualization advantages of OrthographicCamera class with state population visualization project TextBlock elements for visuals class for [See Visual3D class] defined 2nd models, relationship to 2nd not shareable VisualTreeHelper class HitTest method shareable models with Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] WashedOutSquareCuboid.xaml WhatColor program WindowTitle property Wire classes, Petzold.Media3D library Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] X property of Point3D structure X property of Vector3D structures XAML launching in Internet Explorer serialization of objects to XamlCruncher 2.0 with XamlWriter.Save XPS (XML Paper Specification) Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Y property of Point3D structure Y property of Vector3D structures Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] Z property of Point3D structure Z property of Vector3D structures ZigZag.xaml .. .3D Programming for Windows : ThreeDimensional Graphics Programming for the Windows Presentation Foundation by Charles Petzold Publisher: Microsoft Press Pub Date: July 25, 2007 Print ISBN- 10: 0-7356-2394-5... send them to Microsoft Press via e-mail at: mspinput @microsoft. com or via postal mail at: Microsoft PressAttn: 3D Programming for Windows Editor One Microsoft Way Redmond, WA 98052-6399 Please note that Microsoft software product support is not... Introduction Microsoft Windows Vista is the first version of Windows to have built-in support for three-dimensional graphics This 3D graphics support is integrated with the Microsoft Windows Presentation Foundation (WPF), the client application

Ngày đăng: 26/03/2019, 17:06

TỪ KHÓA LIÊN QUAN