mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 17:43:08 -05:00
move math stuff into client
This commit is contained in:
parent
3cb3831f96
commit
62f0ad560c
15 changed files with 633 additions and 996 deletions
|
@ -184,6 +184,7 @@
|
|||
<Compile Include="Map\Lighting\BasicLighting.cs" />
|
||||
<Compile Include="Map\Lighting\BasicLighting.Heightmap.cs" />
|
||||
<Compile Include="Map\WorldEnv.cs" />
|
||||
<Compile Include="Math\Matrix4.cs" />
|
||||
<Compile Include="Math\Physics\AABB.cs" />
|
||||
<Compile Include="Math\Physics\IntersectionUtils.cs" />
|
||||
<Compile Include="Math\Physics\Searcher.cs" />
|
||||
|
@ -191,6 +192,8 @@
|
|||
<Compile Include="Entities\Model\CustomModel.cs" />
|
||||
<Compile Include="Entities\Model\HumanModels.cs" />
|
||||
<Compile Include="Entities\Model\ModelBuilder.cs" />
|
||||
<Compile Include="Math\Vector3.cs" />
|
||||
<Compile Include="Math\Vector4.cs" />
|
||||
<Compile Include="MeshBuilder\Builder.cs" />
|
||||
<Compile Include="MeshBuilder\FloodFill.cs" />
|
||||
<Compile Include="MeshBuilder\CuboidDrawer.cs" />
|
||||
|
|
|
@ -437,9 +437,7 @@ namespace SharpDX.Direct3D9 {
|
|||
FogStart = 36,
|
||||
FogEnd = 37,
|
||||
FogDensity = 38,
|
||||
Clipping = 136,
|
||||
Lighting = 137,
|
||||
Ambient = 139,
|
||||
FogVertexMode = 140,
|
||||
ColorVertex = 141,
|
||||
LocalViewer = 142,
|
||||
|
@ -521,10 +519,10 @@ namespace SharpDX.Direct3D9 {
|
|||
public unsafe static class DataBuffser { // Either 'VertexBuffer' or 'IndexBuffer
|
||||
|
||||
public static IntPtr Lock(IntPtr ptr, int offsetToLock, int sizeToLock, LockFlags flags) {
|
||||
IntPtr pOut;
|
||||
int res = Interop.Calli(ptr, offsetToLock, sizeToLock, (IntPtr)(void*)&pOut, (int)flags, (*(IntPtr**)ptr)[11]);
|
||||
IntPtr data;
|
||||
int res = Interop.Calli(ptr, offsetToLock, sizeToLock, (IntPtr)(void*)&data, (int)flags, (*(IntPtr**)ptr)[11]);
|
||||
if (res < 0) { throw new SharpDXException(res); }
|
||||
return pOut;
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void SetData(IntPtr ptr, IntPtr data, int bytes, LockFlags flags) {
|
||||
|
|
|
@ -1,219 +1,215 @@
|
|||
#region --- License ---
|
||||
/*
|
||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK {
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Matrix4 : IEquatable<Matrix4> {
|
||||
|
||||
/// <summary> Top row of the matrix </summary>
|
||||
public Vector4 Row0;
|
||||
/// <summary> 2nd row of the matrix </summary>
|
||||
public Vector4 Row1;
|
||||
/// <summary> 3rd row of the matrix </summary>
|
||||
public Vector4 Row2;
|
||||
/// <summary> Bottom row of the matrix </summary>
|
||||
public Vector4 Row3;
|
||||
|
||||
/// <summary> The identity matrix </summary>
|
||||
public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW);
|
||||
|
||||
public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3) {
|
||||
Row0 = row0;
|
||||
Row1 = row1;
|
||||
Row2 = row2;
|
||||
Row3 = row3;
|
||||
}
|
||||
|
||||
public Matrix4(
|
||||
float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33) {
|
||||
Row0 = new Vector4(m00, m01, m02, m03);
|
||||
Row1 = new Vector4(m10, m11, m12, m13);
|
||||
Row2 = new Vector4(m20, m21, m22, m23);
|
||||
Row3 = new Vector4(m30, m31, m32, m33);
|
||||
}
|
||||
|
||||
public static void RotateX(out Matrix4 result, float angle) {
|
||||
float cos = (float)Math.Cos(angle);
|
||||
float sin = (float)Math.Sin(angle);
|
||||
|
||||
result.Row0 = Vector4.UnitX;
|
||||
result.Row1 = new Vector4(0.0f, cos, sin, 0.0f);
|
||||
result.Row2 = new Vector4(0.0f, -sin, cos, 0.0f);
|
||||
result.Row3 = Vector4.UnitW;
|
||||
}
|
||||
|
||||
public static void RotateY(out Matrix4 result, float angle) {
|
||||
float cos = (float)Math.Cos(angle);
|
||||
float sin = (float)Math.Sin(angle);
|
||||
|
||||
result.Row0 = new Vector4(cos, 0.0f, -sin, 0.0f);
|
||||
result.Row1 = Vector4.UnitY;
|
||||
result.Row2 = new Vector4(sin, 0.0f, cos, 0.0f);
|
||||
result.Row3 = Vector4.UnitW;
|
||||
}
|
||||
|
||||
public static void RotateZ(out Matrix4 result, float angle) {
|
||||
float cos = (float)Math.Cos(angle);
|
||||
float sin = (float)Math.Sin(angle);
|
||||
|
||||
result.Row0 = new Vector4(cos, sin, 0.0f, 0.0f);
|
||||
result.Row1 = new Vector4(-sin, cos, 0.0f, 0.0f);
|
||||
result.Row2 = Vector4.UnitZ;
|
||||
result.Row3 = Vector4.UnitW;
|
||||
}
|
||||
|
||||
public static void Translate(out Matrix4 result, float x, float y, float z) {
|
||||
result = Identity;
|
||||
result.Row3 = new Vector4(x, y, z, 1);
|
||||
}
|
||||
|
||||
public static void Scale(out Matrix4 result, float x, float y, float z) {
|
||||
result.Row0 = Vector4.UnitX; result.Row0.X *= x;
|
||||
result.Row1 = Vector4.UnitY; result.Row1.Y *= y;
|
||||
result.Row2 = Vector4.UnitZ; result.Row2.Z *= z;
|
||||
result.Row3 = Vector4.UnitW;
|
||||
}
|
||||
|
||||
public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result) {
|
||||
result = new Matrix4();
|
||||
|
||||
float invRL = 1 / (right - left);
|
||||
float invTB = 1 / (top - bottom);
|
||||
float invFN = 1 / (zFar - zNear);
|
||||
|
||||
result.Row0.X = 2 * invRL;
|
||||
result.Row1.Y = 2 * invTB;
|
||||
result.Row2.Z = -2 * invFN;
|
||||
|
||||
result.Row3.X = -(right + left) * invRL;
|
||||
result.Row3.Y = -(top + bottom) * invTB;
|
||||
result.Row3.Z = -(zFar + zNear) * invFN;
|
||||
result.Row3.W = 1;
|
||||
}
|
||||
|
||||
public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar, out Matrix4 result) {
|
||||
float yMax = zNear * (float)System.Math.Tan(0.5f * fovy);
|
||||
float yMin = -yMax;
|
||||
float xMin = yMin * aspect;
|
||||
float xMax = yMax * aspect;
|
||||
|
||||
CreatePerspectiveOffCenter(xMin, xMax, yMin, yMax, zNear, zFar, out result);
|
||||
}
|
||||
|
||||
public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result) {
|
||||
float x = (2.0f * zNear) / (right - left);
|
||||
float y = (2.0f * zNear) / (top - bottom);
|
||||
float a = (right + left) / (right - left);
|
||||
float b = (top + bottom) / (top - bottom);
|
||||
float c = -(zFar + zNear) / (zFar - zNear);
|
||||
float d = -(2.0f * zFar * zNear) / (zFar - zNear);
|
||||
|
||||
result = new Matrix4(x, 0, 0, 0,
|
||||
0, y, 0, 0,
|
||||
a, b, c, -1,
|
||||
0, 0, d, 0);
|
||||
}
|
||||
|
||||
public static void LookAt(Vector3 eye, Vector3 target, Vector3 up, out Matrix4 result) {
|
||||
Vector3 z = Vector3.Normalize(eye - target);
|
||||
Vector3 x = Vector3.Normalize(Vector3.Cross(up, z));
|
||||
Vector3 y = Vector3.Normalize(Vector3.Cross(z, x));
|
||||
|
||||
Matrix4 rot = new Matrix4(new Vector4(x.X, y.X, z.X, 0.0f),
|
||||
new Vector4(x.Y, y.Y, z.Y, 0.0f),
|
||||
new Vector4(x.Z, y.Z, z.Z, 0.0f),
|
||||
Vector4.UnitW);
|
||||
|
||||
Matrix4 trans;
|
||||
Translate(out trans, -eye.X, -eye.Y, -eye.Z);
|
||||
Mult(out result, ref trans, ref rot);
|
||||
}
|
||||
|
||||
public static void Mult(out Matrix4 result, ref Matrix4 left, ref Matrix4 right) {
|
||||
// Originally from http://www.edais.co.uk/blog/?p=27
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y, lM33 = left.Row2.Z, lM34 = left.Row2.W,
|
||||
lM41 = left.Row3.X, lM42 = left.Row3.Y, lM43 = left.Row3.Z, lM44 = left.Row3.W,
|
||||
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z, rM34 = right.Row2.W,
|
||||
rM41 = right.Row3.X, rM42 = right.Row3.Y, rM43 = right.Row3.Z, rM44 = right.Row3.W;
|
||||
|
||||
result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
|
||||
result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
|
||||
result.Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
|
||||
result.Row0.W = (((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34)) + (lM14 * rM44);
|
||||
|
||||
result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
|
||||
result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
|
||||
result.Row1.Z = (((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33)) + (lM24 * rM43);
|
||||
result.Row1.W = (((lM21 * rM14) + (lM22 * rM24)) + (lM23 * rM34)) + (lM24 * rM44);
|
||||
|
||||
result.Row2.X = (((lM31 * rM11) + (lM32 * rM21)) + (lM33 * rM31)) + (lM34 * rM41);
|
||||
result.Row2.Y = (((lM31 * rM12) + (lM32 * rM22)) + (lM33 * rM32)) + (lM34 * rM42);
|
||||
result.Row2.Z = (((lM31 * rM13) + (lM32 * rM23)) + (lM33 * rM33)) + (lM34 * rM43);
|
||||
result.Row2.W = (((lM31 * rM14) + (lM32 * rM24)) + (lM33 * rM34)) + (lM34 * rM44);
|
||||
|
||||
result.Row3.X = (((lM41 * rM11) + (lM42 * rM21)) + (lM43 * rM31)) + (lM44 * rM41);
|
||||
result.Row3.Y = (((lM41 * rM12) + (lM42 * rM22)) + (lM43 * rM32)) + (lM44 * rM42);
|
||||
result.Row3.Z = (((lM41 * rM13) + (lM42 * rM23)) + (lM43 * rM33)) + (lM44 * rM43);
|
||||
result.Row3.W = (((lM41 * rM14) + (lM42 * rM24)) + (lM43 * rM34)) + (lM44 * rM44);
|
||||
}
|
||||
|
||||
public static bool operator == (Matrix4 left, Matrix4 right) {
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator != (Matrix4 left, Matrix4 right) {
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return (obj is Matrix4) && Equals((Matrix4)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Matrix4 other) {
|
||||
return Row0 == other.Row0 && Row1 == other.Row1 &&
|
||||
Row2 == other.Row2 && Row3 == other.Row3;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format("Row0={0},\r\n Row1={1},\r\n Row2={2},\r\n Row3={3}]", Row0, Row1, Row2, Row3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#region --- License ---
|
||||
/*
|
||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK {
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Matrix4 : IEquatable<Matrix4> {
|
||||
|
||||
/// <summary> Top row of the matrix </summary>
|
||||
public Vector4 Row0;
|
||||
/// <summary> 2nd row of the matrix </summary>
|
||||
public Vector4 Row1;
|
||||
/// <summary> 3rd row of the matrix </summary>
|
||||
public Vector4 Row2;
|
||||
/// <summary> Bottom row of the matrix </summary>
|
||||
public Vector4 Row3;
|
||||
|
||||
/// <summary> The identity matrix </summary>
|
||||
public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW);
|
||||
|
||||
public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3) {
|
||||
Row0 = row0; Row1 = row1; Row2 = row2; Row3 = row3;
|
||||
}
|
||||
|
||||
public Matrix4(
|
||||
float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33) {
|
||||
Row0 = new Vector4(m00, m01, m02, m03);
|
||||
Row1 = new Vector4(m10, m11, m12, m13);
|
||||
Row2 = new Vector4(m20, m21, m22, m23);
|
||||
Row3 = new Vector4(m30, m31, m32, m33);
|
||||
}
|
||||
|
||||
public static void RotateX(out Matrix4 result, float angle) {
|
||||
float cos = (float)Math.Cos(angle);
|
||||
float sin = (float)Math.Sin(angle);
|
||||
|
||||
result.Row0 = Vector4.UnitX;
|
||||
result.Row1 = new Vector4(0.0f, cos, sin, 0.0f);
|
||||
result.Row2 = new Vector4(0.0f, -sin, cos, 0.0f);
|
||||
result.Row3 = Vector4.UnitW;
|
||||
}
|
||||
|
||||
public static void RotateY(out Matrix4 result, float angle) {
|
||||
float cos = (float)Math.Cos(angle);
|
||||
float sin = (float)Math.Sin(angle);
|
||||
|
||||
result.Row0 = new Vector4(cos, 0.0f, -sin, 0.0f);
|
||||
result.Row1 = Vector4.UnitY;
|
||||
result.Row2 = new Vector4(sin, 0.0f, cos, 0.0f);
|
||||
result.Row3 = Vector4.UnitW;
|
||||
}
|
||||
|
||||
public static void RotateZ(out Matrix4 result, float angle) {
|
||||
float cos = (float)Math.Cos(angle);
|
||||
float sin = (float)Math.Sin(angle);
|
||||
|
||||
result.Row0 = new Vector4(cos, sin, 0.0f, 0.0f);
|
||||
result.Row1 = new Vector4(-sin, cos, 0.0f, 0.0f);
|
||||
result.Row2 = Vector4.UnitZ;
|
||||
result.Row3 = Vector4.UnitW;
|
||||
}
|
||||
|
||||
public static void Translate(out Matrix4 result, float x, float y, float z) {
|
||||
result = Identity;
|
||||
result.Row3 = new Vector4(x, y, z, 1);
|
||||
}
|
||||
|
||||
public static void Scale(out Matrix4 result, float x, float y, float z) {
|
||||
result.Row0 = Vector4.UnitX; result.Row0.X *= x;
|
||||
result.Row1 = Vector4.UnitY; result.Row1.Y *= y;
|
||||
result.Row2 = Vector4.UnitZ; result.Row2.Z *= z;
|
||||
result.Row3 = Vector4.UnitW;
|
||||
}
|
||||
|
||||
public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result) {
|
||||
result = new Matrix4();
|
||||
|
||||
float invRL = 1 / (right - left);
|
||||
float invTB = 1 / (top - bottom);
|
||||
float invFN = 1 / (zFar - zNear);
|
||||
|
||||
result.Row0.X = 2 * invRL;
|
||||
result.Row1.Y = 2 * invTB;
|
||||
result.Row2.Z = -2 * invFN;
|
||||
|
||||
result.Row3.X = -(right + left) * invRL;
|
||||
result.Row3.Y = -(top + bottom) * invTB;
|
||||
result.Row3.Z = -(zFar + zNear) * invFN;
|
||||
result.Row3.W = 1;
|
||||
}
|
||||
|
||||
public static void CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar, out Matrix4 result) {
|
||||
float yMax = zNear * (float)System.Math.Tan(0.5f * fovy);
|
||||
float yMin = -yMax;
|
||||
float xMin = yMin * aspect;
|
||||
float xMax = yMax * aspect;
|
||||
|
||||
CreatePerspectiveOffCenter(xMin, xMax, yMin, yMax, zNear, zFar, out result);
|
||||
}
|
||||
|
||||
public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result) {
|
||||
float x = (2.0f * zNear) / (right - left);
|
||||
float y = (2.0f * zNear) / (top - bottom);
|
||||
float a = (right + left) / (right - left);
|
||||
float b = (top + bottom) / (top - bottom);
|
||||
float c = -(zFar + zNear) / (zFar - zNear);
|
||||
float d = -(2.0f * zFar * zNear) / (zFar - zNear);
|
||||
|
||||
result = new Matrix4(x, 0, 0, 0,
|
||||
0, y, 0, 0,
|
||||
a, b, c, -1,
|
||||
0, 0, d, 0);
|
||||
}
|
||||
|
||||
public static void LookAt(Vector3 eye, Vector3 target, Vector3 up, out Matrix4 result) {
|
||||
Vector3 z = Vector3.Normalize(eye - target);
|
||||
Vector3 x = Vector3.Normalize(Vector3.Cross(up, z));
|
||||
Vector3 y = Vector3.Normalize(Vector3.Cross(z, x));
|
||||
|
||||
Matrix4 rot = new Matrix4(new Vector4(x.X, y.X, z.X, 0.0f),
|
||||
new Vector4(x.Y, y.Y, z.Y, 0.0f),
|
||||
new Vector4(x.Z, y.Z, z.Z, 0.0f),
|
||||
Vector4.UnitW);
|
||||
|
||||
Matrix4 trans;
|
||||
Translate(out trans, -eye.X, -eye.Y, -eye.Z);
|
||||
Mult(out result, ref trans, ref rot);
|
||||
}
|
||||
|
||||
public static void Mult(out Matrix4 result, ref Matrix4 left, ref Matrix4 right) {
|
||||
// Originally from http://www.edais.co.uk/blog/?p=27
|
||||
float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
|
||||
lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
|
||||
lM31 = left.Row2.X, lM32 = left.Row2.Y, lM33 = left.Row2.Z, lM34 = left.Row2.W,
|
||||
lM41 = left.Row3.X, lM42 = left.Row3.Y, lM43 = left.Row3.Z, lM44 = left.Row3.W,
|
||||
|
||||
rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
|
||||
rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W,
|
||||
rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z, rM34 = right.Row2.W,
|
||||
rM41 = right.Row3.X, rM42 = right.Row3.Y, rM43 = right.Row3.Z, rM44 = right.Row3.W;
|
||||
|
||||
result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
|
||||
result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
|
||||
result.Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
|
||||
result.Row0.W = (((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34)) + (lM14 * rM44);
|
||||
|
||||
result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
|
||||
result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
|
||||
result.Row1.Z = (((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33)) + (lM24 * rM43);
|
||||
result.Row1.W = (((lM21 * rM14) + (lM22 * rM24)) + (lM23 * rM34)) + (lM24 * rM44);
|
||||
|
||||
result.Row2.X = (((lM31 * rM11) + (lM32 * rM21)) + (lM33 * rM31)) + (lM34 * rM41);
|
||||
result.Row2.Y = (((lM31 * rM12) + (lM32 * rM22)) + (lM33 * rM32)) + (lM34 * rM42);
|
||||
result.Row2.Z = (((lM31 * rM13) + (lM32 * rM23)) + (lM33 * rM33)) + (lM34 * rM43);
|
||||
result.Row2.W = (((lM31 * rM14) + (lM32 * rM24)) + (lM33 * rM34)) + (lM34 * rM44);
|
||||
|
||||
result.Row3.X = (((lM41 * rM11) + (lM42 * rM21)) + (lM43 * rM31)) + (lM44 * rM41);
|
||||
result.Row3.Y = (((lM41 * rM12) + (lM42 * rM22)) + (lM43 * rM32)) + (lM44 * rM42);
|
||||
result.Row3.Z = (((lM41 * rM13) + (lM42 * rM23)) + (lM43 * rM33)) + (lM44 * rM43);
|
||||
result.Row3.W = (((lM41 * rM14) + (lM42 * rM24)) + (lM43 * rM34)) + (lM44 * rM44);
|
||||
}
|
||||
|
||||
public static bool operator == (Matrix4 left, Matrix4 right) {
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator != (Matrix4 left, Matrix4 right) {
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return (obj is Matrix4) && Equals((Matrix4)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Matrix4 other) {
|
||||
return Row0 == other.Row0 && Row1 == other.Row1 &&
|
||||
Row2 == other.Row2 && Row3 == other.Row3;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format("Row0={0},\r\n Row1={1},\r\n Row2={2},\r\n Row3={3}]", Row0, Row1, Row2, Row3);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,234 +1,175 @@
|
|||
#region --- License ---
|
||||
/*
|
||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK {
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vector3 : IEquatable<Vector3>
|
||||
{
|
||||
public float X;
|
||||
|
||||
public float Y;
|
||||
|
||||
public float Z;
|
||||
|
||||
public Vector3(float x, float y, float z) {
|
||||
X = x; Y = y; Z = z;
|
||||
}
|
||||
|
||||
public Vector3(float value) {
|
||||
X = value; Y = value; Z = value;
|
||||
}
|
||||
|
||||
public float Length {
|
||||
get { return (float)Math.Sqrt(X * X + Y * Y + Z * Z); }
|
||||
}
|
||||
|
||||
public float LengthSquared {
|
||||
get { return X * X + Y * Y + Z * Z; }
|
||||
}
|
||||
|
||||
public static readonly Vector3 UnitX = new Vector3(1, 0, 0);
|
||||
|
||||
public static readonly Vector3 UnitY = new Vector3(0, 1, 0);
|
||||
|
||||
public static readonly Vector3 UnitZ = new Vector3(0, 0, 1);
|
||||
|
||||
public static readonly Vector3 Zero = new Vector3(0, 0, 0);
|
||||
|
||||
public static readonly Vector3 One = new Vector3(1, 1, 1);
|
||||
|
||||
public static void Add(ref Vector3 a, ref Vector3 b, out Vector3 result) {
|
||||
result = new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
||||
}
|
||||
|
||||
public static void Subtract(ref Vector3 a, ref Vector3 b, out Vector3 result) {
|
||||
result = new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
||||
}
|
||||
|
||||
public static void Multiply(ref Vector3 vector, float scale, out Vector3 result) {
|
||||
result = new Vector3(vector.X * scale, vector.Y * scale, vector.Z * scale);
|
||||
}
|
||||
|
||||
public static void Multiply(ref Vector3 vector, ref Vector3 scale, out Vector3 result) {
|
||||
result = new Vector3(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z);
|
||||
}
|
||||
|
||||
public static void Divide(ref Vector3 vector, float scale, out Vector3 result) {
|
||||
float invScale = 1 / scale;
|
||||
result = new Vector3(vector.X * invScale, vector.Y * invScale, vector.Z * invScale);
|
||||
}
|
||||
|
||||
public static void Divide(ref Vector3 vector, ref Vector3 scale, out Vector3 result) {
|
||||
result = new Vector3(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z);
|
||||
}
|
||||
|
||||
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) {
|
||||
a.X = blend * (b.X - a.X) + a.X;
|
||||
a.Y = blend * (b.Y - a.Y) + a.Y;
|
||||
a.Z = blend * (b.Z - a.Z) + a.Z;
|
||||
return a;
|
||||
}
|
||||
|
||||
public static void Lerp(ref Vector3 a, ref Vector3 b, float blend, out Vector3 result) {
|
||||
result.X = blend * (b.X - a.X) + a.X;
|
||||
result.Y = blend * (b.Y - a.Y) + a.Y;
|
||||
result.Z = blend * (b.Z - a.Z) + a.Z;
|
||||
}
|
||||
|
||||
public static float Dot(Vector3 left, Vector3 right) {
|
||||
return left.X * right.X + left.Y * right.Y + left.Z * right.Z;
|
||||
}
|
||||
|
||||
public static void Dot(ref Vector3 left, ref Vector3 right, out float result) {
|
||||
result = left.X * right.X + left.Y * right.Y + left.Z * right.Z;
|
||||
}
|
||||
|
||||
public static Vector3 Cross(Vector3 left, Vector3 right) {
|
||||
return new Vector3(left.Y * right.Z - left.Z * right.Y,
|
||||
left.Z * right.X - left.X * right.Z,
|
||||
left.X * right.Y - left.Y * right.X);
|
||||
}
|
||||
|
||||
public static void Cross(ref Vector3 left, ref Vector3 right, out Vector3 result) {
|
||||
result = new Vector3(left.Y * right.Z - left.Z * right.Y,
|
||||
left.Z * right.X - left.X * right.Z,
|
||||
left.X * right.Y - left.Y * right.X);
|
||||
}
|
||||
|
||||
public static Vector3 Normalize(Vector3 vec) {
|
||||
float scale = 1f / vec.Length;
|
||||
vec.X *= scale;
|
||||
vec.Y *= scale;
|
||||
vec.Z *= scale;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Vector3 Normalize(float x, float y, float z) {
|
||||
float scale = 1f / (float)Math.Sqrt(x * x + y * y + z * z);
|
||||
return new Vector3(x * scale, y * scale, z * scale);
|
||||
}
|
||||
|
||||
public static void Normalize(ref Vector3 vec, out Vector3 result) {
|
||||
float scale = 1f / vec.Length;
|
||||
result.X = vec.X * scale;
|
||||
result.Y = vec.Y * scale;
|
||||
result.Z = vec.Z * scale;
|
||||
}
|
||||
|
||||
public static void Transform(ref Vector3 vec, ref Matrix4 mat, out Vector3 result) {
|
||||
result.X = vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + mat.Row3.X;
|
||||
result.Y = vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + mat.Row3.Y;
|
||||
result.Z = vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + mat.Row3.Z;
|
||||
}
|
||||
|
||||
public static void TransformX(float x, ref Matrix4 mat, out Vector3 result) {
|
||||
result.X = x * mat.Row0.X + mat.Row3.X;
|
||||
result.Y = x * mat.Row0.Y + mat.Row3.Y;
|
||||
result.Z = x * mat.Row0.Z + mat.Row3.Z;
|
||||
}
|
||||
|
||||
public static void TransformY(float y, ref Matrix4 mat, out Vector3 result) {
|
||||
result.X = y * mat.Row1.X + mat.Row3.X;
|
||||
result.Y = y * mat.Row1.Y + mat.Row3.Y;
|
||||
result.Z = y * mat.Row1.Z + mat.Row3.Z;
|
||||
}
|
||||
|
||||
public static void TransformZ(float z, ref Matrix4 mat, out Vector3 result) {
|
||||
result.X = z * mat.Row2.X + mat.Row3.X;
|
||||
result.Y = z * mat.Row2.Y + mat.Row3.Y;
|
||||
result.Z = z * mat.Row2.Z + mat.Row3.Z;
|
||||
}
|
||||
|
||||
public static Vector3 operator + (Vector3 left, Vector3 right) {
|
||||
left.X += right.X;
|
||||
left.Y += right.Y;
|
||||
left.Z += right.Z;
|
||||
return left;
|
||||
}
|
||||
|
||||
public static Vector3 operator - (Vector3 left, Vector3 right) {
|
||||
left.X -= right.X;
|
||||
left.Y -= right.Y;
|
||||
left.Z -= right.Z;
|
||||
return left;
|
||||
}
|
||||
|
||||
public static Vector3 operator - (Vector3 vec) {
|
||||
vec.X = -vec.X;
|
||||
vec.Y = -vec.Y;
|
||||
vec.Z = -vec.Z;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Vector3 operator * (Vector3 vec, float scale) {
|
||||
vec.X *= scale;
|
||||
vec.Y *= scale;
|
||||
vec.Z *= scale;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Vector3 operator * (Vector3 vec, Vector3 scale) {
|
||||
vec.X *= scale.X;
|
||||
vec.Y *= scale.Y;
|
||||
vec.Z *= scale.Z;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Vector3 operator / (Vector3 vec, float scale) {
|
||||
float mult = 1f / scale;
|
||||
vec.X *= mult;
|
||||
vec.Y *= mult;
|
||||
vec.Z *= mult;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static bool operator ==(Vector3 left, Vector3 right) {
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector3 left, Vector3 right) {
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return (obj is Vector3) && Equals((Vector3)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Vector3 other) {
|
||||
return X == other.X && Y == other.Y && Z == other.Z;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return X + ", " + Y + ", " + Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region --- License ---
|
||||
/*
|
||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK {
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vector3 : IEquatable<Vector3>
|
||||
{
|
||||
public float X, Y, Z;
|
||||
|
||||
public Vector3(float x, float y, float z) {
|
||||
X = x; Y = y; Z = z;
|
||||
}
|
||||
|
||||
public Vector3(float value) {
|
||||
X = value; Y = value; Z = value;
|
||||
}
|
||||
|
||||
public float LengthSquared { get { return X * X + Y * Y + Z * Z; } }
|
||||
|
||||
public static readonly Vector3 UnitX = new Vector3(1, 0, 0);
|
||||
public static readonly Vector3 UnitY = new Vector3(0, 1, 0);
|
||||
public static readonly Vector3 UnitZ = new Vector3(0, 0, 1);
|
||||
|
||||
public static readonly Vector3 Zero = new Vector3(0, 0, 0);
|
||||
public static readonly Vector3 One = new Vector3(1, 1, 1);
|
||||
|
||||
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) {
|
||||
a.X = blend * (b.X - a.X) + a.X;
|
||||
a.Y = blend * (b.Y - a.Y) + a.Y;
|
||||
a.Z = blend * (b.Z - a.Z) + a.Z;
|
||||
return a;
|
||||
}
|
||||
|
||||
public static void Lerp(ref Vector3 a, ref Vector3 b, float blend, out Vector3 result) {
|
||||
result.X = blend * (b.X - a.X) + a.X;
|
||||
result.Y = blend * (b.Y - a.Y) + a.Y;
|
||||
result.Z = blend * (b.Z - a.Z) + a.Z;
|
||||
}
|
||||
|
||||
public static float Dot(Vector3 left, Vector3 right) {
|
||||
return left.X * right.X + left.Y * right.Y + left.Z * right.Z;
|
||||
}
|
||||
|
||||
public static void Dot(ref Vector3 left, ref Vector3 right, out float result) {
|
||||
result = left.X * right.X + left.Y * right.Y + left.Z * right.Z;
|
||||
}
|
||||
|
||||
public static Vector3 Cross(Vector3 left, Vector3 right) {
|
||||
return new Vector3(left.Y * right.Z - left.Z * right.Y,
|
||||
left.Z * right.X - left.X * right.Z,
|
||||
left.X * right.Y - left.Y * right.X);
|
||||
}
|
||||
|
||||
public static void Cross(ref Vector3 left, ref Vector3 right, out Vector3 result) {
|
||||
result = new Vector3(left.Y * right.Z - left.Z * right.Y,
|
||||
left.Z * right.X - left.X * right.Z,
|
||||
left.X * right.Y - left.Y * right.X);
|
||||
}
|
||||
|
||||
public static Vector3 Normalize(Vector3 vec) {
|
||||
float scale = 1f / (float)Math.Sqrt(vec.LengthSquared);
|
||||
vec.X *= scale; vec.Y *= scale; vec.Z *= scale;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Vector3 Normalize(float x, float y, float z) {
|
||||
float scale = 1f / (float)Math.Sqrt(x * x + y * y + z * z);
|
||||
return new Vector3(x * scale, y * scale, z * scale);
|
||||
}
|
||||
|
||||
public static void Transform(ref Vector3 vec, ref Matrix4 mat, out Vector3 result) {
|
||||
result.X = vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + mat.Row3.X;
|
||||
result.Y = vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + mat.Row3.Y;
|
||||
result.Z = vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + mat.Row3.Z;
|
||||
}
|
||||
|
||||
public static void TransformY(float y, ref Matrix4 mat, out Vector3 result) {
|
||||
result.X = y * mat.Row1.X + mat.Row3.X;
|
||||
result.Y = y * mat.Row1.Y + mat.Row3.Y;
|
||||
result.Z = y * mat.Row1.Z + mat.Row3.Z;
|
||||
}
|
||||
|
||||
public static Vector3 operator + (Vector3 left, Vector3 right) {
|
||||
left.X += right.X;
|
||||
left.Y += right.Y;
|
||||
left.Z += right.Z;
|
||||
return left;
|
||||
}
|
||||
|
||||
public static Vector3 operator - (Vector3 left, Vector3 right) {
|
||||
left.X -= right.X;
|
||||
left.Y -= right.Y;
|
||||
left.Z -= right.Z;
|
||||
return left;
|
||||
}
|
||||
|
||||
public static Vector3 operator - (Vector3 vec) {
|
||||
vec.X = -vec.X;
|
||||
vec.Y = -vec.Y;
|
||||
vec.Z = -vec.Z;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Vector3 operator * (Vector3 vec, float scale) {
|
||||
vec.X *= scale;
|
||||
vec.Y *= scale;
|
||||
vec.Z *= scale;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Vector3 operator * (Vector3 vec, Vector3 scale) {
|
||||
vec.X *= scale.X;
|
||||
vec.Y *= scale.Y;
|
||||
vec.Z *= scale.Z;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static Vector3 operator / (Vector3 vec, float scale) {
|
||||
float mult = 1f / scale;
|
||||
vec.X *= mult;
|
||||
vec.Y *= mult;
|
||||
vec.Z *= mult;
|
||||
return vec;
|
||||
}
|
||||
|
||||
public static bool operator ==(Vector3 left, Vector3 right) {
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector3 left, Vector3 right) {
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return (obj is Vector3) && Equals((Vector3)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Vector3 other) {
|
||||
return X == other.X && Y == other.Y && Z == other.Z;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return X + ", " + Y + ", " + Z;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +1,68 @@
|
|||
#region --- License ---
|
||||
/*
|
||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK {
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vector4 : IEquatable<Vector4> {
|
||||
|
||||
public float X;
|
||||
|
||||
public float Y;
|
||||
|
||||
public float Z;
|
||||
|
||||
public float W;
|
||||
|
||||
public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
|
||||
|
||||
public static Vector4 UnitY = new Vector4(0, 1, 0, 0);
|
||||
|
||||
public static Vector4 UnitZ = new Vector4(0, 0, 1, 0);
|
||||
|
||||
public static Vector4 UnitW = new Vector4(0, 0, 0, 1);
|
||||
|
||||
public static Vector4 Zero = new Vector4(0, 0, 0, 0);
|
||||
|
||||
public static readonly Vector4 One = new Vector4(1, 1, 1, 1);
|
||||
|
||||
public static readonly int SizeInBytes = 4 * sizeof(float);
|
||||
|
||||
|
||||
public Vector4(float x, float y, float z, float w) {
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
|
||||
public static bool operator == (Vector4 left, Vector4 right) {
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator != (Vector4 left, Vector4 right) {
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return (obj is Vector4) && Equals((Vector4)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Vector4 other) {
|
||||
return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return X + " : " + Y + " : " + Z + " : " + W;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region --- License ---
|
||||
/*
|
||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK {
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vector4 : IEquatable<Vector4> {
|
||||
|
||||
public float X, Y, Z, W;
|
||||
|
||||
public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
|
||||
public static Vector4 UnitY = new Vector4(0, 1, 0, 0);
|
||||
public static Vector4 UnitZ = new Vector4(0, 0, 1, 0);
|
||||
public static Vector4 UnitW = new Vector4(0, 0, 0, 1);
|
||||
|
||||
public Vector4(float x, float y, float z, float w) {
|
||||
X = x; Y = y; Z = z; W = w;
|
||||
}
|
||||
|
||||
public static bool operator == (Vector4 left, Vector4 right) {
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator != (Vector4 left, Vector4 right) {
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return (obj is Vector4) && Equals((Vector4)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Vector4 other) {
|
||||
return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return X + " : " + Y + " : " + Z + " : " + W;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -62,9 +62,6 @@
|
|||
<Compile Include="Input\Keyboard.cs" />
|
||||
<Compile Include="Input\MouseButton.cs" />
|
||||
<Compile Include="Input\Mouse.cs" />
|
||||
<Compile Include="Math\Matrix4.cs" />
|
||||
<Compile Include="Math\Vector3.cs" />
|
||||
<Compile Include="Math\Vector4.cs" />
|
||||
<Compile Include="Platform\Configuration.cs" />
|
||||
<Compile Include="Platform\IPlatformFactory.cs" />
|
||||
<Compile Include="Platform\MacOS\AglContext.cs" />
|
||||
|
@ -96,7 +93,6 @@
|
|||
<ItemGroup>
|
||||
<Folder Include="Graphics" />
|
||||
<Folder Include="Input" />
|
||||
<Folder Include="Math" />
|
||||
<Folder Include="Platform" />
|
||||
<Folder Include="Platform\MacOS" />
|
||||
<Folder Include="Platform\MacOS\CarbonBindings" />
|
||||
|
|
|
@ -168,9 +168,6 @@ namespace OpenTK.Platform.MacOS {
|
|||
mIsFullscreen = false;
|
||||
}
|
||||
|
||||
|
||||
#region IGraphicsContext Members
|
||||
|
||||
public override void SwapBuffers() {
|
||||
Agl.aglSwapBuffers(ContextHandle);
|
||||
Agl.CheckReturnValue(0, "aglSwapBuffers");
|
||||
|
@ -182,7 +179,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
}
|
||||
|
||||
public override bool IsCurrent {
|
||||
get { return ContextHandle == Agl.aglGetCurrentContext(); }
|
||||
get { return ContextHandle == Agl.aglGetCurrentContext(); }
|
||||
}
|
||||
|
||||
public override bool VSync {
|
||||
|
@ -194,10 +191,6 @@ namespace OpenTK.Platform.MacOS {
|
|||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
bool IsDisposed;
|
||||
protected override void Dispose(bool disposing) {
|
||||
if (IsDisposed || ContextHandle == IntPtr.Zero) return;
|
||||
|
@ -217,43 +210,31 @@ namespace OpenTK.Platform.MacOS {
|
|||
Agl.CheckReturnValue(code, "aglDestroyContext");
|
||||
ContextHandle = IntPtr.Zero;
|
||||
Debug.Print("Context destruction completed successfully.");
|
||||
} catch(MacOSException) {
|
||||
} catch (MacOSException) {
|
||||
Debug.Print("Failed to destroy context.");
|
||||
if (disposing)
|
||||
throw;
|
||||
if (disposing) throw;
|
||||
}
|
||||
IsDisposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
const string lib = "libdl.dylib";
|
||||
[DllImport(lib, EntryPoint = "NSIsSymbolNameDefined")]
|
||||
static extern bool NSIsSymbolNameDefined(string s);
|
||||
[DllImport(lib, EntryPoint = "NSLookupAndBindSymbol")]
|
||||
static extern IntPtr NSLookupAndBindSymbol(string s);
|
||||
[DllImport(lib, EntryPoint = "NSAddressOfSymbol")]
|
||||
static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
|
||||
|
||||
#region IGraphicsContextInternal Members
|
||||
|
||||
private const string Library = "libdl.dylib";
|
||||
|
||||
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
|
||||
private static extern bool NSIsSymbolNameDefined(string s);
|
||||
[DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")]
|
||||
private static extern IntPtr NSLookupAndBindSymbol(string s);
|
||||
[DllImport(Library, EntryPoint = "NSAddressOfSymbol")]
|
||||
private static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
|
||||
|
||||
public override IntPtr GetAddress(string function)
|
||||
{
|
||||
public override IntPtr GetAddress(string function) {
|
||||
string fname = "_" + function;
|
||||
if (!NSIsSymbolNameDefined(fname))
|
||||
return IntPtr.Zero;
|
||||
if (!NSIsSymbolNameDefined(fname)) return IntPtr.Zero;
|
||||
|
||||
IntPtr symbol = NSLookupAndBindSymbol(fname);
|
||||
if (symbol != IntPtr.Zero)
|
||||
symbol = NSAddressOfSymbol(symbol);
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public override void LoadAll() {
|
||||
}
|
||||
|
||||
#endregion
|
||||
public override void LoadAll() { }
|
||||
}
|
||||
}
|
|
@ -12,41 +12,31 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Platform.MacOS.Carbon
|
||||
{
|
||||
static class Application
|
||||
{
|
||||
static bool mInitialized = false;
|
||||
namespace OpenTK.Platform.MacOS.Carbon {
|
||||
static class Application {
|
||||
static bool mInitialized;
|
||||
static IntPtr uppHandler;
|
||||
static CarbonWindow eventHandler;
|
||||
static int osMajor, osMinor, osBugfix;
|
||||
static MacOSEventHandler handler = EventHandler;
|
||||
internal static CarbonWindow WindowEventHandler;
|
||||
|
||||
static Application()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
static Application() { Initialize(); }
|
||||
|
||||
internal static void Initialize()
|
||||
{
|
||||
if (mInitialized) return;
|
||||
|
||||
internal static void Initialize() {
|
||||
if (mInitialized) return;
|
||||
API.AcquireRootMenu();
|
||||
|
||||
ConnectEvents();
|
||||
|
||||
int osMajor, osMinor, osBugfix;
|
||||
|
||||
API.Gestalt(GestaltSelector.SystemVersionMajor, out osMajor);
|
||||
API.Gestalt(GestaltSelector.SystemVersionMinor, out osMinor);
|
||||
API.Gestalt(GestaltSelector.SystemVersionBugFix, out osBugfix);
|
||||
|
||||
Debug.Print("Running on Mac OS X {0}.{1}.{2}.", osMajor, osMinor, osBugfix);
|
||||
|
||||
TransformProcessToForeground();
|
||||
}
|
||||
|
||||
private static void TransformProcessToForeground()
|
||||
{
|
||||
static void TransformProcessToForeground() {
|
||||
ProcessSerialNumber psn = new ProcessSerialNumber();
|
||||
|
||||
Debug.Print("Setting process to be foreground application.");
|
||||
|
||||
API.GetCurrentProcess(ref psn);
|
||||
|
@ -54,16 +44,8 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
API.SetFrontProcess(ref psn);
|
||||
}
|
||||
|
||||
internal static CarbonWindow WindowEventHandler
|
||||
{
|
||||
get { return eventHandler; }
|
||||
set { eventHandler = value; }
|
||||
}
|
||||
|
||||
static void ConnectEvents()
|
||||
{
|
||||
EventTypeSpec[] eventTypes = new EventTypeSpec[]
|
||||
{
|
||||
static void ConnectEvents() {
|
||||
EventTypeSpec[] eventTypes = new EventTypeSpec[] {
|
||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated),
|
||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated),
|
||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit),
|
||||
|
@ -84,21 +66,15 @@ namespace OpenTK.Platform.MacOS.Carbon
|
|||
new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent),
|
||||
};
|
||||
|
||||
MacOSEventHandler handler = EventHandler;
|
||||
uppHandler = API.NewEventHandlerUPP(handler);
|
||||
|
||||
API.InstallApplicationEventHandler(
|
||||
uppHandler, eventTypes, IntPtr.Zero, IntPtr.Zero);
|
||||
|
||||
uppHandler, eventTypes, IntPtr.Zero, IntPtr.Zero);
|
||||
mInitialized = true;
|
||||
}
|
||||
|
||||
static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
|
||||
{
|
||||
EventInfo evt = new EventInfo(inEvent);
|
||||
|
||||
switch (evt.EventClass)
|
||||
{
|
||||
static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData) {
|
||||
EventInfo evt = new EventInfo(inEvent);
|
||||
switch (evt.EventClass) {
|
||||
case EventClass.AppleEvent:
|
||||
// only event here is the apple event.
|
||||
Debug.Print("Processing apple event.");
|
||||
|
|
|
@ -33,8 +33,8 @@ namespace OpenTK.Platform.MacOS {
|
|||
right = (short)(_left + _width);
|
||||
}
|
||||
|
||||
public short X { get { return left; } }
|
||||
public short Y { get { return top; } }
|
||||
public short X { get { return left; } }
|
||||
public short Y { get { return top; } }
|
||||
public short Width { get { return (short)(right - left); } }
|
||||
public short Height { get { return (short)(bottom - top); } }
|
||||
|
||||
|
@ -97,7 +97,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
}
|
||||
}
|
||||
|
||||
public struct EventInfo {
|
||||
public struct EventInfo {
|
||||
public EventInfo(IntPtr eventRef) {
|
||||
EventClass = API.GetEventClass(eventRef);
|
||||
EventKind = API.GetEventKind(eventRef);
|
||||
|
@ -402,8 +402,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
|
||||
#region --- Carbon API Methods ---
|
||||
|
||||
public static class API
|
||||
{
|
||||
public static class API {
|
||||
const string carbon = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
|
||||
|
||||
[DllImport(carbon)]
|
||||
|
@ -435,77 +434,28 @@ namespace OpenTK.Platform.MacOS {
|
|||
[DllImport(carbon)]
|
||||
static extern OSStatus GetWindowBounds(IntPtr window, WindowRegionCode regionCode, out Rect globalBounds);
|
||||
public static Rect GetWindowBounds(IntPtr window, WindowRegionCode regionCode) {
|
||||
Rect retval;
|
||||
OSStatus error = GetWindowBounds(window, regionCode, out retval);
|
||||
CheckReturn(error);
|
||||
return retval;
|
||||
Rect rect;
|
||||
OSStatus result = GetWindowBounds(window, regionCode, out rect);
|
||||
CheckReturn(result);
|
||||
return rect;
|
||||
}
|
||||
|
||||
[DllImport(carbon)]
|
||||
static extern IntPtr GetEventDispatcherTarget();
|
||||
[DllImport(carbon,EntryPoint="ReceiveNextEvent")]
|
||||
static extern OSStatus ReceiveNextEvent(uint inNumTypes,
|
||||
IntPtr inList,
|
||||
double inTimeout,
|
||||
bool inPullEvent,
|
||||
out IntPtr outEvent);
|
||||
internal static extern IntPtr GetEventDispatcherTarget();
|
||||
[DllImport(carbon)]
|
||||
internal static extern OSStatus ReceiveNextEvent(uint numTypes, IntPtr list,
|
||||
double timeout, bool pullEvent,
|
||||
out IntPtr theEvent);
|
||||
|
||||
[DllImport(carbon)]
|
||||
static extern void SendEventToEventTarget(IntPtr theEvent, IntPtr theTarget);
|
||||
|
||||
internal static extern void SendEventToEventTarget(IntPtr theEvent, IntPtr theTarget);
|
||||
[DllImport(carbon)]
|
||||
static extern void ReleaseEvent(IntPtr theEvent);
|
||||
|
||||
public static void SendEvent(IntPtr theEvent)
|
||||
{
|
||||
IntPtr theTarget = GetEventDispatcherTarget();
|
||||
SendEventToEventTarget(theEvent, theTarget);
|
||||
}
|
||||
|
||||
// Processes events in the queue and then returns.
|
||||
public static void ProcessEvents()
|
||||
{
|
||||
IntPtr theEvent;
|
||||
IntPtr theTarget = GetEventDispatcherTarget();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
OSStatus status = ReceiveNextEvent(0, IntPtr.Zero, 0.0, true, out theEvent);
|
||||
|
||||
if (status == OSStatus.EventLoopTimedOut)
|
||||
break;
|
||||
|
||||
if (status != OSStatus.NoError)
|
||||
{
|
||||
Debug.Print("Message Loop status: {0}", status);
|
||||
break;
|
||||
}
|
||||
if (theEvent == IntPtr.Zero)
|
||||
break;
|
||||
|
||||
try
|
||||
{
|
||||
SendEventToEventTarget(theEvent, theTarget);
|
||||
}
|
||||
catch (System.ExecutionEngineException e)
|
||||
{
|
||||
Console.Error.WriteLine("ExecutionEngineException caught.");
|
||||
Console.Error.WriteLine("theEvent: " + new EventInfo(theEvent).ToString());
|
||||
Console.Error.WriteLine(e.Message);
|
||||
Console.Error.WriteLine(e.StackTrace);
|
||||
}
|
||||
|
||||
ReleaseEvent(theEvent);
|
||||
}
|
||||
|
||||
}
|
||||
internal static extern void ReleaseEvent(IntPtr theEvent);
|
||||
|
||||
#region --- Processing apple event ---
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
||||
struct EventRecord
|
||||
{
|
||||
struct EventRecord {
|
||||
public ushort what;
|
||||
public uint message;
|
||||
public uint when;
|
||||
|
@ -515,14 +465,11 @@ namespace OpenTK.Platform.MacOS {
|
|||
|
||||
[DllImport(carbon)]
|
||||
static extern bool ConvertEventRefToEventRecord(IntPtr inEvent, out EventRecord outEvent);
|
||||
|
||||
[DllImport(carbon)]
|
||||
static extern OSStatus AEProcessAppleEvent(ref EventRecord theEventRecord);
|
||||
|
||||
static public void ProcessAppleEvent(IntPtr inEvent)
|
||||
{
|
||||
public static void ProcessAppleEvent(IntPtr inEvent) {
|
||||
EventRecord record;
|
||||
|
||||
ConvertEventRefToEventRecord(inEvent, out record);
|
||||
AEProcessAppleEvent(ref record);
|
||||
}
|
||||
|
@ -557,9 +504,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.KeyCode, EventParamType.typeUInt32, IntPtr.Zero,
|
||||
sizeof(uint), IntPtr.Zero, (IntPtr)(void*)&code);
|
||||
|
||||
if (result != OSStatus.NoError)
|
||||
throw new MacOSException(result);
|
||||
CheckReturn(result);
|
||||
return (MacOSKeyCode)code;
|
||||
}
|
||||
|
||||
|
@ -568,9 +513,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.KeyMacCharCode, EventParamType.typeChar, IntPtr.Zero,
|
||||
Marshal.SizeOf(typeof(char)), IntPtr.Zero, (IntPtr)(void*)&code);
|
||||
|
||||
if (result != OSStatus.NoError)
|
||||
throw new MacOSException(result);
|
||||
CheckReturn(result);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -579,9 +522,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.MouseButton, EventParamType.typeMouseButton, IntPtr.Zero,
|
||||
sizeof(short), IntPtr.Zero, (IntPtr)(void*)&button);
|
||||
|
||||
if (result != OSStatus.NoError)
|
||||
throw new MacOSException(result);
|
||||
CheckReturn(result);
|
||||
return (MacOSMouseButton)button;
|
||||
}
|
||||
|
||||
|
@ -590,9 +531,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.MouseWheelDelta, EventParamType.typeSInt32,
|
||||
IntPtr.Zero, sizeof(int), IntPtr.Zero, (IntPtr)(void*)&delta);
|
||||
|
||||
if (result != OSStatus.NoError)
|
||||
throw new MacOSException(result);
|
||||
CheckReturn(result);
|
||||
return delta;
|
||||
}
|
||||
|
||||
|
@ -601,27 +540,15 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.WindowMouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
|
||||
Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (IntPtr)(void*)&point);
|
||||
|
||||
pt = point;
|
||||
return result;
|
||||
}
|
||||
|
||||
public unsafe static OSStatus GetEventWindowRef(IntPtr inEvent, out IntPtr windowRef) {
|
||||
IntPtr retval;
|
||||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.WindowRef, EventParamType.typeWindowRef, IntPtr.Zero,
|
||||
sizeof(IntPtr), IntPtr.Zero, (IntPtr)(void*)&retval);
|
||||
|
||||
windowRef = retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
public unsafe static OSStatus GetEventMouseLocation(IntPtr inEvent, out HIPoint pt) {
|
||||
HIPoint point;
|
||||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.MouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
|
||||
Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (IntPtr)(void*)&point);
|
||||
|
||||
pt = point;
|
||||
return result;
|
||||
}
|
||||
|
@ -631,63 +558,45 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus result = API.GetEventParameter(inEvent,
|
||||
EventParamName.KeyModifiers, EventParamType.typeUInt32, IntPtr.Zero,
|
||||
sizeof(uint), IntPtr.Zero, (IntPtr)(void*)&code);
|
||||
|
||||
if (result != OSStatus.NoError)
|
||||
throw new MacOSException(result);
|
||||
CheckReturn(result);
|
||||
return (MacOSKeyModifiers)code;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region --- Event Handlers ---
|
||||
|
||||
public static void InstallWindowEventHandler(IntPtr windowRef, IntPtr uppHandlerProc,
|
||||
EventTypeSpec[] eventTypes, IntPtr userData, IntPtr handlerRef) {
|
||||
IntPtr target = GetWindowEventTarget(windowRef);
|
||||
OSStatus result = InstallEventHandler(target, uppHandlerProc, eventTypes.Length,
|
||||
eventTypes, userData, handlerRef);
|
||||
CheckReturn(result);
|
||||
}
|
||||
|
||||
public static void InstallApplicationEventHandler(IntPtr uppHandlerProc,
|
||||
EventTypeSpec[] eventTypes, IntPtr userData, IntPtr handlerRef) {
|
||||
IntPtr target = GetApplicationEventTarget();
|
||||
OSStatus result = InstallEventHandler(target, uppHandlerProc, eventTypes.Length,
|
||||
eventTypes, userData, handlerRef);
|
||||
CheckReturn(result);
|
||||
}
|
||||
|
||||
[DllImport(carbon)]
|
||||
static extern OSStatus InstallEventHandler(IntPtr eventTargetRef, IntPtr handlerProc,
|
||||
int numtypes, EventTypeSpec[] typeList,
|
||||
IntPtr userData, IntPtr handlerRef);
|
||||
|
||||
public static void InstallWindowEventHandler(IntPtr windowRef, IntPtr uppHandlerProc,
|
||||
EventTypeSpec[] eventTypes, IntPtr userData, IntPtr handlerRef)
|
||||
{
|
||||
IntPtr windowTarget = GetWindowEventTarget(windowRef);
|
||||
OSStatus error = InstallEventHandler(windowTarget, uppHandlerProc,
|
||||
eventTypes.Length, eventTypes,
|
||||
userData, handlerRef);
|
||||
CheckReturn(error);
|
||||
}
|
||||
|
||||
public static void InstallApplicationEventHandler(IntPtr uppHandlerProc,
|
||||
EventTypeSpec[] eventTypes, IntPtr userData, IntPtr handlerRef)
|
||||
{
|
||||
OSStatus error = InstallEventHandler(GetApplicationEventTarget(), uppHandlerProc,
|
||||
eventTypes.Length, eventTypes,
|
||||
userData, handlerRef);
|
||||
CheckReturn(error);
|
||||
}
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern OSStatus RemoveEventHandler(IntPtr inHandlerRef);
|
||||
|
||||
#endregion
|
||||
#region --- GetWindowEventTarget ---
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern IntPtr GetWindowEventTarget(IntPtr window);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern IntPtr GetApplicationEventTarget();
|
||||
|
||||
#endregion
|
||||
#region --- UPP Event Handlers ---
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern IntPtr NewEventHandlerUPP(MacOSEventHandler handler);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern void DisposeEventHandlerUPP(IntPtr userUPP);
|
||||
|
||||
#endregion
|
||||
#region --- Process Manager ---
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern int TransformProcessType(ref ProcessSerialNumber psn, ProcessApplicationTransformState type);
|
||||
[DllImport(carbon)]
|
||||
|
@ -695,26 +604,25 @@ namespace OpenTK.Platform.MacOS {
|
|||
[DllImport(carbon)]
|
||||
public static extern int SetFrontProcess(ref ProcessSerialNumber psn);
|
||||
|
||||
#endregion
|
||||
#region --- Setting Dock Tile ---
|
||||
|
||||
[DllImport(carbon)]
|
||||
public extern static IntPtr CGColorSpaceCreateDeviceRGB();
|
||||
[DllImport(carbon)]
|
||||
public extern static IntPtr CGDataProviderCreateWithData(IntPtr info, IntPtr data, int size, IntPtr releasefunc);
|
||||
[DllImport(carbon)]
|
||||
public extern static IntPtr CGImageCreate(int width, int height, int bitsPerComponent, int bitsPerPixel, int bytesPerRow, IntPtr colorspace,
|
||||
public extern static IntPtr CGImageCreate(int width, int height, int bitsPerComponent, int bitsPerPixel, int bytesPerRow, IntPtr colorspace,
|
||||
uint bitmapInfo, IntPtr provider, IntPtr decode, int shouldInterpolate, int intent);
|
||||
[DllImport(carbon)]
|
||||
public extern static void SetApplicationDockTileImage(IntPtr imageRef);
|
||||
[DllImport(carbon)]
|
||||
public extern static void RestoreApplicationDockTileImage();
|
||||
[DllImport(carbon)]
|
||||
public extern static void CGImageRelease(IntPtr image);
|
||||
[DllImport(carbon)]
|
||||
public extern static void CGDataProviderRelease(IntPtr provider);
|
||||
[DllImport(carbon)]
|
||||
public extern static void CGColorSpaceRelease(IntPtr space);
|
||||
public extern static void CGColorSpaceRelease(IntPtr space);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public extern static void SetApplicationDockTileImage(IntPtr imageRef);
|
||||
[DllImport(carbon)]
|
||||
public extern static void RestoreApplicationDockTileImage();
|
||||
|
||||
[DllImport(carbon)]
|
||||
public extern static void CGContextDrawImage(IntPtr context, HIRect rect, IntPtr image);
|
||||
[DllImport(carbon)]
|
||||
|
@ -723,8 +631,6 @@ namespace OpenTK.Platform.MacOS {
|
|||
public extern static OSStatus QDBeginCGContext(IntPtr port, ref IntPtr context);
|
||||
[DllImport(carbon)]
|
||||
public extern static OSStatus QDEndCGContext(IntPtr port, ref IntPtr context);
|
||||
#endregion
|
||||
#region --- Clipboard ---
|
||||
|
||||
[DllImport (carbon)]
|
||||
public static extern IntPtr CFDataCreate(IntPtr allocator, IntPtr buf, Int32 length);
|
||||
|
@ -745,63 +651,25 @@ namespace OpenTK.Platform.MacOS {
|
|||
public static extern OSStatus PasteboardGetItemIdentifier(IntPtr pbref, UInt32 itemindex, out UInt32 itemid);
|
||||
[DllImport (carbon)]
|
||||
public static extern OSStatus PasteboardPutItemFlavor(IntPtr pbref, UInt32 itemid, IntPtr key, IntPtr data, UInt32 flags);
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern OSStatus ActivateWindow (IntPtr inWindow, bool inActivate);
|
||||
public static extern OSStatus ActivateWindow(IntPtr inWindow, bool inActivate);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern void RunApplicationEventLoop();
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern void QuitApplicationEventLoop();
|
||||
|
||||
#region --- SetWindowTitle ---
|
||||
|
||||
[DllImport(carbon)]
|
||||
static extern void SetWindowTitleWithCFString(IntPtr windowRef, IntPtr title);
|
||||
|
||||
public static void SetWindowTitle(IntPtr windowRef, string title)
|
||||
{
|
||||
IntPtr str = __CFStringMakeConstantString(title);
|
||||
|
||||
Debug.Print("Setting window title: {0}, CFstring : {1}, Text : {2}", windowRef, str, title);
|
||||
|
||||
SetWindowTitleWithCFString(windowRef, str);
|
||||
|
||||
// Apparently releasing this reference to the CFConstantString here
|
||||
// causes the program to crash on the fourth window created. But I am
|
||||
// afraid that not releasing the string would result in a memory leak, but that would
|
||||
// only be a serious issue if the window title is changed a lot.
|
||||
//CFRelease(str);
|
||||
}
|
||||
|
||||
#endregion
|
||||
internal static extern void SetWindowTitleWithCFString(IntPtr windowRef, IntPtr title);
|
||||
|
||||
[DllImport(carbon)]
|
||||
static extern IntPtr __CFStringMakeConstantString(string cStr);
|
||||
|
||||
[DllImport(carbon)]
|
||||
static extern void CFRelease(IntPtr cfStr);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern OSStatus CallNextEventHandler(IntPtr nextHandler, IntPtr theEvent);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern IntPtr GetWindowPort(IntPtr windowRef);
|
||||
|
||||
#region --- Menus ---
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern IntPtr AcquireRootMenu();
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern bool IsWindowCollapsed(IntPtr windowRef);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public static extern OSStatus CollapseWindow(IntPtr windowRef, bool collapse);
|
||||
|
||||
|
@ -810,20 +678,17 @@ namespace OpenTK.Platform.MacOS {
|
|||
throw new MacOSException(error);
|
||||
}
|
||||
|
||||
[DllImport(carbon, EntryPoint="IsWindowInStandardState")]
|
||||
static extern bool _IsWindowInStandardState(IntPtr windowRef, IntPtr inIdealSize, IntPtr outIdealStandardState);
|
||||
|
||||
public static bool IsWindowInStandardState(IntPtr windowRef)
|
||||
{
|
||||
return _IsWindowInStandardState(windowRef, IntPtr.Zero, IntPtr.Zero);
|
||||
[DllImport(carbon)]
|
||||
static extern bool IsWindowInStandardState(IntPtr windowRef, IntPtr inIdealSize, IntPtr outIdealStandardState);
|
||||
public static bool IsWindowInStandardState(IntPtr windowRef) {
|
||||
return IsWindowInStandardState(windowRef, IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
|
||||
[DllImport(carbon)]
|
||||
public unsafe static extern OSStatus ZoomWindowIdeal(IntPtr windowRef, short inPartCode, ref CarbonPoint toIdealSize);
|
||||
public static extern OSStatus ZoomWindowIdeal(IntPtr windowRef, short inPartCode, ref CarbonPoint toIdealSize);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public unsafe static extern OSStatus DMGetGDeviceByDisplayID(
|
||||
IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
|
||||
public static extern OSStatus DMGetGDeviceByDisplayID(IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
|
||||
|
||||
[DllImport(carbon)]
|
||||
public unsafe static extern IntPtr HIGetMousePosition(HICoordinateSpace space, IntPtr obj, ref HIPoint point);
|
||||
|
|
|
@ -81,16 +81,11 @@ namespace OpenTK.Platform.MacOS {
|
|||
DisposeUPP();
|
||||
}
|
||||
|
||||
#region Private Members
|
||||
|
||||
void DisposeUPP()
|
||||
{
|
||||
if (uppHandler != IntPtr.Zero)
|
||||
{
|
||||
void DisposeUPP() {
|
||||
if (uppHandler != IntPtr.Zero) {
|
||||
//API.RemoveEventHandler(uppHandler);
|
||||
//API.DisposeEventHandlerUPP(uppHandler);
|
||||
}
|
||||
|
||||
uppHandler = IntPtr.Zero;
|
||||
}
|
||||
|
||||
|
@ -101,7 +96,10 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out windowRef);
|
||||
API.CheckReturn(err);
|
||||
Debug.Print("Created window " + windowRef.ToString());
|
||||
API.SetWindowTitle(windowRef, title);
|
||||
|
||||
IntPtr titleCF = CF.CFSTR(title);
|
||||
Debug.Print("Setting window title: {0}, CFstring : {1}, Text : {2}", windowRef, titleCF, title);
|
||||
API.SetWindowTitleWithCFString(windowRef, titleCF);
|
||||
|
||||
SetLocation(r.X, r.Y);
|
||||
SetSize(r.Width, r.Height);
|
||||
|
@ -114,10 +112,8 @@ namespace OpenTK.Platform.MacOS {
|
|||
Debug.Print("Attached window events.");
|
||||
}
|
||||
|
||||
void ConnectEvents()
|
||||
{
|
||||
EventTypeSpec[] eventTypes = new EventTypeSpec[]
|
||||
{
|
||||
void ConnectEvents() {
|
||||
EventTypeSpec[] eventTypes = new EventTypeSpec[] {
|
||||
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClose),
|
||||
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClosed),
|
||||
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowBoundsChanged),
|
||||
|
@ -159,26 +155,20 @@ namespace OpenTK.Platform.MacOS {
|
|||
|
||||
internal void UnsetFullscreen(AglContext context) {
|
||||
context.UnsetFullScreen(this);
|
||||
|
||||
Debug.Print("Telling Carbon to reset window state to " + windowState.ToString());
|
||||
|
||||
SetCarbonWindowState();
|
||||
|
||||
SetSize((short)windowedBounds.Width, (short)windowedBounds.Height);
|
||||
}
|
||||
|
||||
internal OSStatus DispatchEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
|
||||
{
|
||||
switch (evt.EventClass)
|
||||
{
|
||||
internal OSStatus DispatchEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
||||
switch (evt.EventClass) {
|
||||
case EventClass.Window:
|
||||
return ProcessWindowEvent(inCaller, inEvent, evt, userData);
|
||||
|
||||
case EventClass.Mouse:
|
||||
return ProcessMouseEvent(inCaller, inEvent, evt, userData);
|
||||
|
||||
case EventClass.Keyboard:
|
||||
return ProcessKeyboardEvent(inCaller, inEvent, evt, userData);
|
||||
|
||||
default:
|
||||
return OSStatus.EventNotHandled;
|
||||
}
|
||||
|
@ -192,15 +182,14 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
||||
MacOSKeyCode code = (MacOSKeyCode)0;
|
||||
char charCode = '\0';
|
||||
|
||||
//Debug.Print("Processing Keyboard event {0}", (KeyboardEventKind)evt.EventKind);
|
||||
|
||||
switch ((KeyboardEventKind)evt.EventKind)
|
||||
{
|
||||
switch ((KeyboardEventKind)evt.EventKind) {
|
||||
case KeyboardEventKind.RawKeyDown:
|
||||
case KeyboardEventKind.RawKeyRepeat:
|
||||
case KeyboardEventKind.RawKeyUp:
|
||||
GetCharCodes(inEvent, out code, out charCode);
|
||||
code = API.GetEventKeyboardKeyCode(inEvent);
|
||||
charCode = API.GetEventKeyboardChar(inEvent);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -210,8 +199,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
return OSStatus.NoError;
|
||||
}
|
||||
|
||||
switch ((KeyboardEventKind)evt.EventKind)
|
||||
{
|
||||
switch ((KeyboardEventKind)evt.EventKind) {
|
||||
case KeyboardEventKind.RawKeyRepeat:
|
||||
Keyboard.KeyRepeat = true;
|
||||
goto case KeyboardEventKind.RawKeyDown;
|
||||
|
@ -228,15 +216,12 @@ namespace OpenTK.Platform.MacOS {
|
|||
case KeyboardEventKind.RawKeyModifiersChanged:
|
||||
ProcessModifierKey(inEvent);
|
||||
return OSStatus.NoError;
|
||||
|
||||
default:
|
||||
return OSStatus.EventNotHandled;
|
||||
}
|
||||
return OSStatus.EventNotHandled;
|
||||
}
|
||||
|
||||
OSStatus ProcessWindowEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
||||
switch ((WindowEventKind)evt.EventKind)
|
||||
{
|
||||
switch ((WindowEventKind)evt.EventKind) {
|
||||
case WindowEventKind.WindowClose:
|
||||
RaiseClosing();
|
||||
return OSStatus.EventNotHandled;
|
||||
|
@ -247,28 +232,25 @@ namespace OpenTK.Platform.MacOS {
|
|||
return OSStatus.NoError;
|
||||
|
||||
case WindowEventKind.WindowBoundsChanged:
|
||||
int thisWidth = ClientRectangle.Width;
|
||||
int thisHeight = ClientRectangle.Height;
|
||||
int curWidth = ClientRectangle.Width;
|
||||
int curHeight = ClientRectangle.Height;
|
||||
LoadSize();
|
||||
|
||||
if (thisWidth != ClientRectangle.Width || thisHeight != ClientRectangle.Height)
|
||||
if (curWidth != ClientRectangle.Width || curHeight != ClientRectangle.Height)
|
||||
OnResize();
|
||||
|
||||
return OSStatus.EventNotHandled;
|
||||
|
||||
case WindowEventKind.WindowActivate:
|
||||
OnActivate();
|
||||
mIsActive = true;
|
||||
RaiseFocusedChanged();
|
||||
return OSStatus.EventNotHandled;
|
||||
|
||||
case WindowEventKind.WindowDeactivate:
|
||||
OnDeactivate();
|
||||
return OSStatus.EventNotHandled;
|
||||
|
||||
default:
|
||||
Debug.Print("{0}", evt);
|
||||
|
||||
mIsActive = false;
|
||||
RaiseFocusedChanged();
|
||||
return OSStatus.EventNotHandled;
|
||||
}
|
||||
return OSStatus.EventNotHandled;
|
||||
}
|
||||
|
||||
OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
||||
|
@ -277,70 +259,49 @@ namespace OpenTK.Platform.MacOS {
|
|||
HIPoint screenLoc = new HIPoint();
|
||||
|
||||
OSStatus err = API.GetEventMouseLocation(inEvent, out screenLoc);
|
||||
|
||||
if (this.windowState == WindowState.Fullscreen)
|
||||
{
|
||||
if (windowState == WindowState.Fullscreen) {
|
||||
pt = screenLoc;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
err = API.GetEventWindowMouseLocation(inEvent, out pt);
|
||||
}
|
||||
|
||||
if (err != OSStatus.NoError)
|
||||
{
|
||||
if (err != OSStatus.NoError) {
|
||||
// this error comes up from the application event handler.
|
||||
if (err != OSStatus.EventParameterNotFound)
|
||||
{
|
||||
if (err != OSStatus.EventParameterNotFound) {
|
||||
throw new MacOSException(err);
|
||||
}
|
||||
}
|
||||
|
||||
Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);
|
||||
if (this.windowState != WindowState.Fullscreen)
|
||||
{
|
||||
if (windowState != WindowState.Fullscreen) {
|
||||
mousePosInClient.Y -= mTitlebarHeight;
|
||||
}
|
||||
|
||||
switch ((MouseEventKind)evt.EventKind)
|
||||
{
|
||||
switch ((MouseEventKind)evt.EventKind) {
|
||||
case MouseEventKind.MouseDown:
|
||||
button = API.GetEventMouseButton(inEvent);
|
||||
|
||||
switch (button)
|
||||
{
|
||||
switch (button) {
|
||||
case MacOSMouseButton.Primary:
|
||||
Mouse.Set(MouseButton.Left, true);
|
||||
break;
|
||||
|
||||
Mouse.Set(MouseButton.Left, true); break;
|
||||
case MacOSMouseButton.Secondary:
|
||||
Mouse.Set(MouseButton.Right, true);
|
||||
break;
|
||||
|
||||
Mouse.Set(MouseButton.Right, true); break;
|
||||
case MacOSMouseButton.Tertiary:
|
||||
Mouse.Set(MouseButton.Middle, true);
|
||||
break;
|
||||
Mouse.Set(MouseButton.Middle, true); break;
|
||||
}
|
||||
return OSStatus.NoError;
|
||||
|
||||
case MouseEventKind.MouseUp:
|
||||
button = API.GetEventMouseButton(inEvent);
|
||||
|
||||
switch (button)
|
||||
{
|
||||
switch (button) {
|
||||
case MacOSMouseButton.Primary:
|
||||
Mouse.Set(MouseButton.Left, false);
|
||||
break;
|
||||
|
||||
Mouse.Set(MouseButton.Left, false); break;
|
||||
case MacOSMouseButton.Secondary:
|
||||
Mouse.Set(MouseButton.Right, false);
|
||||
break;
|
||||
|
||||
Mouse.Set(MouseButton.Right, false); break;
|
||||
case MacOSMouseButton.Tertiary:
|
||||
Mouse.Set(MouseButton.Middle, false);
|
||||
break;
|
||||
Mouse.Set(MouseButton.Middle, false); break;
|
||||
}
|
||||
button = API.GetEventMouseButton(inEvent);
|
||||
return OSStatus.NoError;
|
||||
|
||||
case MouseEventKind.WheelMoved:
|
||||
|
@ -366,21 +327,11 @@ namespace OpenTK.Platform.MacOS {
|
|||
}
|
||||
}
|
||||
return OSStatus.EventNotHandled;
|
||||
|
||||
default:
|
||||
Debug.Print("{0}", evt);
|
||||
return OSStatus.EventNotHandled;
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetCharCodes(IntPtr inEvent, out MacOSKeyCode code, out char charCode)
|
||||
{
|
||||
code = API.GetEventKeyboardKeyCode(inEvent);
|
||||
charCode = API.GetEventKeyboardChar(inEvent);
|
||||
return OSStatus.EventNotHandled;
|
||||
}
|
||||
|
||||
private void ProcessModifierKey(IntPtr inEvent)
|
||||
{
|
||||
void ProcessModifierKey(IntPtr inEvent) {
|
||||
MacOSKeyModifiers modifiers = API.GetEventKeyModifiers(inEvent);
|
||||
|
||||
bool caps = (modifiers & MacOSKeyModifiers.CapsLock) != 0;
|
||||
|
@ -402,20 +353,13 @@ namespace OpenTK.Platform.MacOS {
|
|||
Keyboard.KeyRepeat = repeat;
|
||||
}
|
||||
|
||||
Rect GetRegion() {
|
||||
return API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
|
||||
}
|
||||
|
||||
void SetLocation(short x, short y) {
|
||||
if (windowState == WindowState.Fullscreen)
|
||||
return;
|
||||
|
||||
if (windowState == WindowState.Fullscreen) return;
|
||||
API.MoveWindow(WinHandle, x, y, false);
|
||||
}
|
||||
|
||||
void SetSize(short width, short height) {
|
||||
if (WindowState == WindowState.Fullscreen)
|
||||
return;
|
||||
if (WindowState == WindowState.Fullscreen) return;
|
||||
|
||||
// The bounds of the window should be the size specified, but
|
||||
// API.SizeWindow sets the content region size. So
|
||||
|
@ -427,20 +371,17 @@ namespace OpenTK.Platform.MacOS {
|
|||
}
|
||||
|
||||
void SetClientSize(short width, short height) {
|
||||
if (WindowState == WindowState.Fullscreen)
|
||||
return;
|
||||
|
||||
if (WindowState == WindowState.Fullscreen) return;
|
||||
API.SizeWindow(WinHandle, width, height, true);
|
||||
}
|
||||
|
||||
protected void OnResize() {
|
||||
void OnResize() {
|
||||
LoadSize();
|
||||
RaiseResize();
|
||||
}
|
||||
|
||||
private void LoadSize() {
|
||||
if (WindowState == WindowState.Fullscreen)
|
||||
return;
|
||||
void LoadSize() {
|
||||
if (WindowState == WindowState.Fullscreen) return;
|
||||
|
||||
Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.StructureRegion);
|
||||
bounds = new Rectangle(r.X, r.Y, r.Width, r.Height);
|
||||
|
@ -449,12 +390,8 @@ namespace OpenTK.Platform.MacOS {
|
|||
clientRectangle = new Rectangle(0, 0, r.Width, r.Height);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region INativeWindow Members
|
||||
|
||||
IntPtr pbStr, utf16, utf8;
|
||||
public override string GetClipboardText() {
|
||||
public override string GetClipboardText() {
|
||||
IntPtr pbRef = GetPasteboard();
|
||||
API.PasteboardSynchronize(pbRef);
|
||||
|
||||
|
@ -527,8 +464,23 @@ namespace OpenTK.Platform.MacOS {
|
|||
return pbRef;
|
||||
}
|
||||
|
||||
// Processes events in the queue and then returns.
|
||||
public override void ProcessEvents() {
|
||||
API.ProcessEvents();
|
||||
IntPtr theEvent;
|
||||
IntPtr target = API.GetEventDispatcherTarget();
|
||||
|
||||
for (;;) {
|
||||
OSStatus status = API.ReceiveNextEvent(0, IntPtr.Zero, 0.0, true, out theEvent);
|
||||
if (status == OSStatus.EventLoopTimedOut) break;
|
||||
|
||||
if (status != OSStatus.NoError) {
|
||||
Debug.Print("Message Loop status: {0}", status); break;
|
||||
}
|
||||
if (theEvent == IntPtr.Zero) break;
|
||||
|
||||
API.SendEventToEventTarget(theEvent, target);
|
||||
API.ReleaseEvent(theEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public override Point PointToClient(Point point) {
|
||||
|
@ -550,8 +502,7 @@ namespace OpenTK.Platform.MacOS {
|
|||
set { SetIcon(value); }
|
||||
}
|
||||
|
||||
private unsafe void SetIcon(Icon icon)
|
||||
{
|
||||
unsafe void SetIcon(Icon icon) {
|
||||
// The code for this function was adapted from Mono's
|
||||
// XplatUICarbon implementation, written by Geoff Norton
|
||||
// http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs?view=markup&pathrev=136932
|
||||
|
@ -666,7 +617,6 @@ namespace OpenTK.Platform.MacOS {
|
|||
get {
|
||||
if (windowState == WindowState.Fullscreen)
|
||||
return WindowState.Fullscreen;
|
||||
|
||||
if (API.IsWindowCollapsed(WinHandle))
|
||||
return WindowState.Minimized;
|
||||
if (API.IsWindowInStandardState(WinHandle))
|
||||
|
@ -678,7 +628,6 @@ namespace OpenTK.Platform.MacOS {
|
|||
if (value == WindowState) return;
|
||||
Debug.Print("Switching window state from {0} to {1}", WindowState, value);
|
||||
WindowState oldState = WindowState;
|
||||
|
||||
windowState = value;
|
||||
|
||||
if (oldState == WindowState.Fullscreen) {
|
||||
|
@ -692,17 +641,15 @@ namespace OpenTK.Platform.MacOS {
|
|||
OSStatus err = API.CollapseWindow(WinHandle, false);
|
||||
API.CheckReturn(err);
|
||||
}
|
||||
|
||||
SetCarbonWindowState();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCarbonWindowState() {
|
||||
void SetCarbonWindowState() {
|
||||
CarbonPoint idealSize;
|
||||
OSStatus err;
|
||||
OSStatus result;
|
||||
|
||||
switch (windowState)
|
||||
{
|
||||
switch (windowState) {
|
||||
case WindowState.Fullscreen:
|
||||
goFullScreenHack = true;
|
||||
break;
|
||||
|
@ -712,46 +659,27 @@ namespace OpenTK.Platform.MacOS {
|
|||
// meaning they are maximized up to their reported ideal size. So we report a
|
||||
// large ideal size.
|
||||
idealSize = new CarbonPoint(9000, 9000);
|
||||
err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomOut, ref idealSize);
|
||||
API.CheckReturn(err);
|
||||
result = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomOut, ref idealSize);
|
||||
API.CheckReturn(result);
|
||||
break;
|
||||
|
||||
case WindowState.Normal:
|
||||
if (WindowState == WindowState.Maximized)
|
||||
{
|
||||
if (WindowState == WindowState.Maximized) {
|
||||
idealSize = new CarbonPoint();
|
||||
err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomIn, ref idealSize);
|
||||
API.CheckReturn(err);
|
||||
result = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomIn, ref idealSize);
|
||||
API.CheckReturn(result);
|
||||
}
|
||||
break;
|
||||
|
||||
case WindowState.Minimized:
|
||||
err = API.CollapseWindow(WinHandle, true);
|
||||
API.CheckReturn(err);
|
||||
result = API.CollapseWindow(WinHandle, true);
|
||||
API.CheckReturn(result);
|
||||
break;
|
||||
}
|
||||
|
||||
RaiseWindowStateChanged();
|
||||
OnResize();
|
||||
}
|
||||
|
||||
#region --- Event wrappers ---
|
||||
|
||||
private void OnActivate() {
|
||||
mIsActive = true;
|
||||
RaiseFocusedChanged();
|
||||
}
|
||||
|
||||
private void OnDeactivate() {
|
||||
mIsActive = false;
|
||||
RaiseFocusedChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IInputDriver Members
|
||||
|
||||
public override Point DesktopCursorPos {
|
||||
get {
|
||||
|
@ -780,7 +708,5 @@ namespace OpenTK.Platform.MacOS {
|
|||
CG.CGDisplayHideCursor(CG.CGMainDisplayID());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -24,11 +24,9 @@ namespace OpenTK.Platform.Windows {
|
|||
internal static extern bool SetWindowPos(IntPtr handle, IntPtr insertAfter, int x, int y, int cx, int cy, SetWindowPosFlags flags);
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
internal static extern bool AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu);
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
|
||||
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
internal static extern IntPtr CreateWindowEx(ExtendedWindowStyle ExStyle, IntPtr ClassAtom, IntPtr WindowName, WindowStyle Style,
|
||||
internal static extern IntPtr CreateWindowEx(int exStyle, IntPtr ClassAtom, IntPtr WindowName, WindowStyle Style,
|
||||
int X, int Y, int Width, int Height, IntPtr HandleToParentWindow, IntPtr Menu, IntPtr Instance, IntPtr Param);
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
internal static extern bool DestroyWindow(IntPtr windowHandle);
|
||||
|
@ -201,7 +199,7 @@ namespace OpenTK.Platform.Windows {
|
|||
internal byte StencilBits;
|
||||
internal byte AuxBuffers;
|
||||
internal byte LayerType;
|
||||
private byte Reserved;
|
||||
byte Reserved;
|
||||
internal int LayerMask;
|
||||
internal int VisibleMask;
|
||||
internal int DamageMask;
|
||||
|
@ -220,7 +218,7 @@ namespace OpenTK.Platform.Windows {
|
|||
internal string DeviceName;
|
||||
internal short SpecVersion;
|
||||
internal short DriverVersion;
|
||||
private short Size;
|
||||
short Size;
|
||||
internal short DriverExtra;
|
||||
internal int Fields;
|
||||
|
||||
|
@ -467,12 +465,6 @@ namespace OpenTK.Platform.Windows {
|
|||
PopupWindow = Popup | Border | SystemMenu,
|
||||
ChildWindow = Child
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum ExtendedWindowStyle : uint {
|
||||
WindowEdge = 0x00000100,
|
||||
ApplicationWindow = 0x00040000,
|
||||
}
|
||||
|
||||
internal enum GetWindowLongOffsets : int {
|
||||
STYLE = (-16),
|
||||
|
|
|
@ -34,7 +34,6 @@ using OpenTK.Input;
|
|||
|
||||
namespace OpenTK.Platform.Windows {
|
||||
public sealed class WinWindow : INativeWindow {
|
||||
const ExtendedWindowStyle ParentStyleEx = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow;
|
||||
readonly IntPtr Instance = Marshal.GetHINSTANCE(typeof(WinWindow).Module);
|
||||
readonly IntPtr ClassName = Marshal.StringToHGlobalAuto("CS_WindowClass");
|
||||
readonly WindowProcedure WindowProcedureDelegate;
|
||||
|
@ -330,12 +329,11 @@ namespace OpenTK.Platform.Windows {
|
|||
// The style of a parent window is different than that of a child window.
|
||||
// Note: the child window should always be visible, even if the parent isn't.
|
||||
WindowStyle style = WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
|
||||
ExtendedWindowStyle ex_style = ParentStyleEx;
|
||||
|
||||
// Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
|
||||
Win32Rectangle rect = new Win32Rectangle();
|
||||
rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
|
||||
API.AdjustWindowRectEx(ref rect, style, false, ex_style);
|
||||
API.AdjustWindowRect(ref rect, style, false);
|
||||
|
||||
// Create the window class that we will use for this window.
|
||||
// The current approach is to register a new class for each top-level WinGLWindow we create.
|
||||
|
@ -360,7 +358,7 @@ namespace OpenTK.Platform.Windows {
|
|||
|
||||
IntPtr window_name = Marshal.StringToHGlobalAuto(title);
|
||||
IntPtr handle = API.CreateWindowEx(
|
||||
ex_style, ClassName, window_name, style,
|
||||
0, ClassName, window_name, style,
|
||||
rect.left, rect.top, rect.Width, rect.Height,
|
||||
IntPtr.Zero, IntPtr.Zero, Instance, IntPtr.Zero);
|
||||
|
||||
|
@ -614,7 +612,7 @@ namespace OpenTK.Platform.Windows {
|
|||
|
||||
// Make sure client size doesn't change when changing the border style.
|
||||
Win32Rectangle rect = Win32Rectangle.From(bounds);
|
||||
API.AdjustWindowRectEx(ref rect, style, false, ParentStyleEx);
|
||||
API.AdjustWindowRect(ref rect, style, false);
|
||||
|
||||
// This avoids leaving garbage on the background window.
|
||||
if (was_visible)
|
||||
|
|
|
@ -80,24 +80,12 @@ void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat) {
|
|||
result->X = x; result->Y = y; result->Z = z;
|
||||
}
|
||||
|
||||
void Vector3_TransformX(Vector3* result, Real32 x, Matrix* mat) {
|
||||
result->X = x * mat->Row0.X + mat->Row3.X;
|
||||
result->Y = x * mat->Row0.Y + mat->Row3.Y;
|
||||
result->Z = x * mat->Row0.Z + mat->Row3.Z;
|
||||
}
|
||||
|
||||
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat) {
|
||||
result->X = y * mat->Row1.X + mat->Row3.X;
|
||||
result->Y = y * mat->Row1.Y + mat->Row3.Y;
|
||||
result->Z = y * mat->Row1.Z + mat->Row3.Z;
|
||||
}
|
||||
|
||||
void Vector3_TransformZ(Vector3* result, Real32 z, Matrix* mat) {
|
||||
result->X = z * mat->Row2.X + mat->Row3.X;
|
||||
result->Y = z * mat->Row2.Y + mat->Row3.Y;
|
||||
result->Z = z * mat->Row2.Z + mat->Row3.Z;
|
||||
}
|
||||
|
||||
Vector3 Vector3_RotateX(Vector3 v, Real32 angle) {
|
||||
Real32 cosA = Math_CosF(angle), sinA = Math_SinF(angle);
|
||||
return Vector3_Create3(v.X, cosA * v.Y + sinA * v.Z, -sinA * v.Y + cosA * v.Z);
|
||||
|
|
|
@ -45,9 +45,7 @@ void Vector3_Cross(Vector3* result, Vector3* a, Vector3* b);
|
|||
void Vector3_Normalize(Vector3* result, Vector3* a);
|
||||
|
||||
void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat);
|
||||
void Vector3_TransformX(Vector3* result, Real32 x, Matrix* mat);
|
||||
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat);
|
||||
void Vector3_TransformZ(Vector3* result, Real32 z, Matrix* mat);
|
||||
|
||||
Vector3 Vector3_RotateX(Vector3 v, Real32 angle);
|
||||
Vector3 Vector3_RotateY(Vector3 v, Real32 angle);
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <Windows.h>
|
||||
|
||||
#define win_Style WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
|
||||
#define win_StyleEx WS_EX_WINDOWEDGE | WS_EX_APPWINDOW
|
||||
#define win_ClassName "ClassiCube_Window"
|
||||
#define RECT_WIDTH(rect) (rect.right - rect.left)
|
||||
#define RECT_HEIGHT(rect) (rect.bottom - rect.top)
|
||||
|
@ -72,7 +71,7 @@ static void Window_DoSetHiddenBorder(bool value) {
|
|||
rect.left = win_Bounds.X; rect.top = win_Bounds.Y;
|
||||
rect.right = rect.left + win_Bounds.Width;
|
||||
rect.bottom = rect.top + win_Bounds.Height;
|
||||
AdjustWindowRectEx(&rect, style, false, win_StyleEx);
|
||||
AdjustWindowRect(&rect, style, false);
|
||||
|
||||
/* This avoids leaving garbage on the background window. */
|
||||
if (was_visible) Window_SetVisible(false);
|
||||
|
@ -403,7 +402,7 @@ void Window_Create(Int32 x, Int32 y, Int32 width, Int32 height, STRING_REF Strin
|
|||
|
||||
/* Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). */
|
||||
RECT rect; rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
|
||||
AdjustWindowRectEx(&rect, win_Style, false, win_StyleEx);
|
||||
AdjustWindowRect(&rect, win_Style, false);
|
||||
|
||||
WNDCLASSEXA wc = { 0 };
|
||||
wc.cbSize = sizeof(WNDCLASSEXA);
|
||||
|
@ -419,7 +418,7 @@ void Window_Create(Int32 x, Int32 y, Int32 width, Int32 height, STRING_REF Strin
|
|||
ErrorHandler_FailWithCode(GetLastError(), "Failed to register window class");
|
||||
}
|
||||
win_Handle = CreateWindowExA(
|
||||
win_StyleEx, atom, title->buffer, win_Style,
|
||||
0, atom, title->buffer, win_Style,
|
||||
rect.left, rect.top, RECT_WIDTH(rect), RECT_HEIGHT(rect),
|
||||
NULL, NULL, win_Instance, NULL);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue