[cogl/cogl-sharp: 28/29] cogl-sharp: First shot at exposing Quaternions



commit d7d8445ae6b6c604cbe2fc318b290f9e20058a76
Author: Damien Lespiau <damien lespiau intel com>
Date:   Sat Oct 6 16:30:05 2012 +0100

    cogl-sharp: First shot at exposing Quaternions

 cogl-sharp/Makefile.am     |    1 +
 cogl-sharp/Quaternion.cs   |  145 ++++++++++++++++++++++++++++++++++++++++++++
 cogl-sharp/_FrameBuffer.cs |    8 +++
 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 fa705d6..f89ff42 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 0000000..14383e8
--- /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 26d60eb..08a263e 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 e325610..fc76681 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 = (



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]