diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2012-10-06 16:30:05 +0100 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2013-01-04 20:29:35 +0000 |
commit | 7c7516ec1b157828e2e6781255d31edba90e21e0 (patch) | |
tree | e5a56df89d8b8beb2214c0dd0762965e8001ba4a | |
parent | 6c792e2efa29a55d25f6afbbcee6a24a05d59f64 (diff) | |
download | cogl-7c7516ec1b157828e2e6781255d31edba90e21e0.tar.gz |
cogl-sharp: First shot at exposing Quaternions
-rw-r--r-- | cogl-sharp/Makefile.am | 1 | ||||
-rw-r--r-- | cogl-sharp/Quaternion.cs | 145 | ||||
-rw-r--r-- | cogl-sharp/_FrameBuffer.cs | 8 | ||||
-rwxr-xr-x | cogl-sharp/parse-gir.py | 3 |
4 files changed, 156 insertions, 1 deletions
diff --git a/cogl-sharp/Makefile.am b/cogl-sharp/Makefile.am index fa705d6a..f89ff429 100644 --- a/cogl-sharp/Makefile.am +++ b/cogl-sharp/Makefile.am @@ -27,6 +27,7 @@ sources = \ PipelineFilter.cs \ PipelineWrapMode.cs \ PixelFormat.cs \ + Quaternion.cs \ Texture.cs \ _Texture.cs \ TextureFlags.cs \ diff --git a/cogl-sharp/Quaternion.cs b/cogl-sharp/Quaternion.cs new file mode 100644 index 00000000..14383e81 --- /dev/null +++ b/cogl-sharp/Quaternion.cs @@ -0,0 +1,145 @@ +/* + * Cogl + * + * An object oriented GL/GLES Abstraction/Utility Layer + * + * Copyright (C) 2012 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: + * Aaron Bockover <abockover@novell.com> + * Damien Lespiau <damien.lespiau@intel.com> + */ + +using System; +using System.Runtime.InteropServices; + +namespace Cogl +{ + [StructLayout(LayoutKind.Sequential)] + public struct Quaternion + { + public float w; + public float x; + public float y; + public float z; + + /* private */ + /* Those fields are only accessed from the native side, so let's + * disable the unused warning */ +#pragma warning disable 169 + private float padding0; + private float padding1; + private float padding2; + private float padding3; +#pragma warning restore 169 + + [DllImport("cogl2.dll")] + private static extern void cogl_quaternion_init_identity(ref Quaternion q); + + public void InitIdentity() + { + cogl_quaternion_init_identity(ref this); + } + + [DllImport("cogl2.dll")] + private static extern void cogl_quaternion_init(ref Quaternion q, + float angle, + float x, float y, float z); + + public void Init(float angle, float x, float y, float z) + { + cogl_quaternion_init(ref this, angle, x, y, z); + } + + [DllImport("cogl2.dll")] + private static extern void cogl_quaternion_init_from_x_rotation(ref Quaternion q, float angle); + + public void FromXRotation(float angle) + { + cogl_quaternion_init_from_x_rotation(ref this, angle); + } + + [DllImport("cogl2.dll")] + private static extern void cogl_quaternion_init_from_y_rotation(ref Quaternion q, float angle); + + public void FromYRotation(float angle) + { + cogl_quaternion_init_from_y_rotation(ref this, angle); + } + + [DllImport("cogl2.dll")] + private static extern void cogl_quaternion_init_from_z_rotation(ref Quaternion q, float angle); + + public void FromZRotation(float angle) + { + cogl_quaternion_init_from_z_rotation(ref this, angle); + } + + [DllImport("cogl2.dll")] + private static extern void cogl_quaternion_init_from_matrix(ref Quaternion q, ref Matrix m); + + public void FromMatrix(ref Matrix m) + { + cogl_quaternion_init_from_matrix(ref this, ref m); + } + + [DllImport("cogl2.dll")] + private static extern float cogl_quaternion_get_rotation_angle(ref Quaternion q); + + public float GetRotationAngle() + { + return cogl_quaternion_get_rotation_angle(ref this); + } + + [DllImport("cogl2.dll")] + private static extern float cogl_quaternion_normalize(ref Quaternion q); + + public void Normalize() + { + cogl_quaternion_normalize(ref this); + } + + [DllImport("cogl2.dll")] + private static extern float cogl_quaternion_invert(ref Quaternion q); + + public void Invert() + { + cogl_quaternion_invert(ref this); + } + + [DllImport("cogl2.dll")] + private static extern float cogl_quaternion_multiply(out Quaternion r, + ref Quaternion l, + ref Quaternion r); + + public static void Multiply(out Quaternion result, + ref Quaternion left, + ref Quaternion right) + { + cogl_quaternion_multiply(out result, ref left, ref right); + } + + [DllImport("cogl2.dll")] + private static extern float cogl_quaternion_pow(ref Quaternion q, + float exponent); + + public void Pow(float exponent) + { + cogl_quaternion_pow(ref this, exponent); + } + } +} diff --git a/cogl-sharp/_FrameBuffer.cs b/cogl-sharp/_FrameBuffer.cs index 26d60eb1..08a263ed 100644 --- a/cogl-sharp/_FrameBuffer.cs +++ b/cogl-sharp/_FrameBuffer.cs @@ -320,6 +320,14 @@ namespace Cogl } [DllImport("cogl2.dll")] + public static extern void cogl_framebuffer_rotate_quaternion(IntPtr o, ref Quaternion quaternion); + + public void RotateQuaternion(ref Quaternion quaternion) + { + cogl_framebuffer_rotate_quaternion(handle, ref quaternion); + } + + [DllImport("cogl2.dll")] public static extern void cogl_framebuffer_scale(IntPtr o, float x, float y, float z); public void Scale(float x, float y, float z) diff --git a/cogl-sharp/parse-gir.py b/cogl-sharp/parse-gir.py index e3256105..fc766819 100755 --- a/cogl-sharp/parse-gir.py +++ b/cogl-sharp/parse-gir.py @@ -29,7 +29,8 @@ object_types = ( # The struct types (value types) are written by hand struct_types = ( 'Color', - 'Matrix' + 'Matrix', + 'Quaternion', ) hand_written_types = ( |