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); }
/// <summary> /// Handles mouse-move events</summary> /// <param name="sender">Control that raised original event</param> /// <param name="e">Event args</param> /// <returns>true, if controller handled the event</returns> public override bool MouseMove(object sender, MouseEventArgs e) { if (m_dragging && InputScheme.ActiveControlScheme.IsControllingCamera(Control.ModifierKeys, e)) { float dx = (float)(e.X - m_lastMousePoint.X) / 150.0f; float dy = (float)(e.Y - m_lastMousePoint.Y) / 150.0f; if (InputScheme.ActiveControlScheme.IsElevating(Control.ModifierKeys, e)) { // move camera up/down Vec3F p = Camera.Eye; p.Y += (dy < 0) ? m_scale : -m_scale; Camera.Set(p); } else if (InputScheme.ActiveControlScheme.IsTurning(Control.ModifierKeys, e)) { // pitch and yaw camera Matrix4F mat = Matrix4F.RotAxisRH(Camera.Right, -dy); // pitch along camera right Matrix4F yaw = new Matrix4F(); yaw.RotY(-dx); mat.Mul(yaw, mat); Vec3F lookAt = Camera.LookAt; Vec3F up = Camera.Up; mat.Transform(ref lookAt); mat.Transform(ref up); Vec3F position = Camera.Eye; float d = Camera.DistanceFromLookAt; Camera.Set(position, position + lookAt * d, up); } m_lastMousePoint = e.Location; return(true); } return(base.MouseMove(sender, e)); }