private static bool Project(ref Vector3d world, ref Matrix4d modelviewMatrix, ref Matrix4d projectionMatrix, int[] viewport, out Vector3d screen) { Vector4d _in = new Vector4d(world, 1.0); Vector4d _out = new Vector4d(); Vector4d.Transform(ref _in, ref modelviewMatrix, out _out); Vector4d.Transform(ref _out, ref projectionMatrix, out _in); if (_in.W == 0.0) { screen = Vector3d.Zero; return false; } _in.X /= _in.W; _in.Y /= _in.W; _in.Z /= _in.W; /* Map x, y and z to range 0-1 */ _in.X = _in.X * 0.5 + 0.5; _in.Y = _in.Y * 0.5 + 0.5; _in.Z = _in.Z * 0.5 + 0.5; /* Map x,y to viewport */ _in.X = _in.X * viewport[2] + viewport[0]; _in.Y = _in.Y * viewport[3] + viewport[1]; screen = new Vector3d(_in); return true; }
public static Frustum.VISIBILTY GetVisibility(Vector4d clip, Vector3d2[] b, double f) { double o = b[0].x * clip.x + b[0].y * clip.y + b[0].z * clip.z; bool p = o + clip.w > 0.0; if ((o * f + clip.w > 0.0) == p) { o = b[1].x * clip.x + b[1].y * clip.y + b[1].z * clip.z; if ((o + clip.w > 0.0) == p && (o * f + clip.w > 0.0) == p) { o = b[2].x * clip.x + b[2].y * clip.y + b[2].z * clip.z; if ((o + clip.w > 0.0) == p && (o * f + clip.w > 0.0) == p) { o = b[3].x * clip.x + b[3].y * clip.y + b[3].z * clip.z; return (o + clip.w > 0.0) == p && (o * f + clip.w > 0.0) == p ? (p ? Frustum.VISIBILTY.FULLY : Frustum.VISIBILTY.INVISIBLE) : Frustum.VISIBILTY.PARTIALLY; } } } return Frustum.VISIBILTY.PARTIALLY; }
public bool LocationToView(Location location, out PointF point) { // Move location to 3D earth var pos3d = new Vector4d (location.Position, 1); // Camera model var m = Matrix4d.Mult (modelViewMatrix, projectionMatrix); // Project into homogeneous 2D point var pos2h = Vector4d.Transform (pos3d, m); // Perform the perspective divide var pos2 = pos2h / pos2h.W; // Ignore points behind us if (pos2h.W < 0) { point = PointF.Empty; return false; } // Console.WriteLine ("{0} = {1}", "W", pos2h.W); // Stretch into our view var fr = videoCameraView.Frame; point = new PointF ( fr.X + (float)((pos2.X + 1) * 0.5) * fr.Width, fr.Y + (float)((-pos2.Y + 1) * 0.5) * fr.Height ); return true; }
public Vector4d(Vector4d v) { x = v.x; y = v.y; z = v.z; w = v.w; }
public List<KeyValuePair<string, string>> GetOpenGLPNameInfo() { List<KeyValuePair<string, string>> info = new List<KeyValuePair<string, string>>(); foreach (GetPName pname in Enum.GetValues(typeof(GetPName))) { double[] buff = new double[32]; GL.GetDouble(pname, buff); int last = 0; for (int i = 0; i < 32; i++) { if (buff[i] != 0.0) { last = i + 1; } } string str = null; switch (last) { case 0: str = "0"; break; case 1: str = buff[0].ToString(); break; case 2: Vector2d v2 = new Vector2d(buff[0], buff[1]); str = v2.ToString(); break; case 3: Vector3d v3 = new Vector3d(buff[0], buff[1], buff[2]); str = v3.ToString(); break; case 4: Vector4d v4 = new Vector4d(buff[0], buff[1], buff[2], buff[3]); str = v4.ToString(); break; case 16: Matrix4d m4 = new Matrix4d(buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6], buff[7], buff[8], buff[9], buff[10], buff[11], buff[12], buff[13], buff[14], buff[15]); str = m4.ToString(); break; default: StringBuilder sb = new StringBuilder(); for (int i = 0; i < last; i++) { sb.Append(buff[i]); sb.Append(','); } str = sb.ToString(); break; } info.Add(new KeyValuePair<string, string>(pname.ToString(), str)); } return info; }
// https://gist.github.com/871099/8d37734ba22737c69173c2e44eaa332f9c85bcde // http://www.opentk.com/node/1892 // http://www.opentk.com/node/1276 // http://www.opentk.com/node/887 // http://mesa3d.org/ /// <summary> /// Projects a coordinate from world space into screen space. /// </summary> /// <param name="coordinate">The coordinate to project</param> /// <param name="viewport">The viewport dimensions</param> /// <param name="projection">The projection matrix</param> /// <param name="modelview">The modelview matrix</param> /// <returns>The coordinate in screen space.</returns> public static Coordinate Project(Coordinate coordinate, int[] viewport, Matrix4d projection, Matrix4d modelview) { var source = new Vector4d(coordinate.DX, coordinate.DY, coordinate.DZ, 1); var imed = Vector4d.Transform(source, modelview); var vector = Vector4d.Transform(imed, projection); if (Math.Abs(vector.W - 0) < 0.00001) return null; var result = Vector3d.Divide(vector.Xyz, vector.W); result.X = viewport[0] + viewport[2] * (result.X + 1) / 2; result.Y = viewport[1] + viewport[3] * (result.Y + 1) / 2; result.Z = (result.Z + 1) / 2; return new Coordinate((decimal) result.X, (decimal) result.Y, (decimal) result.Z); }
public void Draw(TriMesh front, TriMesh back, Vector3D light) { Vector4d light4d = new Vector4d(light.x, light.y, light.z, 0); Vector3D frontPos = new Vector3D(0.5, 0.5, 0.8); Vector3D backPos = new Vector3D(0, 0, 0); GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); GL.Light(LightName.Light0, LightParameter.Diffuse, Color.White); GL.Light(LightName.Light0, LightParameter.Position, (Vector4)light4d); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Clear(ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.StencilTest); GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace); GL.StencilFunc(StencilFunction.Always, 1, 1); GL.Clear(ClearBufferMask.StencilBufferBit); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); Matrix4d m = Matrix4d.LookAt(light4d.Xyz, Vector3d.Zero, Vector3d.UnitY); GL.MultMatrix(ref m); GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, Color.Red); GL.ColorMask(false, false, false, false); DrawMesh(front, frontPos); GL.ColorMask(true, true, true, true); GL.PopMatrix(); GL.StencilFunc(StencilFunction.Equal, 1, 1); GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, Color.Black); DrawMesh(back, backPos); GL.StencilFunc(StencilFunction.Equal, 0, 1); GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, Color.CornflowerBlue); DrawMesh(back, backPos); GL.Disable(EnableCap.StencilTest); GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, Color.CornflowerBlue); DrawMesh(front, frontPos); GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, Color.Red); DrawMesh(this.sphere, light); GL.Disable(EnableCap.DepthTest); }
/// <summary> /// Converts a screen space point into a corresponding point in world space. /// </summary> /// <param name="coordinate">The coordinate to project</param> /// <param name="viewport">The viewport dimensions</param> /// <param name="projection">The projection matrix</param> /// <param name="modelview">The modelview matrix</param> /// <returns>The coordinate in world space.</returns> public static Coordinate Unproject(Coordinate coordinate, int[] viewport, Matrix4d projection, Matrix4d modelview) { var matrix = Matrix4d.Invert(Matrix4d.Mult(modelview, projection)); var source = new Vector4d( (coordinate.DX - viewport[0]) * 2 / viewport[2] - 1, (coordinate.DY - viewport[1]) * 2 / viewport[3] - 1, 2 * coordinate.DZ - 1, 1); var vector = Vector4d.Transform(source, matrix); if (Math.Abs(vector.W - 0) < 0.00001) return null; var result = Vector3d.Divide(vector.Xyz, vector.W); return new Coordinate((decimal) result.X, (decimal) result.Y, (decimal) result.Z); }
public List<ChunkedLodTreeFactory.ChunkedLodTreeNode> Calculate( ChunkedLodTreeFactory.ChunkedLodTreeNode root, double viewportWidth, double horizontalFieldOfView, Vector3d cameraPosition, double allowedScreenSpaceError, Vector4d[] frustumPlanes) { _frustumPlanes = frustumPlanes; _allowedScreenSpaceError = allowedScreenSpaceError; _cameraPosition = cameraPosition; _visibleNodes = new List<ChunkedLodTreeFactory.ChunkedLodTreeNode>(); _k = viewportWidth / (Math.Tan(horizontalFieldOfView / 2)); CalculateVisibleNodes(root); return _visibleNodes; }
static public Vector4d[] GetFrustumPlanes(Matrix4x4d mat) { //extract frustum planes from a projection matrix Vector4d[] frustumPlanes = new Vector4d[6]; // Extract the LEFT plane frustumPlanes[0] = new Vector4d(); frustumPlanes[0].x = mat.m[3,0] + mat.m[0,0]; frustumPlanes[0].y = mat.m[3,1] + mat.m[0,1]; frustumPlanes[0].z = mat.m[3,2] + mat.m[0,2]; frustumPlanes[0].w = mat.m[3,3] + mat.m[0,3]; // Extract the RIGHT plane frustumPlanes[1] = new Vector4d(); frustumPlanes[1].x = mat.m[3,0] - mat.m[0,0]; frustumPlanes[1].y = mat.m[3,1] - mat.m[0,1]; frustumPlanes[1].z = mat.m[3,2] - mat.m[0,2]; frustumPlanes[1].w = mat.m[3,3] - mat.m[0,3]; // Extract the BOTTOM plane frustumPlanes[2] = new Vector4d(); frustumPlanes[2].x = mat.m[3,0] + mat.m[1,0]; frustumPlanes[2].y = mat.m[3,1] + mat.m[1,1]; frustumPlanes[2].z = mat.m[3,2] + mat.m[1,2]; frustumPlanes[2].w = mat.m[3,3] + mat.m[1,3]; // Extract the TOP plane frustumPlanes[3] = new Vector4d(); frustumPlanes[3].x = mat.m[3,0] - mat.m[1,0]; frustumPlanes[3].y = mat.m[3,1] - mat.m[1,1]; frustumPlanes[3].z = mat.m[3,2] - mat.m[1,2]; frustumPlanes[3].w = mat.m[3,3] - mat.m[1,3]; // Extract the NEAR plane frustumPlanes[4] = new Vector4d(); frustumPlanes[4].x = mat.m[3,0] + mat.m[2,0]; frustumPlanes[4].y = mat.m[3,1] + mat.m[2,1]; frustumPlanes[4].z = mat.m[3,2] + mat.m[2,2]; frustumPlanes[4].w = mat.m[3,3] + mat.m[2,3]; // Extract the FAR plane frustumPlanes[5] = new Vector4d(); frustumPlanes[5].x = mat.m[3,0] - mat.m[2,0]; frustumPlanes[5].y = mat.m[3,1] - mat.m[2,1]; frustumPlanes[5].z = mat.m[3,2] - mat.m[2,2]; frustumPlanes[5].w = mat.m[3,3] - mat.m[2,3]; return frustumPlanes; }
public static void TestVector4Constructor() { Vector4d v0 = new Vector4d(); v0.x.ShouldBe(0); v0.y.ShouldBe(0); v0.z.ShouldBe(0); v0.w.ShouldBe(0); Vector4d v1 = new Vector4d(5); v1.x.ShouldBe(5); v1.y.ShouldBe(0); v1.z.ShouldBe(0); v1.w.ShouldBe(0); Vector4d v2 = new Vector4d(5, 6); v2.x.ShouldBe(5); v2.y.ShouldBe(6); v2.z.ShouldBe(0); v2.w.ShouldBe(0); Vector4d v3 = new Vector4d(5, 6, 7); v3.x.ShouldBe(5); v3.y.ShouldBe(6); v3.z.ShouldBe(7); v3.w.ShouldBe(0); Vector4d v4 = new Vector4d(5, 6, 7, 8); v4.x.ShouldBe(5); v4.y.ShouldBe(6); v4.z.ShouldBe(7); v4.w.ShouldBe(8); Vector4d v5 = new Vector4d(5, 6, 7, 8, 9); v5.x.ShouldBe(5); v5.y.ShouldBe(6); v5.z.ShouldBe(7); v5.w.ShouldBe(8); Vector4d v6 = new Vector4d(v4); v6.ShouldBe(v4); }
static public VISIBILTY GetVisibility(Vector4d[] frustumPlanes, Box3d box) { VISIBILTY v0 = GetVisibility(frustumPlanes[0], box); if (v0 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } VISIBILTY v1 = GetVisibility(frustumPlanes[1], box); if (v1 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } VISIBILTY v2 = GetVisibility(frustumPlanes[2], box); if (v2 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } VISIBILTY v3 = GetVisibility(frustumPlanes[3], box); if (v3 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } VISIBILTY v4 = GetVisibility(frustumPlanes[4], box); if (v4 == VISIBILTY.INVISIBLE) { return VISIBILTY.INVISIBLE; } if (v0 == VISIBILTY.FULLY && v1 == VISIBILTY.FULLY && v2 == VISIBILTY.FULLY && v3 == VISIBILTY.FULLY && v4 == VISIBILTY.FULLY) { return VISIBILTY.FULLY; } return VISIBILTY.PARTIALLY; }
public static void VertexAttrib4(Int32 index, Vector4d v) { GL.VertexAttrib4(index, v.X, v.Y, v.Z, v.W); }
public static bool UnProject(Vector4d winPos, Matrix4d modelMatrix, Matrix4d projMatrix, double[] viewport, ref Vector4d objPos) { Matrix4d p = Matrix4d.Mult(modelMatrix, projMatrix); Matrix4d finalMatrix = Matrix4d.Invert(p); Vector4d @in = winPos; // Map x and y from window coordinates @in.X = (@in.X - viewport[0]) / viewport[2]; @in.Y = (@in.Y - viewport[1]) / viewport[3]; // Map to range -1 to 1 @in.X = @in.X * 2.0 - 1.0; @in.Y = @in.Y * 2.0 - 1.0; @in.Z = @in.Z * 2.0 - 1.0; @in.W = 1.0; Vector4d @out = Vector4d.Transform(@in, finalMatrix); if (@out.W == 0.0) { return(false); } @out.X /= @out.W; @out.Y /= @out.W; @out.Z /= @out.W; objPos = @out; return(true); }
public static void Vertex4(Vector4d v) { GL.Vertex4(v.X, v.Y, v.Z, v.W); }
public double[] NewtonMethod <T>(double[] t, T BezierPatch1, T BezierPatch2, Vector3d Direction, bool addToEnd) where T : IPatch { double StopValue; int stepNumber = 0; var BP1 = BezierPatch1.GetPoint(t[0], t[1]); var StartPointXYZ = BP1; var BP1du = BezierPatch1.GetPointDerivativeU(t[0], t[1]); var BP1dv = BezierPatch1.GetPointDerivativeV(t[0], t[1]); var BP2 = BezierPatch2.GetPoint(t[2], t[3]); var BP2du = BezierPatch2.GetPointDerivativeU(t[2], t[3]); var BP2dv = BezierPatch2.GetPointDerivativeV(t[2], t[3]); var temp = BP1 - BP2; var temp2 = BP1 - StartPointXYZ; var additionalEquation = temp2.X * Direction.X + temp2.Y * Direction.Y + temp2.Z * Direction.Z - NewtonForwardStep; Vector4d Fun = new Vector4d(temp.X, temp.Y, temp.Z, additionalEquation); Vector4d tk = new Vector4d(t[0], t[1], t[2], t[3]); Vector4d tk_1 = new Vector4d(); StopValue = Fun.Length; while (StopValue > NewtonStopCondition) { //Matrix4d jacobian = new Matrix4d(BP1du.X, BP1dv.X, -BP2du.X, -BP2dv.X, // BP1du.Y, BP1dv.Y, -BP2du.Y, -BP2dv.Y, // BP1du.Z, BP1dv.Z, -BP2du.Z, -BP2dv.Z, // Vector3d.Dot(BP1du.GetPointAsVector3D(), Direction), // Vector3d.Dot(BP1dv.GetPointAsVector3D(), Direction), 0, 1); Matrix4d jacobian = new Matrix4d(BP1du.X, BP1dv.X, -BP2du.X, -BP2dv.X, BP1du.Y, BP1dv.Y, -BP2du.Y, -BP2dv.Y, BP1du.Z, BP1dv.Z, -BP2du.Z, -BP2dv.Z, Vector3d.Dot(BP1du.GetPointAsVector3D(), Direction), Vector3d.Dot(BP1dv.GetPointAsVector3D(), Direction), 0, 0); var invertedJcobian = jacobian; NewtonJacobianDeterminant.Add(jacobian.Determinant); try { invertedJcobian.Invert(); } catch { return(null); } var debugVar = invertedJcobian.Multiply(Fun); //0.01->0.1 tk_1 = tk - 0.1 * invertedJcobian.Multiply(Fun); tk_1 = tk - debugtemporaryvariable * invertedJcobian.Multiply(Fun); //if (tk_1.X > 1) //{ // tk_1.X -= 1; // // tk_1.X = 1; // // return null; //} //if (tk_1.X < 0) //{ // tk_1.X += 1; // //tk_1.X = 0; // //return null; //} tk_1.X -= Math.Floor(tk_1.X); //if (tk_1.Y > 1) //{ // tk_1.Y -= 1; // //tk_1.Y = 1; // //return null; //} //if (tk_1.Y < 0) //{ // tk_1.Y += 1; // //return null; //} tk_1.Y -= Math.Floor(tk_1.Y); //if (tk_1.Z > 1) //{ // tk_1.Z -= 1; // //return null; //} //if (tk_1.Z < 0) //{ // tk_1.Z += 1; // //return null; //} tk_1.Z -= Math.Floor(tk_1.Z); //if (tk_1.W > 1) //{ // tk_1.W -= 1; // //return null; //} //if (tk_1.W < 0) //{ // tk_1.W += 1; // // return null; //} tk_1.W -= Math.Floor(tk_1.W); tk = tk_1; BP1 = BezierPatch1.GetPoint(tk.X, tk.Y); BP1du = BezierPatch1.GetPointDerivativeU(tk.X, tk.Y); BP1dv = BezierPatch1.GetPointDerivativeV(tk.X, tk.Y); BP2 = BezierPatch2.GetPoint(tk.Z, tk.W); BP2du = BezierPatch2.GetPointDerivativeU(tk.Z, tk.W); BP2dv = BezierPatch2.GetPointDerivativeV(tk.Z, tk.W); //Visualization NewtonPointToGo.Add(BP1 + NewtonForwardStep * Direction); temp = BP1 - BP2; temp2 = BP1 - StartPointXYZ; additionalEquation = temp2.X * Direction.X + temp2.Y * Direction.Y + temp2.Z * Direction.Z - NewtonForwardStep; Fun = new Vector4d(temp.X, temp.Y, temp.Z, additionalEquation); StopValue = Fun.Length; stepNumber++; if (stepNumber > NewtonStepNumberCondition) { //MessageBox.Show("Metoda Newtona nie znalazła rozwiązania spełniającego kryteria. "); return(null); } } Point[] tempOutputPoints = new Point[2]; tempOutputPoints[0] = BezierPatch1.GetPoint(tk_1.X, tk_1.Y); tempOutputPoints[1] = BezierPatch2.GetPoint(tk_1.Z, tk_1.W); if (addToEnd) { NewtonOuputPoint.Add(tempOutputPoints); } else { NewtonOuputPoint.Insert(0, tempOutputPoints); } double[] result = new double[] { tk.X, tk.Y, tk.Z, tk.W }; return(result); }
public void Abs_Theory(Vector256 <double> vector, Vector4d expected) { Vector256 <double> result = Vector.Abs(vector); Assert.True(TestHelpers.AreEqual(expected, result), $"Expected {expected}, got {result}"); }
protected void LoadUniform(int location, Vector4d value) { GL.Uniform4(location, value.X, value.Y, value.Z, value.W); }
/// <summary> /// Initializes a new instance of the <see cref="Matrix2x4d"/> struct. /// </summary> /// <param name="row0">Top row of the matrix.</param> /// <param name="row1">Bottom row of the matrix.</param> public Matrix2x4d(Vector4d row0, Vector4d row1) { Row0 = row0; Row1 = row1; }
public void Clear(Vector4d value, TextureLevel target) { mainProgram.Uniforms["ClearValue"].Set((Vector4f)value); Run(target, "Clear"); }
public void Clear(Vector4d value, TextureSurface target, int level = 0) { Clear(value, target.Levels[level]); }
/// <summary> /// Initializes a new instance of the <see cref="Matrix3x4d"/> struct. /// </summary> /// <param name="row0">Top row of the matrix.</param> /// <param name="row1">Second row of the matrix.</param> /// <param name="row2">Bottom row of the matrix.</param> public Matrix3x4d(Vector4d row0, Vector4d row1, Vector4d row2) { Row0 = row0; Row1 = row1; Row2 = row2; }
public static bool AreEqual(Vector4d left, Vector256 <double> right) => left.X.Equals(X(right)) && left.Y.Equals(Y(right)) && left.Z.Equals(Z(right)) && left.W.Equals(W(right));
internal void UpdateOrig() { orig_state = chain.cur; Changed = false; }
public static void Length4D_Theory(Vector256 <double> vector, Vector4d expected) { Vector256 <double> result = Vector.LengthSquared4D(vector); Assert.True(TestHelpers.AreEqual(expected, result), $"Expected {expected}, got {result}"); }
/// <summary> /// Divides two quantities. The same operations as for multiplication are supported. /// </summary> /// <param name="obj1">The first object.</param> /// <param name="obj2">The second object.</param> /// <returns>Result cast into object.</returns> public static object Div(object obj1, object obj2) { if (obj1.GetType() != obj2.GetType()) { throw new ArgumentException("Object are not of the same type."); } if (obj1 is BigNum) { return((BigNum)obj1 + (BigNum)obj2); } // Float version: if (obj1 is float) { return((float)obj1 / (float)obj2); } if (obj1 is Vector2f) { return(Vector2f.ComponentDivision((Vector2f)obj1, (Vector2f)obj2)); } if (obj1 is Vector3f) { return(Vector3f.ComponentDivision((Vector3f)obj1, (Vector3f)obj2)); } if (obj1 is Vector4f) { return(Vector4f.ComponentDivision((Vector4f)obj1, (Vector4f)obj2)); } if (obj1 is Matrix.Matrix2x2f) { return((Matrix.Matrix2x2f)obj1 / (Matrix.Matrix2x2f)obj2); } if (obj1 is Matrix.Matrix3x3f) { return((Matrix.Matrix3x3f)obj1 / (Matrix.Matrix3x3f)obj2); } if (obj1 is Matrix.Matrix4x4f) { return((Matrix.Matrix4x4f)obj1 / (Matrix.Matrix4x4f)obj2); } if (obj1 is Complexf) { return((Complexf)obj1 / (Complexf)obj2); } if (obj1 is Quaternionf) { return((Quaternionf)obj1 / (Quaternionf)obj2); } // Double version: if (obj1 is double) { return((double)obj1 / (double)obj2); } if (obj1 is Vector2d) { return(Vector2d.ComponentDivision((Vector2d)obj1, (Vector2d)obj2)); } if (obj1 is Vector3d) { return(Vector3d.ComponentDivision((Vector3d)obj1, (Vector3d)obj2)); } if (obj1 is Vector4d) { return(Vector4d.ComponentDivision((Vector4d)obj1, (Vector4d)obj2)); } if (obj1 is Matrix.Matrix2x2d) { return((Matrix.Matrix2x2d)obj1 / (Matrix.Matrix2x2d)obj2); } if (obj1 is Matrix.Matrix3x3d) { return((Matrix.Matrix3x3d)obj1 / (Matrix.Matrix3x3d)obj2); } if (obj1 is Matrix.Matrix4x4d) { return((Matrix.Matrix4x4d)obj1 / (Matrix.Matrix4x4d)obj2); } if (obj1 is Complexd) { return((Complexd)obj1 / (Complexd)obj2); } if (obj1 is Quaterniond) { return((Quaterniond)obj1 / (Quaterniond)obj2); } // Integer version: if (obj1 is int) { return((int)obj1 / (int)obj2); } // Other types. if (obj1 is uint) { return((uint)obj1 / (uint)obj2); } if (obj1 is short) { return((short)obj1 / (short)obj2); } if (obj1 is ushort) { return((ushort)obj1 / (ushort)obj2); } if (obj1 is byte) { return((byte)obj1 / (byte)obj2); } if (obj1 is ulong) { return((ulong)obj1 / (ulong)obj2); } if (obj1 is long) { return((long)obj1 / (long)obj2); } throw new NotSupportedException("Unsupported type " + obj1.GetType()); }
/// <summary> /// Projects a 2d screenspace coordinate to world coordinates. /// </summary> public static Vector3d Unproject(Vector3d Point, Matrix4d View, Matrix4d Proj) { Matrix4d ma = Matrix4d.Mult(View, Proj); Matrix4d ima = Matrix4d.Invert(ma); Vector4d coord = new Vector4d(Point.X, Point.Y, Point.Z, 1.0); Vector4d res = Vector4d.Transform(coord, ima); return new Vector3d(res.X / res.W, res.Y / res.W, res.Z / res.W); }
public void Min_Theory(Vector256 <double> left, Vector256 <double> right, Vector4d expected) { Vector256 <double> result = Vector.Min(left, right); Assert.True(TestHelpers.AreEqual(expected, result), $"Expected {expected}, got {result}"); }
/// <summary> /// This function creates the elevations data and is called by the <see cref="Tile.Tasks.CreateTileTask"/> when the task is run by the <see cref="Utilities.Schedular"/>. /// The functions needs the tiles parent data to have already been created. If it has not the program will abort. /// </summary> /// <param name="level"></param> /// <param name="tx"></param> /// <param name="ty"></param> /// <param name="slot"></param> public override void DoCreateTile(int level, int tx, int ty, List <TileStorage.Slot> slot) { var gpuSlot = slot[0] as GPUTileStorage.GPUSlot; if (gpuSlot == null) { throw new NullReferenceException("gpuSlot"); } var tileWidth = gpuSlot.Owner.TileSize; var tileSize = tileWidth - (1 + GetBorder() * 2); GPUTileStorage.GPUSlot parentGpuSlot = null; var upsample = level > 0; var parentTile = FindTile(level - 1, tx / 2, ty / 2, false, true); if (upsample) { if (parentTile != null) { parentGpuSlot = parentTile.GetSlot(0) as GPUTileStorage.GPUSlot; } else { throw new MissingTileException("Find parent tile failed"); } } if (parentGpuSlot == null && upsample) { throw new NullReferenceException("parentGpuSlot"); } var rootQuadSize = TerrainNode.TerrainQuadRoot.Length; var tileWSD = Vector4.zero; tileWSD.x = (float)tileWidth; tileWSD.y = (float)rootQuadSize / (float)(1 << level) / (float)tileSize; tileWSD.z = (float)tileSize / (float)(TerrainNode.Body.GridResolution - 1); tileWSD.w = 0.0f; UpSampleMaterial.SetVector(uniforms.tileWSD, tileWSD); if (upsample) { var parentTexture = parentGpuSlot.Texture; UpSampleMaterial.SetTexture(uniforms.coarseLevelSampler, parentTexture); var dx = (float)(tx % 2) * (float)(tileSize / 2.0f); var dy = (float)(ty % 2) * (float)(tileSize / 2.0f); var coarseLevelOSL = new Vector4(dx / (float)parentTexture.width, dy / (float)parentTexture.height, 1.0f / (float)parentTexture.width, 0.0f); UpSampleMaterial.SetVector(uniforms.coarseLevelOSL, coarseLevelOSL); } else { UpSampleMaterial.SetVector(uniforms.coarseLevelOSL, new Vector4(-1.0f, -1.0f, -1.0f, -1.0f)); } UpSampleMaterial.SetTexture(uniforms.residualSampler, null); UpSampleMaterial.SetVector(uniforms.residualOSH, new Vector4(0.0f, 0.0f, 1.0f, 0.0f)); var rs = level < NoiseAmplitudes.Length ? NoiseAmplitudes[level] : 0.0f; rs = rs / AmplitudeDiviner; rs = -Math.Abs(rs); var offset = Vector4d.Zero(); offset.x = ((double)tx / (1 << level) - 0.5) * rootQuadSize; offset.y = ((double)ty / (1 << level) - 0.5) * rootQuadSize; offset.z = rootQuadSize / (1 << level); offset.w = TerrainNode.Body.Radius; if (level == 0) { UpSampleMaterial.SetFloat(uniforms.frequency, UpsampleSettings.Freqeuncy * (1 << level)); } var ltow = TerrainNode.FaceToLocal.ToMatrix4x4(); UpSampleMaterial.SetFloat(uniforms.amp, rs * UpsampleSettings.Amplitude); UpSampleMaterial.SetVector(uniforms.offset, offset.ToVector4()); UpSampleMaterial.SetMatrix(uniforms.localToWorld, ltow); Graphics.Blit(null, gpuSlot.Texture, UpSampleMaterial); base.DoCreateTile(level, tx, ty, slot); }
public virtual void UpdateNode() { //Calculates the required data for the projected grid // compute ltoo = localToOcean transform, where ocean frame = tangent space at // camera projection on sphere radius in local space Matrix4x4d ctol = View.CameraToWorld; Vector3d cl = ctol * Vector3d.Zero; // camera in local space float radius = World.IsDeformed ? World.Radius : 0.0f; if ((radius == 0.0 && cl.z > m_zmin) || (radius > 0.0 && cl.Magnitude > radius + m_zmin) || (radius < 0.0 && (new Vector2d(cl.y, cl.z)).Magnitude < -radius - m_zmin)) { m_oldLtoo = Matrix4x4d.Identity; m_offset = Vector3d.Zero; DrawOcean = false; return; } DrawOcean = true; Vector3d ux, uy, uz, oo; if (radius == 0.0f) { //terrain ocean ux = Vector3d.UnitX; uy = Vector3d.UnitY; uz = Vector3d.UnitZ; oo = new Vector3d(cl.x, cl.y, 0.0); } else { // planet ocean uz = cl.Normalized; // unit z vector of ocean frame, in local space if (m_oldLtoo != Matrix4x4d.Identity) { ux = (new Vector3d(m_oldLtoo[1, 0], m_oldLtoo[1, 1], m_oldLtoo[1, 2])).Cross(uz).Normalized; } else { ux = Vector3d.UnitZ.Cross(uz).Normalized; } uy = uz.Cross(ux); // unit y vector oo = uz * radius; // origin of ocean frame, in local space } Matrix4x4d ltoo = new Matrix4x4d( ux.x, ux.y, ux.z, -Vector3d.Dot(ux, oo), uy.x, uy.y, uy.z, -Vector3d.Dot(uy, oo), uz.x, uz.y, uz.z, -Vector3d.Dot(uz, oo), 0.0, 0.0, 0.0, 1.0); // compute ctoo = cameraToOcean transform Matrix4x4d ctoo = ltoo * ctol; if (m_oldLtoo != Matrix4x4d.Identity) { Vector3d delta = ltoo * (m_oldLtoo.Inverse * Vector3d.Zero); m_offset += delta; } m_oldLtoo = ltoo; Matrix4x4d stoc = View.ScreenToCamera; Vector3d oc = ctoo * Vector3d.Zero; double h = oc.z; Vector4d stoc_w = (stoc * Vector4d.UnitW).xyz0; Vector4d stoc_x = (stoc * Vector4d.UnitX).xyz0; Vector4d stoc_y = (stoc * Vector4d.UnitY).xyz0; Vector3d A0 = (ctoo * stoc_w).xyz; Vector3d dA = (ctoo * stoc_x).xyz; Vector3d B = (ctoo * stoc_y).xyz; Vector3d horizon1, horizon2; Vector3d offset = new Vector3d(-m_offset.x, -m_offset.y, oc.z); if (radius == 0.0) { //Terrain ocean horizon1 = new Vector3d(-(h * 1e-6 + A0.z) / B.z, -dA.z / B.z, 0.0); horizon2 = Vector3d.Zero; } else { //Planet ocean double h1 = h * (h + 2.0 * radius); double h2 = (h + radius) * (h + radius); double alpha = Vector3d.Dot(B, B) * h1 - B.z * B.z * h2; double beta0 = (Vector3d.Dot(A0, B) * h1 - B.z * A0.z * h2) / alpha; double beta1 = (Vector3d.Dot(dA, B) * h1 - B.z * dA.z * h2) / alpha; double gamma0 = (Vector3d.Dot(A0, A0) * h1 - A0.z * A0.z * h2) / alpha; double gamma1 = (Vector3d.Dot(A0, dA) * h1 - A0.z * dA.z * h2) / alpha; double gamma2 = (Vector3d.Dot(dA, dA) * h1 - dA.z * dA.z * h2) / alpha; horizon1 = new Vector3d(-beta0, -beta1, 0.0); horizon2 = new Vector3d(beta0 * beta0 - gamma0, 2.0 * (beta0 * beta1 - gamma1), beta1 * beta1 - gamma2); } Vector3 dir = World.SunNode.Direction; Vector3d sunDir = new Vector3d(dir.x, dir.y, dir.z); Vector3d oceanSunDir = ltoo.ToMatrix3x3d() * sunDir; m_oceanMaterial.SetVector("_Ocean_SunDir", MathConverter.ToVector3(oceanSunDir)); m_oceanMaterial.SetVector("_Ocean_Horizon1", MathConverter.ToVector3(horizon1)); m_oceanMaterial.SetVector("_Ocean_Horizon2", MathConverter.ToVector3(horizon2)); m_oceanMaterial.SetMatrix("_Ocean_CameraToOcean", MathConverter.ToMatrix4x4(ctoo)); m_oceanMaterial.SetMatrix("_Ocean_OceanToCamera", MathConverter.ToMatrix4x4(ctoo.Inverse)); m_oceanMaterial.SetVector("_Ocean_CameraPos", MathConverter.ToVector3(offset)); m_oceanMaterial.SetVector("_Ocean_Color", m_oceanUpwellingColor * 0.1f); m_oceanMaterial.SetVector("_Ocean_ScreenGridSize", new Vector2((float)m_resolution / (float)Screen.width, (float)m_resolution / (float)Screen.height)); m_oceanMaterial.SetFloat("_Ocean_Radius", radius); World.SkyNode.SetUniforms(m_oceanMaterial); World.SunNode.SetUniforms(m_oceanMaterial); World.SetUniforms(m_oceanMaterial); //Draw each mesh that makes up the projected grid foreach (Mesh mesh in m_screenGrids) { Graphics.DrawMesh(mesh, Matrix4x4.identity, m_oceanMaterial, 0, Camera.main); } }
public static void MultiTexCoord4(TextureUnit target, ref Vector4d v) { GL.MultiTexCoord4(target, v.X, v.Y, v.Z, v.W); }
/// <summary>Create a <see cref="Box4d"/> by providing the minimum extent and the size of each side.</summary> public static Box4d Relative( ref Vector4d min , ref Vector4d size ) { Box4d result; result.Min.X = min.X; result.Max.X = min.X + size.X; result.Min.Y = min.Y; result.Max.Y = min.Y + size.Y; result.Min.Z = min.Z; result.Max.Z = min.Z + size.Z; result.Min.W = min.W; result.Max.W = min.W + size.W; return result; }
/// <summary> /// Constructs a new instance from the given Vector4d. /// </summary> /// <param name="v">The Vector4d to copy components from.</param> public Vector3d(Vector4d v) { X = v.X; Y = v.Y; Z = v.Z; }
/// <summary>Get the closest distance between this <see cref="Box4d"/> and the <see cref="Vector4d"/>.</summary> public Double Distance( ref Vector4d point) { Vector4d nearest; NearestPointTo(ref point, out nearest); return point.Distance(ref nearest); }
public override FRUSTUM_VISIBILTY GetVisibility(TerrainNode t, Box3d localBox) { Vector3d[] deformedBox = new Vector3d[4]; deformedBox[0] = LocalToDeformed(new Vector3d(localBox.Min.x, localBox.Min.y, localBox.Min.z)); deformedBox[1] = LocalToDeformed(new Vector3d(localBox.Max.x, localBox.Min.y, localBox.Min.z)); deformedBox[2] = LocalToDeformed(new Vector3d(localBox.Max.x, localBox.Max.y, localBox.Min.z)); deformedBox[3] = LocalToDeformed(new Vector3d(localBox.Min.x, localBox.Max.y, localBox.Min.z)); double a = (localBox.Max.z + R) / (localBox.Min.z + R); double dx = (localBox.Max.x - localBox.Min.x) / 2 * a; double dy = (localBox.Max.y - localBox.Min.y) / 2 * a; double dz = localBox.Max.z + R; double f = Math.Sqrt(dx * dx + dy * dy + dz * dz) / (localBox.Min.z + R); Vector4d[] deformedFrustumPlanes = t.DeformedFrustumPlanes; FRUSTUM_VISIBILTY v0 = GetVisibility(deformedFrustumPlanes[0], deformedBox, f); if (v0 == FRUSTUM_VISIBILTY.INVISIBLE) { return(FRUSTUM_VISIBILTY.INVISIBLE); } FRUSTUM_VISIBILTY v1 = GetVisibility(deformedFrustumPlanes[1], deformedBox, f); if (v1 == FRUSTUM_VISIBILTY.INVISIBLE) { return(FRUSTUM_VISIBILTY.INVISIBLE); } FRUSTUM_VISIBILTY v2 = GetVisibility(deformedFrustumPlanes[2], deformedBox, f); if (v2 == FRUSTUM_VISIBILTY.INVISIBLE) { return(FRUSTUM_VISIBILTY.INVISIBLE); } FRUSTUM_VISIBILTY v3 = GetVisibility(deformedFrustumPlanes[3], deformedBox, f); if (v3 == FRUSTUM_VISIBILTY.INVISIBLE) { return(FRUSTUM_VISIBILTY.INVISIBLE); } FRUSTUM_VISIBILTY v4 = GetVisibility(deformedFrustumPlanes[4], deformedBox, f); if (v4 == FRUSTUM_VISIBILTY.INVISIBLE) { return(FRUSTUM_VISIBILTY.INVISIBLE); } Vector3d c = t.DeformedCameraPos; double lSq = c.SqrMagnitude; double rm = R + Math.Min(0.0, localBox.Min.z); double rM = R + localBox.Max.z; double rmSq = rm * rm; double rMSq = rM * rM; Vector4d farPlane = new Vector4d(c.x, c.y, c.z, Math.Sqrt((lSq - rmSq) * (rMSq - rmSq)) - rmSq); FRUSTUM_VISIBILTY v5 = GetVisibility(farPlane, deformedBox, f); if (v5 == FRUSTUM_VISIBILTY.INVISIBLE) { return(FRUSTUM_VISIBILTY.INVISIBLE); } if (v0 == FRUSTUM_VISIBILTY.FULLY && v1 == FRUSTUM_VISIBILTY.FULLY && v2 == FRUSTUM_VISIBILTY.FULLY && v3 == FRUSTUM_VISIBILTY.FULLY && v4 == FRUSTUM_VISIBILTY.FULLY && v5 == FRUSTUM_VISIBILTY.FULLY) { return(FRUSTUM_VISIBILTY.FULLY); } return(FRUSTUM_VISIBILTY.PARTIALLY); }
/// <summary>Get the nearest point between this <see cref="Box4d"/> and a <see cref="Vector4d"/>. If the <see cref="Vector4d"/> is inside this <see cref="Box4d"/>, it is returned untouched.</summary> public void NearestPointTo( ref Vector4d point , out Vector4d result) { Containment containment = Intersect(ref point); if(containment != Containment.Disjoint) result = point; else point.Clamp(ref Min, ref Max, out result); return; }
public static bool Project(Vector4d objPos, Matrix4d modelMatrix, Matrix4d projMatrix, double[] viewport, ref Vector4d winPos) { objPos.W = 1; Vector4d @out = default(Vector4d); @out = Vector4d.Transform(objPos, modelMatrix); @out = Vector4d.Transform(@out, projMatrix); if (@out.W == 0) { return(false); } @out.W = (1 / @out.W) * 0.5; // Map X/Y/Z to range 0-1 @out.X = @out.X * @out.W + 0.5; @out.Y = @out.Y * @out.W + 0.5; @out.Z = @out.Z * @out.W + 0.5; // Map x, y to viewport winPos = new Vector4d(); winPos.X = @out.X * viewport[2] + viewport[0]; winPos.Y = @out.Y * viewport[3] + viewport[1]; winPos.Z = @out.Z; return(true); }
/// <summary>Get a random position within the box.</summary> public void Random(Random rng , out Vector4d result) { result.X = (Double)(rng.NextDouble() * (Max.X - Min.X) + Min.X); result.Y = (Double)(rng.NextDouble() * (Max.Y - Min.Y) + Min.Y); result.Z = (Double)(rng.NextDouble() * (Max.Z - Min.Z) + Min.Z); result.W = (Double)(rng.NextDouble() * (Max.W - Min.W) + Min.W); return; }
/// <summary> /// Constructs a new Vector2f from the given Vector4d. /// </summary> /// <param name="v">The Vector4d to copy components from.</param> public Vector2i(Vector4d vec) { X = (int)vec.X; Y = (int)vec.Y; }
private Vector4d CalculateEquationOfPlaneInIndices(Vector3d pt1, Vector3d pt2, Vector3d pt3) { Vector3d p1p2 = pt2 - pt1; Vector3d p1p3 = pt3 - pt1; Vector3d tmp = Vector3d.Cross(p1p2, p1p3); Vector4d result = new Vector4d(tmp.x, tmp.y, tmp.z); result.w = result.x * (lowerRightCorner.x - pt1.x) + result.y * (lowerRightCorner.y - pt1.y) + result.z * (lowerRightCorner.z - pt1.z); result.w *= invElementSize; return result; }
public static void TexCoord4(Vector4d v) { GL.TexCoord4(v.X, v.Y, v.Z, v.W); }
public static void GetDouble(GetPName pname, out Vector4d vector) { unsafe { fixed (Vector4d* ptr = &vector) GetDouble(pname, (double*)ptr); } }
public override Frustum.VISIBILITY GetVisibility(TerrainNode node, Box3d localBox) { var deformedBox = new Vector3d[4]; deformedBox[0] = LocalToDeformed(new Vector3d(localBox.xmin, localBox.ymin, localBox.zmin)); deformedBox[1] = LocalToDeformed(new Vector3d(localBox.xmax, localBox.ymin, localBox.zmin)); deformedBox[2] = LocalToDeformed(new Vector3d(localBox.xmax, localBox.ymax, localBox.zmin)); deformedBox[3] = LocalToDeformed(new Vector3d(localBox.xmin, localBox.ymax, localBox.zmin)); var a = (localBox.zmax + R) / (localBox.zmin + R); var dx = (localBox.xmax - localBox.xmin) / 2 * a; var dy = (localBox.ymax - localBox.ymin) / 2 * a; var dz = localBox.zmax + R; var f = Math.Sqrt(dx * dx + dy * dy + dz * dz) / (localBox.zmin + R); var v0 = GetClipVisibility(node.DeformedFrustumPlanes[0], deformedBox, f); if (v0 == Frustum.VISIBILITY.INVISIBLE) { return(Frustum.VISIBILITY.INVISIBLE); } var v1 = GetClipVisibility(node.DeformedFrustumPlanes[1], deformedBox, f); if (v1 == Frustum.VISIBILITY.INVISIBLE) { return(Frustum.VISIBILITY.INVISIBLE); } var v2 = GetClipVisibility(node.DeformedFrustumPlanes[2], deformedBox, f); if (v2 == Frustum.VISIBILITY.INVISIBLE) { return(Frustum.VISIBILITY.INVISIBLE); } var v3 = GetClipVisibility(node.DeformedFrustumPlanes[3], deformedBox, f); if (v3 == Frustum.VISIBILITY.INVISIBLE) { return(Frustum.VISIBILITY.INVISIBLE); } var v4 = GetClipVisibility(node.DeformedFrustumPlanes[4], deformedBox, f); if (v4 == Frustum.VISIBILITY.INVISIBLE) { return(Frustum.VISIBILITY.INVISIBLE); } var lSq = node.DeformedCameraPosition.SqrMagnitude(); var rm = R + Math.Min(0.0, localBox.zmin); var rM = R + localBox.zmax; var rmSq = rm * rm; var rMSq = rM * rM; var farPlane = new Vector4d(node.DeformedCameraPosition.x, node.DeformedCameraPosition.y, node.DeformedCameraPosition.z, Math.Sqrt((lSq - rmSq) * (rMSq - rmSq)) - rmSq); var v5 = GetClipVisibility(farPlane, deformedBox, f); if (v5 == Frustum.VISIBILITY.INVISIBLE) { return(Frustum.VISIBILITY.INVISIBLE); } if (v0 == Frustum.VISIBILITY.FULLY && v1 == Frustum.VISIBILITY.FULLY && v2 == Frustum.VISIBILITY.FULLY && v3 == Frustum.VISIBILITY.FULLY && v4 == Frustum.VISIBILITY.FULLY && v5 == Frustum.VISIBILITY.FULLY) { return(Frustum.VISIBILITY.FULLY); } return(Frustum.VISIBILITY.PARTIALLY); }
/// <summary>Create a <see cref="Box4d"/> by providing minimum and maximum extents.</summary> public Box4d( ref Vector4d min, ref Vector4d max) { this.Min = min; this.Max = max; }
public static void Cross4D_Theory(Vector256 <double> left, Vector256 <double> right, Vector256 <double> third, Vector4d expected) { Vector256 <double> result = Vector.Cross4D(left, right, third); Assert.True(TestHelpers.AreEqual(expected, result), $"Expected {expected}, got {result}"); }
/// <summary>Create a <see cref="Box4d"/> by providing the minimum extent and the size of each side.</summary> public static void Relative( ref Vector4d min , ref Vector4d size , out Box4d result) { result.Min.X = min.X; result.Max.X = min.X + size.X; result.Min.Y = min.Y; result.Max.Y = min.Y + size.Y; result.Min.Z = min.Z; result.Max.Z = min.Z + size.Z; result.Min.W = min.W; result.Max.W = min.W + size.W; return; }
public void ParseLoadedObject() { List <Point> PointsCollection = new List <Point>(); foreach (var item in result.toruses) { Vector4d temp = new Vector4d(item.center[0], item.center[1], item.center[2], 0); TorusCollection1.Add(new Torus(temp, item.r1, item.R, item.u, item.v)); } foreach (var item in result.points) { PointsCollection.Add(new Point(item.x, item.y, item.z, item.name)); } foreach (var item in result.surfacesC2) { Point[,] convertedPoints = new Point[item.points.GetLength(0), item.points[0].GetLength(0)]; for (int i = 0; i < item.points.GetLength(0); i++) { for (int j = 0; j < item.points[0].GetLength(0); j++) { convertedPoints[i, j] = new Point(translate.X + scale * result.points[(int)item.points[i][j]].x, translate.Y + scale * result.points[(int)item.points[i][j]].y, translate.Z + scale * result.points[(int)item.points[i][j]].z); } } BezierPatchC2Collection1.Add(new BezierPatchC2(item.flakeU, item.flakeV, item.u, item.v, item.cylinder, convertedPoints, item.name)); } foreach (var item in result.surfacesC0) { Point[,] convertedPoints = new Point[item.points.GetLength(0), item.points[0].GetLength(0)]; for (int i = 0; i < item.points.GetLength(0); i++) { for (int j = 0; j < item.points[0].GetLength(0); j++) { //convertedPoints[i, j] = new Point(result.points[(int)item.points[i][j]].x, result.points[(int)item.points[i][j]].y, result.points[(int)item.points[i][j]].z); convertedPoints[i, j] = scale * PointsCollection[item.points[i][j]] + translate; } } BezierPatchCollection1.Add(new BezierPatch(item.flakeU, item.flakeV, item.u, item.v, item.cylinder, convertedPoints, item.name)); } foreach (var item in result.curvesC0) { List <Point> convertedPoints = new List <Point>(); for (int i = 0; i < item.points.GetLength(0); i++) { convertedPoints.Add(new Point(result.points[(int)item.points[i]].x, result.points[(int)item.points[i]].y, result.points[(int)item.points[i]].z)); PointsCollection1.Add(convertedPoints.Last()); } _bezierCurveCollection1.Add(new BezierCurve(convertedPoints)); } foreach (var item in result.curvesC2) { List <Point> convertedPoints = new List <Point>(); for (int i = 0; i < item.points.GetLength(0); i++) { convertedPoints.Add(new Point(result.points[(int)item.points[i]].x, result.points[(int)item.points[i]].y, result.points[(int)item.points[i]].z)); PointsCollection1.Add(convertedPoints.Last()); } _bezierCurveCollection1.Add(new BezierCurveC2(convertedPoints, false, item.name)); } foreach (var item in result.curvesC2I) { List <Point> convertedPoints = new List <Point>(); for (int i = 0; i < item.points.GetLength(0); i++) { convertedPoints.Add(new Point(result.points[(int)item.points[i]].x, result.points[(int)item.points[i]].y, result.points[(int)item.points[i]].z)); PointsCollection1.Add(convertedPoints.Last()); } _bezierCurveCollection1.Add(new BezierCurveC2(convertedPoints, true, item.name)); } }
/// <summary>Get the intersection type between this box and the point.</summary> public Containment Intersect( ref Vector4d point) { // Most points should be outside, so check that first. if ( point.X < Min.X || point.X > Max.X || point.Y < Min.Y || point.Y > Max.Y || point.Z < Min.Z || point.Z > Max.Z || point.W < Min.W || point.W > Max.W ) return Containment.Disjoint; // Now check for boundaries, which will usually be cut short on the first axis. if ( (point.X == Min.X || point.X == Max.X) && (point.Y == Min.Y || point.Y == Max.Y) && (point.Z == Min.Z || point.Z == Max.Z) && (point.W == Min.W || point.W == Max.W) ) return Containment.Intersects; return Containment.Contains; }
public static Vector3 ToVector3(Vector4d v) { return(new Vector3((float)v.x, (float)v.y, (float)v.z)); }
/// <summary>Get whether this <see cref="Box4d"/> inclusively intersects with the <see cref="Vector4d"/>.</summary> public bool Overlaps( ref Vector4d point) { return point.X >= Min.X && point.X <= Max.X && point.Y >= Min.Y && point.Y <= Max.Y && point.Z >= Min.Z && point.Z <= Max.Z && point.W >= Min.W && point.W <= Max.W ; }
public static Vector4 ToVector4(Vector4d v) { return(new Vector4((float)v.x, (float)v.y, (float)v.z, (float)v.w)); }
private Vector4d CalculateEquationOfPlane(Vector3d pt1, Vector3d pt2, Vector3d pt3) { Vector3d p1p2 = pt2 - pt1; Vector3d p1p3 = pt3 - pt1; Vector3d tmp = Vector3d.Cross(p1p2, p1p3); Vector4d result = new Vector4d(tmp.x, tmp.y, tmp.z); result.w = -(pt1.x * result.x + pt1.y * result.y + pt1.z * result.z); return result; }
public static void RasterPos4(Vector4d pos) { GL.RasterPos4(pos.X, pos.Y, pos.Z, pos.W); }
private Vector4d TransformPlaneToIndices(Vector4d plane) { Vector4d newPlane = new Vector4d(); newPlane.x = plane.x * elementSize; newPlane.y = plane.y * elementSize; newPlane.z = plane.z * elementSize; newPlane.w = plane.w + plane.x * lowerRightCorner.x + plane.y * lowerRightCorner.y + plane.z * lowerRightCorner.z; return newPlane; }
static VISIBILTY GetVisibility(Vector4d clip, Box3d box) { double x0 = box.xmin * clip.x; double x1 = box.xmax * clip.x; double y0 = box.ymin * clip.y; double y1 = box.ymax * clip.y; double z0 = box.zmin * clip.z + clip.w; double z1 = box.zmax * clip.z + clip.w; double p1 = x0 + y0 + z0; double p2 = x1 + y0 + z0; double p3 = x1 + y1 + z0; double p4 = x0 + y1 + z0; double p5 = x0 + y0 + z1; double p6 = x1 + y0 + z1; double p7 = x1 + y1 + z1; double p8 = x0 + y1 + z1; if(p1 <= 0 && p2 <= 0 && p3 <= 0 && p4 <= 0 && p5 <= 0 && p6 <= 0 && p7 <= 0 && p8 <= 0) { return VISIBILTY.INVISIBLE; } if (p1 > 0 && p2 > 0 && p3 > 0 && p4 > 0 && p5 > 0 && p6 > 0 && p7 > 0 && p8 > 0) { return VISIBILTY.FULLY; } return VISIBILTY.PARTIALLY; }
public static void Normalize4D_Theory(Vector256 <double> vector, Vector4d expected) { Vector256 <double> result = Vector.Normalize4D(vector); Assert.True(TestHelpers.AreApproxEqual(expected, result, 0.00001d), $"Expected: {expected}, got {result}"); }