private void RenderRotationTool(Camera Camera, Ray Ray) { Matrix4 mat = b.transform.ClearScale(); Vector3 center = Vector3.TransformPosition(Vector3.Zero, mat); Matrix4 invTrasnform = b.transform.ClearScale().Inverted(); Vector3 point; if (state == 0) { hit = Ray.LineSphereIntersect(center, Size, out point); if (hit) { Vector3 angle = Angles(Vector3.TransformPosition(point, invTrasnform)) * new Vector3(180f / (float)Math.PI); angle.X = Math.Abs(angle.X); angle.Y = Math.Abs(angle.Y); angle.Z = Math.Abs(angle.Z); _hiX = false; _hiY = false; _hiZ = false; float _axisSnapRange = 14f; if (Math.Abs(angle.Y - 90.0f) <= _axisSnapRange) { _hiX = true; } else if (angle.X >= (180.0f - _axisSnapRange) || angle.X <= _axisSnapRange) { _hiY = true; } else if (angle.Y >= (180.0f - _axisSnapRange) || angle.Y <= _axisSnapRange) { _hiZ = true; } } if (!_hiX && !_hiZ && !_hiY) { hit = false; } } if (state == 1) { float sx = (Ray.mouseX - PrevPoint.X) / 100; float sy = (Ray.mouseY - PrevPoint.Y) / 100; float s = sx + sy; if (_hiX) { b.rot = b.rot * Quaternion.FromAxisAngle(Vector3.UnitX, s); } if (_hiY) { b.rot = b.rot * Quaternion.FromAxisAngle(Vector3.UnitY, s); } if (_hiZ) { b.rot = b.rot * Quaternion.FromAxisAngle(Vector3.UnitZ, s); } b.vbnParent.update(); } GL.PushMatrix(); GL.MultMatrix(ref mat); GL.Color4(0.25f, 0.25f, 0.25f, 0.2f); ShapeDrawing.DrawSphere(Vector3.Zero, Size, 25); GL.Color3(_hiZ ? Color.Yellow : Color.Green); GL.LineWidth(3); ShapeDrawing.DrawCircleOutline(Vector3.Zero, Size, 25); GL.Rotate(90.0f, 0.0f, 1.0f, 0.0f); GL.Color3(_hiX ? Color.Yellow : Color.Red); ShapeDrawing.DrawCircleOutline(Vector3.Zero, Size, 25); GL.Rotate(90.0f, 1.0f, 0.0f, 0.0f); GL.Color3(_hiY ? Color.Yellow : Color.Blue); ShapeDrawing.DrawCircleOutline(Vector3.Zero, Size, 25); GL.PopMatrix(); }
public void RenderScaleTool(Camera Camera, Ray Ray) { Matrix4 mat = b.transform.ClearScale(); // Matrix4.CreateTranslation(b.transform.ExtractTranslation()); Vector3 center = Vector3.TransformPosition(Vector3.Zero, mat); if (state == 0) { _hiX = false; _hiY = false; _hiZ = false; Vector3 close; if (Ray.CheckSphereHit(center, 0.5f, out close)) { _hiX = true; _hiY = true; _hiZ = true; } else if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(2, 0, 0), mat), 0.5f, out close)) { _hiX = true; } else if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(0, 2, 0), mat), 0.5f, out close)) { _hiY = true; } else if (Ray.CheckSphereHit(Vector3.TransformPosition(new Vector3(0, 0, 2), mat), 0.5f, out close)) { _hiZ = true; } hit = true; if (!_hiX && !_hiZ && !_hiY) { hit = false; } } if (state == 1) { float sx = (Ray.mouseX - PrevPoint.X) / 100; float sy = (Ray.mouseY - PrevPoint.Y) / 100; float s = sx + sy; b.sca = b.sca + new Vector3(_hiX ? s : 0, _hiY ? s : 0, _hiZ ? s : 0); b.vbnParent.update(); } GL.PushMatrix(); GL.MultMatrix(ref mat); GL.LineWidth(2f); GL.Begin(PrimitiveType.Lines); GL.Color3(_hiX ? Color.Yellow : Color.Red); GL.Vertex3(0, 0, 0); GL.Vertex3(2, 0, 0); GL.Color3(_hiY ? Color.Yellow : Color.Green); GL.Vertex3(0, 0, 0); GL.Vertex3(0, 2, 0); GL.Color3(_hiZ ? Color.Yellow : Color.Blue); GL.Vertex3(0, 0, 0); GL.Vertex3(0, 0, 2); GL.End(); GL.Color3(_hiX ? Color.Yellow : Color.Red); ShapeDrawing.DrawCube(new Vector3(2, 0, 0), 0.25f); GL.Color3(_hiY ? Color.Yellow : Color.Green); ShapeDrawing.DrawCube(new Vector3(0, 2, 0), 0.25f); GL.Color3(_hiZ ? Color.Yellow : Color.Blue); ShapeDrawing.DrawCube(new Vector3(0, 0, 2), 0.25f); GL.PopMatrix(); }