private static extern void NativeDrawPrimitive(PrimitiveType pt, ulong vb, uint StartVertex, uint vertexCount, float *color, float *xform, BasicRendererFlags renderFlag);
//Draw primitive with the given parameters. public static void DrawPrimitive(PrimitiveType pt, ulong vb, uint StartVertex, uint vertexCount, Color color, Matrix4F xform, BasicRendererFlags renderFlag) { Vec4F vc; vc.X = color.R / 255.0f; vc.Y = color.G / 255.0f; vc.Z = color.B / 255.0f; vc.W = color.A / 255.0f; fixed(float *mtrx = &xform.M11) { NativeDrawPrimitive(pt, vb, StartVertex, vertexCount, &vc.X, mtrx, renderFlag); } }
/// <summary> /// Sets render flags used for basic drawing.</summary> public static void SetRendererFlag(GUILayer.SimpleRenderingContext context, BasicRendererFlags renderFlags) { context.InitState( (renderFlags & BasicRendererFlags.DisableDepthTest) == 0, (renderFlags & BasicRendererFlags.DisableDepthWrite) == 0); }
public override void Render(ViewControl vc) { BasicRendererFlags solid = BasicRendererFlags.Solid | BasicRendererFlags.DisableDepthTest; BasicRendererFlags wire = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) { return; } Camera camera = vc.Camera; int axis = (int)m_hitRegion; // axis colors Color saveColor = m_axisColor[axis]; m_axisColor[axis] = m_highlightColor; Color xcolor = m_axisColor[(int)HitRegion.XAxis]; Color ycolor = m_axisColor[(int)HitRegion.YAxis]; Color zcolor = m_axisColor[(int)HitRegion.ZAxis]; Color nxcolor = m_axisColor[(int)HitRegion.NegXAxis]; Color nycolor = m_axisColor[(int)HitRegion.NegYAxis]; Color nzcolor = m_axisColor[(int)HitRegion.NegZAxis]; m_axisColor[axis] = saveColor; Vec3F deltaTrans = Vec3F.ZeroVector; if (m_hitRegion != HitRegion.None) { normWorld.Translation = HitMatrix.Translation; } Vec3F pos = normWorld.Translation; float s; Util.CalcAxisLengths(vc.Camera, pos, out s); Vec3F sv = new Vec3F(s, s, s); Vec3F axscale = new Vec3F(s, s, s); Vec3F negAxscale = new Vec3F(-s, -s, -s); bool negativeAxis = m_hitRegion == HitRegion.NegXAxis || m_hitRegion == HitRegion.NegYAxis || m_hitRegion == HitRegion.NegZAxis; if (negativeAxis) { negAxscale.X *= Math.Abs(m_scale.X); negAxscale.Y *= Math.Abs(m_scale.Y); negAxscale.Z *= Math.Abs(m_scale.Z); } else { axscale.X *= Math.Abs(m_scale.X); axscale.Y *= Math.Abs(m_scale.Y); axscale.Z *= Math.Abs(m_scale.Z); } Matrix4F scale = new Matrix4F(); scale.Scale(axscale); Matrix4F xform = scale * normWorld; Util3D.RenderFlag = wire; Util3D.DrawX(xform, xcolor); Util3D.DrawY(xform, ycolor); Util3D.DrawZ(xform, zcolor); scale.Scale(negAxscale); xform = scale * normWorld; Util3D.DrawX(xform, nxcolor); Util3D.DrawY(xform, nycolor); Util3D.DrawZ(xform, nzcolor); Vec3F handle = sv * HandleRatio; float handleWidth = handle.X / 2; scale.Scale(handle); Matrix4F trans = new Matrix4F(); Util3D.RenderFlag = solid; // X handle trans.Translation = new Vec3F(axscale.X - handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, xcolor); // y handle trans.Translation = new Vec3F(0, axscale.Y - handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, ycolor); // z handle trans.Translation = new Vec3F(0, 0, axscale.Z - handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(xform, zcolor); // -x handle trans.Translation = new Vec3F(negAxscale.X + handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, nxcolor); // -y handle trans.Translation = new Vec3F(0, negAxscale.Y + handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, nycolor); // -z handle trans.Translation = new Vec3F(0, 0, negAxscale.Z + handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(xform, nzcolor); }
private static extern void NativeSetRendererFlag(BasicRendererFlags renderFlag);
/// <summary> /// Sets render flags used for basic drawing.</summary> public static void SetRendererFlag(BasicRendererFlags renderFlags) { NativeSetRendererFlag(renderFlags); }
public override void Render(ViewControl vc) { BasicRendererFlags solid = BasicRendererFlags.Solid | BasicRendererFlags.DisableDepthTest; BasicRendererFlags wire = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) { return; } Camera camera = vc.Camera; Vec3F pos = normWorld.Translation; float s; Util.CalcAxisLengths(vc.Camera, pos, out s); Vec3F sv = new Vec3F(s, s, s); Vec3F axscale = new Vec3F(Math.Abs(s * m_scale.X), Math.Abs(s * m_scale.Y), Math.Abs(s * m_scale.Z)); Color xcolor = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.FreeRect) ? Color.Gold : Color.Red; Color ycolor = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.FreeRect) ? Color.Gold : Color.Green; Color Zcolor = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.FreeRect) ? Color.Gold : Color.Blue; Color freeRect = (m_hitRegion == HitRegion.FreeRect) ? Color.Gold : Color.White; Matrix4F scale = new Matrix4F(); scale.Scale(axscale); Matrix4F xform = scale * normWorld; Util3D.RenderFlag = wire; Util3D.DrawX(xform, xcolor); Util3D.DrawY(xform, ycolor); Util3D.DrawZ(xform, Zcolor); Vec3F rectScale = sv * FreeRectRatio; scale.Scale(rectScale); Matrix4F b = Util.CreateBillboard(pos, camera.WorldEye, camera.Up, camera.LookAt); Matrix4F recXform = Matrix4F.Multiply(scale, b); Util3D.DrawRect(recXform, freeRect); Vec3F handle = sv * HandleRatio; float handleWidth = handle.X / 2; scale.Scale(handle); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(axscale.X - handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.RenderFlag = solid; Util3D.DrawCube(xform, xcolor); trans.Translation = new Vec3F(0, axscale.Y - handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, ycolor); trans.Translation = new Vec3F(0, 0, axscale.Z - handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(xform, Zcolor); }
public static void SetRenderFlag(GUILayer.SimpleRenderingContext context, BasicRendererFlags flags) { GameEngine.SetRendererFlag(context, flags); }
public void Render(Matrix4F normWorld, float s) { BasicRendererFlags solid = BasicRendererFlags.Solid | BasicRendererFlags.DisableDepthTest; BasicRendererFlags wire = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; Color xcolor = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.XYSquare || m_hitRegion == HitRegion.XZSquare) ? Color.Gold : Color.Red; Color ycolor = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.XYSquare || m_hitRegion == HitRegion.YZSquare) ? Color.Gold : Color.Green; Color Zcolor = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.XZSquare || m_hitRegion == HitRegion.YZSquare) ? Color.Gold : Color.Blue; Color XYx = m_hitRegion == HitRegion.XYSquare ? Color.Gold : Color.Red; Color XYy = m_hitRegion == HitRegion.XYSquare ? Color.Gold : Color.Green; Color XZx = m_hitRegion == HitRegion.XZSquare ? Color.Gold : Color.Red; Color XZz = m_hitRegion == HitRegion.XZSquare ? Color.Gold : Color.Blue; Color YZy = m_hitRegion == HitRegion.YZSquare ? Color.Gold : Color.Green; Color YZz = m_hitRegion == HitRegion.YZSquare ? Color.Gold : Color.Blue; Vec3F axScale = new Vec3F(s, s, s); Matrix4F axisXform = ComputeAxis(normWorld, axScale); Util3D.RenderFlag = wire; Util3D.DrawX(axisXform, xcolor); Util3D.DrawY(axisXform, ycolor); Util3D.DrawZ(axisXform, Zcolor); Matrix4F arrowHead = ComputeXhead(normWorld, s); Util3D.RenderFlag = solid; Util3D.DrawCone(arrowHead, xcolor); arrowHead = ComputeYhead(normWorld, s); Util3D.DrawCone(arrowHead, ycolor); arrowHead = ComputeZhead(normWorld, s); Util3D.DrawCone(arrowHead, Zcolor); Util3D.RenderFlag = wire; // draw xy rect. Matrix4F scale = new Matrix4F(); scale.Scale(axScale * SquareLength); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, s * SquareLength, 0); Matrix4F squareXform = scale * trans * normWorld; Util3D.DrawX(squareXform, XYy); trans.Translation = new Vec3F(s * SquareLength, 0, 0); squareXform = scale * trans * normWorld; Util3D.DrawY(squareXform, XYx); // draw xz rect. trans.Translation = new Vec3F(0, 0, s * SquareLength); squareXform = scale * trans * normWorld; Util3D.DrawX(squareXform, XZz); trans.Translation = new Vec3F(s * SquareLength, 0, 0); squareXform = scale * trans * normWorld; Util3D.DrawZ(squareXform, XZx); // draw yz trans.Translation = new Vec3F(0, s * SquareLength, 0); squareXform = scale * trans * normWorld; Util3D.DrawZ(squareXform, YZy); trans.Translation = new Vec3F(0, 0, s * SquareLength); squareXform = scale * trans * normWorld; Util3D.DrawY(squareXform, YZz); }
private static extern void NativeDrawIndexedPrimitive(PrimitiveType pt, ulong vb, ulong ib, uint startIndex, uint indexCount, uint startVertex, float* color, float* xform, BasicRendererFlags renderFlag);
public static void DrawIndexedPrimitive(PrimitiveType pt, ulong vb, ulong ib, uint startIndex, uint indexCount, uint startVertex, Color color, Matrix4F xform, BasicRendererFlags renderFlag) { Vec4F vc; vc.X = color.R / 255.0f; vc.Y = color.G / 255.0f; vc.Z = color.B / 255.0f; vc.W = color.A / 255.0f; fixed (float* mtrx = &xform.M11) { NativeDrawIndexedPrimitive(pt, vb, ib, startIndex, indexCount, startVertex, &vc.X, mtrx, renderFlag); } }
/// <summary> /// Sets render flags used for basic drawing.</summary> public static void SetRendererFlag(BasicRendererFlags renderFlags) { using (var context = XLEBridgeUtils.NativeDesignControl.CreateSimpleRenderingContext(s_savedRenderResources)) { context.InitState( (renderFlags & BasicRendererFlags.DisableDepthTest)==0, (renderFlags & BasicRendererFlags.DisableDepthWrite) == 0); } }