Sie sind auf Seite 1von 3

Home

Library

Learn

Downloads

Support

Community

Signin | UnitedStatesEnglish | Preferences

SearchMSDNwithBing MSDNLibrary DevelopmentToolsandLanguages XNAGameStudio XNAGameStudioExpress ProgrammingGuide Graphics 3DGraphics Howto:DrawPoints,Lines,andOther

Howto:DrawPoints,Lines,andOther3D Primitives
XNAGameStudioExpress OtherVersions IntheXNAFramework,a3Dprimitiveisaspecialtypeof3Dshapethatdescribeshowthegraphicsdevice interpretsverticesstoredinavertexarrayorvertexstream.Thisexampledemonstrateshowtousethepoint, line,andtriangleprimitivetypesthatarethebasisforalllowleveldrawingcallsintheXNAFramework.

Note
Torenderprimitives,itisnecessarytocreateaneffectandtransformationmatrix.Here,thestepsdescribedinHowto:UseBasicEffectareused tocreateaninstanceof BasicEffect.ThecompletesourcecodeincludingthecreationoftheBasicEffectobjectisavailableattheendofthepage (seeCompleteExample).

Todrawapointlist
1. Createalistofverticesin3Dspacethatrepresentthepointstodraw.Inthisexample,eightpointsalongtheedgeofacircleandthecenterof thecirclearedrawnalongtheplanez=0.Thefollowingcodecalculatestheseeightpointsandstorestheminanarrayoftype VertexPositionNormalTexture.Thisresultsinanarraywiththefollowingvertexpositions.

VB C# C++ F# JScript
Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

2. ThesizeofapointrenderedfromapointlistiscontrolledbysettingthepropertyRenderState.PointSize.Here,thepointsizeisspecifiedas10, soateachpointinthelista10pixelsquareisdrawn. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

3. RenderthepointsbycallingDrawUserPrimitives,specifyingPrimitiveType.PointListtodeterminehowthedatainthevertexarrayisinterpreted. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

Todrawalinelist
1. Thisexampleusesthesamplevertexlistcreatedinstep1of"Todrawapointlist".Here,anindexarrayiscreatedthatindexesintothatvertex buffertoidentifyaseriesoflines. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

ThisisequivalenttosettinglineListIndicestothefollowingarray,consistingofaseriesoflinesbetweenpointList[1]andpointList[2],pointList[2] andpointList[3],andsoforth.
lineListIndices=newshort[16]{1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,1}

2. RenderthelinesbycallingDrawUserIndexedPrimitives,specifyingPrimitiveType.LineListtodeterminehowthedatainthevertexarrayis interpreted.

ThisisequivalenttosettinglineListIndicestothefollowingarray,consistingofaseriesoflinesbetweenpointList[1]andpointList[2],pointList[2] andpointList[3],andsoforth.
lineListIndices=newshort[16]{1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,1}

2. RenderthelinesbycallingDrawUserIndexedPrimitives,specifyingPrimitiveType.LineListtodeterminehowthedatainthevertexarrayis interpreted. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

Todrawalinestrip
Thisexampleusesthesamepointlistandrendersthesameoutputas"Todrawalinelist",butitusesalinestripprimitivetypewhenidentifyingthe indicesofthevertexarraytodraw.Becausealinelistisused,fewerindicesarestored. 1. Createalistofindicesthatidentifytheorderinwhichtodrawthepointsinthespecifiedpointlist.Here,weneedonlyhalfthenumberof indicesaswereusedtodrawwithalinelist,becausethedataconsistsofaseriesofconnectedlines. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

ThisisequivalenttosettinglineStripIndicestothefollowingarray,consistingofaseriesofconnectedlinesbetweenpointList[1],pointList[2], andpointList[3],andsoforth.
lineStripIndices=newshort[9]{1,2,3,4,5,6,7,8,1}

2. RenderthelinesbycallingDrawUserIndexedPrimitives,specifyingPrimitiveType.LineStriptodeterminehowthedatainthevertexarrayis interpreted.Notethatheretherearefewerverticesusedtorenderthesamenumberofprimitivesrenderedwhenusingalinelist. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

Todrawatrianglelist
Likealinelist,atrianglelistisaprimitivetypethatindicatesthattheverticesinthevertexbufferaretobeinterpretedasaseriesofseparately drawntriangles. 1. Createanarraytoholdthelistofindicesthatidentifyaseriesoftrianglestodrawfromthespecifiedpointlist. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

ThisisequivalenttosettingtriangleListIndicestothefollowingarray,consistingofaseriesoftrianglesbetweenpointList[1],pointList[2],and pointList[3],andsoforth.
triangleListIndices=newshort[24]{0,1,2,0,2,3,0,3,4,0,4,5,0,5,6,0,7,8,0,8,1}

2. RenderthelinesbycallingDrawUserIndexedPrimitives,specifyingPrimitiveType.TriangleListtodeterminehowthedatainthevertexarrayis interpreted. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

Todrawatrianglefan
Atrianglefanisaseriesoftrianglesthatshareasinglepoint.Thisexampleshowshowtorenderanobjectthatlooksthesameastheobjectrendered withatrianglelist,butwithfewerverticesneededbecausethetrianglesshareapoint. 1. Createanarraytoholdthelistofindicesidentifyingaseriesofconnectedtrianglesthatshareacentralpoint.Noteherethatthecenterpointis thefirstitemidentifiedinthelistofindices VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

ThisisequivalenttosettingtriangleFanIndicestothefollowingarray,consistingofaseriesofconnectedtrianglesbetweenpointList[1],pointList [2],andpointList[3],andsoforth,allsharingonepointatthecenterofthetriangle.
triangleFanIndices=newshort[10]{0,1,2,3,4,5,6,7,8,1}

2. RenderthelinesbycallingDrawUserIndexedPrimitives,specifyingPrimitiveType.TriangleFantodeterminehowthedatainthevertexarrayis interpreted.Notethatheretherearefewerverticesusedtorenderthesamenumberofprimitivesrenderedwhenusingatrianglelist. VB C# C++ F# JScript

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

CompleteExample
VB C# C++ F# JScript
Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

CompleteExample
VB C# C++ F# JScript
Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.

2011Microsoft.Allrightsreserved. TermsofUse | Trademarks | PrivacyStatement | Feedback

Das könnte Ihnen auch gefallen