/// <summary> /// Returns the coordinates and type of the current path segment in /// the iteration. /// The return value is the path segment type: /// SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. /// A float array of length 6 must be passed in and may be used to /// store the coordinates of the point(s). /// Each point is stored as a pair of float x,y coordinates. /// SEG_MOVETO and SEG_LINETO types will return one point, /// SEG_QUADTO will return two points, /// SEG_CUBICTO will return 3 points /// and SEG_CLOSE will not return any points. </summary> /// <seealso cref= #SEG_MOVETO </seealso> /// <seealso cref= #SEG_LINETO </seealso> /// <seealso cref= #SEG_QUADTO </seealso> /// <seealso cref= #SEG_CUBICTO </seealso> /// <seealso cref= #SEG_CLOSE </seealso> public virtual int CurrentSegment(float[] coords) { if (Done) { throw new NoSuchElementException("rect iterator out of bounds"); } if (Index == 5) { return(PathIterator_Fields.SEG_CLOSE); } coords[0] = (float)x; coords[1] = (float)y; if (Index == 1 || Index == 2) { coords[0] += (float)w; } if (Index == 2 || Index == 3) { coords[1] += (float)h; } if (Affine != null) { Affine.Transform(coords, 0, coords, 0, 1); } return(Index == 0 ? PathIterator_Fields.SEG_MOVETO : PathIterator_Fields.SEG_LINETO); }
/// <summary> /// Returns the coordinates and type of the current path segment in /// the iteration. /// The return value is the path segment type: /// SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. /// A float array of length 6 must be passed in and may be used to /// store the coordinates of the point(s). /// Each point is stored as a pair of float x,y coordinates. /// SEG_MOVETO and SEG_LINETO types will return one point, /// SEG_QUADTO will return two points, /// SEG_CUBICTO will return 3 points /// and SEG_CLOSE will not return any points. </summary> /// <seealso cref= #SEG_MOVETO </seealso> /// <seealso cref= #SEG_LINETO </seealso> /// <seealso cref= #SEG_QUADTO </seealso> /// <seealso cref= #SEG_CUBICTO </seealso> /// <seealso cref= #SEG_CLOSE </seealso> public virtual int CurrentSegment(float[] coords) { if (Done) { throw new NoSuchElementException("quad iterator iterator out of bounds"); } int type; if (Index == 0) { coords[0] = (float)Quad.X1; coords[1] = (float)Quad.Y1; type = PathIterator_Fields.SEG_MOVETO; } else { coords[0] = (float)Quad.CtrlX; coords[1] = (float)Quad.CtrlY; coords[2] = (float)Quad.X2; coords[3] = (float)Quad.Y2; type = PathIterator_Fields.SEG_QUADTO; } if (Affine != null) { Affine.Transform(coords, 0, coords, 0, Index == 0 ? 1 : 2); } return(type); }
/// <summary> /// Returns the coordinates and type of the current path segment in /// the iteration. /// The return value is the path segment type: /// SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. /// A float array of length 6 must be passed in and may be used to /// store the coordinates of the point(s). /// Each point is stored as a pair of float x,y coordinates. /// SEG_MOVETO and SEG_LINETO types will return one point, /// SEG_QUADTO will return two points, /// SEG_CUBICTO will return 3 points /// and SEG_CLOSE will not return any points. </summary> /// <seealso cref= #SEG_MOVETO </seealso> /// <seealso cref= #SEG_LINETO </seealso> /// <seealso cref= #SEG_QUADTO </seealso> /// <seealso cref= #SEG_CUBICTO </seealso> /// <seealso cref= #SEG_CLOSE </seealso> public virtual int CurrentSegment(float[] coords) { if (Done) { throw new NoSuchElementException("ellipse iterator out of bounds"); } if (Index == 5) { return(PathIterator_Fields.SEG_CLOSE); } if (Index == 0) { double[] ctrls = Ctrlpts[3]; coords[0] = (float)(x + ctrls[4] * w); coords[1] = (float)(y + ctrls[5] * h); if (Affine != null) { Affine.Transform(coords, 0, coords, 0, 1); } return(PathIterator_Fields.SEG_MOVETO); } double[] ctrls = Ctrlpts[Index - 1]; coords[0] = (float)(x + ctrls[0] * w); coords[1] = (float)(y + ctrls[1] * h); coords[2] = (float)(x + ctrls[2] * w); coords[3] = (float)(y + ctrls[3] * h); coords[4] = (float)(x + ctrls[4] * w); coords[5] = (float)(y + ctrls[5] * h); if (Affine != null) { Affine.Transform(coords, 0, coords, 0, 3); } return(PathIterator_Fields.SEG_CUBICTO); }
/// <summary> /// Returns the coordinates and type of the current path segment in /// the iteration. /// The return value is the path segment type: /// SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. /// A float array of length 6 must be passed in and may be used to /// store the coordinates of the point(s). /// Each point is stored as a pair of float x,y coordinates. /// SEG_MOVETO and SEG_LINETO types will return one point, /// SEG_QUADTO will return two points, /// SEG_CUBICTO will return 3 points /// and SEG_CLOSE will not return any points. </summary> /// <seealso cref= #SEG_MOVETO </seealso> /// <seealso cref= #SEG_LINETO </seealso> /// <seealso cref= #SEG_QUADTO </seealso> /// <seealso cref= #SEG_CUBICTO </seealso> /// <seealso cref= #SEG_CLOSE </seealso> public virtual int CurrentSegment(float[] coords) { if (Done) { throw new NoSuchElementException("line iterator out of bounds"); } int type; if (Index == 0) { coords[0] = (float)Line.X1; coords[1] = (float)Line.Y1; type = PathIterator_Fields.SEG_MOVETO; } else { coords[0] = (float)Line.X2; coords[1] = (float)Line.Y2; type = PathIterator_Fields.SEG_LINETO; } if (Affine != null) { Affine.Transform(coords, 0, coords, 0, 1); } return(type); }
private static Point[] BuildCoordinates(Rectangle targetBoundingBox, AffineTransform transformation) { double xCenter = targetBoundingBox.GetX() + targetBoundingBox.GetWidth() / 2; Point start = transformation.Transform(new Point(xCenter, targetBoundingBox.GetBottom()), null); Point end = transformation.Transform(new Point(xCenter, targetBoundingBox.GetTop()), null); Point[] baseVector = new Point[] { start, end }; double[] targetDomain = EvaluateCoveringDomain(baseVector, targetBoundingBox); return(CreateCoordinatesForNewDomain(targetDomain, baseVector)); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 13JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Returns the coordinates and type of the current path segment in * the iteration. * The return Value is the path segment type: * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. * A float array of length 6 must be passed in and may be used to * store the coordinates of the point(s). * Each point is stored as a pair of float x,y coordinates. * SEG_MOVETO and SEG_LINETO types will return one point, * SEG_QUADTO will return two points, * SEG_CUBICTO will return 3 points * and SEG_CLOSE will not return any points. * @see #SEG_MOVETO * @see #SEG_LINETO * @see #SEG_QUADTO * @see #SEG_CUBICTO * @see #SEG_CLOSE */ public override int CurrentSegment(int[] coords) { if (IsDone()) { throw new IndexOutOfRangeException("arc iterator out of bounds"); } double angle = _angStRad; if (_index == 0) { coords[0] = (int)(_x + MathEx.Cos(angle) * _w + .5); coords[1] = (int)(_y + MathEx.Sin(angle) * _h + .5); if (_affine != null) { _affine.Transform(coords, 0, coords, 0, 1); } return(SEG_MOVETO); } if (_index > _arcSegs) { if (_index == _arcSegs + _lineSegs) { return(SEG_CLOSE); } coords[0] = (int)(_x + .5); coords[1] = (int)(_y + .5); if (_affine != null) { _affine.Transform(coords, 0, coords, 0, 1); } return(SEG_LINETO); } angle += _increment * (_index - 1); double relx = MathEx.Cos(angle); double rely = MathEx.Sin(angle); coords[0] = (int)(_x + (relx - _cv * rely) * _w + .5); coords[1] = (int)(_y + (rely + _cv * relx) * _h + .5); angle += _increment; relx = MathEx.Cos(angle); rely = MathEx.Sin(angle); coords[2] = (int)(_x + (relx + _cv * rely) * _w + .5); coords[3] = (int)(_y + (rely - _cv * relx) * _h + .5); coords[4] = (int)(_x + relx * _w + .5); coords[5] = (int)(_y + rely * _h + .5); if (_affine != null) { _affine.Transform(coords, 0, coords, 0, 3); } return(SEG_CUBICTO); }
/// <summary> /// Returns the coordinates and type of the current path segment in /// the iteration. /// The return value is the path segment type: /// SEG_MOVETO, SEG_LINETO, or SEG_CLOSE. /// A <code>float</code> array of length 2 must be passed in and /// can be used to store the coordinates of the point(s). /// Each point is stored as a pair of <code>float</code> x, y /// coordinates. SEG_MOVETO and SEG_LINETO types return one /// point, and SEG_CLOSE does not return any points. </summary> /// <param name="coords"> a <code>float</code> array that specifies the /// coordinates of the point(s) </param> /// <returns> an integer representing the type and coordinates of the /// current path segment. </returns> /// <seealso cref= PathIterator#SEG_MOVETO </seealso> /// <seealso cref= PathIterator#SEG_LINETO </seealso> /// <seealso cref= PathIterator#SEG_CLOSE </seealso> public virtual int CurrentSegment(float[] coords) { if (Index >= Poly.Npoints) { return(geom.PathIterator_Fields.SEG_CLOSE); } coords[0] = Poly.Xpoints[Index]; coords[1] = Poly.Ypoints[Index]; if (Transform != null) { Transform.Transform(coords, 0, coords, 0, 1); } return(Index == 0 ? geom.PathIterator_Fields.SEG_MOVETO : geom.PathIterator_Fields.SEG_LINETO); }
public override void GetMeshData(List <VertexPositionNormalTexture> vertices, List <ushort> indices) { var tempVertices = new VertexPositionNormalTexture[DisplayedObject.Shape.TriangleMesh.Data.Vertices.Length]; for (int i = 0; i < DisplayedObject.Shape.TriangleMesh.Data.Vertices.Length; i++) { tempVertices[i] = new VertexPositionNormalTexture( AffineTransform.Transform(DisplayedObject.Shape.TriangleMesh.Data.Vertices[i], DisplayedObject.WorldTransform), Vector3.Zero, Vector2.Zero); } for (int i = 0; i < DisplayedObject.Shape.TriangleMesh.Data.Indices.Length; i++) { indices.Add((ushort)DisplayedObject.Shape.TriangleMesh.Data.Indices[i]); } for (int i = 0; i < indices.Count; i += 3) { int a = indices[i]; int b = indices[i + 1]; int c = indices[i + 2]; Vector3 normal = Vector3.Normalize(Vector3.Cross( tempVertices[c].Position - tempVertices[a].Position, tempVertices[b].Position - tempVertices[a].Position)); tempVertices[a].Normal += normal; tempVertices[b].Normal += normal; tempVertices[c].Normal += normal; } for (int i = 0; i < tempVertices.Length; i++) { tempVertices[i].Normal.Normalize(); vertices.Add(tempVertices[i]); } }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 13JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Returns the coordinates and type of the current path segment in * the iteration. * The return Value is the path segment type: * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. * A long array of length 6 must be passed in and may be used to * store the coordinates of the point(s). * Each point is stored as a pair of long x,y coordinates. * SEG_MOVETO and SEG_LINETO types will return one point, * SEG_QUADTO will return two points, * SEG_CUBICTO will return 3 points * and SEG_CLOSE will not return any points. * @see #SEG_MOVETO * @see #SEG_LINETO * @see #SEG_QUADTO * @see #SEG_CUBICTO * @see #SEG_CLOSE */ public override int CurrentSegment(int[] coords) { if (IsDone()) { throw new IndexOutOfRangeException("rect iterator out of bounds"); } if (_index == 5) { return(SEG_CLOSE); } coords[0] = _x; coords[1] = _y; if (_index == 1 || _index == 2) { coords[0] += _w; } if (_index == 2 || _index == 3) { coords[1] += _h; } if (_affine != null) { _affine.Transform(coords, 0, coords, 0, 1); } return(_index == 0 ? SEG_MOVETO : SEG_LINETO); }
///<summary> /// Gets the triangle vertex positions at a given index. ///</summary> ///<param name="triangleIndex">First index of a triangle's vertices in the index buffer.</param> ///<param name="v1">First vertex of the triangle.</param> ///<param name="v2">Second vertex of the triangle.</param> ///<param name="v3">Third vertex of the triangle.</param> public override void GetTriangle(int triangleIndex, out Vector3 v1, out Vector3 v2, out Vector3 v3) { Vector3 tv1; Vector3 tv2; Vector3 tv3; if (byteVertices != null) { var bv1 = byteVertices[uindices[triangleIndex]].Position; var bv2 = byteVertices[uindices[triangleIndex + 1]].Position; var bv3 = byteVertices[uindices[triangleIndex + 2]].Position; tv1 = new Vector3(_globalMove.X + bv1.X, _globalMove.Y + bv1.Y, _globalMove.Z + bv1.Z); tv2 = new Vector3(_globalMove.X + bv2.X, _globalMove.Y + bv2.Y, _globalMove.Z + bv2.Z); tv3 = new Vector3(_globalMove.X + bv3.X, _globalMove.Y + bv3.Y, _globalMove.Z + bv3.Z); } else { tv1 = vertices[_indices[triangleIndex]]; tv2 = vertices[_indices[triangleIndex + 1]]; tv3 = vertices[_indices[triangleIndex + 2]]; } AffineTransform.Transform(ref tv1, ref worldTransform, out v1); AffineTransform.Transform(ref tv2, ref worldTransform, out v2); AffineTransform.Transform(ref tv3, ref worldTransform, out v3); }
/// <summary> /// Gets the world space position of a vertex in the terrain at the given indices. /// </summary> ///<param name="i">Index in the first dimension.</param> ///<param name="j">Index in the second dimension.</param> /// <param name="transform">Transform to apply to the vertex.</param> /// <param name="position">Transformed position of the vertex at the given indices.</param> public void GetPosition(int i, int j, ref AffineTransform transform, out Vector3 position) { if (i <= 0) { i = 0; } else if (i >= heights.GetLength(0)) { i = heights.GetLength(0) - 1; } if (j <= 0) { j = 0; } else if (j >= heights.GetLength(1)) { j = heights.GetLength(1) - 1; } #if !WINDOWS position = new Vector3(); #endif position.X = i; position.Y = heights[i, j]; position.Z = j; AffineTransform.Transform(ref position, ref transform, out position); }
protected override bool ConfigureTriangle(int i, out TriangleIndices indices) { MeshBoundingBoxTreeData data = mesh.Shape.TriangleMesh.Data; int triangleIndex = overlappedTriangles.Elements[i]; data.GetTriangle(triangleIndex, out localTriangleShape.vA, out localTriangleShape.vB, out localTriangleShape.vC); AffineTransform.Transform(ref localTriangleShape.vA, ref mesh.worldTransform, out localTriangleShape.vA); AffineTransform.Transform(ref localTriangleShape.vB, ref mesh.worldTransform, out localTriangleShape.vB); AffineTransform.Transform(ref localTriangleShape.vC, ref mesh.worldTransform, out localTriangleShape.vC); //In instanced meshes, the bounding box we found in local space could collect more triangles than strictly necessary. //By doing a second pass, we should be able to prune out quite a few of them. BoundingBox triangleAABB; Toolbox.GetTriangleBoundingBox(ref localTriangleShape.vA, ref localTriangleShape.vB, ref localTriangleShape.vC, out triangleAABB); bool toReturn; triangleAABB.Intersects(ref convex.boundingBox, out toReturn); if (!toReturn) { indices = new TriangleIndices(); return(false); } localTriangleShape.sidedness = mesh.sidedness; localTriangleShape.collisionMargin = 0; indices = new TriangleIndices() { A = data.indices[triangleIndex], B = data.indices[triangleIndex + 1], C = data.indices[triangleIndex + 2] }; return(true); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 13JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Returns the coordinates and type of the current path segment in * the iteration. * The return Value is the path segment type: * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. * A long array of length 6 must be passed in and may be used to * store the coordinates of the point(s). * Each point is stored as a pair of long x,y coordinates. * SEG_MOVETO and SEG_LINETO types will return one point, * SEG_QUADTO will return two points, * SEG_CUBICTO will return 3 points * and SEG_CLOSE will not return any points. * @see #SEG_MOVETO * @see #SEG_LINETO * @see #SEG_QUADTO * @see #SEG_CUBICTO * @see #SEG_CLOSE */ public override int CurrentSegment(int[] coords) { if (IsDone()) { throw new IndexOutOfRangeException("line iterator out of bounds"); } int type; if (_index == 0) { coords[0] = _line.X1; coords[1] = _line.Y1; type = SEG_MOVETO; } else { coords[0] = _line.X2; coords[1] = _line.Y2; type = SEG_LINETO; } if (_affine != null) { _affine.Transform(coords, 0, coords, 0, 1); } return(type); }
/** * Returns the coordinates and type of the current path segment in * the iteration. * The return Value is the path segment type: * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. * A double array of length 6 must be passed in and may be used to * store the coordinates of the point(s). * Each point is stored as a pair of double x,y coordinates. * SEG_MOVETO and SEG_LINETO types will return one point, * SEG_QUADTO will return two points, * SEG_CUBICTO will return 3 points * and SEG_CLOSE will not return any points. * @see #SEG_MOVETO * @see #SEG_LINETO * @see #SEG_QUADTO * @see #SEG_CUBICTO * @see #SEG_CLOSE */ public override int CurrentSegment(int[] coords) { if (IsDone()) { throw new IndexOutOfRangeException("cubic iterator iterator out of bounds"); } int type; if (_index == 0) { coords[0] = _cubic.GetX1(); coords[1] = _cubic.GetY1(); type = SEG_MOVETO; } else { coords[0] = _cubic.GetCtrlX1(); coords[1] = _cubic.GetCtrlY1(); coords[2] = _cubic.GetCtrlX2(); coords[3] = _cubic.GetCtrlY2(); coords[4] = _cubic.GetX2(); coords[5] = _cubic.GetY2(); type = SEG_CUBICTO; } if (_affine != null) { _affine.Transform(coords, 0, coords, 0, _index == 0 ? 1 : 3); } return(type); }
/// <summary> /// Gets the world space position of a vertex in the terrain at the given indices. /// </summary> ///<param name="columnIndex">Index in the first dimension.</param> ///<param name="rowIndex">Index in the second dimension.</param> /// <param name="transform">Transform to apply to the vertex.</param> /// <param name="position">Transformed position of the vertex at the given indices.</param> public void GetPosition(int columnIndex, int rowIndex, ref AffineTransform transform, out Vector3 position) { if (columnIndex <= 0) { columnIndex = 0; } else if (columnIndex >= heights.GetLength(0)) { columnIndex = heights.GetLength(0) - 1; } if (rowIndex <= 0) { rowIndex = 0; } else if (rowIndex >= heights.GetLength(1)) { rowIndex = heights.GetLength(1) - 1; } #if !WINDOWS position = new Vector3(); #endif position.X = columnIndex; position.Y = heights[columnIndex, rowIndex]; position.Z = rowIndex; AffineTransform.Transform(ref position, ref transform, out position); }
protected IList <Point> TransformPoints(IList <Point> points, AffineTransform transform) { foreach (Point point in points) { transform.Transform(point, point); } return(points); }
/// <summary> /// Casts a convex shape against the collidable. /// </summary> /// <param name="castShape">Shape to cast.</param> /// <param name="startingTransform">Initial transform of the shape.</param> /// <param name="sweep">Sweep to apply to the shape.</param> /// <param name="hit">Hit data, if any.</param> /// <returns>Whether or not the cast hit anything.</returns> public override bool ConvexCast(CollisionShapes.ConvexShapes.ConvexShape castShape, ref RigidTransform startingTransform, ref Vector3 sweep, out RayHit hit) { hit = new RayHit(); BoundingBox boundingBox; castShape.GetSweptLocalBoundingBox(ref startingTransform, ref worldTransform, ref sweep, out boundingBox); var tri = PhysicsThreadResources.GetTriangle(); var hitElements = CommonResources.GetIntList(); if (this.Shape.TriangleMesh.Tree.GetOverlaps(boundingBox, hitElements)) { hit.T = float.MaxValue; for (int i = 0; i < hitElements.Count; i++) { Shape.TriangleMesh.Data.GetTriangle(hitElements[i], out tri.vA, out tri.vB, out tri.vC); AffineTransform.Transform(ref tri.vA, ref worldTransform, out tri.vA); AffineTransform.Transform(ref tri.vB, ref worldTransform, out tri.vB); AffineTransform.Transform(ref tri.vC, ref worldTransform, out tri.vC); Vector3 center; Vector3.Add(ref tri.vA, ref tri.vB, out center); Vector3.Add(ref center, ref tri.vC, out center); Vector3.Multiply(ref center, 1f / 3f, out center); Vector3.Subtract(ref tri.vA, ref center, out tri.vA); Vector3.Subtract(ref tri.vB, ref center, out tri.vB); Vector3.Subtract(ref tri.vC, ref center, out tri.vC); tri.MaximumRadius = tri.vA.LengthSquared(); float radius = tri.vB.LengthSquared(); if (tri.MaximumRadius < radius) { tri.MaximumRadius = radius; } radius = tri.vC.LengthSquared(); if (tri.MaximumRadius < radius) { tri.MaximumRadius = radius; } tri.MaximumRadius = (float)Math.Sqrt(tri.MaximumRadius); tri.collisionMargin = 0; var triangleTransform = new RigidTransform { Orientation = Quaternion.Identity, Position = center }; RayHit tempHit; if (MPRToolbox.Sweep(castShape, tri, ref sweep, ref Toolbox.ZeroVector, ref startingTransform, ref triangleTransform, out tempHit) && tempHit.T < hit.T) { hit = tempHit; } } tri.MaximumRadius = 0; PhysicsThreadResources.GiveBack(tri); CommonResources.GiveBack(hitElements); return(hit.T != float.MaxValue); } PhysicsThreadResources.GiveBack(tri); CommonResources.GiveBack(hitElements); return(false); }
protected override bool ConfigureTriangle(int i, out TriangleIndices indices) { MeshBoundingBoxTreeData data = mesh.Shape.TriangleMesh.Data; int triangleIndex = overlappedTriangles.Elements[i]; data.GetTriangle(triangleIndex, out localTriangleShape.vA, out localTriangleShape.vB, out localTriangleShape.vC); AffineTransform transform; AffineTransform.CreateFromRigidTransform(ref mesh.worldTransform, out transform); AffineTransform.Transform(ref localTriangleShape.vA, ref transform, out localTriangleShape.vA); AffineTransform.Transform(ref localTriangleShape.vB, ref transform, out localTriangleShape.vB); AffineTransform.Transform(ref localTriangleShape.vC, ref transform, out localTriangleShape.vC); //In instanced meshes, the bounding box we found in local space could collect more triangles than strictly necessary. //By doing a second pass, we should be able to prune out quite a few of them. BoundingBox triangleAABB; Toolbox.GetTriangleBoundingBox(ref localTriangleShape.vA, ref localTriangleShape.vB, ref localTriangleShape.vC, out triangleAABB); bool toReturn; triangleAABB.Intersects(ref convex.boundingBox, out toReturn); if (!toReturn) { indices = new TriangleIndices(); return(false); } TriangleSidedness sidedness; switch (mesh.Shape.solidity) { case MobileMeshSolidity.Clockwise: sidedness = TriangleSidedness.Clockwise; break; case MobileMeshSolidity.Counterclockwise: sidedness = TriangleSidedness.Counterclockwise; break; case MobileMeshSolidity.DoubleSided: sidedness = TriangleSidedness.DoubleSided; break; default: sidedness = mesh.Shape.solidSidedness; break; } localTriangleShape.sidedness = sidedness; localTriangleShape.collisionMargin = 0; indices = new TriangleIndices() { A = data.uindices[triangleIndex], B = data.uindices[triangleIndex + 1], C = data.uindices[triangleIndex + 2] }; return(true); }
/** * Returns the coordinates and type of the current path segment in * the iteration. * The return Value is the path segment type: * SEG_MOVETO, SEG_LINETO, or SEG_CLOSE. * A <code>int</code> array of length 2 must be passed in and * can be used to store the coordinates of the point(s). * Each point is stored as a pair of <code>int</code> x, y * coordinates. SEG_MOVETO and SEG_LINETO types return one * point, and SEG_CLOSE does not return any points. * @param coords a <code>int</code> array that specifies the * coordinates of the point(s) * @return an integer representing the type and coordinates of the * current path segment. */ public override int CurrentSegment(int[] coords) { coords[0] = _poly.Xpoints[_index]; coords[1] = _poly.Ypoints[_index]; if (_transform != null) { _transform.Transform(coords, 0, coords, 0, 1); } return(_index == 0 ? SEG_MOVETO : SEG_LINETO); }
private Rectangle CalcImageRect(ImageRenderInfo renderInfo) { Matrix ctm = renderInfo.GetImageCTM(); if (ctm == null) { return(null); } AffineTransform t = new AffineTransform(ctm[Matrix.I11], ctm[Matrix.I12], ctm[Matrix.I21], ctm[Matrix.I22], ctm[Matrix.I31], ctm[Matrix.I32]); Point2D p1 = t.Transform(new Point(0, 0), null); Point2D p2 = t.Transform(new Point(0, 1), null); Point2D p3 = t.Transform(new Point(1, 0), null); Point2D p4 = t.Transform(new Point(1, 1), null); return(GetRectangle(p1, p2, p3, p4)); }
private void MoveShape(Point start, Point end) { if (CurrentState.IsMoveShape == false) { return; } AffineTransform affine = new AffineTransform(); affine.Translate(end.X - start.X, end.Y - start.Y); foreach (Shape currShape in ListOfInstances) { if (currShape.IsChosen == true) { currShape.PixelsInLine = affine.Transform(savedPointInLine); currShape.PixelsInArea = affine.Transform(savedPointInArea); } } }
private IList <Point> TransformBBox(float left, float bottom, float right, float top, AffineTransform transform , IList <Point> bBoxPoints) { bBoxPoints.AddAll(iText.IO.Util.JavaUtil.ArraysAsList(new Point(left, bottom), new Point(right, bottom), new Point(right, top), new Point(left, top))); foreach (Point point in bBoxPoints) { transform.Transform(point, point); } return(bBoxPoints); }
/// <summary>Evaluates the minimal domain that covers the box with vector normals.</summary> /// <remarks> /// Evaluates the minimal domain that covers the box with vector normals. /// The domain corresponding to the initial vector is [0, 1]. /// </remarks> /// <param name="coords"> /// the array of exactly two elements that describe /// the base vector (corresponding to [0,1] domain, that need to be adjusted /// to cover the box /// </param> /// <param name="toCover">the box that needs to be covered</param> /// <returns> /// the array of two elements in ascending order specifying the calculated covering /// domain /// </returns> protected internal static double[] EvaluateCoveringDomain(Point[] coords, Rectangle toCover) { if (toCover == null) { return(new double[] { 0d, 1d }); } AffineTransform transform = new AffineTransform(); double scale = 1d / (coords[0].Distance(coords[1])); double sin = -(coords[1].GetY() - coords[0].GetY()) * scale; double cos = (coords[1].GetX() - coords[0].GetX()) * scale; if (Math.Abs(cos) < ZERO_EPSILON) { cos = 0d; sin = sin > 0d ? 1d : -1d; } else { if (Math.Abs(sin) < ZERO_EPSILON) { sin = 0d; cos = cos > 0d ? 1d : -1d; } } transform.Concatenate(new AffineTransform(cos, sin, -sin, cos, 0, 0)); transform.Scale(scale, scale); transform.Translate(-coords[0].GetX(), -coords[0].GetY()); Point[] rectanglePoints = toCover.ToPointsArray(); double minX = transform.Transform(rectanglePoints[0], null).GetX(); double maxX = minX; for (int i = 1; i < rectanglePoints.Length; ++i) { double currentX = transform.Transform(rectanglePoints[i], null).GetX(); minX = Math.Min(minX, currentX); maxX = Math.Max(maxX, currentX); } return(new double[] { minX, maxX }); }
/** * Returns the coordinates and type of the current path segment in * the iteration. * The return Value is the path segment type: * SEG_MOVETO, SEG_LINETO, or SEG_CLOSE. * A <code>int</code> array of length 2 must be passed in and * can be used to store the coordinates of the point(s). * Each point is stored as a pair of <code>int</code> x, y * coordinates. SEG_MOVETO and SEG_LINETO types return one * point, and SEG_CLOSE does not return any points. * @param coords a <code>int</code> array that specifies the * coordinates of the point(s) * @return an integer representing the type and coordinates of the * current path segment. */ public override int CurrentSegment(int[] coords) { if (index >= poly.NumOfNpoints) { return(SEG_CLOSE); } coords[0] = poly.Xpoints[index]; coords[1] = poly.Ypoints[index]; if (transform != null) { transform.Transform(coords, 0, coords, 0, 1); } return(index == 0 ? SEG_MOVETO : SEG_LINETO); }
/// <summary> /// Returns the bounding box of the transformed destination. The /// rectangle returned will be the actual bounding box of the /// transformed points. The coordinates of the upper-left corner /// of the returned rectangle might not be (0, 0). /// </summary> /// <param name="src"> The <CODE>Raster</CODE> to be transformed. /// </param> /// <returns> The <CODE>Rectangle2D</CODE> representing the destination's /// bounding box. </returns> public Rectangle2D GetBounds2D(Raster src) { int w = src.Width; int h = src.Height; // Get the bounding box of the src and transform the corners float[] pts = new float[] { 0, 0, w, 0, w, h, 0, h }; Xform.Transform(pts, 0, pts, 0, 4); // Get the min, max of the dst float fmaxX = pts[0]; float fmaxY = pts[1]; float fminX = pts[0]; float fminY = pts[1]; for (int i = 2; i < 8; i += 2) { if (pts[i] > fmaxX) { fmaxX = pts[i]; } else if (pts[i] < fminX) { fminX = pts[i]; } if (pts[i + 1] > fmaxY) { fmaxY = pts[i + 1]; } else if (pts[i + 1] < fminY) { fminY = pts[i + 1]; } } return(new Rectangle2D.Float(fminX, fminY, fmaxX - fminX, fmaxY - fminY)); }
private Point[] TransformPoints(Matrix transformationMatrix, params Point[] points) { try { AffineTransform t = new AffineTransform(transformationMatrix.Get(Matrix.I11), transformationMatrix.Get(Matrix .I12), transformationMatrix.Get(Matrix.I21), transformationMatrix.Get(Matrix.I22), transformationMatrix .Get(Matrix.I31), transformationMatrix.Get(Matrix.I32)); t = t.CreateInverse(); Point[] transformed = new Point[points.Length]; t.Transform(points, 0, transformed, 0, points.Length); return(transformed); } catch (NoninvertibleTransformException e) { throw new Exception(e.Message, e); } }
///<summary> /// Gets the position of a vertex in the data. ///</summary> ///<param name="i">Index of the vertex.</param> ///<param name="vertex">Position of the vertex.</param> public override void GetVertexPosition(int i, out Vector3 vertex) { Vector3 v; if (byteVertices != null) { var bv = byteVertices[i].Position; v = new Vector3(_globalMove.X + bv.X, _globalMove.Y + bv.Y, _globalMove.Z + bv.Z); } else { v = vertices[i]; } AffineTransform.Transform(ref v, ref worldTransform, out vertex); }
/** * Returns the coordinates and type of the current path segment in * the iteration. * The return Value is the path segment type: * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. * A int array of length 6 must be passed in and may be used to * store the coordinates of the point(s). * Each point is stored as a pair of int x,y coordinates. * SEG_MOVETO and SEG_LINETO types will return one point, * SEG_QUADTO will return two points, * SEG_CUBICTO will return 3 points * and SEG_CLOSE will not return any points. * @see #SEG_MOVETO * @see #SEG_LINETO * @see #SEG_QUADTO * @see #SEG_CUBICTO * @see #SEG_CLOSE */ public override int CurrentSegment(int[] coords) { if (IsDone()) { throw new IndexOutOfRangeException("ellipse iterator out of bounds"); } if (_index == 5) { return(SEG_CLOSE); } if (_index == 0) { double[] ctrls = Ctrlpts[3]; coords[0] = (int)(_x + ctrls[4] * _w + .5); coords[1] = (int)(_y + ctrls[5] * _h + .5); if (_affine != null) { _affine.Transform(coords, 0, coords, 0, 1); } return(SEG_MOVETO); } { double[] ctrls = Ctrlpts[_index - 1]; coords[0] = (int)(_x + ctrls[0] * _w + .5); coords[1] = (int)(_y + ctrls[1] * _h + .5); coords[2] = (int)(_x + ctrls[2] * _w + .5); coords[3] = (int)(_y + ctrls[3] * _h + .5); coords[4] = (int)(_x + ctrls[4] * _w + .5); coords[5] = (int)(_y + ctrls[5] * _h + .5); if (_affine != null) { _affine.Transform(coords, 0, coords, 0, 3); } } return(SEG_CUBICTO); }
virtual public PdfRectangle Transform(AffineTransform transform) { float[] pts = { llx, lly, urx, ury }; transform.Transform(pts, 0, pts, 0, 2); float[] dstPts = { pts[0], pts[1], pts[2], pts[3] }; if (pts[0] > pts[2]) { dstPts[0] = pts[2]; dstPts[2] = pts[0]; } if (pts[1] > pts[3]) { dstPts[1] = pts[3]; dstPts[3] = pts[1]; } return(new PdfRectangle(dstPts[0], dstPts[1], dstPts[2], dstPts[3])); }
private Point2D[] TransformPoints(Matrix transormationMatrix, bool inverse, params Point2D[] points) { AffineTransform t = new AffineTransform(transormationMatrix[Matrix.I11], transormationMatrix[Matrix.I12], transormationMatrix[Matrix.I21], transormationMatrix[Matrix.I22], transormationMatrix[Matrix.I31], transormationMatrix[Matrix.I32]); Point2D[] transformed = new Point2D[points.Length]; if (inverse) { t = t.CreateInverse(); } t.Transform(points, 0, transformed, 0, points.Length); return(transformed); }
public void InverseAffineTransformationTest () { //Local coordinate system MNAU (Kraftwerk Mäuserich) (based on Gau?Krüger using affine transformation) // affine transform // 1) Offset: X=-3454886,640m Y=-5479481,278m; // 2)Rotation: 332,0657, Rotation point X=3456926,640m Y=5481071,278m; // 3) Scale: 1.0 //TODO MathTransformFactory fac = new MathTransformFactory (); double[,] matrix = new double[,] {{0.883485346527455, -0.468458794848877, 3455869.17937689}, {0.468458794848877, 0.883485346527455, 5478710.88035753}, {0.0 , 0.0, 1},}; IMathTransform mt = new AffineTransform (matrix); Assert.IsNotNull (mt); Assert.AreEqual (2, mt.DimSource); Assert.AreEqual (2, mt.DimTarget); //Transformation example (MNAU -> GK) // Start point (MNAU) X=2040,000m Y=1590,000m] // Target point (GK): X=3456926,640m Y=5481071,278m; //check source transform double[] outPt = mt.Transform (new double[] { 2040.0, 1590.0 }); Assert.AreEqual (2, outPt.Length); Assert.AreEqual (3456926.640, outPt[0], 0.00000001); Assert.AreEqual (5481071.278, outPt[1], 0.00000001); IMathTransform invMt = mt.Inverse (); double[] inPt = invMt.Transform (new double[] { 3456926.640, 5481071.278 }); Assert.AreEqual (2, inPt.Length); Assert.AreEqual (2040.0, inPt[0], 0.00000001); Assert.AreEqual (1590.0, inPt[1], 0.00000001); //check source transform - once more double[] outPt2 = mt.Transform (new double[] { 2040.0, 1590.0 }); Assert.AreEqual (2, outPt2.Length); Assert.AreEqual (3456926.640, outPt2[0], 0.00000001); Assert.AreEqual (5481071.278, outPt2[1], 0.00000001); }