Beruflich Dokumente
Kultur Dokumente
Library
Learn
Downloads
Support
Community
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.
Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.
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}
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}
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}
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}
Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.
CompleteExample
VB C# C++ F# JScript
Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.
Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.
CompleteExample
VB C# C++ F# JScript
Nocodeexampleiscurrentlyavailableorthislanguagemaynotbesupported.