public override void Render(object opaqueContext, ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) { return; } var context = opaqueContext as GUILayer.SimpleRenderingContext; if (context == null) { return; } float RingDiameter = 2 * AxisLength; Color xcolor = (m_hitRegion == HitRegion.XAxis) ? Color.Gold : XAxisColor; Color ycolor = (m_hitRegion == HitRegion.YAxis) ? Color.Gold : YAxisColor; Color Zcolor = (m_hitRegion == HitRegion.ZAxis) ? Color.Gold : ZAxisColor; Color lColor = (m_hitRegion == HitRegion.LookAxis) ? Color.Gold : Color.Cyan; float s = Util.CalcAxisScale(vc.Camera, normWorld.Translation, RingDiameter, vc.Height); Vec3F axScale = new Vec3F(s, s, s); Matrix4F rot = new Matrix4F(); Matrix4F scale = new Matrix4F(); scale.Scale(axScale); rot.RotX(MathHelper.PiOver2); Matrix4F xform = scale * rot * normWorld; Util3D.DrawRing(context, xform, Zcolor); rot.RotZ(-MathHelper.PiOver2); xform = scale * rot * normWorld; Util3D.DrawRing(context, xform, xcolor); xform = scale * normWorld; Util3D.DrawRing(context, xform, ycolor); Matrix4F billboard = Util.CreateBillboard(normWorld.Translation, vc.Camera.WorldEye, vc.Camera.Up, vc.Camera.LookAt); rot.RotX(MathHelper.PiOver2); scale.Scale(s * LookRingScale); xform = scale * rot * billboard; Util3D.DrawRing(context, xform, lColor); }
public override void Render(ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) { return; } Camera camera = vc.Camera; float s; Util.CalcAxisLengths(camera, normWorld.Translation, out s); m_translatorControl.Render(normWorld, s); Matrix4F sc = new Matrix4F(); Vec3F pos = normWorld.Translation; s /= 12.0f; sc.Scale(s); Matrix4F bl = new Matrix4F(); Util.CreateBillboard(bl, pos, camera.WorldEye, camera.Up, camera.LookAt); Matrix4F recXform = new Matrix4F(); Matrix4F.Multiply(sc, bl, recXform); Util3D.DrawPivot(recXform, Color.Yellow); }
private Matrix4F ComputeAxis(Matrix4F normWorld, Vec3F axisScale) { Matrix4F scale = new Matrix4F(); scale.Scale(axisScale); Matrix4F xform = scale * normWorld; return(xform); }
private void RenderSystemAxis() { float nz = Camera.Frustum.NearZ; float x = 0.05f * Width; Vec3F pos = new Vec3F(x, Height - x, 0.0f); Matrix4F vp = Camera.ViewMatrix * Camera.ProjectionMatrix; pos = this.Unproject(pos, vp); if (Camera.Frustum.IsOrtho) { pos = pos + Camera.LookAt; } else { pos = pos + Camera.LookAt * (Camera.NearZ * 0.1f); } float s; Util.CalcAxisLengths(Camera, pos, out s); Matrix4F scale = new Matrix4F(); scale.Scale(s * 0.3f); Matrix4F trans = new Matrix4F(pos); Matrix4F xform = scale * trans; Util3D.RenderFlag = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; Util3D.DrawX(xform, Color.Red); Util3D.DrawY(xform, Color.Green); Util3D.DrawZ(xform, Color.Blue); Matrix4F wvp = xform * vp; if (ViewType != ViewTypes.Left && ViewType != ViewTypes.Right) { Vec3F xaxis = new Vec3F(1, 0, 0); Point scPt = Project(wvp, xaxis); GameEngine.DrawText2D("X", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Red); } if (ViewType != ViewTypes.Top && ViewType != ViewTypes.Bottom) { Vec3F yaxis = new Vec3F(0, 1.6f, 0); Point scPt = Project(wvp, yaxis); GameEngine.DrawText2D("Y", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Green); } if (ViewType != ViewTypes.Front && ViewType != ViewTypes.Back) { Vec3F zaxis = new Vec3F(0, 0, 1); Point scPt = Project(wvp, zaxis); GameEngine.DrawText2D("Z", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Blue); } }
public override void Render(object opaqueContext, ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) { return; } var context = opaqueContext as GUILayer.SimpleRenderingContext; if (context == null) { return; } Vec3F pos = normWorld.Translation; float s = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height); bool highlight = m_hitRegion == HitRegion.XYSquare; Color centerCubeColor = highlight ? Color.Gold : Color.White; Vec3F sv = new Vec3F(s, s, s); Vec3F centerCubeScale = sv * CenterCubeSize; Matrix4F scale = new Matrix4F(); scale.Scale(centerCubeScale); Matrix4F centerCubeXform = scale * normWorld; Util3D.DrawCube(context, centerCubeXform, centerCubeColor); Matrix4F arrowScale = new Matrix4F(); arrowScale.Scale(0.75f); Util3D.DrawArrowCap( context, arrowScale * Matrix4F.CreateTranslation(new Vec3F(1.0f, 0.0f, -0.5f)) * centerCubeXform, highlight ? Color.Gold : Color.Red); Util3D.DrawArrowCap( context, arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, Math.PI) * Matrix4F.CreateTranslation(new Vec3F(-1.0f, 0.0f, -0.5f)) * centerCubeXform, highlight ? Color.Gold : Color.Red); Util3D.DrawArrowCap( context, arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, .5 * Math.PI) * Matrix4F.CreateTranslation(new Vec3F(0.0f, 1.0f, -0.5f)) * centerCubeXform, highlight ? Color.Gold : Color.Green); Util3D.DrawArrowCap( context, arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, 1.5f * Math.PI) * Matrix4F.CreateTranslation(new Vec3F(0.0f, -1.0f, -0.5f)) * centerCubeXform, highlight ? Color.Gold : Color.Green); }
private Matrix4F ComputeYhead(Matrix4F normWorld, float s) { Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, s * (1 - ConeHeight), 0); Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s * ConeDiameter, s * ConeHeight, s * ConeDiameter)); Matrix4F xform = scale * trans * normWorld; return(xform); }
private Matrix4F ComputeYhead(Matrix4F normWorld, float s) { Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, s * (1 - hr), 0); Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s * br, s * hr, s * br)); Matrix4F xform = scale * trans * normWorld; return(xform); }
private Matrix4F ComputeXhead(Matrix4F normWorld, float s) { Matrix4F headrot = new Matrix4F(); headrot.RotZ(-MathHelper.PiOver2); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(s * (1 - hr), 0, 0); Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s * br, s * hr, s * br)); Matrix4F xform = scale * headrot * trans * normWorld; return(xform); }
private Matrix4F ComputeZhead(Matrix4F normWorld, float s) { Matrix4F headrot = new Matrix4F(); headrot.RotX(MathHelper.PiOver2); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, 0, s * (1 - ConeHeight)); Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s * ConeDiameter, s * ConeHeight, s * ConeDiameter)); Matrix4F xform = scale * headrot * trans * normWorld; return(xform); }
/// <summary> /// Calculates the transformation matrix corresponding to the given transform components</summary> /// <param name="translation">Translation</param> /// <param name="rotation">Rotation</param> /// <param name="scale">Scale</param> /// <param name="scalePivot">Translation to origin of scaling</param> /// <param name="scalePivotTranslate">Translation after scaling</param> /// <param name="rotatePivot">Translation to origin of rotation</param> /// <param name="rotatePivotTranslate">Translation after rotation</param> /// <returns>Transformation matrix corresponding to the given transform components</returns> public static Matrix4F CalcTransform( Vec3F translation, Vec3F rotation, Vec3F scale, Vec3F scalePivot, Vec3F scalePivotTranslate, Vec3F rotatePivot, Vec3F rotatePivotTranslate) { Matrix4F M = new Matrix4F(); Matrix4F temp = new Matrix4F(); M.Set(-scalePivot); temp.Scale(scale); M.Mul(M, temp); temp.Set(scalePivot + scalePivotTranslate - rotatePivot); M.Mul(M, temp); if (rotation.X != 0) { temp.RotX(rotation.X); M.Mul(M, temp); } if (rotation.Y != 0) { temp.RotY(rotation.Y); M.Mul(M, temp); } if (rotation.Z != 0) { temp.RotZ(rotation.Z); M.Mul(M, temp); } temp.Set(rotatePivot + rotatePivotTranslate + translation); M.Mul(M, temp); return(M); }
public override bool Pick(ViewControl vc, Point scrPt) { m_hitRegion = HitRegion.None; if (base.Pick(vc, scrPt) == false) { return(false); } Camera camera = vc.Camera; Matrix4F view = camera.ViewMatrix; Matrix4F vp = view * camera.ProjectionMatrix; Matrix4F wvp = HitMatrix * vp; Ray3F rayL = vc.GetRay(scrPt, wvp); float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height); // There's only one hot-spot for this manipulator: // a square at the manipulator origin. Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); float centerCubeScale = s * CenterCubeSize; Matrix4F centerCubeXform = new Matrix4F(); centerCubeXform.Scale(centerCubeScale); centerCubeXform.Invert(centerCubeXform); Ray3F ray = rayL; ray.Transform(centerCubeXform); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XYSquare; return(true); } m_hitRegion = HitRegion.None; return(false); }
public override void Render(ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) return; Camera camera = vc.Camera; float s; Util.CalcAxisLengths(camera, normWorld.Translation, out s); m_translatorControl.Render(normWorld, s); Matrix4F sc = new Matrix4F(); Vec3F pos = normWorld.Translation; s /= 12.0f; sc.Scale(s); Matrix4F bl = new Matrix4F(); Util.CreateBillboard(bl, pos, camera.WorldEye, camera.Up, camera.LookAt); Matrix4F recXform = new Matrix4F(); Matrix4F.Multiply(sc, bl, recXform); Util3D.DrawPivot(recXform, Color.Yellow); }
public override bool Pick(ViewControl vc, Point scrPt) { m_hitRegion = HitRegion.None; if (base.Pick(vc, scrPt) == false) return false; Camera camera = vc.Camera; Matrix4F view = camera.ViewMatrix; Matrix4F vp = view * camera.ProjectionMatrix; Matrix4F wvp = HitMatrix * vp; Ray3F rayL = vc.GetRay(scrPt,wvp); float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height); // There's only one hot-spot for this manipulator: // a square at the manipulator origin. Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); float centerCubeScale = s * CenterCubeSize; Matrix4F centerCubeXform = new Matrix4F(); centerCubeXform.Scale(centerCubeScale); centerCubeXform.Invert(centerCubeXform); Ray3F ray = rayL; ray.Transform(centerCubeXform); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XYSquare; return true; } m_hitRegion = HitRegion.None; return false; }
public override void Render(ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) { return; } Util3D.RenderFlag = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; Color xcolor = (m_hitRegion == HitRegion.XAxis) ? Color.LightSalmon : Color.Red; Color ycolor = (m_hitRegion == HitRegion.YAxis) ? Color.LightGreen : Color.Green; Color Zcolor = (m_hitRegion == HitRegion.ZAxis) ? Color.LightBlue : Color.Blue; float s; Util.CalcAxisLengths(vc.Camera, normWorld.Translation, out s); Vec3F axScale = new Vec3F(s, s, s); Matrix4F scale = new Matrix4F(); scale.Scale(axScale); Matrix4F xform = scale * normWorld; Util3D.DrawCircle(xform, Zcolor); Matrix4F rot = new Matrix4F(); rot.RotY(MathHelper.PiOver2); xform = scale * rot * normWorld; Util3D.DrawCircle(xform, xcolor); rot.RotX(MathHelper.PiOver2); xform = scale * rot * normWorld; Util3D.DrawCircle(xform, ycolor); }
public void Render(Camera cam) { GameEngine.SetRendererFlag(BasicRendererFlags.WireFrame); IGrid grid = this.As<IGrid>(); if (grid.Visible == false) return; float s = grid.Size; Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s, s, s)); Matrix4F gridXform = new Matrix4F(); if (cam.Frustum.IsOrtho) { float dist = cam.ViewMatrix.Translation.Z; ViewTypes vt = cam.ViewType; if (vt == ViewTypes.Top) { gridXform.Translation = new Vec3F(0, dist, 0); } else if (vt == ViewTypes.Bottom) { gridXform.Translation = new Vec3F(0, -dist, 0); } else if (vt == ViewTypes.Right) { gridXform.RotZ(MathHelper.PiOver2); gridXform.Translation = new Vec3F(dist, 0, 0); } else if (vt == ViewTypes.Left) { gridXform.RotZ(MathHelper.PiOver2); gridXform.Translation = new Vec3F(-dist, 0, 0); } else if (vt == ViewTypes.Front) { gridXform.RotX(MathHelper.PiOver2); gridXform.Translation = new Vec3F(0, 0, dist); } else if (vt == ViewTypes.Back) { gridXform.RotX(MathHelper.PiOver2); gridXform.Translation = new Vec3F(0, 0, -dist); } gridXform.Mul(scale, gridXform); } else { Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, grid.Height, 0); gridXform = Matrix4F.Multiply(scale, trans); } GameEngine.DrawPrimitive(PrimitiveType.LineList, m_gridVBId, 0, m_gridVertexCount, Color.LightGray, Matrix4F.Multiply(gridXform, cam.AxisSystem)); GameEngine.DrawPrimitive(PrimitiveType.LineList, m_basisAxesVBId, 0, m_basisAxesVertexCount, Color.White, gridXform); }
public override void Render(ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) return; 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; if (m_hitRegion != HitRegion.None) { normWorld.Translation = HitMatrix.Translation; } Vec3F pos = normWorld.Translation; float s = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height); Vec3F sv = new Vec3F(s, s, s); Vec3F axscale = new Vec3F(s*AxisThickness, s, s*AxisThickness); bool negativeAxis = m_hitRegion == HitRegion.NegXAxis || m_hitRegion == HitRegion.NegYAxis || m_hitRegion == HitRegion.NegZAxis; Vec3F dragScale = new Vec3F(Math.Abs(m_scale.X), Math.Abs(m_scale.Y), Math.Abs(m_scale.Z)); Matrix4F rot = new Matrix4F(); Matrix4F scale = new Matrix4F(); axscale.Y = negativeAxis ? s : s * dragScale.X; scale.Scale(axscale); rot.RotZ(-MathHelper.PiOver2); Matrix4F xform = scale * rot * normWorld; Util3D.DrawCylinder(xform, xcolor); axscale.Y = negativeAxis ? s : s * dragScale.Y; scale.Scale(axscale); xform = scale * normWorld; Util3D.DrawCylinder(xform, ycolor); axscale.Y = negativeAxis ? s : s * dragScale.Z; scale.Scale(axscale); rot.RotX(MathHelper.PiOver2); xform = scale * rot * normWorld; Util3D.DrawCylinder(xform, zcolor); rot.RotZ(MathHelper.PiOver2); axscale.Y = negativeAxis ? s * dragScale.X : s; scale.Scale(axscale); xform = scale * rot * normWorld; Util3D.DrawCylinder(xform, nxcolor); rot.RotZ(MathHelper.Pi); axscale.Y = negativeAxis ? s * dragScale.Y : s; scale.Scale(axscale); xform = scale * rot * normWorld; Util3D.DrawCylinder(xform, nycolor); rot.RotX(-MathHelper.PiOver2); axscale.Y = negativeAxis ? s * dragScale.Z : s; scale.Scale(axscale); xform = scale * rot * normWorld; Util3D.DrawCylinder(xform, nzcolor); // draw center cube scale.Scale(s*(1.0f / 16.0f)); xform = scale * normWorld; Util3D.DrawCube(xform, Color.White); Vec3F handle = sv*AxisHandle; float handleWidth = handle.X/2; scale.Scale(handle); Matrix4F trans = new Matrix4F(); // X handle float drag = m_hitRegion == HitRegion.XAxis ? dragScale.X : 1.0f; trans.Translation = new Vec3F(drag * sv.X - handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, xcolor); // y handle drag = m_hitRegion == HitRegion.YAxis ? dragScale.Y : 1.0f; trans.Translation = new Vec3F(0, drag * sv.Y - handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, ycolor); // z handle drag = m_hitRegion == HitRegion.ZAxis ? dragScale.Z : 1.0f; trans.Translation = new Vec3F(0, 0, drag * sv.Z - handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(xform, zcolor); // -x handle drag = m_hitRegion == HitRegion.NegXAxis ? dragScale.X : 1.0f; trans.Translation = new Vec3F(-sv.X * drag + handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, nxcolor); // -y handle drag = m_hitRegion == HitRegion.NegYAxis ? dragScale.Y : 1.0f; trans.Translation = new Vec3F(0, -sv.Y * drag + handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, nycolor); // -z handle drag = m_hitRegion == HitRegion.NegZAxis ? dragScale.Z : 1.0f; trans.Translation = new Vec3F(0, 0, -sv.Z * drag + handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(xform, nzcolor); }
public override void Render(ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) return; Vec3F pos = normWorld.Translation; float s = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height); bool highlight = m_hitRegion == HitRegion.XYSquare; Color centerCubeColor = highlight ? Color.Gold : Color.White; Vec3F sv = new Vec3F(s, s, s); Vec3F centerCubeScale = sv * CenterCubeSize; Matrix4F scale = new Matrix4F(); scale.Scale(centerCubeScale); Matrix4F centerCubeXform = scale * normWorld; Util3D.DrawCube(centerCubeXform, centerCubeColor); Matrix4F arrowScale = new Matrix4F(); arrowScale.Scale(0.75f); Util3D.DrawArrowCap( arrowScale * Matrix4F.CreateTranslation(new Vec3F(1.0f, 0.0f, -0.5f)) * centerCubeXform, highlight ? Color.Gold : Color.Red); Util3D.DrawArrowCap( arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, Math.PI) * Matrix4F.CreateTranslation(new Vec3F(-1.0f, 0.0f, -0.5f)) * centerCubeXform, highlight ? Color.Gold : Color.Red); Util3D.DrawArrowCap( arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, .5 * Math.PI) * Matrix4F.CreateTranslation(new Vec3F(0.0f, 1.0f, -0.5f)) * centerCubeXform, highlight ? Color.Gold : Color.Green); Util3D.DrawArrowCap( arrowScale * Matrix4F.RotAxisRH(Vec3F.ZAxis, 1.5f * Math.PI) * Matrix4F.CreateTranslation(new Vec3F(0.0f, -1.0f, -0.5f)) * centerCubeXform, highlight ? Color.Gold : Color.Green); }
private Matrix4F ComputeZhead(Matrix4F normWorld, float s) { Matrix4F headrot = new Matrix4F(); headrot.RotX(MathHelper.PiOver2); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, 0, s * (1 - hr)); Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s * br, s * hr, s * br)); Matrix4F xform = scale * headrot * trans * normWorld; return xform; }
public HitRegion Pick(ViewControl vc, Matrix4F world, Matrix4F view, Ray3F rayL, Ray3F rayV) { float s = Util.CalcAxisScale(vc.Camera, world.Translation, Manipulator.AxisLength, vc.Height); m_hitRegion = HitRegion.None; m_hitRayV = rayV; m_hitMatrix.Set(world); m_hitWorldView = world * view; float sl = s * SquareLength; // test xy square. Vec3F p1 = new Vec3F(0, 0, 0); Vec3F p2 = new Vec3F(sl, 0, 0); Vec3F p3 = new Vec3F(sl, sl, 0); Vec3F p4 = new Vec3F(0, sl, 0); Plane3F plane = new Plane3F(p1, p2, p3); Vec3F p; if (rayL.IntersectPlane(plane, out p)) { // test point in 2d rectangle. if (p.X > p1.X && p.X < p2.X && p.Y > p1.Y && p.Y < p4.Y) { m_hitRegion = HitRegion.XYSquare; return(m_hitRegion); } } // test xz square p1 = new Vec3F(0, 0, 0); p2 = new Vec3F(sl, 0, 0); p3 = new Vec3F(sl, 0, sl); p4 = new Vec3F(0, 0, sl); plane = new Plane3F(p1, p2, p3); if (rayL.IntersectPlane(plane, out p)) { // test point in 2d rectangle. if (p.X > p1.X && p.X < p2.X && p.Z > p1.Z && p.Z < p4.Z) { m_hitRegion = HitRegion.XZSquare; return(m_hitRegion); } } // test yz square p1 = new Vec3F(0, 0, 0); p2 = new Vec3F(0, 0, sl); p3 = new Vec3F(0, sl, sl); p4 = new Vec3F(0, sl, 0); plane = new Plane3F(p1, p2, p3); if (rayL.IntersectPlane(plane, out p)) { // test point in 2d rectangle. if (p.Z > p1.Z && p.Z < p2.Z && p.Y > p1.Z && p.Y < p4.Y) { m_hitRegion = HitRegion.YZSquare; return(m_hitRegion); } } Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); Matrix4F boxScale = new Matrix4F(); Matrix4F boxTrans = new Matrix4F(); Matrix4F BoxMtrx = new Matrix4F(); // X axis boxScale.Scale(new Vec3F(s, s * ConeDiameter, s * ConeDiameter)); boxTrans.Translation = new Vec3F(s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; Ray3F ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XAxis; return(m_hitRegion); } // y axis boxScale.Scale(new Vec3F(s * ConeDiameter, s, s * ConeDiameter)); boxTrans.Translation = new Vec3F(0, s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.YAxis; return(m_hitRegion); } // z axis boxScale.Scale(new Vec3F(s * ConeDiameter, s * ConeDiameter, s)); boxTrans.Translation = new Vec3F(0, 0, s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.ZAxis; } return(m_hitRegion); }
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 Matrix4F ComputeAxis(Matrix4F normWorld, Vec3F axisScale) { Matrix4F scale = new Matrix4F(); scale.Scale(axisScale); Matrix4F xform = scale * normWorld; return xform; }
public override bool Pick(ViewControl vc, Point scrPt) { m_hitRegion = HitRegion.None; if (base.Pick(vc, scrPt) == false) { return(false); } Camera camera = vc.Camera; float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height); Matrix4F vp = camera.ViewMatrix * camera.ProjectionMatrix; Matrix4F wvp = HitMatrix * vp; // get ray in object space space. Ray3F rayL = vc.GetRay(scrPt, wvp); m_scale = new Vec3F(1, 1, 1); m_hitScale = s; Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); float centerCubeScale = s * CenterCubeSize; Matrix4F centerCubeXform = new Matrix4F(); centerCubeXform.Scale(centerCubeScale); centerCubeXform.Invert(centerCubeXform); Ray3F ray = rayL; ray.Transform(centerCubeXform); if (box.Intersect(ray)) { m_hitRegion = HitRegion.CenterCube; return(true); } Matrix4F boxScale = new Matrix4F(); Matrix4F boxTrans = new Matrix4F(); Matrix4F BoxMtrx = new Matrix4F(); float handleScale = s * AxisHandle; // X axis boxScale.Scale(new Vec3F(s, handleScale, handleScale)); boxTrans.Translation = new Vec3F(s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XAxis; return(true); } // y axis boxScale.Scale(new Vec3F(handleScale, s, handleScale)); boxTrans.Translation = new Vec3F(0, s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.YAxis; return(true); } // z axis boxScale.Scale(new Vec3F(handleScale, handleScale, s)); boxTrans.Translation = new Vec3F(0, 0, s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.ZAxis; return(true); } return(false); }
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 void Render(Camera cam) { GameEngine.SetRendererFlag(BasicRendererFlags.WireFrame); IGrid grid = this.As <IGrid>(); if (grid.Visible == false) { return; } float s = grid.Size; Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s, s, s)); Matrix4F gridXform = new Matrix4F(); if (cam.Frustum.IsOrtho) { float dist = cam.ViewMatrix.Translation.Z; ViewTypes vt = cam.ViewType; if (vt == ViewTypes.Top) { gridXform.Translation = new Vec3F(0, dist, 0); } else if (vt == ViewTypes.Bottom) { gridXform.Translation = new Vec3F(0, -dist, 0); } else if (vt == ViewTypes.Right) { gridXform.RotZ(MathHelper.PiOver2); gridXform.Translation = new Vec3F(dist, 0, 0); } else if (vt == ViewTypes.Left) { gridXform.RotZ(MathHelper.PiOver2); gridXform.Translation = new Vec3F(-dist, 0, 0); } else if (vt == ViewTypes.Front) { gridXform.RotX(MathHelper.PiOver2); gridXform.Translation = new Vec3F(0, 0, dist); } else if (vt == ViewTypes.Back) { gridXform.RotX(MathHelper.PiOver2); gridXform.Translation = new Vec3F(0, 0, -dist); } gridXform.Mul(scale, gridXform); } else { Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, grid.Height, 0); gridXform = Matrix4F.Multiply(scale, trans); } GameEngine.DrawPrimitive(PrimitiveType.LineList, m_gridVBId, 0, m_gridVertexCount, Color.LightGray, gridXform); }
public override void Render(object opaqueContext, ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) { return; } var context = opaqueContext as GUILayer.SimpleRenderingContext; if (context == null) { return; } Vec3F pos = normWorld.Translation; float s = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height); Color xcolor = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.CenterCube) ? Color.Gold : XAxisColor; Color ycolor = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.CenterCube) ? Color.Gold : YAxisColor; Color zcolor = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.CenterCube) ? Color.Gold : ZAxisColor; Color centerCubeColor = (m_hitRegion == HitRegion.CenterCube) ? Color.Gold : Color.White; Vec3F sv = new Vec3F(s, s, s); Vec3F axscale = new Vec3F(s * AxisThickness, s, s * AxisThickness); Matrix4F scale = new Matrix4F(); axscale.Y = Math.Abs(s * m_scale.X); scale.Scale(axscale); Matrix4F rot = new Matrix4F(); rot.RotZ(-MathHelper.PiOver2); Matrix4F xform = scale * rot * normWorld; Util3D.DrawCylinder(context, xform, xcolor); axscale.Y = Math.Abs(s * m_scale.Y); scale.Scale(axscale); xform = scale * normWorld; Util3D.DrawCylinder(context, xform, ycolor); rot.RotX(MathHelper.PiOver2); axscale.Y = Math.Abs(s * m_scale.Z); scale.Scale(axscale); xform = scale * rot * normWorld; Util3D.DrawCylinder(context, xform, zcolor); Vec3F centerCubeScale = sv * CenterCubeSize; scale.Scale(centerCubeScale); Matrix4F centerCubeXform = scale * normWorld; Util3D.DrawCube(context, centerCubeXform, centerCubeColor); Vec3F handleScale = new Vec3F(Math.Abs(s * m_scale.X), Math.Abs(s * m_scale.Y), Math.Abs(s * m_scale.Z)); Vec3F handle = sv * AxisHandle; float handleWidth = handle.X / 2; scale.Scale(handle); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(handleScale.X - handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, xcolor); trans.Translation = new Vec3F(0, handleScale.Y - handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, ycolor); trans.Translation = new Vec3F(0, 0, handleScale.Z - handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, zcolor); }
private void RenderSystemAxis() { float nz = Camera.Frustum.NearZ; float x = 0.05f * Width; Vec3F pos = new Vec3F(x, Height-x , 0.0f); Matrix4F vp = Camera.ViewMatrix * Camera.ProjectionMatrix; pos = this.Unproject(pos, vp); if (Camera.Frustum.IsOrtho) pos = pos + Camera.LookAt; else pos = pos + Camera.LookAt * (Camera.NearZ * 0.1f); float s; Util.CalcAxisLengths(Camera, pos, out s); Matrix4F scale = new Matrix4F(); scale.Scale(s * 0.3f); Matrix4F trans = new Matrix4F(pos); Matrix4F xform = scale * trans; Util3D.RenderFlag = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; Util3D.DrawX(xform, Color.Red); Util3D.DrawY(xform, Color.Green); Util3D.DrawZ(xform, Color.Blue); Matrix4F wvp = xform * vp; if (ViewType != ViewTypes.Left && ViewType != ViewTypes.Right) { Vec3F xaxis = new Vec3F(1, 0, 0); Point scPt = Project(wvp, xaxis); GameEngine.DrawText2D("X", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Red); } if (ViewType != ViewTypes.Top && ViewType != ViewTypes.Bottom) { Vec3F yaxis = new Vec3F(0, 1.6f, 0); Point scPt = Project(wvp, yaxis); GameEngine.DrawText2D("Y", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Green); } if (ViewType != ViewTypes.Front && ViewType != ViewTypes.Back) { Vec3F zaxis = new Vec3F(0, 0, 1); Point scPt = Project(wvp, zaxis); GameEngine.DrawText2D("Z", Util3D.CaptionFont, scPt.X, scPt.Y, Color.Blue); } }
private void RenderProperties(IEnumerable <object> objects, bool renderCaption, bool renderBound, bool renderPivot) { bool renderAny = renderCaption || renderBound || renderPivot; if (renderAny == false) { return; } Util3D.RenderFlag = BasicRendererFlags.WireFrame; Matrix4F vp = Camera.ViewMatrix * Camera.ProjectionMatrix; foreach (object obj in objects) { IBoundable bnode = obj.As <IBoundable>(); if (bnode == null || bnode.BoundingBox.IsEmpty || obj.Is <IGameObjectFolder>()) { continue; } INameable nnode = obj.As <INameable>(); ITransformable trans = obj.As <ITransformable>(); if (renderBound) { Util3D.DrawAABB(bnode.BoundingBox); } if (renderCaption && nnode != null) { Vec3F topCenter = bnode.BoundingBox.Center; topCenter.Y = bnode.BoundingBox.Max.Y; Point pt = Project(vp, topCenter); GameEngine.DrawText2D(nnode.Name, Util3D.CaptionFont, pt.X, pt.Y, Color.White); } } if (renderPivot) { Util3D.RenderFlag = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; // create few temp matrics to Matrix4F toWorld = new Matrix4F(); Matrix4F PV = new Matrix4F(); Matrix4F sc = new Matrix4F(); Matrix4F bl = new Matrix4F(); Matrix4F recXform = new Matrix4F(); foreach (object obj in objects) { ITransformable trans = obj.As <ITransformable>(); IBoundable bnode = obj.As <IBoundable>(); if (trans == null || bnode == null || bnode.BoundingBox.IsEmpty || obj.Is <IGameObjectFolder>()) { continue; } Path <DomNode> path = new Path <DomNode>(trans.Cast <DomNode>().GetPath()); toWorld.Set(Vec3F.ZeroVector); TransformUtils.CalcPathTransform(toWorld, path, path.Count - 1); // Offset by pivot PV.Set(trans.Pivot); toWorld.Mul(PV, toWorld); Vec3F pos = toWorld.Translation; float s; Util.CalcAxisLengths(Camera, pos, out s); s /= 12.0f; sc.Scale(s); Util.CreateBillboard(bl, pos, Camera.WorldEye, Camera.Up, Camera.LookAt); Matrix4F.Multiply(sc, bl, recXform); Util3D.DrawPivot(recXform, Color.Yellow); } } }
private Matrix4F ComputeXhead(Matrix4F normWorld, float s) { Matrix4F headrot = new Matrix4F(); headrot.RotZ(-MathHelper.PiOver2); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(s * (1 - ConeHeight), 0, 0); Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s * ConeDiameter, s * ConeHeight, s * ConeDiameter)); Matrix4F xform = scale * headrot * trans * normWorld; return xform; }
public override bool Pick(ViewControl vc, Point scrPt) { m_hitRegion = HitRegion.None; if (base.Pick(vc, scrPt) == false) { return(false); } Camera camera = vc.Camera; float s; Util.CalcAxisLengths(camera, HitMatrix.Translation, out s); Matrix4F vp = camera.ViewMatrix * camera.ProjectionMatrix; Matrix4F wvp = HitMatrix * vp; // get ray in object space space. Ray3F rayL = vc.GetRay(scrPt, wvp); m_scale = new Vec3F(1, 1, 1); m_hitScale = s; float rectScale = s * FreeRectRatio; Vec3F topRight = rectScale * (new Vec3F(1, 1, 0)); Vec3F topLeft = rectScale * (new Vec3F(-1, 1, 0)); Vec3F bottomLeft = rectScale * (new Vec3F(-1, -1, 0)); Vec3F bottomRight = rectScale * (new Vec3F(1, -1, 0)); Matrix4F planeXform = Util.CreateBillboard(HitMatrix.Translation, camera.WorldEye, camera.Up, camera.LookAt); Matrix4F wvpPlane = planeXform * vp; // create ray in plane's local space. Ray3F rayP = vc.GetRay(scrPt, wvpPlane); Plane3F plane = new Plane3F(topRight, topLeft, bottomLeft); Vec3F p; bool intersect = rayP.IntersectPlane(plane, out p); if (intersect) { bool inside = p.X > topLeft.X && p.X <topRight.X && p.Y> bottomLeft.Y && p.Y < topLeft.Y; if (inside) { m_hitRegion = HitRegion.FreeRect; return(true); } } Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); Matrix4F boxScale = new Matrix4F(); Matrix4F boxTrans = new Matrix4F(); Matrix4F BoxMtrx = new Matrix4F(); float handleScale = s * HandleRatio; // X axis boxScale.Scale(new Vec3F(s, handleScale, handleScale)); boxTrans.Translation = new Vec3F(s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; Ray3F ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XAxis; return(true); } // y axis boxScale.Scale(new Vec3F(handleScale, s, handleScale)); boxTrans.Translation = new Vec3F(0, s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.YAxis; return(true); } // z axis boxScale.Scale(new Vec3F(handleScale, handleScale, s)); boxTrans.Translation = new Vec3F(0, 0, s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.ZAxis; return(true); } return(false); }
private Matrix4F ComputeYhead(Matrix4F normWorld, float s) { Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, s * (1 - ConeHeight), 0); Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s * ConeDiameter, s * ConeHeight, s * ConeDiameter)); Matrix4F xform = scale * trans * normWorld; return xform; }
public override void Render(ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) return; Vec3F pos = normWorld.Translation; float s = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height); Color xcolor = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.CenterCube ) ? Color.Gold : XAxisColor; Color ycolor = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.CenterCube ) ? Color.Gold : YAxisColor; Color zcolor = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.CenterCube ) ? Color.Gold : ZAxisColor; Color centerCubeColor = (m_hitRegion == HitRegion.CenterCube) ? Color.Gold : Color.White; Vec3F sv = new Vec3F(s, s, s); Vec3F axscale = new Vec3F(s * AxisThickness, s, s * AxisThickness); Matrix4F scale = new Matrix4F(); axscale.Y = Math.Abs(s * m_scale.X); scale.Scale(axscale); Matrix4F rot = new Matrix4F(); rot.RotZ(-MathHelper.PiOver2); Matrix4F xform = scale * rot * normWorld; Util3D.DrawCylinder(xform, xcolor); axscale.Y = Math.Abs(s * m_scale.Y); scale.Scale(axscale); xform = scale * normWorld; Util3D.DrawCylinder(xform, ycolor); rot.RotX(MathHelper.PiOver2); axscale.Y = Math.Abs(s * m_scale.Z); scale.Scale(axscale); xform = scale * rot * normWorld; Util3D.DrawCylinder(xform, zcolor); Vec3F centerCubeScale = sv * CenterCubeSize; scale.Scale(centerCubeScale); Matrix4F centerCubeXform = scale * normWorld; Util3D.DrawCube(centerCubeXform, centerCubeColor); Vec3F handleScale = new Vec3F(Math.Abs(s * m_scale.X), Math.Abs(s * m_scale.Y), Math.Abs(s * m_scale.Z)); Vec3F handle = sv * AxisHandle; float handleWidth = handle.X / 2; scale.Scale(handle); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(handleScale.X - handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, xcolor); trans.Translation = new Vec3F(0, handleScale.Y - handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(xform, ycolor); trans.Translation = new Vec3F(0, 0, handleScale.Z - handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(xform, zcolor); }
public HitRegion Pick(Matrix4F world, Matrix4F view, Ray3F rayL, Ray3F rayV, float s) { m_hitRegion = HitRegion.None; m_hitRayV = rayV; m_hitMatrix.Set(world); m_hitWorldView = world * view; float sl = s * SquareLength; // test xy square. Vec3F p1 = new Vec3F(0, 0, 0); Vec3F p2 = new Vec3F(sl, 0, 0); Vec3F p3 = new Vec3F(sl, sl, 0); Vec3F p4 = new Vec3F(0, sl, 0); Plane3F plane = new Plane3F(p1, p2, p3); Vec3F p; if (rayL.IntersectPlane(plane, out p)) { // test point in 2d rectangle. if (p.X > p1.X && p.X < p2.X && p.Y > p1.Y && p.Y < p4.Y) { m_hitRegion = HitRegion.XYSquare; return m_hitRegion; } } // test xz square p1 = new Vec3F(0, 0, 0); p2 = new Vec3F(sl, 0, 0); p3 = new Vec3F(sl, 0, sl); p4 = new Vec3F(0, 0, sl); plane = new Plane3F(p1, p2, p3); if (rayL.IntersectPlane(plane, out p)) { // test point in 2d rectangle. if (p.X > p1.X && p.X < p2.X && p.Z > p1.Z && p.Z < p4.Z) { m_hitRegion = HitRegion.XZSquare; return m_hitRegion; } } // test yz square p1 = new Vec3F(0, 0, 0); p2 = new Vec3F(0, 0, sl); p3 = new Vec3F(0, sl, sl); p4 = new Vec3F(0, sl, 0); plane = new Plane3F(p1, p2, p3); if (rayL.IntersectPlane(plane, out p)) { // test point in 2d rectangle. if (p.Z > p1.Z && p.Z < p2.Z && p.Y > p1.Z && p.Y < p4.Y) { m_hitRegion = HitRegion.YZSquare; return m_hitRegion; } } Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); Matrix4F boxScale = new Matrix4F(); Matrix4F boxTrans = new Matrix4F(); Matrix4F BoxMtrx = new Matrix4F(); // X axis boxScale.Scale(new Vec3F(s, s * br, s * br)); boxTrans.Translation = new Vec3F(s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; Ray3F ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XAxis; return m_hitRegion; } // y axis boxScale.Scale(new Vec3F(s * br, s, s * br)); boxTrans.Translation = new Vec3F(0, s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.YAxis; return m_hitRegion; } // z axis boxScale.Scale(new Vec3F(s * br, s * br, s)); boxTrans.Translation = new Vec3F(0, 0, s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.ZAxis; } return m_hitRegion; }
public override void Render(ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) return; Util3D.RenderFlag = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; Color xcolor = (m_hitRegion == HitRegion.XAxis ) ? Color.LightSalmon : Color.Red; Color ycolor = (m_hitRegion == HitRegion.YAxis ) ? Color.LightGreen : Color.Green; Color Zcolor = (m_hitRegion == HitRegion.ZAxis ) ? Color.LightBlue : Color.Blue; float s; Util.CalcAxisLengths(vc.Camera, normWorld.Translation, out s); Vec3F axScale = new Vec3F(s, s, s); Matrix4F scale = new Matrix4F(); scale.Scale(axScale); Matrix4F xform = scale*normWorld; Util3D.DrawCircle(xform, Zcolor); Matrix4F rot = new Matrix4F(); rot.RotY(MathHelper.PiOver2); xform = scale * rot * normWorld; Util3D.DrawCircle(xform, xcolor); rot.RotX(MathHelper.PiOver2); xform = scale * rot * normWorld; Util3D.DrawCircle(xform,ycolor); }
private Matrix4F ComputeYhead(Matrix4F normWorld, float s) { Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, s * (1 - hr), 0); Matrix4F scale = new Matrix4F(); scale.Scale(new Vec3F(s * br, s * hr, s * br)); Matrix4F xform = scale * trans * normWorld; return xform; }
public override ManipulatorPickResult Pick(ViewControl vc, Point scrPt) { m_hitRegion = HitRegion.None; if (base.Pick(vc, scrPt) == ManipulatorPickResult.Miss) { return(ManipulatorPickResult.Miss); } Camera camera = vc.Camera; float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height); Matrix4F vp = camera.ViewMatrix * camera.ProjectionMatrix; Matrix4F wvp = HitMatrix * vp; // get ray in object space space. Ray3F rayL = vc.GetRay(scrPt, wvp); m_scale = new Vec3F(1, 1, 1); m_hitScale = s; Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); Matrix4F boxScale = new Matrix4F(); Matrix4F boxTrans = new Matrix4F(); Matrix4F BoxMtrx = new Matrix4F(); float handleScale = s * AxisHandle; // +X axis boxScale.Scale(new Vec3F(s, handleScale, handleScale)); boxTrans.Translation = new Vec3F(s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; Ray3F ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XAxis; return(ManipulatorPickResult.DeferredBeginDrag); } // -X boxTrans.Translation = new Vec3F(-s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.NegXAxis; return(ManipulatorPickResult.DeferredBeginDrag); } // y axis boxScale.Scale(new Vec3F(handleScale, s, handleScale)); boxTrans.Translation = new Vec3F(0, s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.YAxis; return(ManipulatorPickResult.DeferredBeginDrag); } // -Y boxTrans.Translation = new Vec3F(0, -s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.NegYAxis; return(ManipulatorPickResult.DeferredBeginDrag); } // z axis boxScale.Scale(new Vec3F(handleScale, handleScale, s)); boxTrans.Translation = new Vec3F(0, 0, s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.ZAxis; return(ManipulatorPickResult.DeferredBeginDrag); } // -Z boxTrans.Translation = new Vec3F(0, 0, -s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.NegZAxis; return(ManipulatorPickResult.DeferredBeginDrag); } return(ManipulatorPickResult.Miss); }
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); }
public void Render(ViewControl vc, Matrix4F normWorld) { float s = Util.CalcAxisScale(vc.Camera, normWorld.Translation, Manipulator.AxisLength, vc.Height); Color xcolor = (m_hitRegion == HitRegion.XAxis || m_hitRegion == HitRegion.XYSquare || m_hitRegion == HitRegion.XZSquare) ? Color.Gold : Manipulator.XAxisColor; Color ycolor = (m_hitRegion == HitRegion.YAxis || m_hitRegion == HitRegion.XYSquare || m_hitRegion == HitRegion.YZSquare) ? Color.Gold : Manipulator.YAxisColor; Color Zcolor = (m_hitRegion == HitRegion.ZAxis || m_hitRegion == HitRegion.XZSquare || m_hitRegion == HitRegion.YZSquare) ? Color.Gold : Manipulator.ZAxisColor; Color XYx = m_hitRegion == HitRegion.XYSquare ? Color.Gold : Manipulator.XAxisColor; Color XYy = m_hitRegion == HitRegion.XYSquare ? Color.Gold : Manipulator.YAxisColor; Color XZx = m_hitRegion == HitRegion.XZSquare ? Color.Gold : Manipulator.XAxisColor; Color XZz = m_hitRegion == HitRegion.XZSquare ? Color.Gold : Manipulator.ZAxisColor; Color YZy = m_hitRegion == HitRegion.YZSquare ? Color.Gold : Manipulator.YAxisColor; Color YZz = m_hitRegion == HitRegion.YZSquare ? Color.Gold : Manipulator.ZAxisColor; var axisScale = new Matrix4F(); axisScale.Scale(new Vec3F(s * Manipulator.AxisThickness, s * (1 - ConeHeight), s * Manipulator.AxisThickness)); var axisrot = new Matrix4F(); // Draw X axis axisrot.RotZ(-MathHelper.PiOver2); Matrix4F scaleRot = axisScale * axisrot; Matrix4F axisXform = scaleRot * normWorld; Util3D.DrawCylinder(axisXform, xcolor); // draw y axisXform = axisScale * normWorld; Util3D.DrawCylinder(axisXform, ycolor); // draw z axisrot.RotX(MathHelper.PiOver2); scaleRot = axisScale * axisrot; axisXform = scaleRot * normWorld; Util3D.DrawCylinder(axisXform, Zcolor); // draw center cube. Matrix4F cubeScale = new Matrix4F(); cubeScale.Scale(CenterCube * s); var cubexform = cubeScale * normWorld; Util3D.DrawCube(cubexform, Color.White); Matrix4F arrowHead = ComputeXhead(normWorld, s); Util3D.DrawCone(arrowHead, xcolor); arrowHead = ComputeYhead(normWorld, s); Util3D.DrawCone(arrowHead, ycolor); arrowHead = ComputeZhead(normWorld, s); Util3D.DrawCone(arrowHead, Zcolor); // draw xy rect. Matrix4F scale = new Matrix4F(); scale.Scale(s * Manipulator.AxisThickness, s * SquareLength, s * Manipulator.AxisThickness); Matrix4F trans = new Matrix4F(); trans.Translation = new Vec3F(0, s * SquareLength, 0); Matrix4F rot = new Matrix4F(); rot.RotZ(-MathHelper.PiOver2); Matrix4F squareXform = scale * rot * trans * normWorld; Util3D.DrawCylinder(squareXform, XYy); trans.Translation = new Vec3F(s * SquareLength, 0, 0); squareXform = scale * trans * normWorld; Util3D.DrawCylinder(squareXform, XYx); // draw xz rect. trans.Translation = new Vec3F(0, 0, s * SquareLength); rot.RotZ(-MathHelper.PiOver2); squareXform = scale * rot * trans * normWorld; Util3D.DrawCylinder(squareXform, XZz); trans.Translation = new Vec3F(s * SquareLength, 0, 0); rot.RotX(MathHelper.PiOver2); squareXform = scale * rot * trans * normWorld; Util3D.DrawCylinder(squareXform, XZx); // draw yz trans.Translation = new Vec3F(0, s * SquareLength, 0); rot.RotX(MathHelper.PiOver2); squareXform = scale * rot * trans * normWorld; Util3D.DrawCylinder(squareXform, YZy); trans.Translation = new Vec3F(0, 0, s * SquareLength); squareXform = scale * trans * normWorld; Util3D.DrawCylinder(squareXform, YZz); }
private void RenderProperties(IEnumerable<object> objects, bool renderCaption, bool renderBound, bool renderPivot) { if (renderCaption || renderBound) { Util3D.RenderFlag = BasicRendererFlags.WireFrame; Matrix4F vp = Camera.ViewMatrix * Camera.ProjectionMatrix; foreach (object obj in objects) { IBoundable bnode = obj.As<IBoundable>(); if (bnode == null || bnode.BoundingBox.IsEmpty || obj.Is<IGameObjectFolder>()) continue; INameable nnode = obj.As<INameable>(); ITransformable trans = obj.As<ITransformable>(); if (renderBound) { Util3D.DrawAABB(bnode.BoundingBox); } if (renderCaption && nnode != null) { Vec3F topCenter = bnode.BoundingBox.Center; topCenter.Y = bnode.BoundingBox.Max.Y; Point pt = Project(vp, topCenter); GameEngine.DrawText2D(nnode.Name, Util3D.CaptionFont, pt.X, pt.Y, Color.White); } } } if (renderPivot) { Util3D.RenderFlag = BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest; // create few temp matrics to Matrix4F toWorld = new Matrix4F(); Matrix4F PV = new Matrix4F(); Matrix4F sc = new Matrix4F(); Matrix4F bl = new Matrix4F(); Matrix4F recXform = new Matrix4F(); foreach (object obj in objects) { ITransformable trans = obj.As<ITransformable>(); IBoundable bnode = obj.As<IBoundable>(); if (trans == null || bnode == null || bnode.BoundingBox.IsEmpty || obj.Is<IGameObjectFolder>()) continue; Path<DomNode> path = new Path<DomNode>(trans.Cast<DomNode>().GetPath()); toWorld.Set(Vec3F.ZeroVector); TransformUtils.CalcPathTransform(toWorld, path, path.Count - 1); // Offset by pivot PV.Set(trans.Pivot); toWorld.Mul(PV, toWorld); Vec3F pos = toWorld.Translation; const float pivotDiameter = 16; // in pixels float s = Util.CalcAxisScale(Camera, pos, pivotDiameter, Height); sc.Scale(s); Util.CreateBillboard(bl, pos, Camera.WorldEye, Camera.Up, Camera.LookAt); recXform = sc * bl; Util3D.DrawPivot(recXform, Color.Yellow); } } }
/// <summary> /// Performs initialization when the adapter's node is set. /// This method is called each time the adapter is connected to its underlying node. /// Typically overridden by creators of DOM adapters.</summary> protected override void OnNodeSet() { base.OnNodeSet(); // get trans, scale, and rot. foreach (DomNode domNode in this.DomNode.GetChildList(Schema.node.scaleChild)) { m_scale = Tools.GetVector3(domNode, Schema.TargetableFloat3.Attribute); break; } foreach (DomNode domNode in this.DomNode.GetChildList(Schema.node.translateChild)) { m_translation = Tools.GetVector3(domNode, Schema.TargetableFloat3.Attribute); break; } const float PiOver180 = (float)(Math.PI / 180.0f); foreach (DomNode node in DomNode.GetChildList(Schema.node.rotateChild)) { double[] arr = (double[])node.GetAttribute(Schema.rotate.Attribute); float angle = (float)arr[3] * PiOver180; string sid = node.GetAttribute(Schema.rotate.sidAttribute) as string; if (string.IsNullOrEmpty(sid)) { continue; } if (sid == "rotateX") { m_rotation.X = angle; } else if (sid == "rotateY") { m_rotation.Y = angle; } else if (sid == "rotateZ") { m_rotation.Z = angle; } } Matrix4F M = new Matrix4F(); Matrix4F temp = new Matrix4F(); temp.Scale(Scale); M.Mul(M, temp); if (m_rotation.X != 0) { temp.RotX(m_rotation.X); M.Mul(M, temp); } if (m_rotation.Y != 0) { temp.RotY(m_rotation.Y); M.Mul(M, temp); } if (m_rotation.Z != 0) { temp.RotZ(m_rotation.Z); M.Mul(M, temp); } temp.Set(Translation); M.Mul(M, temp); Transform = M; m_boundingBox = new Cached <Box>(CalculateBoundingBox); Visible = true; }
public override void Render(object opaqueContext, ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) { return; } var context = opaqueContext as GUILayer.SimpleRenderingContext; if (context == null) { return; } 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; if (m_hitRegion != HitRegion.None) { normWorld.Translation = HitMatrix.Translation; } Vec3F pos = normWorld.Translation; float s = Util.CalcAxisScale(vc.Camera, pos, AxisLength, vc.Height); Vec3F sv = new Vec3F(s, s, s); Vec3F axscale = new Vec3F(s * AxisThickness, s, s * AxisThickness); bool negativeAxis = m_hitRegion == HitRegion.NegXAxis || m_hitRegion == HitRegion.NegYAxis || m_hitRegion == HitRegion.NegZAxis; Vec3F dragScale = new Vec3F(Math.Abs(m_scale.X), Math.Abs(m_scale.Y), Math.Abs(m_scale.Z)); Matrix4F rot = new Matrix4F(); Matrix4F scale = new Matrix4F(); axscale.Y = negativeAxis ? s : s * dragScale.X; scale.Scale(axscale); rot.RotZ(-MathHelper.PiOver2); Matrix4F xform = scale * rot * normWorld; Util3D.DrawCylinder(context, xform, xcolor); axscale.Y = negativeAxis ? s : s * dragScale.Y; scale.Scale(axscale); xform = scale * normWorld; Util3D.DrawCylinder(context, xform, ycolor); axscale.Y = negativeAxis ? s : s * dragScale.Z; scale.Scale(axscale); rot.RotX(MathHelper.PiOver2); xform = scale * rot * normWorld; Util3D.DrawCylinder(context, xform, zcolor); rot.RotZ(MathHelper.PiOver2); axscale.Y = negativeAxis ? s * dragScale.X : s; scale.Scale(axscale); xform = scale * rot * normWorld; Util3D.DrawCylinder(context, xform, nxcolor); rot.RotZ(MathHelper.Pi); axscale.Y = negativeAxis ? s * dragScale.Y : s; scale.Scale(axscale); xform = scale * rot * normWorld; Util3D.DrawCylinder(context, xform, nycolor); rot.RotX(-MathHelper.PiOver2); axscale.Y = negativeAxis ? s * dragScale.Z : s; scale.Scale(axscale); xform = scale * rot * normWorld; Util3D.DrawCylinder(context, xform, nzcolor); // draw center cube scale.Scale(s * (1.0f / 16.0f)); xform = scale * normWorld; Util3D.DrawCube(context, xform, Color.White); Vec3F handle = sv * AxisHandle; float handleWidth = handle.X / 2; scale.Scale(handle); Matrix4F trans = new Matrix4F(); // X handle float drag = m_hitRegion == HitRegion.XAxis ? dragScale.X : 1.0f; trans.Translation = new Vec3F(drag * sv.X - handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, xcolor); // y handle drag = m_hitRegion == HitRegion.YAxis ? dragScale.Y : 1.0f; trans.Translation = new Vec3F(0, drag * sv.Y - handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, ycolor); // z handle drag = m_hitRegion == HitRegion.ZAxis ? dragScale.Z : 1.0f; trans.Translation = new Vec3F(0, 0, drag * sv.Z - handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, zcolor); // -x handle drag = m_hitRegion == HitRegion.NegXAxis ? dragScale.X : 1.0f; trans.Translation = new Vec3F(-sv.X * drag + handleWidth, 0, 0); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, nxcolor); // -y handle drag = m_hitRegion == HitRegion.NegYAxis ? dragScale.Y : 1.0f; trans.Translation = new Vec3F(0, -sv.Y * drag + handleWidth, 0); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, nycolor); // -z handle drag = m_hitRegion == HitRegion.NegZAxis ? dragScale.Z : 1.0f; trans.Translation = new Vec3F(0, 0, -sv.Z * drag + handleWidth); xform = scale * trans * normWorld; Util3D.DrawCube(context, xform, nzcolor); }
/// <summary> /// Performs initialization when the adapter's node is set. /// This method is called each time the adapter is connected to its underlying node. /// Typically overridden by creators of DOM adapters.</summary> protected override void OnNodeSet() { base.OnNodeSet(); // get trans, scale, and rot. foreach (DomNode domNode in this.DomNode.GetChildList(Schema.node.scaleChild)) { m_scale = Tools.GetVector3(domNode, Schema.TargetableFloat3.Attribute); break; } foreach (DomNode domNode in this.DomNode.GetChildList(Schema.node.translateChild)) { m_translation = Tools.GetVector3(domNode, Schema.TargetableFloat3.Attribute); break; } const float PiOver180 = (float)(Math.PI / 180.0f); foreach (DomNode node in DomNode.GetChildList(Schema.node.rotateChild)) { double[] arr = (double[])node.GetAttribute(Schema.rotate.Attribute); float angle = (float)arr[3] * PiOver180; string sid = node.GetAttribute(Schema.rotate.sidAttribute) as string; if (string.IsNullOrEmpty(sid)) continue; if (sid == "rotateX") m_rotation.X = angle; else if (sid == "rotateY") m_rotation.Y = angle; else if (sid == "rotateZ") m_rotation.Z = angle; } Matrix4F M = new Matrix4F(); Matrix4F temp = new Matrix4F(); temp.Scale(Scale); M.Mul(M, temp); if (m_rotation.X != 0) { temp.RotX(m_rotation.X); M.Mul(M, temp); } if (m_rotation.Y != 0) { temp.RotY(m_rotation.Y); M.Mul(M, temp); } if (m_rotation.Z != 0) { temp.RotZ(m_rotation.Z); M.Mul(M, temp); } temp.Set(Translation); M.Mul(M, temp); Transform = M; m_boundingBox = new Cached<Box>(CalculateBoundingBox); Visible = true; }
public override bool Pick(ViewControl vc, Point scrPt) { m_hitRegion = HitRegion.None; if (base.Pick(vc, scrPt) == false) return false; Camera camera = vc.Camera; float s = Util.CalcAxisScale(vc.Camera, HitMatrix.Translation, AxisLength, vc.Height); Matrix4F vp = camera.ViewMatrix * camera.ProjectionMatrix; Matrix4F wvp = HitMatrix * vp; // get ray in object space space. Ray3F rayL = vc.GetRay(scrPt, wvp); m_scale = new Vec3F(1, 1, 1); m_hitScale = s; Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); Matrix4F boxScale = new Matrix4F(); Matrix4F boxTrans = new Matrix4F(); Matrix4F BoxMtrx = new Matrix4F(); float handleScale = s * AxisHandle; // +X axis boxScale.Scale(new Vec3F(s, handleScale, handleScale)); boxTrans.Translation = new Vec3F(s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; Ray3F ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XAxis; return true; } // -X boxTrans.Translation = new Vec3F(-s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.NegXAxis; return true; } // y axis boxScale.Scale(new Vec3F(handleScale, s, handleScale)); boxTrans.Translation = new Vec3F(0, s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.YAxis; return true; } // -Y boxTrans.Translation = new Vec3F(0, -s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.NegYAxis; return true; } // z axis boxScale.Scale(new Vec3F(handleScale, handleScale, s)); boxTrans.Translation = new Vec3F(0, 0, s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.ZAxis; return true; } // -Z boxTrans.Translation = new Vec3F(0, 0, -s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.NegZAxis; return true; } return false; }
/// <summary> /// Calculates the transformation matrix corresponding to the given transform components /// </summary> /// <param name="translation">Translation</param> /// <param name="rotation">Rotation</param> /// <param name="scale">Scale</param> /// <param name="scalePivot">Translation to origin of scaling</param> /// <param name="scalePivotTranslate">Translation after scaling</param> /// <param name="rotatePivot">Translation to origin of rotation</param> /// <param name="rotatePivotTranslate">Translation after rotation</param> /// <returns>transformation matrix corresponding to the given transform components</returns> public static Matrix4F CalcTransform( Vec3F translation, Vec3F rotation, Vec3F scale, Vec3F pivot) { Matrix4F M = new Matrix4F(); Matrix4F temp = new Matrix4F(); M.Set(-pivot); temp.Scale(scale); M.Mul(M, temp); if (rotation.X != 0) { temp.RotX(rotation.X); M.Mul(M, temp); } if (rotation.Y != 0) { temp.RotY(rotation.Y); M.Mul(M, temp); } if (rotation.Z != 0) { temp.RotZ(rotation.Z); M.Mul(M, temp); } temp.Set(pivot + translation); M.Mul(M, temp); return M; }
public override void Render(object opaqueContext, ViewControl vc) { Matrix4F normWorld = GetManipulatorMatrix(); if (normWorld == null) return; var context = opaqueContext as GUILayer.SimpleRenderingContext; if (context == null) return; float RingDiameter = 2 * AxisLength; Color xcolor = (m_hitRegion == HitRegion.XAxis) ? Color.Gold : XAxisColor; Color ycolor = (m_hitRegion == HitRegion.YAxis ) ? Color.Gold : YAxisColor; Color Zcolor = (m_hitRegion == HitRegion.ZAxis ) ? Color.Gold : ZAxisColor; Color lColor = (m_hitRegion == HitRegion.LookAxis) ? Color.Gold : Color.Cyan; float s = Util.CalcAxisScale(vc.Camera, normWorld.Translation, RingDiameter, vc.Height); Vec3F axScale = new Vec3F(s, s, s); Matrix4F rot = new Matrix4F(); Matrix4F scale = new Matrix4F(); scale.Scale(axScale); rot.RotX(MathHelper.PiOver2); Matrix4F xform = scale * rot * normWorld; Util3D.DrawRing(context, xform, Zcolor); rot.RotZ(-MathHelper.PiOver2); xform = scale * rot * normWorld; Util3D.DrawRing(context, xform, xcolor); xform = scale * normWorld; Util3D.DrawRing(context, xform, ycolor); Matrix4F billboard = Util.CreateBillboard(normWorld.Translation, vc.Camera.WorldEye, vc.Camera.Up, vc.Camera.LookAt); rot.RotX(MathHelper.PiOver2); scale.Scale(s * LookRingScale); xform = scale * rot * billboard; Util3D.DrawRing(context, xform, lColor); }
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 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 void RenderProperties(GUILayer.SimpleRenderingContext context, IEnumerable <object> objects, bool renderCaption, bool renderBound, bool renderPivot) { if (renderCaption || renderBound) { Util3D.SetRenderFlag(context, BasicRendererFlags.WireFrame); Matrix4F vp = Camera.ViewMatrix * Camera.ProjectionMatrix; foreach (object obj in objects) { IBoundable bnode = obj.As <IBoundable>(); if (bnode == null || bnode.BoundingBox.IsEmpty || obj.Is <IGameObjectFolder>()) { continue; } INameable nnode = obj.As <INameable>(); ITransformable trans = obj.As <ITransformable>(); if (renderBound) { Util3D.DrawAABB(context, bnode.BoundingBox); } if (renderCaption && nnode != null) { Vec3F topCenter = bnode.BoundingBox.Center; topCenter.Y = bnode.BoundingBox.Max.Y; Point pt = Project(vp, topCenter); GameEngine.DrawText2D(nnode.Name, Util3D.CaptionFont, pt.X, pt.Y, Color.White); } } } if (renderPivot) { Util3D.SetRenderFlag(context, BasicRendererFlags.WireFrame | BasicRendererFlags.DisableDepthTest); // create few temp matrics to Matrix4F toWorld = new Matrix4F(); Matrix4F PV = new Matrix4F(); Matrix4F sc = new Matrix4F(); Matrix4F bl = new Matrix4F(); Matrix4F recXform = new Matrix4F(); foreach (object obj in objects) { ITransformable trans = obj.As <ITransformable>(); IBoundable bnode = obj.As <IBoundable>(); if (trans == null || bnode == null || bnode.BoundingBox.IsEmpty || obj.Is <IGameObjectFolder>()) { continue; } Path <DomNode> path = new Path <DomNode>(trans.Cast <DomNode>().GetPath()); toWorld.Set(Vec3F.ZeroVector); TransformUtils.CalcPathTransform(toWorld, path, path.Count - 1); // Offset by pivot PV.Set(trans.Pivot); toWorld.Mul(PV, toWorld); Vec3F pos = toWorld.Translation; const float pivotDiameter = 16; // in pixels float s = Util.CalcAxisScale(Camera, pos, pivotDiameter, Height); sc.Scale(s); Util.CreateBillboard(bl, pos, Camera.WorldEye, Camera.Up, Camera.LookAt); recXform = sc * bl; Util3D.DrawPivot(context, recXform, Color.Yellow); } } }
public override bool Pick(ViewControl vc, Point scrPt) { m_hitRegion = HitRegion.None; if (base.Pick(vc, scrPt) == false) return false; Camera camera = vc.Camera; float s; Util.CalcAxisLengths(camera, HitMatrix.Translation, out s); Matrix4F vp = camera.ViewMatrix * camera.ProjectionMatrix; Matrix4F wvp = HitMatrix * vp; // get ray in object space space. Ray3F rayL = vc.GetRay(scrPt, wvp); m_scale = new Vec3F(1, 1, 1); m_hitScale = s; float rectScale = s*FreeRectRatio; Vec3F topRight = rectScale * (new Vec3F(1, 1, 0)); Vec3F topLeft = rectScale * (new Vec3F(-1, 1, 0)); Vec3F bottomLeft = rectScale * (new Vec3F(-1, -1, 0)); Vec3F bottomRight = rectScale * (new Vec3F(1, -1, 0)); Matrix4F planeXform = Util.CreateBillboard(HitMatrix.Translation, camera.WorldEye, camera.Up, camera.LookAt); Matrix4F wvpPlane = planeXform * vp; // create ray in plane's local space. Ray3F rayP = vc.GetRay(scrPt, wvpPlane); Plane3F plane = new Plane3F(topRight,topLeft,bottomLeft); Vec3F p; bool intersect = rayP.IntersectPlane(plane, out p); if(intersect) { bool inside = p.X > topLeft.X && p.X < topRight.X && p.Y > bottomLeft.Y && p.Y < topLeft.Y; if (inside) { m_hitRegion = HitRegion.FreeRect; return true; } } Vec3F min = new Vec3F(-0.5f, -0.5f, -0.5f); Vec3F max = new Vec3F(0.5f, 0.5f, 0.5f); AABB box = new AABB(min, max); Matrix4F boxScale = new Matrix4F(); Matrix4F boxTrans = new Matrix4F(); Matrix4F BoxMtrx = new Matrix4F(); float handleScale = s * HandleRatio; // X axis boxScale.Scale(new Vec3F(s, handleScale, handleScale)); boxTrans.Translation = new Vec3F(s / 2, 0, 0); BoxMtrx = boxScale * boxTrans; Ray3F ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.XAxis; return true; } // y axis boxScale.Scale(new Vec3F(handleScale, s, handleScale)); boxTrans.Translation = new Vec3F(0, s / 2, 0); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.YAxis; return true; } // z axis boxScale.Scale(new Vec3F(handleScale, handleScale, s)); boxTrans.Translation = new Vec3F(0, 0, s / 2); BoxMtrx = boxScale * boxTrans; ray = rayL; BoxMtrx.Invert(BoxMtrx); ray.Transform(BoxMtrx); if (box.Intersect(ray)) { m_hitRegion = HitRegion.ZAxis; return true; } return false; }