/// <summary> /// Creates an orthographic projection matrix. /// </summary> /// <param name="left">The left edge of the projection volume.</param> /// <param name="right">The right edge of the projection volume.</param> /// <param name="bottom">The bottom edge of the projection volume.</param> /// <param name="top">The top edge of the projection volume.</param> /// <param name="zNear">The near edge of the projection volume.</param> /// <param name="zFar">The far edge of the projection volume.</param> /// <param name="result">The resulting SCNMatrix4 instance.</param> public static void CreateOrthographicOffCenter(pfloat left, pfloat right, pfloat bottom, pfloat top, pfloat zNear, pfloat zFar, out SCNMatrix4 result) { result = new SCNMatrix4(); pfloat invRL = 1 / (right - left); pfloat invTB = 1 / (top - bottom); pfloat invFN = 1 / (zFar - zNear); result.M11 = 2 * invRL; result.M22 = 2 * invTB; result.M33 = -2 * invFN; result.M41 = -(right + left) * invRL; result.M42 = -(top + bottom) * invTB; result.M43 = -(zFar + zNear) * invFN; result.M44 = 1; }
public static UIColor InterpolateTextColor(UIColor a, UIColor b, float linearInterpolation) { System.nfloat[] colorsA = new System.nfloat[4]; System.nfloat[] colorsB = new System.nfloat[4]; a.GetRGBA(out colorsA [0], out colorsA [1], out colorsA [2], out colorsA [3]); b.GetRGBA(out colorsB [0], out colorsB [1], out colorsB [2], out colorsB [3]); UIColor finalColor = new UIColor( (colorsA[0] + (linearInterpolation * (colorsB[0] - colorsA[0]))), (colorsA[1] + (linearInterpolation * (colorsB[1] - colorsA[1]))), (colorsA[2] + (linearInterpolation * (colorsB[2] - colorsA[2]))), (colorsA[3] + (linearInterpolation * (colorsB[3] - colorsA[3]))) ); return(finalColor); }
protected override void OnElementChanged(ElementChangedEventArgs <Label> e) { base.OnElementChanged(e); if (Control != null && Element != null && !string.IsNullOrWhiteSpace(Element.Text)) { var attr = new NSAttributedStringDocumentAttributes(); var nsError = new NSError(); attr.DocumentType = NSDocumentType.HTML; //var myHtmlData = NSData.FromString(Element.Text, NSStringEncoding.Unicode); UIKit.UIFont font = Control.Font; string fontName = font.Name; System.nfloat fontSize = font.PointSize; string htmlContents = "<span style=\"font-family: '" + fontName + "'; font-size: " + fontSize + "\">" + Element.Text + "</span>"; var myHtmlData = NSData.FromString(htmlContents, NSStringEncoding.Unicode); Control.Lines = 0; Control.AttributedText = new NSAttributedString(myHtmlData, attr, ref nsError); } }
private void ScrollTheView(bool move) {//Scroll view up or down UIView.BeginAnimations(string.Empty, System.IntPtr.Zero); UIView.SetAnimationDuration(0.3); CGRect frame = View.Frame; if (move) { frame.Y -= scroll_amount; } else { frame.Y += scroll_amount; scroll_amount = 0; } View.Frame = frame; UIView.CommitAnimations(); }
private void ScrollTheView(bool move) {//Scroll view up or down UIView.BeginAnimations(string.Empty, System.IntPtr.Zero); UIView.SetAnimationDuration(0.3); CGRect frame = View.Frame; if (move) { frame.Y = -100.0f; //Move view down } else { frame.Y = 0.0f; //Reset view back to original position scroll_amount = 0; } View.Frame = frame; UIView.CommitAnimations(); }
} //Constructor private void KeyBoardUpNotification(NSNotification notification) {//Moves the screen up, when the keyboard shows //Getting the keyboards size var val = (NSValue)notification.UserInfo.ValueForKey(UIKeyboard.FrameEndUserInfoKey); CGRect r = val.CGRectValue; // Find what view opened the keyboard and assign it to activeview foreach (UIView view in this.View.Subviews) { if (view.IsFirstResponder) { activeview = view; } } // Bottom of the controller = initial position + height + offset if (activeview == null) { bottom = offset; } else { bottom = (activeview.Frame.Y + activeview.Frame.Height + offset); } // Calculate how far we need to scroll scroll_amount = (r.Height - (View.Frame.Size.Height - bottom)); // Perform the scrolling if (scroll_amount > 0) { moveViewUp = true; ScrollTheView(moveViewUp); } else { moveViewUp = false; } }
/// <summary> /// Build a world space to camera space matrix /// </summary> /// <param name="eyeX">Eye (camera) position in world space</param> /// <param name="eyeY">Eye (camera) position in world space</param> /// <param name="eyeZ">Eye (camera) position in world space</param> /// <param name="targetX">Target position in world space</param> /// <param name="targetY">Target position in world space</param> /// <param name="targetZ">Target position in world space</param> /// <param name="upX">Up vector in world space (should not be parallel to the camera direction, that is target - eye)</param> /// <param name="upY">Up vector in world space (should not be parallel to the camera direction, that is target - eye)</param> /// <param name="upZ">Up vector in world space (should not be parallel to the camera direction, that is target - eye)</param> /// <returns>A SCNMatrix4 that transforms world space to camera space</returns> public static SCNMatrix4 LookAt(pfloat eyeX, pfloat eyeY, pfloat eyeZ, pfloat targetX, pfloat targetY, pfloat targetZ, pfloat upX, pfloat upY, pfloat upZ) { return(LookAt(new SCNVector3(eyeX, eyeY, eyeZ), new SCNVector3(targetX, targetY, targetZ), new SCNVector3(upX, upY, upZ))); }
/// <summary> /// Creates an perspective projection matrix. /// </summary> /// <param name="left">Left edge of the view frustum</param> /// <param name="right">Right edge of the view frustum</param> /// <param name="bottom">Bottom edge of the view frustum</param> /// <param name="top">Top edge of the view frustum</param> /// <param name="zNear">Distance to the near clip plane</param> /// <param name="zFar">Distance to the far clip plane</param> /// <returns>A projection matrix that transforms camera space to raster space</returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown under the following conditions: /// <list type="bullet"> /// <item>zNear is negative or zero</item> /// <item>zFar is negative or zero</item> /// <item>zNear is larger than zFar</item> /// </list> /// </exception> public static SCNMatrix4 CreatePerspectiveOffCenter(pfloat left, pfloat right, pfloat bottom, pfloat top, pfloat zNear, pfloat zFar) { SCNMatrix4 result; CreatePerspectiveOffCenter(left, right, bottom, top, zNear, zFar, out result); return(result); }
/// <summary> /// Creates a perspective projection matrix. /// </summary> /// <param name="fovy">Angle of the field of view in the y direction (in radians)</param> /// <param name="aspect">Aspect ratio of the view (width / height)</param> /// <param name="zNear">Distance to the near clip plane</param> /// <param name="zFar">Distance to the far clip plane</param> /// <returns>A projection matrix that transforms camera space to raster space</returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown under the following conditions: /// <list type="bullet"> /// <item>fovy is zero, less than zero or larger than Math.PI</item> /// <item>aspect is negative or zero</item> /// <item>zNear is negative or zero</item> /// <item>zFar is negative or zero</item> /// <item>zNear is larger than zFar</item> /// </list> /// </exception> public static SCNMatrix4 CreatePerspectiveFieldOfView(pfloat fovy, pfloat aspect, pfloat zNear, pfloat zFar) { SCNMatrix4 result; CreatePerspectiveFieldOfView(fovy, aspect, zNear, zFar, out result); return(result); }
/// <summary> /// Creates an orthographic projection matrix. /// </summary> /// <param name="width">The width of the projection volume.</param> /// <param name="height">The height of the projection volume.</param> /// <param name="zNear">The near edge of the projection volume.</param> /// <param name="zFar">The far edge of the projection volume.</param> /// <param name="result">The resulting SCNMatrix4 instance.</param> public static void CreateOrthographic(pfloat width, pfloat height, pfloat zNear, pfloat zFar, out SCNMatrix4 result) { CreateOrthographicOffCenter(-width / 2, width / 2, -height / 2, height / 2, zNear, zFar, out result); }
public System.nfloat ConstrainSplitPosition(AppKit.NSSplitView splitView, System.nfloat proposedPosition, System.nint subviewDividerIndex) { return(250); //return NMath.Max (proposedPosition, 150); }
public static void Multiply(ref SCNVector3 vector, pfloat scale, out SCNVector3 result) { result = new SCNVector3(vector.X * scale, vector.Y * scale, vector.Z * scale); }
public static SCNVector3 Multiply(SCNVector3 vector, pfloat scale) { Multiply(ref vector, scale, out vector); return(vector); }
public SCNVector3(SCNVector4 v) { X = v.X; Y = v.Y; Z = v.Z; }
public System.nfloat ConstrainSplitPosition(AppKit.NSSplitView splitView, System.nfloat proposedPosition, System.nint subviewDividerIndex) { return(NMath.Min(MaxSideBarWidth, NMath.Max(proposedPosition, MinSideBarWidth))); }
public SCNVector3(Vector3 v) { X = v.X; Y = v.Y; Z = v.Z; }
public static void CalculateAngle(ref SCNVector3 first, ref SCNVector3 second, out pfloat result) { pfloat temp; SCNVector3.Dot(ref first, ref second, out temp); result = (pfloat)System.Math.Acos(temp / (first.Length * second.Length)); }
public static SCNVector3 Divide(SCNVector3 vector, pfloat scale) { Divide(ref vector, scale, out vector); return(vector); }
/// <summary> /// Creates a translation matrix. /// </summary> /// <param name="x">X translation.</param> /// <param name="y">Y translation.</param> /// <param name="z">Z translation.</param> /// <param name="result">The resulting SCNMatrix4 instance.</param> public static void CreateTranslation(pfloat x, pfloat y, pfloat z, out SCNMatrix4 result) { result = Identity; result.Row3 = new SCNVector4(x, y, z, 1); }
public static void Divide(ref SCNVector3 vector, pfloat scale, out SCNVector3 result) { Multiply(ref vector, 1 / scale, out result); }
/// <summary> /// Creates an orthographic projection matrix. /// </summary> /// <param name="width">The width of the projection volume.</param> /// <param name="height">The height of the projection volume.</param> /// <param name="zNear">The near edge of the projection volume.</param> /// <param name="zFar">The far edge of the projection volume.</param> /// <rereturns>The resulting SCNMatrix4 instance.</rereturns> public static SCNMatrix4 CreateOrthographic(pfloat width, pfloat height, pfloat zNear, pfloat zFar) { SCNMatrix4 result; CreateOrthographicOffCenter(-width / 2, width / 2, -height / 2, height / 2, zNear, zFar, out result); return(result); }
public static void Dot(ref SCNVector3 left, ref SCNVector3 right, out pfloat result) { result = left.X * right.X + left.Y * right.Y + left.Z * right.Z; }
/// <summary> /// Creates a perspective projection matrix. /// </summary> /// <param name="fovy">Angle of the field of view in the y direction (in radians)</param> /// <param name="aspect">Aspect ratio of the view (width / height)</param> /// <param name="zNear">Distance to the near clip plane</param> /// <param name="zFar">Distance to the far clip plane</param> /// <param name="result">A projection matrix that transforms camera space to raster space</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown under the following conditions: /// <list type="bullet"> /// <item>fovy is zero, less than zero or larger than Math.PI</item> /// <item>aspect is negative or zero</item> /// <item>zNear is negative or zero</item> /// <item>zFar is negative or zero</item> /// <item>zNear is larger than zFar</item> /// </list> /// </exception> public static void CreatePerspectiveFieldOfView(pfloat fovy, pfloat aspect, pfloat zNear, pfloat zFar, out SCNMatrix4 result) { if (fovy <= 0 || fovy > Math.PI) { throw new ArgumentOutOfRangeException("fovy"); } if (aspect <= 0) { throw new ArgumentOutOfRangeException("aspect"); } if (zNear <= 0) { throw new ArgumentOutOfRangeException("zNear"); } if (zFar <= 0) { throw new ArgumentOutOfRangeException("zFar"); } if (zNear >= zFar) { throw new ArgumentOutOfRangeException("zNear"); } pfloat yMax = zNear * (float)System.Math.Tan(0.5f * fovy); pfloat yMin = -yMax; pfloat xMin = yMin * aspect; pfloat xMax = yMax * aspect; CreatePerspectiveOffCenter(xMin, xMax, yMin, yMax, zNear, zFar, out result); }
public static void Lerp(ref SCNVector3 a, ref SCNVector3 b, pfloat blend, out SCNVector3 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; }
/// <summary> /// Creates an perspective projection matrix. /// </summary> /// <param name="left">Left edge of the view frustum</param> /// <param name="right">Right edge of the view frustum</param> /// <param name="bottom">Bottom edge of the view frustum</param> /// <param name="top">Top edge of the view frustum</param> /// <param name="zNear">Distance to the near clip plane</param> /// <param name="zFar">Distance to the far clip plane</param> /// <param name="result">A projection matrix that transforms camera space to raster space</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown under the following conditions: /// <list type="bullet"> /// <item>zNear is negative or zero</item> /// <item>zFar is negative or zero</item> /// <item>zNear is larger than zFar</item> /// </list> /// </exception> public static void CreatePerspectiveOffCenter(pfloat left, pfloat right, pfloat bottom, pfloat top, pfloat zNear, pfloat zFar, out SCNMatrix4 result) { if (zNear <= 0) { throw new ArgumentOutOfRangeException("zNear"); } if (zFar <= 0) { throw new ArgumentOutOfRangeException("zFar"); } if (zNear >= zFar) { throw new ArgumentOutOfRangeException("zNear"); } pfloat x = (2.0f * zNear) / (right - left); pfloat y = (2.0f * zNear) / (top - bottom); pfloat a = (right + left) / (right - left); pfloat b = (top + bottom) / (top - bottom); pfloat c = -(zFar + zNear) / (zFar - zNear); pfloat d = -(2.0f * zFar * zNear) / (zFar - zNear); result = new SCNMatrix4(x, 0, 0, 0, 0, y, 0, 0, a, b, c, -1, 0, 0, d, 0); }
public static SCNVector3 BaryCentric(SCNVector3 a, SCNVector3 b, SCNVector3 c, pfloat u, pfloat v) { return(a + u * (b - a) + v * (c - a)); }
/// <summary> /// Build a scaling matrix /// </summary> /// <param name="scale">Single scale factor for x,y and z axes</param> /// <returns>A scaling matrix</returns> public static SCNMatrix4 Scale(pfloat scale) { return(Scale(scale, scale, scale)); }
public static void BaryCentric(ref SCNVector3 a, ref SCNVector3 b, ref SCNVector3 c, pfloat u, pfloat v, out SCNVector3 result) { result = a; // copy SCNVector3 temp = b; // copy Subtract(ref temp, ref a, out temp); Multiply(ref temp, u, out temp); Add(ref result, ref temp, out result); temp = c; // copy Subtract(ref temp, ref a, out temp); Multiply(ref temp, v, out temp); Add(ref result, ref temp, out result); }
/// <summary> /// Calculate the inverse of the given matrix /// </summary> /// <param name="mat">The matrix to invert</param> /// <returns>The inverse of the given matrix if it has one, or the input if it is singular</returns> /// <exception cref="InvalidOperationException">Thrown if the SCNMatrix4 is singular.</exception> public static SCNMatrix4 Invert(SCNMatrix4 mat) { int[] colIdx = { 0, 0, 0, 0 }; int[] rowIdx = { 0, 0, 0, 0 }; int[] pivotIdx = { -1, -1, -1, -1 }; // convert the matrix to an array for easy looping pfloat[,] inverse = { { mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W }, { mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W }, { mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W }, { mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W } }; int icol = 0; int irow = 0; for (int i = 0; i < 4; i++) { // Find the largest pivot value pfloat maxPivot = 0.0f; for (int j = 0; j < 4; j++) { if (pivotIdx[j] != 0) { for (int k = 0; k < 4; ++k) { if (pivotIdx[k] == -1) { pfloat absVal = (pfloat)System.Math.Abs(inverse[j, k]); if (absVal > maxPivot) { maxPivot = absVal; irow = j; icol = k; } } else if (pivotIdx[k] > 0) { return(mat); } } } } ++(pivotIdx[icol]); // Swap rows over so pivot is on diagonal if (irow != icol) { for (int k = 0; k < 4; ++k) { pfloat f = inverse[irow, k]; inverse[irow, k] = inverse[icol, k]; inverse[icol, k] = f; } } rowIdx[i] = irow; colIdx[i] = icol; pfloat pivot = inverse[icol, icol]; // check for singular matrix if (pivot == 0.0f) { throw new InvalidOperationException("Matrix is singular and cannot be inverted."); //return mat; } // Scale row so it has a unit diagonal pfloat oneOverPivot = 1.0f / pivot; inverse[icol, icol] = 1.0f; for (int k = 0; k < 4; ++k) { inverse[icol, k] *= oneOverPivot; } // Do elimination of non-diagonal elements for (int j = 0; j < 4; ++j) { // check this isn't on the diagonal if (icol != j) { pfloat f = inverse[j, icol]; inverse[j, icol] = 0.0f; for (int k = 0; k < 4; ++k) { inverse[j, k] -= inverse[icol, k] * f; } } } } for (int j = 3; j >= 0; --j) { int ir = rowIdx[j]; int ic = colIdx[j]; for (int k = 0; k < 4; ++k) { pfloat f = inverse[k, ir]; inverse[k, ir] = inverse[k, ic]; inverse[k, ic] = f; } } mat.Row0 = new SCNVector4(inverse[0, 0], inverse[0, 1], inverse[0, 2], inverse[0, 3]); mat.Row1 = new SCNVector4(inverse[1, 0], inverse[1, 1], inverse[1, 2], inverse[1, 3]); mat.Row2 = new SCNVector4(inverse[2, 0], inverse[2, 1], inverse[2, 2], inverse[2, 3]); mat.Row3 = new SCNVector4(inverse[3, 0], inverse[3, 1], inverse[3, 2], inverse[3, 3]); return(mat); }
public SCNVector3(pfloat x, pfloat y, pfloat z) { X = x; Y = y; Z = z; }