Skip to content

Instantly share code, notes, and snippets.

var settings = new XmlWriterSettings()
{
NewLineOnAttributes = true
};
using(XmlWriter writer = XmlWriter.Create(filestream, settings))
{
// Write out document..
}
MIN_INSIDE_FACES = 4;
MIN_INSIDE_PERCENTAGE = 0.03f;
int cubemap_sides_seeing_inside = 0;
for (int i = 0; i < 6; i++)
{
RenderCubeMapSide(i);
float backfacePercentage = CalculateBackfacePercentage(i);
void main()
{
gl_FragColor = gl_FrontFacing ? vec4(0,0,1,1) : vec4(1,0,0,1);
}
%typemap(cscode) YourBaseRTTIObject
%{
internal YourBaseRTTIObject m_castedSource;
public bool IsKindOf<T>()
{
// Use your C++ RTTI system to test if this wrapped C# object's
// native object is a 'typeof(T).Name'
}
%}
private static Dictionary<Type, Func<IntPtr, bool, object>> constructorCache =
new Dictionary<Type, Func<IntPtr, bool, object>>();
private static Func<IntPtr, bool, object> CreateConstructorDelegate<T>()
{
// We need to first grab the reflection information for the more derrived type we're casting to.
// SWIG has protected constructors we'll be able to call that take 2 parameters, the native pointer
// to the type and whether or not SWIG owns the memory
ConstructorInfo ctor = typeof(T).GetConstructor(
BindingFlags.Instance | BindingFlags.NonPublic, null,
public static T CastTo<t>(YourBaseRTTIObject self) where T : YourBaseRTTIObject
{
if (self == null)
return null;
// Check if the object is actually the type we're trying to cast to.
if (self.IsKindOf<t>())
{
Type type = typeof(T);
#if !defined(SWIG)
#define MYNEW ...
#define MYDELETE ...
#endif
%typemap(out) const Vector3& %{ $result = new Vector3(*$1); %}
class Matrix
{
Matrix();
Matrix& Identity();
}
Matrix4 wrappedMatrix = new Matrix4();
return wrappedMatrix.Identity();