From: Bourke F. <ch...@gm...> - 2012-05-08 02:11:39
|
I've made progress, but I'm still working on the ctype, cstype, csin, in, directorout, directorin, ... %immutable; %typemap(csbase) btVector3 "" %typemap(csclassmodifiers) btVector3 "public struct" %typemap(csimports) btVector3 "\nusing System;\nusing System.Runtime.InteropServices;\n" %typemap(csinterfaces) btVector3 "" %typemap(csinterfaces_derived) btVector3 "" %typemap(csfinalize) btVector3 "" %typemap(csdestruct) btVector3 "" %typemap(csdestruct_derived) btVector3 "" %typemap(csbody) btVector3 %{ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public float[] m_floats; public float X { get { return m_floats[0]; } } public float Y { get { return m_floats[1]; } } public float Z { get { return m_floats[2]; } } public $csclassname(float x, float y, float z) { m_floats = new float[] { x, y, z, 0 }; } %} %typemap(csattributes) btVector3 "[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]" %typemap(csbody_derived) btVector3 "" %typemap(csbody) btVector3 *, btVector3 &, btVector3 [] "" %typemap(cscode) btVector3 "" %nodefaultctor; %nodefaultdtor; %mutable; C.H. Bourke Floyd IV On Sun, May 6, 2012 at 11:28 PM, Bourke Floyd <ch...@gm...> wrote: > I want to change the output of my SWIG of the class btVector3 to a struct > btVector3. The main issue I'm having is that I'm using BulletPhysics and I > need a few core components to use structs as normal to prevent cache > trashing. > > "btVector3 can be used to represent 3D points and vectors. It has an > un-used w component to suit 16-byte alignment when btVector3 is stored in > containers." > > ************************** C++ aligned class ************************ > __declspec(align(16)) class btVector3 > { > public: > union { > __m128 mVec128; > btScalar m_floats[4]; > }; > //... > } > > ************************** c# Wrapper OUTPUT ************************ > > public class btVector3 : IDisposable { > private HandleRef swigCPtr; > protected bool swigCMemOwn; > > internal btVector3(IntPtr cPtr, bool cMemoryOwn) { > swigCMemOwn = cMemoryOwn; > swigCPtr = new HandleRef(this, cPtr); > } > > internal static HandleRef getCPtr(btVector3 obj) { > return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; > } > > ~btVector3() { > Dispose(); > } > > public virtual void Dispose() { > lock(this) { > if (swigCPtr.Handle != IntPtr.Zero) { > if (swigCMemOwn) { > swigCMemOwn = false; > BulletPhysicsPINVOKE.delete_btVector3(swigCPtr); > } > swigCPtr = new HandleRef(null, IntPtr.Zero); > } > GC.SuppressFinalize(this); > } > } > ///... > } > > ************************** C# Wrapper GOAL (TARGET) > ************************ > [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)] > public struct btVector3 { > > [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] > public float[] m_floats; > > } > > } > > > C.H. Bourke Floyd IV > |