/// <summary> /// Initializes a new instance of the <see cref="ColoredStaticMesh"/> class. /// </summary> /// <param name="viewProjection">The provider for the view and projection matrices to use when rendering.</param> /// <param name="vertices">The vertices of the mesh.</param> /// <param name="indices">The indices (into the provided vertices) to use for actually rendering the mesh.</param> public ColoredStaticMesh( IViewProjection viewProjection, IEnumerable <Vertex> vertices, IEnumerable <uint> indices) { this.viewProjection = viewProjection; if (program == null && programBuilder == null) { lock (ProgramStateLock) { if (program == null && programBuilder == null) { programBuilder = new GlProgramBuilder() .WithVertexShaderFromEmbeddedResource("Colored.Vertex.glsl") .WithFragmentShaderFromEmbeddedResource("Colored.Fragment.glsl") .WithDefaultUniformBlock <DefaultUniformBlock>() .WithSharedUniformBufferObject <CameraUniformBlock>("Camera", BufferUsageHint.DynamicDraw, 1); } } } this.vertexArrayObjectBuilder = new VertexArrayObjectBuilder(PrimitiveType.Triangles) .WithNewAttributeBuffer(BufferUsageHint.StaticDraw, vertices.ToArray()) .WithNewIndexBuffer(BufferUsageHint.StaticDraw, indices.ToArray()); }
/// <summary> /// Returns the ray-direction towards the center of the view. /// </summary> public static V3d CentralDirection(this IViewProjection vp) { var trafo = vp.View.ViewTrafo.Backward * vp.Projection.ProjectionTrafo.Backward; var nearPoint = trafo.TransformPosProj(V3d.OOO); var farPoint = trafo.TransformPosProj(V3d.OOI); return((farPoint - nearPoint).Normalized); }
/// <summary> /// Initializes a new instance of the <see cref="PrimitiveRenderer"/> class. /// </summary> /// <param name="camera">Provider for view and projection matrices.</param> /// <param name="source">Source data. Outer sequence pushes different renderable entities, each of which pushes each time its state changes.</param> /// <param name="capacity">The maximum number of triangles and lines that can be rendered at once.</param> public PrimitiveRenderer( IViewProjection camera, IObservable <IObservable <IList <Primitive> > > source, int capacity) { this.camera = camera; this.source = source; if (program == null && programBuilder == null) { lock (ProgramStateLock) { if (program == null && programBuilder == null) { programBuilder = new GlProgramBuilder() .WithVertexShaderFromEmbeddedResource("Colored.Vertex.glsl") .WithFragmentShaderFromEmbeddedResource("Colored.Fragment.glsl") .WithDefaultUniformBlock <Uniforms>(); } } } // Re-use a single vertex list for every primitive to reduce GC burden - NB not re-entrant var triangleVertexList = new List <PrimitiveVertex>(); this.coloredTriangleBufferBuilder = new ReactiveBufferBuilder <PrimitiveVertex>( PrimitiveType.Triangles, capacity, new[] { 0, 1, 2 }, this.source.Select(pso => pso.Select(ps => { triangleVertexList.Clear(); for (int i = 0; i < ps.Count; i++) { if (ps[i].IsTrianglePrimitive) { triangleVertexList.AddRange(ps[i].Vertices); } } return(triangleVertexList); }))); // Re-use a single vertex list for every primitive to reduce GC burden - NB not re-entrant var lineVertexList = new List <PrimitiveVertex>(); this.coloredLineBufferBuilder = new ReactiveBufferBuilder <PrimitiveVertex>( PrimitiveType.Lines, capacity, new[] { 0, 1 }, this.source.Select(pso => pso.Select(ps => { lineVertexList.Clear(); for (int i = 0; i < ps.Count; i++) { if (!ps[i].IsTrianglePrimitive) { lineVertexList.AddRange(ps[i].Vertices); } } return(lineVertexList); }))); }
/// <summary> /// Builds a hull from the given view-projection (left, right, top, bottom, near, far). /// The normals of the hull planes point to the inside. /// A point inside the visual hull will have positive height to all planes. /// </summary> public static Hull3d GetVisualHull(this IViewProjection vp) => vp.ViewProjTrafo().GetVisualHull();
/// <summary> /// Returns the multiplied View-Projection transformation. /// </summary> public static Trafo3d ViewProjTrafo(this IViewProjection vp) => vp.View.ViewTrafo * vp.Projection.ProjectionTrafo;
/// <summary> /// Builds a hull from the given view-projection (left, right, top, bottom, near, far). /// The normals of the hull planes point to the inside. /// A point inside the visual hull will have positive height to all planes. /// </summary> public static Hull3d GetVisualHull(this IViewProjection vp) { return(vp.ViewProjTrafo().GetVisualHull()); }
/// <summary> /// Returns the multiplied View-Projection transformation. /// </summary> public static Trafo3d ViewProjTrafo(this IViewProjection vp) { return(vp.View.ViewTrafo * vp.Projection.ProjectionTrafo); }