[IronPython] XNA and how to specify the type arguments explicitly

2010-02-02 Thread Richard Steventon
A newbie here.  I am trying to use the XNA infrastructure to render
some data, since all I need is points and colored triangles and a
movable camera.

Code snippet:
def SetupVerticies(self):
l = Array.CreateInstance(VertexPositionColor,6)
l[0] = VertexPositionColor(Vector3(0., 0., 0.), Color.White)
l[1] = VertexPositionColor(Vector3(5., 0., 0.), Color.White)
l[2] = VertexPositionColor(Vector3(10., 0., 0.), Color.White)
l[3] = VertexPositionColor(Vector3(5., 0., -5.), Color.White)
l[4] = VertexPositionColor(Vector3(0., 0., 0.), Color.White)
l[5] = VertexPositionColor(Vector3(10., 0., -5.), Color.White)
self.vertices = l

def CopyTerrainToGraphicsBuffers(self):
self.VertexBuffer = VertexBuffer(self.graphics.GraphicsDevice, \
len(self.vertices) * VertexPositionColor.SizeInBytes, \
BufferUsage.WriteOnly)
self.VertexBuffer.SetData(self.vertices)

This dies with:
TypeError: The type arguments for method 'SetData' cannot be inferred
from the usage. Try specifying the type arguments explicitly.


Any idea how to do this ?
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] XNA and how to specify the type arguments explicitly

2010-02-02 Thread Michael Foord

On 02/02/2010 10:23, Richard Steventon wrote:

A newbie here.  I am trying to use the XNA infrastructure to render
some data, since all I need is points and colored triangles and a
movable camera.

Code snippet:
 def SetupVerticies(self):
 l = Array.CreateInstance(VertexPositionColor,6)
 l[0] = VertexPositionColor(Vector3(0., 0., 0.), Color.White)
 l[1] = VertexPositionColor(Vector3(5., 0., 0.), Color.White)
 l[2] = VertexPositionColor(Vector3(10., 0., 0.), Color.White)
 l[3] = VertexPositionColor(Vector3(5., 0., -5.), Color.White)
 l[4] = VertexPositionColor(Vector3(0., 0., 0.), Color.White)
 l[5] = VertexPositionColor(Vector3(10., 0., -5.), Color.White)
 self.vertices = l

 def CopyTerrainToGraphicsBuffers(self):
 self.VertexBuffer = VertexBuffer(self.graphics.GraphicsDevice, \
 len(self.vertices) * VertexPositionColor.SizeInBytes, \
 BufferUsage.WriteOnly)
 self.VertexBuffer.SetData(self.vertices)

This dies with:
TypeError: The type arguments for method 'SetData' cannot be inferred
from the usage. Try specifying the type arguments explicitly.


Any idea how to do this ?
   


Try this:

self.VertexBuffer.SetData[Array[VertexPositionColor]](self.vertices)

Michael

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
   



--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of 
your employer, to release me from all obligations and waivers arising from any 
and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, 
clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and 
acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your 
employer, its partners, licensors, agents and assigns, in perpetuity, without 
prejudice to my ongoing rights and privileges. You further represent that you 
have the authority to release me from any BOGUS AGREEMENTS on behalf of your 
employer.


___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] XNA and how to specify the type arguments explicitly

2010-02-02 Thread Richard Steventon
Okay, so problem #2 calling the correct version of the interface
(I think this is the problem?), since I am getting a violates the
constraint of type 'T' error.

I set up a XNA VertexBuffer using:
l = Array.CreateInstance(VertexPositionColor,6)
.
self.vertices = l

Then:
self.VertexBuffer = VertexBuffer(self.graphics.GraphicsDevice, \
len(self.vertices) * VertexPositionColor.SizeInBytes, \
BufferUsage.WriteOnly)
self.VertexBuffer.SetData[Array[VertexPositionColor]](self.vertices)

And I get:
ValueError: GenericArguments[0],
'Microsoft.Xna.Framework.Graphics.VertexPositionColor[]', on 'Void
SetData[T](Int32, T[], Int32, Int32, Int32)' violates the constraint
of type 'T'.

The documentation for the VertexBuffer.SetData method can be found here:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.vertexbuffer.setdata.aspx

The methods are:
  VertexBuffer.SetData (Int32, T[], Int32, Int32, Int32)
  VertexBuffer.SetData (T[])
  VertexBuffer.SetData (T[], Int32, Int32)  

This works fine in C# with a List of VertexPositionColor objects, so I
assume that Array in IronPython is the equivalent ?  So why does it
not work ?
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] XNA and how to specify the type arguments explicitly

2010-02-02 Thread Curt Hagenlocher
You should template on VertexPositionColor, not on VertexPositionColor[].

The reason for the error message is that you're saying T is
VertexPositionColor[]. An array is a reference type, while the template
constraint specifies a value type.
On Tue, Feb 2, 2010 at 7:51 AM, Richard Steventon steven...@gmail.comwrote:

 Okay, so problem #2 calling the correct version of the interface
 (I think this is the problem?), since I am getting a violates the
 constraint of type 'T' error.

 I set up a XNA VertexBuffer using:
l = Array.CreateInstance(VertexPositionColor,6)
.
self.vertices = l

 Then:
self.VertexBuffer = VertexBuffer(self.graphics.GraphicsDevice, \
len(self.vertices) * VertexPositionColor.SizeInBytes, \
BufferUsage.WriteOnly)
self.VertexBuffer.SetData[Array[VertexPositionColor]](self.vertices)

 And I get:
 ValueError: GenericArguments[0],
 'Microsoft.Xna.Framework.Graphics.VertexPositionColor[]', on 'Void
 SetData[T](Int32, T[], Int32, Int32, Int32)' violates the constraint
 of type 'T'.

 The documentation for the VertexBuffer.SetData method can be found here:

 http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.vertexbuffer.setdata.aspx

 The methods are:
  VertexBuffer.SetData (Int32, T[], Int32, Int32, Int32)
  VertexBuffer.SetData (T[])
  VertexBuffer.SetData (T[], Int32, Int32)

 This works fine in C# with a List of VertexPositionColor objects, so I
 assume that Array in IronPython is the equivalent ?  So why does it
 not work ?
 ___
 Users mailing list
 Users@lists.ironpython.com
 http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com