/// <summary> /// Draws the specified background /// </summary> /// <param name="g">The drawing context.</param> /// <param name="itemRectangle">Position and size of the item for which this background is intended. For text, this is the position and size of the text rectangle, already with a margin around. /// This parameter should have the same size as was used in the previous call to <see cref="Measure(RectangleD3D)" /></param> /// <param name="material">The material to use for this background.</param> /// <exception cref="NotImplementedException"></exception> public void Draw(IGraphicsContext3D g, RectangleD3D itemRectangle, IMaterial material) { var rectangleToDraw = GetRectangleToDraw(itemRectangle); var buffers = g.GetPositionNormalIndexedTriangleBuffer(material); if (null != buffers.PositionNormalColorIndexedTriangleBuffer) { var c = material.Color.Color; var voffs = buffers.PositionNormalColorIndexedTriangleBuffer.VertexCount; Altaxo.Drawing.D3D.SolidCube.Add( rectangleToDraw.X, rectangleToDraw.Y, rectangleToDraw.Z, rectangleToDraw.SizeX, rectangleToDraw.SizeY, rectangleToDraw.SizeZ, (point, normal) => buffers.PositionNormalColorIndexedTriangleBuffer.AddTriangleVertex(point.X, point.Y, point.Z, normal.X, normal.Y, normal.Z, c.ScR, c.ScG, c.ScB, c.ScA), (i1, i2, i3) => buffers.IndexedTriangleBuffer.AddTriangleIndices(i1 + voffs, i2 + voffs, i3 + voffs), ref voffs); } else if (null != buffers.PositionNormalIndexedTriangleBuffer) { var voffs = buffers.PositionNormalIndexedTriangleBuffer.VertexCount; Altaxo.Drawing.D3D.SolidCube.Add( rectangleToDraw.X, rectangleToDraw.Y, rectangleToDraw.Z, rectangleToDraw.SizeX, rectangleToDraw.SizeY, rectangleToDraw.SizeZ, (point, normal) => buffers.PositionNormalIndexedTriangleBuffer.AddTriangleVertex(point.X, point.Y, point.Z, normal.X, normal.Y, normal.Z), (i1, i2, i3) => buffers.IndexedTriangleBuffer.AddTriangleIndices(i1 + voffs, i2 + voffs, i3 + voffs), ref voffs); } else { throw new NotImplementedException(); } }
public void PaintBackground(IGraphicsContext3D g, IPlotArea layer) { if (null == _background) { return; } var cs = layer.CoordinateSystem; if (layer.CoordinateSystem is CS.G3DCartesicCoordinateSystem) { var p = new PointD3D[4]; p[0] = cs.GetPointOnPlane(_planeID, 0, 0); p[1] = cs.GetPointOnPlane(_planeID, 0, 1); p[2] = cs.GetPointOnPlane(_planeID, 1, 0); p[3] = cs.GetPointOnPlane(_planeID, 1, 1); var normal = VectorD3D.CrossProduct(p[1] - p[0], p[2] - p[0]).Normalized; var buffer = g.GetPositionNormalIndexedTriangleBuffer(_background); if (null != buffer.PositionNormalIndexedTriangleBuffer) { // front faces var offs = buffer.IndexedTriangleBuffer.VertexCount; for (int i = 0; i < 4; ++i) { buffer.PositionNormalIndexedTriangleBuffer.AddTriangleVertex(p[i].X, p[i].Y, p[i].Z, normal.X, normal.Y, normal.Z); } buffer.IndexedTriangleBuffer.AddTriangleIndices(0 + offs, 1 + offs, 3 + offs); buffer.IndexedTriangleBuffer.AddTriangleIndices(2 + offs, 0 + offs, 3 + offs); // back faces offs = buffer.IndexedTriangleBuffer.VertexCount; for (int i = 0; i < 4; ++i) { buffer.PositionNormalIndexedTriangleBuffer.AddTriangleVertex(p[i].X, p[i].Y, p[i].Z, -normal.X, -normal.Y, -normal.Z); } buffer.IndexedTriangleBuffer.AddTriangleIndices(0 + offs, 3 + offs, 1 + offs); buffer.IndexedTriangleBuffer.AddTriangleIndices(2 + offs, 3 + offs, 0 + offs); } else { throw new NotImplementedException(); } } else { throw new NotImplementedException(); } }
public override void Paint(IGraphicsContext3D g, IMaterial material, PointD3D centerLocation, double symbolSize) { // Note: the symbolSize provided in the argument is the diameter of an imaginary sphere in which the cube has to fit in // thus the cube's diagonal should be equal to the sphere's diameter var size = symbolSize * Sqrt1By3; // size of the cube var sizeBy2 = size * 0.5; var buffers = g.GetPositionNormalIndexedTriangleBuffer(material); if (null != buffers.PositionNormalIndexedTriangleBuffer) { var buf = buffers.PositionNormalIndexedTriangleBuffer; var voffs = buffers.PositionNormalIndexedTriangleBuffer.VertexCount; SolidCube.Add( centerLocation.X - sizeBy2, centerLocation.Y - sizeBy2, centerLocation.Z - sizeBy2, size, size, size, (point, normal) => buf.AddTriangleVertex(point.X, point.Y, point.Z, normal.X, normal.Y, normal.Z), (i1, i2, i3) => buf.AddTriangleIndices(i1 + voffs, i2 + voffs, i3 + voffs), ref voffs); } }
public override void Paint(IGraphicsContext3D g, IMaterial material, PointD3D centerLocation, double symbolSize) { // Note: the symbolSize provided in the argument is the diameter of an imaginary sphere in which the cube has to fit in // thus the cube's diagonal should be equal to the sphere's diameter var size = symbolSize * Sqrt1By3; // size of the cube var sizeBy2 = size * 0.5; var buffers = g.GetPositionNormalIndexedTriangleBuffer(material); if (null != buffers.PositionNormalIndexedTriangleBuffer) { var buf = buffers.PositionNormalIndexedTriangleBuffer; var voffs = buffers.PositionNormalIndexedTriangleBuffer.VertexCount; SolidCube.Add( centerLocation.X - sizeBy2, centerLocation.Y - sizeBy2, centerLocation.Z - sizeBy2, size, size, size, (point, normal) => buf.AddTriangleVertex(point.X, point.Y, point.Z, normal.X, normal.Y, normal.Z), (i1, i2, i3) => buf.AddTriangleIndices(i1 + voffs, i2 + voffs, i3 + voffs), ref voffs); } }
public override void Paint(IGraphicsContext3D g, IMaterial material, PointD3D centerLocation, double symbolSize) { var radius = symbolSize / 2; var buffers = g.GetPositionNormalIndexedTriangleBuffer(material); if (null != buffers.PositionNormalIndexedTriangleBuffer) { var buffer = buffers.PositionNormalIndexedTriangleBuffer; var offs = buffer.VertexCount; foreach (var entry in GetVerticesAndNormals()) { var pt = centerLocation + radius * entry.Item1; var nm = entry.Item2; buffer.AddTriangleVertex(pt.X, pt.Y, pt.Z, nm.X, nm.Y, nm.Z); } foreach (var idx in GetTriangleIndices()) { buffer.AddTriangleIndices(idx.Item1 + offs, idx.Item2 + offs, idx.Item3 + offs); } } }
public override void Paint(IGraphicsContext3D g, IMaterial material, PointD3D centerLocation, double symbolSize) { var radius = symbolSize / 2; var buffers = g.GetPositionNormalIndexedTriangleBuffer(material); if (null != buffers.PositionNormalIndexedTriangleBuffer) { var buffer = buffers.PositionNormalIndexedTriangleBuffer; var offs = buffer.VertexCount; foreach (var entry in GetVerticesAndNormals()) { var pt = centerLocation + radius * entry.Item1; var nm = entry.Item2; buffer.AddTriangleVertex(pt.X, pt.Y, pt.Z, nm.X, nm.Y, nm.Z); } foreach (var idx in GetTriangleIndices()) { buffer.AddTriangleIndices(idx.Item1 + offs, idx.Item2 + offs, idx.Item3 + offs); } } }
public override void Paint(IGraphicsContext3D g, IPaintContext context) { var buffers = g.GetPositionNormalIndexedTriangleBuffer(_material); if (null != buffers.PositionNormalIndexedTriangleBuffer) { var buffer = buffers.PositionNormalIndexedTriangleBuffer; var offs = buffer.VertexCount; var sphere = new SolidIcoSphere(3); // gives a sphere with radius = 1 var bounds = Bounds; double sx = Bounds.SizeX / 2; double sy = Bounds.SizeY / 2; double sz = Bounds.SizeZ / 2; var dx = Bounds.X + sx; var dy = Bounds.Y + sy; var dz = Bounds.Z + sz; var transformation = Matrix4x3.NewScalingShearingRotationDegreesTranslation(sx, sy, sz, 0, 0, 0, 0, 0, 0, dx, dy, dz); transformation.AppendTransform(_transformation); var normalTransform = transformation.GetTransposedInverseMatrix3x3(); foreach (var entry in sphere.VerticesAndNormalsForSphere) { var pt = transformation.Transform(entry.Item1); var nm = normalTransform.Transform(entry.Item2).Normalized; buffer.AddTriangleVertex(pt.X, pt.Y, pt.Z, nm.X, nm.Y, nm.Z); } foreach (var idx in sphere.TriangleIndicesForSphere) { buffer.AddTriangleIndices(idx.Item1 + offs, idx.Item2 + offs, idx.Item3 + offs); } } }
public override void Paint(IGraphicsContext3D g, IPaintContext context) { var buffers = g.GetPositionNormalIndexedTriangleBuffer(_material); if (null != buffers.PositionNormalIndexedTriangleBuffer) { var buffer = buffers.PositionNormalIndexedTriangleBuffer; var offs = buffer.VertexCount; var sphere = new SolidIcoSphere(3); // gives a sphere with radius = 1 var bounds = this.Bounds; double sx = this.Bounds.SizeX / 2; double sy = this.Bounds.SizeY / 2; double sz = this.Bounds.SizeZ / 2; var dx = this.Bounds.X + sx; var dy = this.Bounds.Y + sy; var dz = this.Bounds.Z + sz; var transformation = Matrix4x3.NewScalingShearingRotationDegreesTranslation(sx, sy, sz, 0, 0, 0, 0, 0, 0, dx, dy, dz); transformation.AppendTransform(_transformation); var normalTransform = transformation.GetTransposedInverseMatrix3x3(); foreach (var entry in sphere.VerticesAndNormalsForSphere) { var pt = transformation.Transform(entry.Item1); var nm = normalTransform.Transform(entry.Item2).Normalized; buffer.AddTriangleVertex(pt.X, pt.Y, pt.Z, nm.X, nm.Y, nm.Z); } foreach (var idx in sphere.TriangleIndicesForSphere) { buffer.AddTriangleIndices(idx.Item1 + offs, idx.Item2 + offs, idx.Item3 + offs); } } }
/// <summary> /// Draws the specified background /// </summary> /// <param name="g">The drawing context.</param> /// <param name="itemRectangle">Position and size of the item for which this background is intended. For text, this is the position and size of the text rectangle, already with a margin around. /// This parameter should have the same size as was used in the previous call to <see cref="Measure(RectangleD3D)" /></param> /// <param name="material">The material to use for this background.</param> /// <exception cref="NotImplementedException"></exception> public void Draw(IGraphicsContext3D g, RectangleD3D itemRectangle, IMaterial material) { var rectangleToDraw = GetRectangleToDraw(itemRectangle); var buffers = g.GetPositionNormalIndexedTriangleBuffer(material); if (null != buffers.PositionNormalColorIndexedTriangleBuffer) { var c = material.Color.Color; var voffs = buffers.PositionNormalColorIndexedTriangleBuffer.VertexCount; Altaxo.Drawing.D3D.SolidCube.Add( rectangleToDraw.X, rectangleToDraw.Y, rectangleToDraw.Z, rectangleToDraw.SizeX, rectangleToDraw.SizeY, rectangleToDraw.SizeZ, (point, normal) => buffers.PositionNormalColorIndexedTriangleBuffer.AddTriangleVertex(point.X, point.Y, point.Z, normal.X, normal.Y, normal.Z, c.ScR, c.ScG, c.ScB, c.ScA), (i1, i2, i3) => buffers.IndexedTriangleBuffer.AddTriangleIndices(i1 + voffs, i2 + voffs, i3 + voffs), ref voffs); } else if (null != buffers.PositionNormalIndexedTriangleBuffer) { var voffs = buffers.PositionNormalIndexedTriangleBuffer.VertexCount; Altaxo.Drawing.D3D.SolidCube.Add( rectangleToDraw.X, rectangleToDraw.Y, rectangleToDraw.Z, rectangleToDraw.SizeX, rectangleToDraw.SizeY, rectangleToDraw.SizeZ, (point, normal) => buffers.PositionNormalIndexedTriangleBuffer.AddTriangleVertex(point.X, point.Y, point.Z, normal.X, normal.Y, normal.Z), (i1, i2, i3) => buffers.IndexedTriangleBuffer.AddTriangleIndices(i1 + voffs, i2 + voffs, i3 + voffs), ref voffs); } else { throw new NotImplementedException(); } }