IronPythonでXNAで線を引く
import clr clr.AddReference('System') clr.AddReference('Microsoft.Xna.Framework') clr.AddReference('Microsoft.Xna.Framework.Game') from System import * from Microsoft.Xna.Framework import * from Microsoft.Xna.Framework.Graphics import * class Game1(Game): def __init__(self): self.graphics = GraphicsDeviceManager(self) a = [VertexPositionColor(Vector3(0.0, 0.0, 0.0), Color.Black), VertexPositionColor(Vector3(1.0, 1.0, 0.0), Color.Black), VertexPositionColor(Vector3(0.0, 0.0, 0.0), Color.Red), VertexPositionColor(Vector3(-1.0,-1.0,0.0), Color.Red), VertexPositionColor(Vector3(-1.0, 1.0,0.0), Color.Blue), VertexPositionColor(Vector3(1.0,-1.0, 0.0), Color.Blue)] self.points = Array[VertexPositionColor](a) def Initialize(self): Game.Initialize(self) def LoadGraphicsContent(self, loadAllContent): self.declaration = VertexDeclaration( self.graphics.GraphicsDevice, VertexPositionColor.VertexElements) self.effect = BasicEffect(self.graphics.GraphicsDevice, None) self.graphics.GraphicsDevice.VertexDeclaration = self.declaration self.effect.VertexColorEnabled = True Game.LoadGraphicsContent(self, loadAllContent) def UnloadGraphicsContent(self, unloadAllContent): self.declaration.Dispose() self.effect.Dispose() Game.UnloadGraphicsContent(self, unloadAllContent) def Draw(self, gameTime): self.graphics.GraphicsDevice.Clear(Color.White) self.effect.Begin() for pas in self.effect.CurrentTechnique.Passes: pas.Begin() self.graphics.GraphicsDevice.DrawUserPrimitives[VertexPositionColor]( PrimitiveType.LineList, self.points, 0, 3) pas.End() self.effect.End() Game.Draw(self, gameTime) Game1().Run()
線を引きます。なんかXNAのhelpのサンプルのまるうつし。
ここで前に書いたタイプパラメーターが出てますね。なんか位置情報を配列に入れて描画担当に渡すんだけどさ、そんときの配列が生Python配列だとだめで、一回、位置情報型のArrayを作ってそれに生配列をいれるみたいな。な。
でも生配列→位置情報配列はそのままいけるという。