private void ComputePositions(Particle p, Point3DCollection list) { double size = p.Size; Vector center = new Vector(p.Position.X, p.Position.Y); //najdeme body Vector p1 = new Vector(p.Position.X - size, p.Position.Y - size); Vector p2 = new Vector(p.Position.X - size, p.Position.Y + size); Vector p3 = new Vector(p.Position.X + size, p.Position.Y + size); Vector p4 = new Vector(p.Position.X + size, p.Position.Y - size); //pokud ma particle rotaci orotujeme if (p.Rotation > 0) { p1 = p1.Rotate(p.Rotation, center); p2 = p2.Rotate(p.Rotation, center); p3 = p3.Rotate(p.Rotation, center); p4 = p4.Rotate(p.Rotation, center); } double z = p.Position.Z; list.Add(new Point3D(p1.X, p1.Y, z)); list.Add(new Point3D(p2.X, p2.Y, z)); list.Add(new Point3D(p3.X, p3.Y, z)); list.Add(new Point3D(p4.X, p4.Y, z)); }
/// <summary> /// Updates the view of a simulation model for an /// aggregate on a 2D lattice. /// </summary> public void Update() { // get the most recently added particle AggregateParticle p = particle_stack.Peek(); int position_index = particle_stack.Count * 4; // add points to particle positions collection particle_positions.Add(new Point3D(p.position.X, p.position.Y, p.position.Z)); particle_positions.Add(new Point3D(p.position.X, p.position.Y + p.size, p.position.Z)); particle_positions.Add(new Point3D(p.position.X + p.size, p.position.Y + p.size, p.position.Z)); particle_positions.Add(new Point3D(p.position.X + p.size, p.position.Y, p.position.Z)); // add texture co-ords points to texcoords collection tex_coords.Add(new Point(0.0, 0.0)); tex_coords.Add(new Point(0.0, 1.0)); tex_coords.Add(new Point(1.0, 1.0)); tex_coords.Add(new Point(1.0, 0.0)); // add position indices to indices collection triangle_indices.Add(position_index); triangle_indices.Add(position_index + 2); triangle_indices.Add(position_index + 1); triangle_indices.Add(position_index); triangle_indices.Add(position_index + 3); triangle_indices.Add(position_index + 2); // set particle_model Geometry model properties rad_brush.GradientStops.Add(new GradientStop(p.colour, 0.0)); render_bitmap.Render(ellipse); }
private void ajouterLigne(Point3D p1, Point3D p2, Color color, float thickness) { bufSkel.Add(p1); bufSkel.Add(p2); lignes.Color = color; lignes.Thickness = thickness; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { /* No lines, OK, don't render anything */ if (value == null) { return(null); } var inputPoints = value as ObservableCollection <Line3D>; if (inputPoints == null) { /* If not a list of points...bug, so throw exception */ throw new Exception("Invalid Convesion Point, must provide ObservableCollection of Line3D"); } var outputPoints = new Point3DCollection(); foreach (var inputPoint in inputPoints) { outputPoints.Add(new Point3D() { X = inputPoint.Start.X, Y = inputPoint.Start.Y, Z = inputPoint.Start.Z }); outputPoints.Add(new Point3D() { X = inputPoint.End.X, Y = inputPoint.End.Y, Z = inputPoint.End.Z }); } return(outputPoints); }
/* internal void drawLine(Point3D start, Point3D pt, bool hit) * { * TubeVisual3D line; * lines.TryGetValue(start, out line); * * if (line != null) * { * this.Children.Remove(line); * lines.Remove(start); * } * Point3DCollection contours = new Point3DCollection(); * contours.Add(ToWorld(start)); * contours.Add(ToWorld(pt)); * line = new TubeVisual3D { Diameter = 0.5, Path = contours, Fill = Brushes.SandyBrown }; * lines.Add(start,line); * this.Children.Add(line); * * addBox(start); * if(hit) addBox(pt); * } */ internal void drawLine(Point3D start, Point3D end) { TubeVisual3D line; lines.TryGetValue(start, out line); if (line != null) { this.Children.Remove(line); lines.Remove(start); } Point3DCollection contours = new Point3DCollection(); contours.Add(ToWorld(start)); contours.Add(ToWorld(end)); line = new TubeVisual3D { Diameter = 0.3, Path = contours, Fill = Brushes.DarkOliveGreen }; lines.Add(start, line); this.Children.Add(line); string x = string.Format("{0:0.00}", end.X); string y = string.Format("{0:0.00}", end.Y); string z = string.Format("{0:0.00}", end.Z); string text = x + "," + y + "," + z; addBox(start); addBox(end); add3DText(end, text); }
private void AddSegment(Point3DCollection positions, Point3D startPoint, Point3D endPoint, double halfThickness) { // NOTE: We want the vector below to be perpendicular post projection so // we need to compute the line direction in post-projective space. Vector3D lineDirection = endPoint * _visualToScreen - startPoint * _visualToScreen; lineDirection.Z = 0; lineDirection.Normalize(); // NOTE: Implicit Rot(90) during construction to get a perpendicular vector. Vector delta = new Vector(-lineDirection.Y, lineDirection.X); delta *= halfThickness; Point3D pOut1, pOut2; Widen(startPoint, delta, out pOut1, out pOut2); positions.Add(pOut1); positions.Add(pOut2); Widen(endPoint, delta, out pOut1, out pOut2); positions.Add(pOut1); positions.Add(pOut2); }
public void Update() { if (p == null) { return; } if (!is_done) { int position_index = id * 4; // add points to particle positions collection particle_positions.Add(new Point3D(p.position.X, p.position.Y, p.position.Z)); particle_positions.Add(new Point3D(p.position.X, p.position.Y + p.size, p.position.Z)); particle_positions.Add(new Point3D(p.position.X + p.size, p.position.Y + p.size, p.position.Z)); particle_positions.Add(new Point3D(p.position.X + p.size, p.position.Y, p.position.Z)); // add texture co-ords points to texcoords collection tex_coords.Add(new Point(0.0, 0.0)); tex_coords.Add(new Point(0.0, 1.0)); tex_coords.Add(new Point(1.0, 1.0)); tex_coords.Add(new Point(1.0, 0.0)); // add position indices to indices collection triangle_indices.Add(position_index); triangle_indices.Add(position_index + 2); triangle_indices.Add(position_index + 1); triangle_indices.Add(position_index); triangle_indices.Add(position_index + 3); triangle_indices.Add(position_index + 2); //is_done = true; } }
private void init() { DirectionalLight qLight = new DirectionalLight(); const double pi = 1.4142135623730950488016887242097; Point3DCollection positionspoitnr = new Point3DCollection(); const double pi_2minus = 2.4494897427831780981972840747059; Int32Collection tringalesofshape = new Int32Collection(); //init tringalesofshape.Add(0); tringalesofshape.Add(3); tringalesofshape.Add(2); tringalesofshape.Add(0); tringalesofshape.Add(2); tringalesofshape.Add(1); tringalesofshape.Add(1); tringalesofshape.Add(2); tringalesofshape.Add(3); tringalesofshape.Add(0); tringalesofshape.Add(1); tringalesofshape.Add(3); positionspoitnr.Add(new Point3D(-pi / 3.0, -1.0 / 3.0, pi_2minus / 3.0)); positionspoitnr.Add(new Point3D(-pi / 3.0, -1.0 / 3.0, -pi_2minus / 3.0)); positionspoitnr.Add(new Point3D(0.0, 1.0, 0.0)); positionspoitnr.Add(new Point3D(2.0 * pi / 3.0, -1.0 / 3.0, 0.0)); MeshGeometry3D qMesh = new MeshGeometry3D(); tr.Positions = positionspoitnr; tr.TriangleIndices = tringalesofshape; }
/// <summary> /// 依照更新完的描述子渲染前端 /// </summary> private void UpdateGeometry() { Point3DCollection positions = new Point3DCollection(); Int32Collection indices = new Int32Collection(); PointCollection texcoords = new PointCollection(); for (int i = 0; i < this.particleList.Count; ++i) { int positionIndex = i * 4; ParticleDescriptor3D p = this.particleList[i]; Point3D p1 = new Point3D(p.Position.X, p.Position.Y, p.Position.Z); Point3D p2 = new Point3D(p.Position.X, p.Position.Y + p.Size, p.Position.Z); Point3D p3 = new Point3D(p.Position.X + p.Size, p.Position.Y + p.Size, p.Position.Z); Point3D p4 = new Point3D(p.Position.X + p.Size, p.Position.Y, p.Position.Z); positions.Add(p1); positions.Add(p2); positions.Add(p3); positions.Add(p4); texcoords.Add(renderDirectionT1); texcoords.Add(renderDirectionT2); texcoords.Add(renderDirectionT3); texcoords.Add(renderDirectionT4); indices.Add(positionIndex); indices.Add(positionIndex + 2); indices.Add(positionIndex + 1); indices.Add(positionIndex); indices.Add(positionIndex + 3); indices.Add(positionIndex + 2); } ((MeshGeometry3D)this.particleModel.Geometry).Positions = positions; ((MeshGeometry3D)this.particleModel.Geometry).TriangleIndices = indices; ((MeshGeometry3D)this.particleModel.Geometry).TextureCoordinates = texcoords; }
/// <summary> /// Sets the coordinates of all the individual lines in the visual. /// </summary> /// <param name="args"> /// The <c>DependencyPropertyChangedEventArgs</c> object associated /// with the property-changed event that resulted in this method /// being called. /// </param> /// <param name="lines"> /// The <c>Point3DCollection</c> to be filled. /// </param> /// <remarks> /// <para> /// Classes that derive from <c>WireBase</c> override this /// method to fill the <c>lines</c> collection. /// It is custmary for implementations of this method to clear /// the <c>lines</c> collection first before filling it. /// Each pair of successive members of the <c>lines</c> /// collection indicate one straight line. /// </para> /// <para> /// The <c>WireLine</c> class implements this method by /// clearing the <c>lines</c> collection and then adding /// <c>Point1</c> and <c>Point2</c> to the collection. /// </para> /// </remarks> protected override void Generate(DependencyPropertyChangedEventArgs args, Point3DCollection lines) { lines.Clear(); lines.Add(Point1); lines.Add(Point2); }
private GeometryModel3D Triangle(double x, double y, double s) { //define the geometry as a set of points and order the points are connected up Point3DCollection corners = new Point3DCollection(); corners.Add(new Point3D(x, y, 0)); corners.Add(new Point3D(x, y + s, 0)); corners.Add(new Point3D(x + s, y + s, 0)); Int32Collection Triangles = new Int32Collection(); Triangles.Add(0); Triangles.Add(1); Triangles.Add(2); //After the geometry is defined MeshGeometry3D tmesh = new MeshGeometry3D(); tmesh.Positions = corners; tmesh.TriangleIndices = Triangles; //Defines the normal vector tmesh.Normals.Add(new Vector3D(0, 0, -1)); //Puts the geometry together with some material properties GeometryModel3D msheet = new GeometryModel3D(); msheet.Geometry = tmesh; return(msheet); }
public MainWindow() { InitializeComponent(); this.Loaded += MainWindow_Loaded; MeshGeometry3D mesh = new MeshGeometry3D(); PointCollection textures = new PointCollection(); textures.Add(new Point(0, 0)); textures.Add(new Point(0, 1)); textures.Add(new Point(1, 1)); textures.Add(new Point(1, 0)); Point3DCollection asd = new Point3DCollection(); asd.Add(new Point3D(-1, 1, 0)); asd.Add(new Point3D(-1, -1, 0)); asd.Add(new Point3D(1, -1, 0)); asd.Add(new Point3D(1, 1, 0)); Int32Collection TIndex = new Int32Collection(); TIndex.Add(0); TIndex.Add(1); TIndex.Add(2); TIndex.Add(0); TIndex.Add(2); TIndex.Add(3); mesh.Positions = asd; mesh.TriangleIndices = TIndex; mesh.TextureCoordinates = textures; v2dv3d.Geometry = mesh; }
private void CreateDashLine(AxisGrid.AxisDash axisdash, List <TickInfo> horTicks, List <TickInfo> verTicks) { Point3DCollection dashPnts = new Point3DCollection(); double hGap = _length / (double)axisdash.HDashCount; double vGap = _length / (double)axisdash.VDashCount; Vector3D hV = hGap * axisdash.HVector; Vector3D vV = vGap * axisdash.VVector; Point3D originalPnt = new Point3D(0.0, 0.0, 0.0); for (int i = 1; i < horTicks.Count - 1; i++) { for (int j = 0; j <= axisdash.HDashCount; j++) { dashPnts.Add(originalPnt + hV * (double)j + horTicks[i].AxisValue * axisdash.VVector); } } for (int i = 1; i < verTicks.Count - 1; i++) { for (int j = 0; j <= axisdash.VDashCount; j++) { dashPnts.Add(originalPnt + vV * (double)j + verTicks[i].AxisValue * axisdash.HVector); } } axisdash.Points3D.Color = Colors.Blue; axisdash.Points3D.Points = dashPnts; }
/// <summary> /// Draw a window /// </summary> /// <param name="material">Brush for the window.</param> /// <param name="p1">Bottom left corner point of the window.</param> /// <param name="p2">Top right corner point of the window.</param> private void DrawRectangle(Material material, Point3D p1, Point3D p2) { // The geometry specifes the shape of the 3D plane. MeshGeometry3D winGeometry = new MeshGeometry3D(); // Create a collection of vertex positions for the MeshGeometry3D. Point3DCollection winPositions = new Point3DCollection(); winPositions.Add(new Point3D(p1.X, p1.Y, p2.Z)); winPositions.Add(p1); winPositions.Add(p2); winPositions.Add(new Point3D(p2.X, p2.Y, p1.Z)); winGeometry.Positions = winPositions; // Create a collection of triangle indices for the MeshGeometry3D. Int32Collection winTriangleIndices = new Int32Collection(); winTriangleIndices.Add(0); winTriangleIndices.Add(1); winTriangleIndices.Add(2); winTriangleIndices.Add(1); winTriangleIndices.Add(3); winTriangleIndices.Add(2); winGeometry.TriangleIndices = winTriangleIndices; // Draw the window GeometryModel3D window = new GeometryModel3D(winGeometry, material); exteriorWalls.Children.Add(window); }
void DoLine(Point3D pt1, Point3D pt2, Point3DCollection points, Int32Collection indices, ref int indicesBase) { Point3D pt1Screen = pt1 * matxVisualToScreen; Point3D pt2Screen = pt2 * matxVisualToScreen; Vector3D vectLine = pt2Screen - pt1Screen; vectLine.Z = 0; vectLine.Normalize(); Vector delta = (Thickness / 2) * new Vector(-vectLine.Y, vectLine.X); points.Add(Widen(pt1, delta)); points.Add(Widen(pt1, -delta)); points.Add(Widen(pt2, delta)); points.Add(Widen(pt2, -delta)); indices.Add(indicesBase); indices.Add(indicesBase + 2); indices.Add(indicesBase + 1); indices.Add(indicesBase + 1); indices.Add(indicesBase + 2); indices.Add(indicesBase + 3); indicesBase += 4; if (Rounding > 0) { AddRounding(pt1, delta, points, indices, ref indicesBase); AddRounding(pt2, -delta, points, indices, ref indicesBase); } }
public static Geometry3D Quad(Point3D center, Vector size) { MeshGeometry3D quadMesh = new MeshGeometry3D(); Point3DCollection vertices = new Point3DCollection(4); vertices.Add(new Point3D(center.X - size.X / 2, 0, center.Y - size.Y / 2)); vertices.Add(new Point3D(center.X + size.X / 2, 0, center.Y - size.Y / 2)); vertices.Add(new Point3D(center.X + size.X / 2, 0, center.Y + size.Y / 2)); vertices.Add(new Point3D(center.X - size.X / 2, 0, center.Y + size.Y / 2)); Int32Collection indices = new Int32Collection(6); indices.Add(0); indices.Add(2); indices.Add(1); indices.Add(0); indices.Add(3); indices.Add(2); PointCollection texCoords = new PointCollection(4); texCoords.Add(new Point(0, 0)); texCoords.Add(new Point(1, 0)); texCoords.Add(new Point(1, 1)); texCoords.Add(new Point(0, 1)); quadMesh.Positions = vertices; quadMesh.TriangleIndices = indices; quadMesh.TextureCoordinates = texCoords; return(quadMesh); }
protected void CreatePositionsAndIndices(double thickness = 1.0, double depthOffset = 0.0) { Points = new Point3DCollection(); GeometryModel3D geomModel = _model.Content as GeometryModel3D; MeshGeometry3D mesh = geomModel.Geometry as MeshGeometry3D; double halfThickness = 0.5 * thickness; int segmentCount = mesh.TriangleIndices.Count; for (int i = 0; i < segmentCount; i += 3) { var p0 = mesh.Positions [mesh.TriangleIndices [i]]; var p1 = mesh.Positions [mesh.TriangleIndices [i + 1]]; var p2 = mesh.Positions [mesh.TriangleIndices [i + 2]]; Point3DCollection tmp = CreateSegment(p0, p1, halfThickness, depthOffset); foreach (Point3D pt in tmp) { Points.Add(pt); } tmp = CreateSegment(p1, p2, halfThickness, depthOffset); foreach (Point3D pt in tmp) { Points.Add(pt); } tmp = CreateSegment(p2, p0, halfThickness, depthOffset); foreach (Point3D pt in tmp) { Points.Add(pt); } } CreateIndices(); }
private Point3DCollection InitializePositions(Int32 parallels, Int32 meridians) { var positions = new Point3DCollection(parallels * (meridians + 1) + 2); Double dPhi = Math.PI / (parallels + 1); Double dTheta = 2d * Math.PI / meridians; positions.Add(new Point3D(0, 1, 0)); for (Int32 parallel = 1; parallel <= parallels; parallel++) { Double phi = dPhi * parallel; Double y, r; GetYR(phi, out y, out r); for (Int32 meridian = 0; meridian <= meridians; meridian++) { Double theta = dTheta * meridian; Double x, z; GetXZ(theta, out x, out z); positions.Add(new Point3D(x * r, y, z * r)); } } positions.Add(new Point3D(0, -1, 0)); return(positions); }
public void backside(double x, double y, double z, ref GeometryModel3D side, DiffuseMaterial material1, DiffuseMaterial material2) { MeshGeometry3D mymeshgeometry3D6 = new MeshGeometry3D(); Point3DCollection myPositionCollection6 = new Point3DCollection(); PointCollection myTextureCoordinatesCollection6 = new PointCollection(); Int32Collection myTriangleIndicesCollection6 = new Int32Collection(); myPositionCollection6.Add(new Point3D(-x, 0, -z)); myPositionCollection6.Add(new Point3D(-x, y, -z)); myPositionCollection6.Add(new Point3D(x, y, -z)); myPositionCollection6.Add(new Point3D(x, 0, -z)); myTriangleIndicesCollection6.Add(0); myTriangleIndicesCollection6.Add(1); myTriangleIndicesCollection6.Add(2); myTriangleIndicesCollection6.Add(0); myTriangleIndicesCollection6.Add(2); myTriangleIndicesCollection6.Add(3); myTextureCoordinatesCollection6.Add(new Point(0, 1)); myTextureCoordinatesCollection6.Add(new Point(0, 0)); myTextureCoordinatesCollection6.Add(new Point(1, 0)); myTextureCoordinatesCollection6.Add(new Point(1, 1)); mymeshgeometry3D6.Positions = myPositionCollection6; mymeshgeometry3D6.TextureCoordinates = myTextureCoordinatesCollection6; mymeshgeometry3D6.TriangleIndices = myTriangleIndicesCollection6; side.Geometry = mymeshgeometry3D6; side.Material = material1; side.BackMaterial = material2; }
/// <summary> /// Sets the coordinates of all the individual lines in the visual. /// </summary> /// <param name="args"> /// The <c>DependencyPropertyChangedEventArgs</c> object associated /// with the property-changed event that resulted in this method /// being called. /// </param> /// <param name="lines"> /// The <c>Point3DCollection</c> to be filled. /// </param> /// <remarks> /// <para> /// Classes that derive from <c>WireBase</c> override this /// method to fill the <c>lines</c> collection. /// It is custmary for implementations of this method to clear /// the <c>lines</c> collection first before filling it. /// Each pair of successive members of the <c>lines</c> /// collection indicate one straight line. /// </para> /// </remarks> protected override void Generate(DependencyPropertyChangedEventArgs args, Point3DCollection lines) { lines.Clear(); if (Data == null) { return; } Transform3D xform = Data.Transform; foreach (PathFigure3D fig in Data.Figures) { PathFigure3D figFlattened = fig.GetFlattenedPathFigure(); Point3D pointStart = xform.Transform(figFlattened.StartPoint); foreach (PathSegment3D seg in figFlattened.Segments) { PolyLineSegment3D segPoly = seg as PolyLineSegment3D; for (int i = 0; i < segPoly.Points.Count; i++) { lines.Add(pointStart); Point3D point = xform.Transform(segPoly.Points[i]); lines.Add(point); pointStart = point; } } } }
/// <summary> /// Формирование Point3DCollection для Path для конкретного этажа /// </summary> public static Point3DCollection PathToPoint3DCollection(List <Vertex> vertexsList, int layerID, Graph graph) { //var vertexsList = FindPathVertex(destPoint, destPointLayerID, graph); if (vertexsList == null || vertexsList.Count == 0 || graph.StartVertex == null) { return(null); } var points = new Point3DCollection(); //построение пути на этаже с учетом того, что путь может прерываться for (int i = 0; i < vertexsList.Count(); i++) { var vertex = vertexsList[i]; if (i > 0) { var prevVertex = vertexsList[i - 1]; if ((prevVertex.Layer.LayerID == layerID) && (vertex.Layer.LayerID == layerID)) { points.Add(new Point3D(prevVertex.Point.Y, prevVertex.Point.X, 3)); points.Add(new Point3D(vertex.Point.Y, vertex.Point.X, 3)); } } } return(points); }
/// <summary> /// Returns the scaled positions of this wall (scaled by Web Mercator Projection: http://en.wikipedia.org/wiki/Web_Mercator) /// </summary> /// <param name="nodesDict">List of all the nodes on the map</param> /// <param name="map">bounds of the map</param> /// <returns>List of scaled positions</returns> private Point3DCollection getScaledPositionsWall(Dictionary <long, OsmSharp.Osm.Node> nodesDict, Map map) { Point3DCollection positions = new Point3DCollection(); foreach (long node in nodes) { float longitude = (float)nodesDict[node].Longitude; float latitude = (float)nodesDict[node].Latitude; // Scaled positions int x = (int)((128 / Math.PI) * Math.Pow(2, zoom) * (longitude + Math.PI)); int y = (int)((128 / Math.PI) * Math.Pow(2, zoom) * (Math.PI - Math.Log(Math.Tan(Math.PI / 4 + latitude / 2)))); // Necessary variables to do a translation int minX = (int)((128 / Math.PI) * Math.Pow(2, zoom) * (map.MinLong + Math.PI)); int minY = (int)((128 / Math.PI) * Math.Pow(2, zoom) * (Math.PI - Math.Log(Math.Tan(Math.PI / 4 + map.MinLat / 2)))); int maxX = (int)((128 / Math.PI) * Math.Pow(2, zoom) * (map.MaxLong + Math.PI)); int maxY = (int)((128 / Math.PI) * Math.Pow(2, zoom) * (Math.PI - Math.Log(Math.Tan(Math.PI / 4 + map.MaxLat / 2)))); // Translate these points so the center of the villaga/city becomes the point (0, 0, 0) x = x - (minX + ((maxX - minX) / 2)); y = y - (minY + ((maxY - minY) / 2)); // Add the point on the ground and the point on the roof positions.Add(new Point3D(x, y, 0)); positions.Add(new Point3D(x, y, height)); } return(positions); }
private Point3DCollection CreateSnakePositions(Point3D startPosition, double segmentsLength, double startAngle, double maxAngle) { var point3DCollection = new Point3DCollection(); point3DCollection.Add(startPosition); double angle = startAngle; bool negateAngle = false; var currentPosition = startPosition; var initialDirectionVector = new Vector3D(segmentsLength, 0, 0); var axisAngleRotation3D = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0); var rotateTransform3D = new RotateTransform3D(axisAngleRotation3D); while (angle <= maxAngle) { axisAngleRotation3D.Angle = negateAngle ? -angle : angle; var currentDirectionVector = rotateTransform3D.Transform(initialDirectionVector); currentPosition += currentDirectionVector; point3DCollection.Add(currentPosition); angle += 5; negateAngle = !negateAngle; } return(point3DCollection); }
private static void OnNumberOfSidesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { WheelMesh wheel = (WheelMesh)d; Point3DCollection points = new Point3DCollection(3 + wheel.NumberOfSides - 2); Int32Collection triangles = new Int32Collection(wheel.NumberOfSides); // Center points.Add(new Point3D(wheel.Radius, wheel.Radius, wheel.Height)); // Top points.Add(new Point3D(wheel.Radius, 0, 0)); for (int i = 1; i < wheel.NumberOfSides; i++) { double beta = 2 * Math.PI / wheel.NumberOfSides * i; double alpha = (Math.PI - beta) / 2; double length = 2 * wheel.Radius * Math.Sin(beta / 2); double x = length * Math.Cos(Math.PI / 2 - alpha); double y = length * Math.Sin(Math.PI / 2 - alpha); points.Add(new Point3D(wheel.Radius + x, y, 0)); triangles.Add(0); triangles.Add(i); triangles.Add(i + 1); } triangles.Add(0); triangles.Add(wheel.NumberOfSides); triangles.Add(1); wheel.SetValue(PointsProperty, points); wheel.SetValue(TriangleIndicesProperty, triangles); }
public static MeshGeometry3D CreateCylinder(double radius, double height, int steps) { var geometry = new MeshGeometry3D(); var positions = new Point3DCollection(); var indicies = new Int32Collection(); var normals = new Vector3DCollection(); // center positions.Add(new Point3D(0, height, 0)); normals.Add(new Vector3D(0, 1, 0)); var delta = 360.0 / steps; for (int i = 0; i < steps; ++i) { var rad = Helper.DegreesToRadians * (i * delta); var v1 = new Point3D(Math.Sin(rad) * radius, 0, Math.Cos(rad) * radius); var v2 = new Point3D(Math.Sin(rad) * radius, height, Math.Cos(rad) * radius); var n = new Vector3D(Math.Sin(rad), 0, Math.Cos(rad)); positions.Add(v1); normals.Add(n); positions.Add(v2); normals.Add(n); } // top disc for (int i = 0; i < steps; ++i) { indicies.Add(0); int j = i; int k = j + 1; j %= steps; k %= steps; indicies.Add((j + 1) * 2); indicies.Add((k + 1) * 2); } // border quads for (int i = 0; i < steps; ++i) { int j = i; int k = j + 1; j %= steps; k %= steps; indicies.Add(((j + 1) * 2) - 1); indicies.Add(((k + 1) * 2) + 0); indicies.Add(((j + 1) * 2) + 0); indicies.Add(((k + 1) * 2) - 1); indicies.Add(((k + 1) * 2) + 0); indicies.Add(((j + 1) * 2) - 1); } geometry.TriangleIndices = indicies; geometry.Positions = positions; geometry.Normals = normals; return(geometry); }
private GeometryModel3D Triangle(double x, double y, double s) { Point3DCollection corners = new Point3DCollection(); corners.Add(new Point3D(x, y, 0)); corners.Add(new Point3D(x, y + s, 0)); corners.Add(new Point3D(x + s, y + s, 0)); corners.Add(new Point3D(x + y + s, x + y + s, 0)); Int32Collection Triangles = new Int32Collection(); Triangles.Add(0); Triangles.Add(1); Triangles.Add(2); Triangles.Add(3); MeshGeometry3D tmesh = new MeshGeometry3D(); tmesh.Positions = corners; tmesh.TriangleIndices = Triangles; tmesh.Normals.Add(new Vector3D(0, 0, -1)); GeometryModel3D msheet = new GeometryModel3D(); msheet.Geometry = tmesh; msheet.Material = new DiffuseMaterial(new SolidColorBrush(Colors.Red)); return(msheet); }
protected override void CalculateGeometry() { int numberOfSeparators = 4 * _NumberOfSegments + 4; _Points = new Point3DCollection(_NumberOfSegments + 1); _TriangleIndices = new Int32Collection((numberOfSeparators + 1) * 3); _Points.Add(new Point3D(0, 0, 0)); for (int divider = 0; divider < numberOfSeparators; divider++) { double alpha = Math.PI / 2 / (_NumberOfSegments + 1) * divider; _Points.Add(new Point3D(_Radius * Math.Cos(alpha), 0, -1 * Math.Sin(alpha))); _TriangleIndices.Add(0); _TriangleIndices.Add(divider + 1); if (divider == numberOfSeparators - 1) { _TriangleIndices.Add(1); } else { _TriangleIndices.Add(divider + 2); } } }
private void DrawXAxisMinorTicks(Point3DCollection points) { Point3DCollection pointsColl = new Point3DCollection(); var minorTicks = this.TicksProvider.CreateMinorTicks(_xRange, _length); foreach (var tick in minorTicks) { Point3D start = new Point3D() { X = tick.AxisValue, Y = 0, Z = _length }; Point3D end = new Point3D() { X = tick.AxisValue, Y = 0, Z = _length - this.TicksProvider.MinorTickSize }; pointsColl.Add(start); pointsColl.Add(end); } //Add (1,0,0) side minor ticks Point3D[] oneSidesPoints = new Point3D[pointsColl.Count]; pointsColl.CopyTo(oneSidesPoints, 0); Transform3D transform = new TranslateTransform3D() { OffsetX = 0, OffsetY = 0, OffsetZ = this.TicksProvider.MinorTickSize - _length }; AddTransformedPoints(pointsColl, transform, oneSidesPoints); //Add the other two sides points on XOZ Point3D[] towSidesPoints = new Point3D[pointsColl.Count]; pointsColl.CopyTo(towSidesPoints, 0); transform = new RotateTransform3D() { CenterX = _length / 2, CenterY = 0, CenterZ = _length / 2, Rotation = new AxisAngleRotation3D() { Axis = new Vector3D(0, 1, 0), Angle = 90 } }; AddTransformedPoints(pointsColl, transform, towSidesPoints); foreach (var point in pointsColl) { points.Add(point); } }
protected override void CalculateGeometry() { int e; double segmentRad = Math.PI / 2 / (n + 1); int numberOfSeparators = 4 * n + 4; points = new Point3DCollection(); triangleIndices = new Int32Collection(); for (e = -n; e <= n; e++) { double r_e = r * Math.Cos(segmentRad * e); double y_e = r * Math.Sin(segmentRad * e); for (int s = 0; s <= (numberOfSeparators - 1); s++) { double z_s = r_e * Math.Sin(segmentRad * s) * (-1); double x_s = r_e * Math.Cos(segmentRad * s); points.Add(new Point3D(x_s, y_e, z_s)); } } points.Add(new Point3D(0, r, 0)); points.Add(new Point3D(0, -1 * r, 0)); for (e = 0; e < 2 * n; e++) { for (int i = 0; i < numberOfSeparators; i++) { triangleIndices.Add(e * numberOfSeparators + i); triangleIndices.Add(e * numberOfSeparators + i + numberOfSeparators); triangleIndices.Add(e * numberOfSeparators + (i + 1) % numberOfSeparators + numberOfSeparators); triangleIndices.Add(e * numberOfSeparators + (i + 1) % numberOfSeparators + numberOfSeparators); triangleIndices.Add(e * numberOfSeparators + (i + 1) % numberOfSeparators); triangleIndices.Add(e * numberOfSeparators + i); } } for (int i = 0; i < numberOfSeparators; i++) { triangleIndices.Add(e * numberOfSeparators + i); triangleIndices.Add(e * numberOfSeparators + (i + 1) % numberOfSeparators); triangleIndices.Add(numberOfSeparators * (2 * n + 1)); } for (int i = 0; i < numberOfSeparators; i++) { triangleIndices.Add(i); triangleIndices.Add((i + 1) % numberOfSeparators); triangleIndices.Add(numberOfSeparators * (2 * n + 1) + 1); } }
public VideoSurface(string mediaSource) { this.ModelVisual3D = new ModelVisual3D(); var geometryModel = new GeometryModel3D(); this.ModelVisual3D.Content = geometryModel; this.geometry = new MeshGeometry3D(); geometryModel.Geometry = geometry; var positions = new Point3DCollection(); positions.Add(new Point3D(0, 0, 0)); positions.Add(new Point3D(640, 0, 0)); positions.Add(new Point3D(640, 480, 0)); positions.Add(new Point3D(0, 480, 0)); this.geometry.Positions = positions; var textureCoordinates = new PointCollection(); textureCoordinates.Add(new System.Windows.Point(0, 1)); textureCoordinates.Add(new System.Windows.Point(1, 1)); textureCoordinates.Add(new System.Windows.Point(1, 0)); textureCoordinates.Add(new System.Windows.Point(0, 0)); this.geometry.TextureCoordinates = textureCoordinates; var triangleIndices = new Int32Collection(); triangleIndices.Add(0); triangleIndices.Add(1); triangleIndices.Add(2); triangleIndices.Add(2); triangleIndices.Add(3); triangleIndices.Add(0); this.geometry.TriangleIndices = triangleIndices; var material = new EmissiveMaterial(); var brush = new VisualBrush(); this.border = new Border(); this.border.BorderBrush = Brushes.White; this.border.BorderThickness = new Thickness(10); this.border.Opacity = 0; this.mediaElement = new MediaElement(); mediaElement.LoadedBehavior = MediaState.Manual; mediaElement.Source = new Uri(mediaSource); this.border.Child = mediaElement; brush.Visual = border; material.Brush = brush; geometryModel.Material = material; this.mediaElement.MediaEnded += new RoutedEventHandler(mediaElement_MediaEnded); }