From: <ron...@us...> - 2007-10-30 02:59:19
|
Revision: 28043 http://crystal.svn.sourceforge.net/crystal/?rev=28043&view=rev Author: ronsaldo Date: 2007-10-29 19:59:16 -0700 (Mon, 29 Oct 2007) Log Message: ----------- ronsaldo added more operators to the 2d and 3d vector, and also to the matrix2 and matrix3 into the c# bindings. Modified Paths: -------------- CS/branches/feature/csharpbinding/docs/history.txt CS/branches/feature/csharpbinding/include/bindings/csharp/cshoperators.i Modified: CS/branches/feature/csharpbinding/docs/history.txt =================================================================== --- CS/branches/feature/csharpbinding/docs/history.txt 2007-10-29 13:12:51 UTC (rev 28042) +++ CS/branches/feature/csharpbinding/docs/history.txt 2007-10-30 02:59:16 UTC (rev 28043) @@ -5,6 +5,9 @@ each new day's entries appears before the previous day's entries. The individual changes for each given day, however, are in normal (ascending) chronological order. +30-Oct-2007 + - ronsaldo added more operators to the 2d and 3d vector, and also + to the matrix2 and matrix3 into the c# bindings. 29-Oct-2007 - ronsaldo added some operators to the 2d and 3d vectors in the c# bindings, and fixed somes issues with the CS module generations. Modified: CS/branches/feature/csharpbinding/include/bindings/csharp/cshoperators.i =================================================================== --- CS/branches/feature/csharpbinding/include/bindings/csharp/cshoperators.i 2007-10-29 13:12:51 UTC (rev 28042) +++ CS/branches/feature/csharpbinding/include/bindings/csharp/cshoperators.i 2007-10-30 02:59:16 UTC (rev 28043) @@ -128,10 +128,125 @@ { return v1.x!=v2.x || v1.y!=v2.y || v1.z!=v2.z; } + + public static bool operator<(csVector3 v, float epsilon) + { + return Math.Abs(v.x) < epsilon && Math.Abs(v.y) < epsilon + && Math.Abs(v.z) < epsilon; + } + + public static bool operator<(csVector3 v, float epsilon) + { + return Math.Abs(v.x) > epsilon && Math.Abs(v.y) > epsilon + && Math.Abs(v.z) > epsilon; + } %} %enddef VECTOR3_CSHARP_CODE +%define MATRIX2_CSHARP_CODE +%typemap (cscode) csMatrix2 +%{ + public static csMatrix2 operator+(csMatrix2 m1, csMatrix2 m2) + { + return new csMatrix2(m1.m11 + m2.m11, m1.m12 + m2.m12, + m1.m21 + m2.m21, m1.m22 + m2.m22); + } + + public static csMatrix2 operator-(csMatrix2 m1, csMatrix2 m2) + { + return new csMatrix2(m1.m11 - m2.m11, m1.m12 - m2.m12, + m1.m21 - m2.m21, m1.m22 - m2.m22); + } + + public static csMatrix2 operator*(csMatrix2 m1, csMatrix2 m2) + { + return new csMatrix2(m1.m11 * m2.m11 + m1.m12 * m2.m21, + m1.m11 * m2.m12 + m1.m12 * m2.m22, + m1.m21 * m2.m11 + m1.m22 * m2.m21, + m1.m21 * m2.m12 + m1.m22 * m2.m22); + } + + public static csMatrix2 operator*(csMatrix2 m, float s) + { + return new csMatrix2(m.m11 * s, m.m12 * s + m.m21 * s, m.m22 * s); + } + + public static csMatrix2 operator*(float s, csMatrix2 m) + { + return new csMatrix2(m.m11 * s, m.m12 * s + m.m21 * s, m.m22 * s); + } + + /// Multiply a vector by a matrix (transform it). + public static csVector2 operator* (csMatrix2 m, csVector2 v) + { + return csVector2 (m.m11*v.x + m.m12*v.y, m.m21*v.x + m.m22*v.y); + } + + public static csMatrix2 operator/(csMatrix2 m, float s) + { + return new csMatrix2(m.m11 / s, m.m12 / s, + m.m21 / s, m.m22 / s); + } + + public static bool operator==(csMatrix2 m1, csMatrix2 m2) + { + return m1.m11 == m2.m11 && m1.m12 == m2.m12 + && m1.m21 == m2.m21 && m1.m22 == m2.m22; + } + + public static bool operator!=(csMatrix2 m1, csMatrix2 m2) + { + return m1.m11 != m2.m11 || m1.m12 != m2.m12 + || m1.m21 != m2.m21 || m1.m22 != m2.m22; + } +%} +%enddef +MATRIX2_CSHARP_CODE + +%define MATRIX3_CSHARP_CODE +%typemap (cscode) csMatrix3 +%{ + public static csMatrix3 operator+(csMatrix3 m1, csMatrix3 m2) + { + return new csMatrix3(m1.m11 + m2.m11, m1.m12 + m2.m12, m1.m13 + m2.m13, + m1.m21 + m2.m21, m1.m22 + m2.m22, m1.m23 + m2.m23, + m1.m31 + m2.m31, m1.m32 + m2.m32, m1.m33 + m2.m33,) + } + + public static csMatrix3 operator-(csMatrix3 m1, csMatrix3 m2) + { + return new csMatrix3(m1.m11 - m2.m11, m1.m12 - m2.m12, m1.m13 - m2.m13, + m1.m21 - m2.m21, m1.m22 - m2.m22, m1.m23 - m2.m23, + m1.m31 - m2.m31, m1.m32 - m2.m32, m1.m33 - m2.m33,) + } + + public static bool operator==(csMatrix3 m1, csMatrix3 m2) + { + return m1.m11==m2.m11 && m1.m12==m2.12 && m1.m13==m2.13 + && m1.m21==m2.m21 && m1.m22==m2.22 && m1.m23==m2.23 + && m1.m31==m2.m31 && m1.m32==m2.32 && m1.m33==m2.33; + } + + public static bool operator!=(csMatrix3 m1, csMatrix3 m2) + { + return m1.m11!=m2.m11 || m1.m12!=m2.12 || m1.m13!=m2.13 + || m1.m21!=m2.m21 || m1.m22!=m2.22 || m1.m23!=m2.23 + || m1.m31!=m2.m31 || m1.m32!=m2.32 || m1.m33!=m2.33; + } + + public static csVector3 operator* (csMatrix3 m, csVector3 v) + { + return csVector3 (m.m11*v.x + m.m12*v.y + m.m13*v.z, + m.m21*v.x + m.m22*v.y + m.m23*v.z, + m.m31*v.x + m.m32*v.y + m.m33*v.z); + } +%} +%enddef +MATRIX3_CSHARP_CODE + #endif // CS_MINI_SWIG #endif //SWIGCSHARP This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |