/// <summary> /// Renders the control</summary> /// <param name="action">Render action</param> /// <param name="camera">Camera</param> /// <param name="state">Render state</param> /// <param name="transform">Transform</param> public void Render(IRenderAction action, Camera camera, RenderState state, Matrix4F transform) { float s1, s2, s3; // apply xform Gl.glPushMatrix(); Util3D.glMultMatrixf(transform); CalcAxisLengths(camera, transform, out s1, out s2, out s3); bool drawX, drawY, drawZ; DecideArrowDrawing(transform, camera, out drawX, out drawY, out drawZ); if (drawX) { RenderXArrow(s1); RenderXAxis(s1); } if (drawY) { RenderYArrow(s2); RenderYAxis(s2); } if (drawZ) { RenderZArrow(s3); RenderZAxis(s3); } RenderXYSquare(s1 * SquareLength, s2 * SquareLength, true); RenderYZSquare(s2 * SquareLength, s3 * SquareLength, true); RenderXZSquare(s1 * SquareLength, s3 * SquareLength, true); Gl.glPopMatrix(); }
/// <summary> /// Renders the object. Called from Dispatch().</summary> /// <param name="graphPath">The path leading to the RenderObject</param> /// <param name="renderState">The render state to use</param> /// <param name="renderAction">The render action used</param> /// <param name="camera">The camera</param> protected virtual void Render( SceneNode[] graphPath, RenderState renderState, IRenderAction renderAction, Camera camera) { }
/// <summary> /// Performs actions at the beginning of control drag</summary> /// <param name="hit">Hit record</param> /// <param name="x">Mouse x position</param> /// <param name="y">Mouse y position</param> /// <param name="action">Render action</param> /// <param name="camera">Camera</param> /// <param name="transform">Transform</param> /// <returns>Code for control element under mouse x, y</returns> public HitElement OnHit(HitRecord hit, float x, float y, IRenderAction action, Camera camera, Matrix4F transform) { // Store pick coords m_iX = x; m_iY = y; return((HitElement)hit.RenderObjectData[1]); }
private void Render(IRenderAction action) { int[] sizes = m_primitives.PrimitiveSizes; int[] indices = m_primitives.PrimitiveIndices; int nPrims = (m_subMesh != null) ? m_subMesh.Count : sizes.Length; int primBaseIndex = 0; Util3D.RenderStats.PrimCount += nPrims; for (int i = 0; i < nPrims; i++) { int primSize = sizes[i % sizes.Length]; Util3D.RenderStats.VertexCount += primSize; Gl.glBegin(m_drawMode); for (int j = 0; j < primSize; j++) { foreach (DrawCommand cmd in m_commands) { int offset = indices[primBaseIndex + j * m_bindingCount + cmd.PrimitiveIndex] * cmd.Stride; CallFunction(cmd, offset); } } Gl.glEnd(); primBaseIndex += primSize * m_bindingCount; } }
protected override void beforeEach() { _requestData = new InMemoryRequestData(); _renderAction = MockFor <IRenderAction>(); _renderAction.Expect(x => x.RenderPartial()); Services.Inject <IRequestData>(_requestData); }
/// <summary> /// Traverses the specified graph path</summary> /// <param name="graphPath">The graph path</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> /// <param name="list">The list</param> /// <returns></returns> public override TraverseState Traverse(Stack<SceneNode> graphPath, IRenderAction action, Camera camera, ICollection<TraverseNode> list) { // Get the "top matrix" before we push a new matrix on to it, just in case we need // it for the bounding box test. Matrix4F parentToWorld = action.TopMatrix; // Push matrix onto the matrix stack even if we're not visible because this class // implements the marker interface ISetsLocalTransform. action.PushMatrix(m_node.Transform, true); // If node is invisible then cull if (!m_node.Visible) return TraverseState.Cull; TraverseState dResult = action.TraverseState; if (dResult == TraverseState.None) { // Test if bounding sphere is contained in frustum if (s_enableVFCull) { // Construct bounding box Box box = new Box(); box.Extend(m_node.BoundingBox); // Transform the bounding box into view space Matrix4F localToView = Matrix4F.Multiply(parentToWorld, camera.ViewMatrix); box.Transform(localToView); if (!camera.Frustum.Contains(box)) dResult = TraverseState.Cull; } } return dResult; }
protected override void beforeEach() { _writer = new StringWriter(); _nestedOutput = new NestedOutput(); _renderAction = MockFor <IRenderAction>(); _renderAction.Expect(x => x.RenderPartial()); Services.Inject(_nestedOutput); }
/// <summary> /// Dispatches the RenderObject for rendering</summary> /// <param name="graphPath">The path leading to the RenderObject</param> /// <param name="renderState">The render state to use</param> /// <param name="renderAction">The render action dispatching the object</param> /// <param name="camera">The Camera used in the dispatch process</param> public virtual void Dispatch(SceneNode[] graphPath, RenderState renderState, IRenderAction renderAction, Camera camera) { renderAction.RenderStateGuardian.Commit(renderState); Render(graphPath, renderState, renderAction, camera); }
/// <summary> /// Traverses the control for rendering</summary> /// <param name="graphPath">The path leading to the control</param> /// <param name="action">Render action</param> /// <param name="list">Traverse list</param> public void Traverse( Stack<SceneNode> graphPath, IRenderAction action, ICollection<TraverseNode> list) { TraverseNode node = action.GetUnusedNode(); node.Init(action.RenderObject, action.TopMatrix, graphPath, s_renderState); list.Add(node); }
/// <summary> /// Traverses the specified graph path.</summary> /// <param name="graphPath">The graph path</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> /// <param name="list">The list</param> /// <returns></returns> public override TraverseState Traverse(Stack<SceneNode> graphPath, IRenderAction action, Camera camera, ICollection<TraverseNode> list) { // If invisible then cull if (!m_primitives.Visible) return TraverseState.Cull; return base.Traverse(graphPath, action, camera, list); }
/// <summary> /// Custom pick rendering</summary> /// <param name="graphPath">The graph path</param> /// <param name="renderState">The render state</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> public void PickDispatch(SceneNode[] graphPath, RenderState renderState, IRenderAction action, Camera camera) { action.RenderStateGuardian.Commit(renderState); // apply xform Gl.glPushMatrix(); Util3D.glMultMatrixf(action.TopMatrix); RenderVertices(action); Gl.glPopMatrix(); }
/// <summary> /// Traverses the control for rendering</summary> /// <param name="graphPath">The path leading to the control</param> /// <param name="action">Render action</param> /// <param name="list">Traverse list</param> public void Traverse( Stack <SceneNode> graphPath, IRenderAction action, ICollection <TraverseNode> list) { TraverseNode node = action.GetUnusedNode(); node.Init(action.RenderObject, action.TopMatrix, graphPath, s_renderState); list.Add(node); }
/// <summary> /// Traverses the specified graph path.</summary> /// <param name="graphPath">The graph path</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> /// <param name="list">The list</param> /// <returns></returns> public override TraverseState Traverse(Stack <SceneNode> graphPath, IRenderAction action, Camera camera, ICollection <TraverseNode> list) { // If invisible then cull if (!m_primitives.Visible) { return(TraverseState.Cull); } return(base.Traverse(graphPath, action, camera, list)); }
/// <summary> /// Performs any traverse actions</summary> /// <param name="graphPath">The path leading to the RenderObject</param> /// <param name="renderAction">The render action used to dispatch the object</param> /// <param name="camera">The Camera used</param> /// <param name="traverseList">The traverse list used in the dispatch phase. /// RenderObjects participating in the dispatch phase need to push themselves onto the traverse list.</param> /// <returns>The TraverseState</returns> public virtual TraverseState Traverse(Stack <SceneNode> graphPath, IRenderAction renderAction, Camera camera, ICollection <TraverseNode> traverseList) { RenderState state = renderAction.RenderState; Box boundingBox = null; bool alpha = ((state.RenderMode & RenderMode.Alpha) != 0); if (alpha) { boundingBox = GetBoundingBoxObjectSpace(); boundingBox.Transform(renderAction.TopMatrix); } if ((state.RenderMode & RenderMode.Smooth) != 0) { RenderMode origRenderMode = state.RenderMode; state.RenderMode &= ~(RenderMode.Wireframe | RenderMode.WireframeColor); TraverseNode node = renderAction.GetUnusedNode(); node.Init(renderAction.RenderObject, renderAction.TopMatrix, graphPath, state); if (alpha) { node.WorldSpaceBoundingBox = boundingBox; } traverseList.Add(node); state.RenderMode = origRenderMode; } if ((state.RenderMode & RenderMode.Wireframe) != 0) { RenderMode origRenderMode = state.RenderMode; state.RenderMode &= ~(RenderMode.Smooth | RenderMode.SolidColor | RenderMode.Textured | RenderMode.Lit); TraverseNode node = renderAction.GetUnusedNode(); node.Init(renderAction.RenderObject, renderAction.TopMatrix, graphPath, state); if (alpha) { node.WorldSpaceBoundingBox = boundingBox; } traverseList.Add(node); state.RenderMode = origRenderMode; } return(renderAction.TraverseState); }
public void InstrumentLayer(IRenderAction renderAction, IGraphSceneDisplay <IVisual, IVisualEdge> display) { var layer = renderAction as ILayer <IGraphScene <IVisual, IVisualEdge> >; if (layer != null) { layer.Data = () => display.Data; layer.Camera = () => display.Viewport.Camera; } var graphLayer = layer as GraphSceneLayer <IVisual, IVisualEdge>; if (graphLayer != null) { graphLayer.Layout = () => display.Layout; } display.ActionDispatcher.Add(renderAction); }
/// <summary> /// Performs any traverse actions</summary> /// <param name="graphPath">The path leading to the RenderObject</param> /// <param name="renderAction">The render action used to dispatch the object</param> /// <param name="camera">The Camera used</param> /// <param name="traverseList">The traverse list used in the dispatch phase. /// RenderObjects participating in the dispatch phase need to push themselves onto the traverse list.</param> /// <returns>The TraverseState</returns> public virtual TraverseState Traverse(Stack<SceneNode> graphPath, IRenderAction renderAction, Camera camera, ICollection<TraverseNode> traverseList) { RenderState state = renderAction.RenderState; Box boundingBox = null; bool alpha = ((state.RenderMode & RenderMode.Alpha) != 0); if (alpha) { boundingBox = GetBoundingBoxObjectSpace(); boundingBox.Transform(renderAction.TopMatrix); } if ((state.RenderMode & RenderMode.Smooth) != 0) { RenderMode origRenderMode = state.RenderMode; state.RenderMode &= ~(RenderMode.Wireframe | RenderMode.WireframeColor); TraverseNode node = renderAction.GetUnusedNode(); node.Init(renderAction.RenderObject, renderAction.TopMatrix, graphPath, state); if (alpha) node.WorldSpaceBoundingBox = boundingBox; traverseList.Add(node); state.RenderMode = origRenderMode; } if ((state.RenderMode & RenderMode.Wireframe) != 0) { RenderMode origRenderMode = state.RenderMode; state.RenderMode &= ~(RenderMode.Smooth | RenderMode.SolidColor | RenderMode.Textured | RenderMode.Lit); TraverseNode node = renderAction.GetUnusedNode(); node.Init(renderAction.RenderObject, renderAction.TopMatrix, graphPath, state); if (alpha) node.WorldSpaceBoundingBox = boundingBox; traverseList.Add(node); state.RenderMode = origRenderMode; } return renderAction.TraverseState; }
/// <summary> /// Generates a thumbnail image and saves it to the given path as a PNG-format file</summary> /// <param name="scene">Scene to render</param> /// <param name="action">Rendering action</param> /// <param name="path">Path of bitmap file, in the PNG format. The extension must be "png".</param> /// <param name="camera">Camera to use</param> public void Generate(Scene scene, IRenderAction action, Camera camera, string path) { if (Path.GetExtension(path) != ".png") throw new ArgumentException("the extension must be 'png'"); m_scene = scene; m_action = action; m_camera = camera; // Paint the scene and save it. using (Bitmap bitmap = m_bitmapContext.CreateBitmap(Paint)) bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Png); m_scene = null; m_action = null; m_camera = null; }
private void RenderAxisSystem(IRenderAction action) { // Calc width and height float width, height; float nearP = Camera.Frustum.Near * 1.1f; if (Camera.Frustum.IsOrtho) { width = (Camera.Frustum.Right - Camera.Frustum.Left) / 2 * 0.95f; height = (Camera.Frustum.Top - Camera.Frustum.Bottom) / 2 * 0.90f; } else { // Set the projection to orthogonal for perspective views float h = (float)Height / (float)Width; Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(-1, 1, -h, h, 1, 1000); nearP = 1.1f; width = 0.92f; height = h * 0.90f; } // Push the view matrix Gl.glMatrixMode(Gl.GL_MODELVIEW); Matrix4F V = new Matrix4F(Camera.ViewMatrix); V.Translation = Vec3F.ZeroVector; // Disable lighting Gl.glDisable(Gl.GL_LIGHTING); Gl.glDisable(Gl.GL_TEXTURE_2D); Gl.glPushMatrix(); Gl.glLoadIdentity(); Gl.glTranslatef(-width, -height, -nearP); Util3D.glMultMatrixf(V); // Render the system RenderAxis(width / 15); Gl.glPopMatrix(); }
/// <summary> /// Generates a thumbnail image and saves it to the given path as a PNG-format file</summary> /// <param name="scene">Scene to render</param> /// <param name="action">Rendering action</param> /// <param name="path">Path of bitmap file, in the PNG format. The extension must be "png".</param> /// <param name="camera">Camera to use</param> public void Generate(Scene scene, IRenderAction action, Camera camera, string path) { if (Path.GetExtension(path) != ".png") { throw new ArgumentException("the extension must be 'png'"); } m_scene = scene; m_action = action; m_camera = camera; // Paint the scene and save it. using (Bitmap bitmap = m_bitmapContext.CreateBitmap(Paint)) bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Png); m_scene = null; m_action = null; m_camera = null; }
/// <summary> /// Traverses the specified graph path</summary> /// <param name="graphPath">The graph path</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> /// <param name="list">The list</param> /// <returns></returns> public override TraverseState Traverse(Stack <SceneNode> graphPath, IRenderAction action, Camera camera, ICollection <TraverseNode> list) { // Get the "top matrix" before we push a new matrix on to it, just in case we need // it for the bounding box test. Matrix4F parentToWorld = action.TopMatrix; // Push matrix onto the matrix stack even if we're not visible because this class // implements the marker interface ISetsLocalTransform. action.PushMatrix(m_node.Transform, true); // If node is invisible then cull if (!m_node.Visible) { return(TraverseState.Cull); } TraverseState dResult = action.TraverseState; if (dResult == TraverseState.None) { // Test if bounding sphere is contained in frustum if (s_enableVFCull) { // Construct bounding box Box box = new Box(); box.Extend(m_node.BoundingBox); // Transform the bounding box into view space Matrix4F localToView = Matrix4F.Multiply(parentToWorld, camera.ViewMatrix); box.Transform(localToView); if (!camera.Frustum.Contains(box)) { dResult = TraverseState.Cull; } } } return(dResult); }
/// <summary> /// Renders the control</summary> /// <param name="action">Render action</param> /// <param name="camera">Camera</param> /// <param name="state">Render state</param> /// <param name="transform">Transform</param> public void Render(IRenderAction action, Camera camera, RenderState state, Matrix4F transform) { float s1, s2, s3; // apply xform Gl.glPushMatrix(); Util3D.glMultMatrixf(transform); CalcAxisLengths(camera, transform, out s1, out s2, out s3); bool drawX, drawY, drawZ; DecideArrowDrawing(transform, camera, out drawX, out drawY, out drawZ); if (drawX) { RenderXArrow(s1); RenderXAxis(s1); } if (drawY) { RenderYArrow(s2); RenderYAxis(s2); } if (drawZ) { RenderZArrow(s3); RenderZAxis(s3); } RenderXYSquare(s1 * SquareLength, s2 * SquareLength, true); RenderYZSquare(s2 * SquareLength, s3 * SquareLength, true); RenderXZSquare(s1 * SquareLength, s3 * SquareLength, true); Gl.glPopMatrix(); }
/// <summary> /// Called after post visiting the SceneNode specified by the graph path</summary> /// <param name="graphPath">The graph path</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> /// <param name="list">The traverse list</param> /// <returns></returns> public override TraverseState PostTraverse(Stack<SceneNode> graphPath, IRenderAction action, Camera camera, ICollection<TraverseNode> list) { action.PopMatrix(); return TraverseState.Continue; }
/// <summary> /// Performs actions at the beginning of control drag</summary> /// <param name="hit">Hit record</param> /// <param name="x">Mouse x position</param> /// <param name="y">Mouse y position</param> /// <param name="action">Render action</param> /// <param name="camera">Camera</param> /// <param name="transform">Transform</param> /// <returns>Code for control element under mouse x, y</returns> public HitElement OnHit(HitRecord hit, float x, float y, IRenderAction action, Camera camera, Matrix4F transform) { // Store pick coords m_iX = x; m_iY = y; return (HitElement)hit.RenderObjectData[1]; }
/// <summary> /// Renders control for picking</summary> /// <param name="action">Render action</param> /// <param name="camera">Camera</param> /// <param name="renderState">Render state</param> /// <param name="transform">Transform, local to world</param> public void RenderPick(IRenderAction action, Camera camera, RenderState renderState, Matrix4F transform) { action.RenderStateGuardian.Commit(renderState); // apply xform Gl.glPushMatrix(); Util3D.glMultMatrixf(transform); float s1, s2, s3; CalcAxisLengths(camera, transform, out s1, out s2, out s3); float squareSideX = s1 * SquareLength; float squareSideY = s2 * SquareLength; float squareSideZ = s3 * SquareLength; bool drawX, drawY, drawZ; DecideArrowDrawing(transform, camera, out drawX, out drawY, out drawZ); // Mark each axis with a different name. // Since the OpenGl selection buffer does a bad job in detecting lines we'll use // triangles instead. Gl.glPushName(m_nameBase); if (drawX) { Gl.glPushName((int)HitElement.X_ARROW); Gl.glBegin(Gl.GL_TRIANGLES); Gl.glVertex3f(squareSideX, 0, 0); Gl.glVertex3f(s1, 0, 0); Gl.glVertex3f(squareSideX, 0, 0); Gl.glEnd(); RenderXArrow(s1); Gl.glPopName(); } if (drawY) { Gl.glPushName((int)HitElement.Y_ARROW); Gl.glBegin(Gl.GL_TRIANGLES); Gl.glVertex3f(0, squareSideY, 0); Gl.glVertex3f(0, s2, 0); Gl.glVertex3f(0, squareSideY, 0); Gl.glEnd(); RenderYArrow(s2); Gl.glPopName(); } if (drawZ) { Gl.glPushName((int)HitElement.Z_ARROW); Gl.glBegin(Gl.GL_TRIANGLES); Gl.glVertex3f(0, 0, squareSideZ); Gl.glVertex3f(0, 0, s3); Gl.glVertex3f(0, 0, squareSideZ); Gl.glEnd(); RenderZArrow(s3); Gl.glPopName(); } if (drawX && drawY) { Gl.glPushName((int)HitElement.XY_SQUARE); RenderXYSquare(squareSideX, squareSideY, true); Gl.glPopName(); } if (drawY && drawZ) { Gl.glPushName((int)HitElement.YZ_SQUARE); RenderYZSquare(squareSideY, squareSideZ, true); Gl.glPopName(); } if (drawX && drawZ) { Gl.glPushName((int)HitElement.XZ_SQUARE); RenderXZSquare(squareSideX, squareSideZ, true); Gl.glPopName(); } Gl.glPopMatrix(); Gl.glPopName(); }
/// <summary> /// Performs actions during control drag</summary> /// <param name="hit">Hit record</param> /// <param name="x">Mouse x position</param> /// <param name="y">Mouse y position</param> /// <param name="action">Render action</param> /// <param name="camera">Camera</param> /// <param name="transform">Transform</param> /// <returns>Translation, in world coordinates</returns> public Vec3F OnDrag(HitRecord hit, float x, float y, IRenderAction action, Camera camera, Matrix4F transform) { float a1, a2; Matrix4F W = new Matrix4F(); W.Mul(transform, camera.ViewMatrix); // Setup rays, in view space. (-z goes into the screen.) Ray3F ray0 = camera.CreateRay(m_iX, m_iY); Ray3F ray = camera.CreateRay(x, y); // Build axis and origin in view space Vec3F xAxis = W.XAxis; Vec3F yAxis = W.YAxis; Vec3F zAxis = W.ZAxis; Vec3F origin = W.Translation; Vec3F trans = new Vec3F(); // Choose the best projection plane according to the projection angle switch ((HitElement)hit.RenderObjectData[1]) { case HitElement.X_ARROW: { a1 = Math.Abs(Vec3F.Dot(ray0.Direction, yAxis)); a2 = Math.Abs(Vec3F.Dot(ray0.Direction, zAxis)); Vec3F axis = (a1 > a2 ? yAxis : zAxis); Vec3F p0 = ray0.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); Vec3F p1 = ray.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); float dragAmount = Vec3F.Dot(xAxis, p1 - p0); Vec3F xLocal = transform.XAxis; trans = dragAmount * xLocal; } break; case HitElement.Y_ARROW: { a1 = Math.Abs(Vec3F.Dot(ray0.Direction, zAxis)); a2 = Math.Abs(Vec3F.Dot(ray0.Direction, xAxis)); Vec3F axis = (a1 > a2 ? zAxis : xAxis); Vec3F p0 = ray0.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); Vec3F p1 = ray.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); float dragAmount = Vec3F.Dot(yAxis, p1 - p0); Vec3F yLocal = transform.YAxis; trans = dragAmount * yLocal; } break; case HitElement.Z_ARROW: { a1 = Math.Abs(Vec3F.Dot(ray0.Direction, xAxis)); a2 = Math.Abs(Vec3F.Dot(ray0.Direction, yAxis)); Vec3F axis = (a1 > a2 ? xAxis : yAxis); Vec3F p0 = ray0.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); Vec3F p1 = ray.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); float dragAmount = Vec3F.Dot(zAxis, p1 - p0); Vec3F zLocal = transform.ZAxis; trans = dragAmount * zLocal; } break; case HitElement.XY_SQUARE: { Vec3F p0 = ray0.IntersectPlane(zAxis, -Vec3F.Dot(zAxis, origin)); Vec3F p1 = ray.IntersectPlane(zAxis, -Vec3F.Dot(zAxis, origin)); Vec3F deltaLocal = p1 - p0; float dragX = Vec3F.Dot(xAxis, deltaLocal); float dragY = Vec3F.Dot(yAxis, deltaLocal); Vec3F xLocal = transform.XAxis; Vec3F yLocal = transform.YAxis; trans = dragX * xLocal + dragY * yLocal; } break; case HitElement.YZ_SQUARE: { Vec3F p0 = ray0.IntersectPlane(xAxis, -Vec3F.Dot(xAxis, origin)); Vec3F p1 = ray.IntersectPlane(xAxis, -Vec3F.Dot(xAxis, origin)); Vec3F deltaLocal = p1 - p0; float dragY = Vec3F.Dot(yAxis, deltaLocal); float dragZ = Vec3F.Dot(zAxis, deltaLocal); Vec3F yLocal = transform.YAxis; Vec3F zLocal = transform.ZAxis; trans = dragY * yLocal + dragZ * zLocal; } break; case HitElement.XZ_SQUARE: { Vec3F p0 = ray0.IntersectPlane(yAxis, -Vec3F.Dot(yAxis, origin)); Vec3F p1 = ray.IntersectPlane(yAxis, -Vec3F.Dot(yAxis, origin)); Vec3F deltaLocal = p1 - p0; float dragX = Vec3F.Dot(xAxis, deltaLocal); float dragZ = Vec3F.Dot(zAxis, deltaLocal); Vec3F xLocal = transform.XAxis; Vec3F zLocal = transform.ZAxis; trans = dragX * xLocal + dragZ * zLocal; } break; } return(trans); }
public void Invoke(IRenderAction action) { action.RenderPartial(); }
public CreateProductFunction(IMediator mediator, IRenderAction <InsertProductDto, Result <GetProductResponse> > responseFormatter, ILogger <CreateProductFunction> logger) { _mediator = mediator; _responseFormatter = responseFormatter; _logger = logger; }
// For 'action', first set the TypeFilter and call Init. If picking is true and pickManipulatorOnly // is true, then only the currently active manipulator is tested against, which is a huge speed-up. private void Render(IRenderAction action, bool picking, bool pickManipulatorOnly) { base.BeginPaint(picking); action.Title = Camera.ViewTypeName; action.ViewportWidth = Width; action.ViewportHeight = Height; // If we're doing a picking operation, then we don't need to display the results to the user, etc. if (picking) { RenderState pickState = new RenderState(m_renderState); pickState.RenderMode &= ~(RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha); pickState.OverrideChildState = RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha; pickState.InheritState = 0; RenderStateGuardian.Reset(); // Manipulator picking can be further optimized to only render the manipulator. if (pickManipulatorOnly && m_manipulator != null && m_manipulatorNode != null) { // Replace the scene node's children temporarily with just our one child of interest. // Replacing the children is easier than creating a new Scene because the manipulators // need the HitRecord.GraphPath to have the full correct Scene, not a temp Scene. List<SceneNode> originalChildren = new List<SceneNode>(m_scene.Children); m_scene.Children.Clear(); m_scene.Children.Add(m_manipulatorNode); m_scene.StateStack.Push(pickState); action.PushMatrix(m_manipulatorParentToWorld, false); action.Dispatch(m_scene, Camera); action.PopMatrix(); m_scene.StateStack.Pop(); m_scene.Children.Clear(); foreach (SceneNode node in originalChildren) m_scene.Children.Add(node); } else { //Regular picking. Render the whole scene. m_scene.StateStack.Push(pickState); action.Dispatch(m_scene, Camera); m_scene.StateStack.Pop(); } // When picking, we don't want to display this buffer, so don't swap OpenGl buffers. // This property gets reset by base.EndPaint(). SwapBuffers = false; } else { m_scene.StateStack.Push(m_renderState); RenderStateGuardian.Reset(); action.Dispatch(m_scene, Camera); RenderAxisSystem(action); m_scene.StateStack.Pop(); } base.EndPaint(); }
private void RenderVertices(IRenderAction action) { int[] sizes = m_primitives.PrimitiveSizes; int[] indices = m_primitives.PrimitiveIndices; int nPrims = (m_subMesh != null) ? m_subMesh.Count : sizes.Length; int primBaseIndex = 0; Util3D.RenderStats.PrimCount += nPrims; for (int i = 0; i < nPrims; i++) { int primSize = sizes[i % sizes.Length]; Util3D.RenderStats.VertexCount += primSize; Gl.glBegin(m_drawMode); for (int j = 0; j < primSize; j++) { int offset = indices[primBaseIndex + j * m_bindingCount + m_vxCommand.PrimitiveIndex] * m_vxCommand.Stride; CallFunction(m_vxCommand, offset); } Gl.glEnd(); primBaseIndex += primSize * m_bindingCount; } }
/// <summary> /// Custom pick rendering</summary> /// <param name="graphPath">The graph path</param> /// <param name="renderState">The render state</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> public void PickDispatch(SceneNode[] graphPath, RenderState renderState, IRenderAction action, Camera camera) { action.RenderStateGuardian.Commit(renderState); // apply xform Gl.glPushMatrix(); Util3D.glMultMatrixf(action.TopMatrix); RenderVertices(action); Gl.glPopMatrix(); }
/// <summary> /// Called after post visiting the SceneNode specified by the graph path</summary> /// <param name="graphPath">The graph path</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> /// <param name="list">The traverse list</param> /// <returns></returns> public override TraverseState PostTraverse(Stack <SceneNode> graphPath, IRenderAction action, Camera camera, ICollection <TraverseNode> list) { action.PopMatrix(); return(TraverseState.Continue); }
/// <summary> /// Copies all of the given render action's properties to this instance</summary> /// <param name="other">Other render action</param> public void Set(IRenderAction other) { m_renderStateGuardian = other.RenderStateGuardian; m_height = other.ViewportHeight; m_width = other.ViewportWidth; }
public static RenderAction Create <T>(IRenderAction <T> renderAction) { return(new RenderAction(typeof(T), (node, ctx) => renderAction.Render((T)node, ctx))); }
private void AddRenderAction <T>(IRenderAction <T> renderAction) { myRenderActions.Add(RenderAction.Create(renderAction)); }
/// <summary> /// Performs actions during control drag</summary> /// <param name="hit">Hit record</param> /// <param name="x">Mouse x position</param> /// <param name="y">Mouse y position</param> /// <param name="action">Render action</param> /// <param name="camera">Camera</param> /// <param name="transform">Transform</param> /// <returns>Translation, in world coordinates</returns> public Vec3F OnDrag(HitRecord hit, float x, float y, IRenderAction action, Camera camera, Matrix4F transform) { float a1, a2; Matrix4F W = new Matrix4F(); W.Mul(transform, camera.ViewMatrix); // Setup rays, in view space. (-z goes into the screen.) Ray3F ray0 = camera.CreateRay(m_iX, m_iY); Ray3F ray = camera.CreateRay(x, y); // Build axis and origin in view space Vec3F xAxis = W.XAxis; Vec3F yAxis = W.YAxis; Vec3F zAxis = W.ZAxis; Vec3F origin = W.Translation; Vec3F trans = new Vec3F(); // Choose the best projection plane according to the projection angle switch ((HitElement)hit.RenderObjectData[1]) { case HitElement.X_ARROW: { a1 = Math.Abs(Vec3F.Dot(ray0.Direction, yAxis)); a2 = Math.Abs(Vec3F.Dot(ray0.Direction, zAxis)); Vec3F axis = (a1 > a2 ? yAxis : zAxis); Vec3F p0 = ray0.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); Vec3F p1 = ray.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); float dragAmount = Vec3F.Dot(xAxis, p1 - p0); Vec3F xLocal = transform.XAxis; trans = dragAmount * xLocal; } break; case HitElement.Y_ARROW: { a1 = Math.Abs(Vec3F.Dot(ray0.Direction, zAxis)); a2 = Math.Abs(Vec3F.Dot(ray0.Direction, xAxis)); Vec3F axis = (a1 > a2 ? zAxis : xAxis); Vec3F p0 = ray0.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); Vec3F p1 = ray.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); float dragAmount = Vec3F.Dot(yAxis, p1 - p0); Vec3F yLocal = transform.YAxis; trans = dragAmount * yLocal; } break; case HitElement.Z_ARROW: { a1 = Math.Abs(Vec3F.Dot(ray0.Direction, xAxis)); a2 = Math.Abs(Vec3F.Dot(ray0.Direction, yAxis)); Vec3F axis = (a1 > a2 ? xAxis : yAxis); Vec3F p0 = ray0.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); Vec3F p1 = ray.IntersectPlane(axis, -Vec3F.Dot(axis, origin)); float dragAmount = Vec3F.Dot(zAxis, p1 - p0); Vec3F zLocal = transform.ZAxis; trans = dragAmount * zLocal; } break; case HitElement.XY_SQUARE: { Vec3F p0 = ray0.IntersectPlane(zAxis, -Vec3F.Dot(zAxis, origin)); Vec3F p1 = ray.IntersectPlane(zAxis, -Vec3F.Dot(zAxis, origin)); Vec3F deltaLocal = p1 - p0; float dragX = Vec3F.Dot(xAxis, deltaLocal); float dragY = Vec3F.Dot(yAxis, deltaLocal); Vec3F xLocal = transform.XAxis; Vec3F yLocal = transform.YAxis; trans = dragX * xLocal + dragY * yLocal; } break; case HitElement.YZ_SQUARE: { Vec3F p0 = ray0.IntersectPlane(xAxis, -Vec3F.Dot(xAxis, origin)); Vec3F p1 = ray.IntersectPlane(xAxis, -Vec3F.Dot(xAxis, origin)); Vec3F deltaLocal = p1 - p0; float dragY = Vec3F.Dot(yAxis, deltaLocal); float dragZ = Vec3F.Dot(zAxis, deltaLocal); Vec3F yLocal = transform.YAxis; Vec3F zLocal = transform.ZAxis; trans = dragY * yLocal + dragZ * zLocal; } break; case HitElement.XZ_SQUARE: { Vec3F p0 = ray0.IntersectPlane(yAxis, -Vec3F.Dot(yAxis, origin)); Vec3F p1 = ray.IntersectPlane(yAxis, -Vec3F.Dot(yAxis, origin)); Vec3F deltaLocal = p1 - p0; float dragX = Vec3F.Dot(xAxis, deltaLocal); float dragZ = Vec3F.Dot(zAxis, deltaLocal); Vec3F xLocal = transform.XAxis; Vec3F zLocal = transform.ZAxis; trans = dragX * xLocal + dragZ * zLocal; } break; } return trans; }
/// <summary> /// Renders the object. Called from Dispatch().</summary> /// <param name="graphPath">The path leading to the RenderObject</param> /// <param name="renderState">The render state to use</param> /// <param name="renderAction">The render action used</param> /// <param name="camera">The camera</param> protected virtual void Render( SceneNode[] graphPath, RenderState renderState, IRenderAction renderAction, Camera camera) { }
public GetProductByCodeFunction(IMediator mediator, IRenderAction <GetProductByCodeDto, Result <GetProductResponse> > responseFormatter, ILogger <GetProductByCodeFunction> logger) { _mediator = mediator; _responseFormatter = responseFormatter; _logger = logger; }
protected override void beforeEach() { _renderAction = MockFor <IRenderAction>(); _renderAction.Expect(x => x.Render()); }
private void RenderAxisSystem(IRenderAction action) { // Calc width and height float width, height; float nearP = Camera.Frustum.Near * 1.1f; if (Camera.Frustum.IsOrtho) { width = (Camera.Frustum.Right - Camera.Frustum.Left) / 2 * 0.95f; height = (Camera.Frustum.Top - Camera.Frustum.Bottom) / 2 * 0.90f; } else { // Set the projection to orthogonal for perspective views float h = (float)Height / (float)Width; Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(-1, 1, -h, h, 1,1000); nearP = 1.1f; width = 0.92f; height = h * 0.90f; } // Push the view matrix Gl.glMatrixMode(Gl.GL_MODELVIEW); Matrix4F V = new Matrix4F(Camera.ViewMatrix); V.Translation = Vec3F.ZeroVector; // Disable lighting Gl.glDisable(Gl.GL_LIGHTING); Gl.glDisable(Gl.GL_TEXTURE_2D); Gl.glPushMatrix(); Gl.glLoadIdentity(); Gl.glTranslatef(-width, -height, -nearP); Util3D.glMultMatrixf(V); // Render the system RenderAxis(width/15); Gl.glPopMatrix(); }
/// <summary> /// Renders the specified graph path</summary> /// <param name="graphPath">The graph path</param> /// <param name="renderState">The render state</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> protected override void Render(SceneNode[] graphPath, RenderState renderState, IRenderAction action, Camera camera) { // apply xform Gl.glPushMatrix(); Util3D.glMultMatrixf(action.TopMatrix); if (m_displayListId == 0) { RenderStats globalStats = Util3D.RenderStats; RenderStats ourStats = new RenderStats(); Util3D.RenderStats = ourStats; m_displayListId = Gl.glGenLists(1); #if MEMORY_DEBUG lock (s_lock) NumDisplayListIds++; #endif Gl.glNewList(m_displayListId, Gl.GL_COMPILE); Render(action); Gl.glEndList(); m_numPrimitives = ourStats.PrimCount; m_numVertices = ourStats.VertexCount; Util3D.RenderStats = globalStats; } Gl.glCallList(m_displayListId); Gl.glPopMatrix(); Util3D.RenderStats.PrimCount += m_numPrimitives; Util3D.RenderStats.VertexCount += m_numVertices; }
public void Invoke(IRenderAction action) { action.Render(); }
/// <summary> /// Dispatches the RenderObject for rendering</summary> /// <param name="graphPath">The path leading to the RenderObject</param> /// <param name="renderState">The render state to use</param> /// <param name="renderAction">The render action dispatching the object</param> /// <param name="camera">The Camera used in the dispatch process</param> public virtual void Dispatch(SceneNode[] graphPath, RenderState renderState, IRenderAction renderAction, Camera camera) { renderAction.RenderStateGuardian.Commit(renderState); Render(graphPath, renderState, renderAction, camera); }
// For 'action', first set the TypeFilter and call Init. If picking is true and pickManipulatorOnly // is true, then only the currently active manipulator is tested against, which is a huge speed-up. private void Render(IRenderAction action, bool picking, bool pickManipulatorOnly) { base.BeginPaint(picking); action.Title = Camera.ViewTypeName; action.ViewportWidth = Width; action.ViewportHeight = Height; // If we're doing a picking operation, then we don't need to display the results to the user, etc. if (picking) { RenderState pickState = new RenderState(m_renderState); pickState.RenderMode &= ~(RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha); pickState.OverrideChildState = RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha; pickState.InheritState = 0; RenderStateGuardian.Reset(); // Manipulator picking can be further optimized to only render the manipulator. if (pickManipulatorOnly && m_manipulator != null && m_manipulatorNode != null) { // Replace the scene node's children temporarily with just our one child of interest. // Replacing the children is easier than creating a new Scene because the manipulators // need the HitRecord.GraphPath to have the full correct Scene, not a temp Scene. List <SceneNode> originalChildren = new List <SceneNode>(m_scene.Children); m_scene.Children.Clear(); m_scene.Children.Add(m_manipulatorNode); m_scene.StateStack.Push(pickState); action.PushMatrix(m_manipulatorParentToWorld, false); action.Dispatch(m_scene, Camera); action.PopMatrix(); m_scene.StateStack.Pop(); m_scene.Children.Clear(); foreach (SceneNode node in originalChildren) { m_scene.Children.Add(node); } } else { //Regular picking. Render the whole scene. m_scene.StateStack.Push(pickState); action.Dispatch(m_scene, Camera); m_scene.StateStack.Pop(); } // When picking, we don't want to display this buffer, so don't swap OpenGl buffers. // This property gets reset by base.EndPaint(). SwapBuffers = false; } else { m_scene.StateStack.Push(m_renderState); RenderStateGuardian.Reset(); action.Dispatch(m_scene, Camera); RenderAxisSystem(action); m_scene.StateStack.Pop(); } base.EndPaint(); }
/// <summary> /// Performs any post-traverse actions</summary> /// <param name="graphPath">The path leading to the RenderObject</param> /// <param name="renderAction">The render action used to dispatch the object</param> /// <param name="camera">The Camera used</param> /// <param name="traverseList">The traverse list used in the dispatch phase</param> /// <returns>The TraverseState</returns> public virtual TraverseState PostTraverse(Stack<SceneNode> graphPath, IRenderAction renderAction, Camera camera, ICollection<TraverseNode> traverseList) { return TraverseState.Continue; }
/// <summary> /// Performs any post-traverse actions</summary> /// <param name="graphPath">The path leading to the RenderObject</param> /// <param name="renderAction">The render action used to dispatch the object</param> /// <param name="camera">The Camera used</param> /// <param name="traverseList">The traverse list used in the dispatch phase</param> /// <returns>The TraverseState</returns> public virtual TraverseState PostTraverse(Stack <SceneNode> graphPath, IRenderAction renderAction, Camera camera, ICollection <TraverseNode> traverseList) { return(TraverseState.Continue); }
/// <summary> /// Copies all of the given render action's properties to this instance</summary> /// <param name="other">Other render action</param> public void Set(IRenderAction other) { m_renderStateGuardian = other.RenderStateGuardian; m_height = other.ViewportHeight; m_width = other.ViewportWidth; }
public void Invoke(IRenderAction action) { action.Render(); }
/// <summary> /// Renders control for picking</summary> /// <param name="action">Render action</param> /// <param name="camera">Camera</param> /// <param name="renderState">Render state</param> /// <param name="transform">Transform, local to world</param> public void RenderPick(IRenderAction action, Camera camera, RenderState renderState, Matrix4F transform) { action.RenderStateGuardian.Commit(renderState); // apply xform Gl.glPushMatrix(); Util3D.glMultMatrixf(transform); float s1, s2, s3; CalcAxisLengths(camera, transform, out s1, out s2, out s3); float squareSideX = s1 * SquareLength; float squareSideY = s2 * SquareLength; float squareSideZ = s3 * SquareLength; bool drawX, drawY, drawZ; DecideArrowDrawing(transform, camera, out drawX, out drawY, out drawZ); // Mark each axis with a different name. // Since the OpenGl selection buffer does a bad job in detecting lines we'll use // triangles instead. Gl.glPushName(m_nameBase); if (drawX) { Gl.glPushName((int)HitElement.X_ARROW); Gl.glBegin(Gl.GL_TRIANGLES); Gl.glVertex3f(squareSideX, 0, 0); Gl.glVertex3f(s1, 0, 0); Gl.glVertex3f(squareSideX, 0, 0); Gl.glEnd(); RenderXArrow(s1); Gl.glPopName(); } if (drawY) { Gl.glPushName((int)HitElement.Y_ARROW); Gl.glBegin(Gl.GL_TRIANGLES); Gl.glVertex3f(0, squareSideY, 0); Gl.glVertex3f(0, s2, 0); Gl.glVertex3f(0, squareSideY, 0); Gl.glEnd(); RenderYArrow(s2); Gl.glPopName(); } if (drawZ) { Gl.glPushName((int)HitElement.Z_ARROW); Gl.glBegin(Gl.GL_TRIANGLES); Gl.glVertex3f(0, 0, squareSideZ); Gl.glVertex3f(0, 0, s3); Gl.glVertex3f(0, 0, squareSideZ); Gl.glEnd(); RenderZArrow(s3); Gl.glPopName(); } if (drawX && drawY) { Gl.glPushName((int)HitElement.XY_SQUARE); RenderXYSquare(squareSideX, squareSideY, true); Gl.glPopName(); } if (drawY && drawZ) { Gl.glPushName((int)HitElement.YZ_SQUARE); RenderYZSquare(squareSideY, squareSideZ, true); Gl.glPopName(); } if (drawX && drawZ) { Gl.glPushName((int)HitElement.XZ_SQUARE); RenderXZSquare(squareSideX, squareSideZ, true); Gl.glPopName(); } Gl.glPopMatrix(); Gl.glPopName(); }
public ViewRenderer(IEnumerable <IRenderStrategy> strategies, IRenderAction renderAction) { _strategies = strategies; _renderAction = renderAction; }
public ViewRenderer(IEnumerable<IRenderStrategy> strategies, IRenderAction renderAction) { _strategies = strategies; _renderAction = renderAction; }
public void Invoke(IRenderAction action) { action.RenderPartial(); }
/// <summary> /// Renders the specified graph path</summary> /// <param name="graphPath">The graph path</param> /// <param name="renderState">The render state</param> /// <param name="action">The render action</param> /// <param name="camera">The camera</param> protected override void Render(SceneNode[] graphPath, RenderState renderState, IRenderAction action, Camera camera) { // apply xform Gl.glPushMatrix(); Util3D.glMultMatrixf(action.TopMatrix); if (m_displayListId == 0) { RenderStats globalStats = Util3D.RenderStats; RenderStats ourStats = new RenderStats(); Util3D.RenderStats = ourStats; m_displayListId = Gl.glGenLists(1); #if MEMORY_DEBUG lock(s_lock) NumDisplayListIds++; #endif Gl.glNewList(m_displayListId, Gl.GL_COMPILE); Render(action); Gl.glEndList(); m_numPrimitives = ourStats.PrimCount; m_numVertices = ourStats.VertexCount; Util3D.RenderStats = globalStats; } Gl.glCallList(m_displayListId); Gl.glPopMatrix(); Util3D.RenderStats.PrimCount += m_numPrimitives; Util3D.RenderStats.VertexCount += m_numVertices; }