public static void DrawGridBackground(utlMatrix34 mtx, Vector2 gridStart, Vector2 gridEnd, Vector2 gridSize, int lineWidth, Color lineColor) { Vector2 startPos = new Vector2(gridStart.x, gridStart.y); Vector2 endPos = new Vector2(gridEnd.x, gridStart.y); float distance = utlMath.FloatDistance(gridStart.x, gridEnd.x); float gridCount = distance / gridSize.x; for (int indexX = 0; indexX < gridCount; indexX++) { startPos.y += gridSize.y; endPos.y += gridSize.y; endPos.x = gridEnd.x; DrawLine(mtx.Transform(startPos), mtx.Transform(endPos), lineWidth, lineColor); } startPos.Set(gridStart.x, gridStart.y); endPos.Set(gridStart.x, gridEnd.x); for (int indexY = 0; indexY < gridCount; indexY++) { startPos.x += gridSize.x; endPos.x += gridSize.x; endPos.y = gridEnd.y; DrawLine(mtx.Transform(startPos), mtx.Transform(endPos), lineWidth, lineColor); } }
public static void DrawArrowTranformed(utlMatrix34 mtx, Vector2 startPos, Vector2 endPos, Rect winRectStart, Rect winRectEnd, float lineWidth, Color lineColor, Color bodyColor) { Vector3 startPosTrans = new Vector3(); startPosTrans = mtx.Transform(startPos); Vector3 endPosTrans = new Vector3(); endPosTrans = mtx.Transform(endPos); Rect transStartRect = new Rect(winRectStart); Rect transEndRect = new Rect(winRectEnd); transStartRect.position = mtx.Transform(transStartRect.position); transEndRect.position = mtx.Transform(transEndRect.position); DrawArrow(startPosTrans, endPosTrans, transStartRect, transEndRect, lineWidth, lineColor, bodyColor); }
/// <summary> /// Is within the window using the scroll transform. /// </summary> /// <param name="tranVect"></param> /// <returns></returns> public bool IsWithinUsingPanZoomTransform(Vector2 vect, utlMatrix34 mtx) { Vector3 transVect = new Vector3(); transVect = mtx.Transform(vect); if (transVect.x >= m_WinRect.x && transVect.x < m_WinRect.x + m_WinRect.width) { if (transVect.y >= m_WinRect.y && transVect.y < m_WinRect.y + m_WinRect.height) { return(true); } } return(false); }
public static void DrawArrow(Vector3 startPos, Vector3 endPos, Rect winRectspawnPointStart, Rect winRectEnd, int lineWidth, Color lineColor, int shadowWidth, Color shadowColor, Color bodyColor) { //clip the line through the window rects Vector2 colPos = new Vector2(); if (LineRectIntersection(startPos, endPos, winRectspawnPointStart, ref colPos)) { startPos = colPos; } if (LineRectIntersection(startPos, endPos, winRectEnd, ref colPos)) { endPos = colPos; } Handles.color = shadowColor; for (int i = 0; i < 3; i++) { Handles.DrawBezier(startPos, endPos, endPos, startPos, shadowColor, null, (i + shadowWidth) * 4); } // Handles.DrawLine(startPos, endPos); //Handles.color = lineColor; //Handles.DrawLine(startPos, endPos); //Handles.DrawBezier(startPos, endPos, endPos, startPos, shadowColor, null, shadowWidth); Handles.DrawBezier(startPos, endPos, endPos, startPos, lineColor, null, lineWidth); Handles.color = bodyColor; for (float i = 0; i < 10; i += 0.5f) { Handles.DrawWireCube(startPos, new Vector3(i, i, i)); } Handles.color = lineColor; Handles.DrawWireCube(startPos, new Vector3(10, 10, 10)); const int arrowHeadSize = 3; Vector3[] arrowHead = new Vector3[arrowHeadSize]; float arrowSize = 15; arrowHead[0] = new Vector3(0, 0, 0); arrowHead[1] = new Vector3(0, arrowSize * 0.5f, arrowSize); arrowHead[2] = new Vector3(0, -arrowSize * 0.5f, arrowSize); utlMatrix34 mtx = new utlMatrix34(endPos); Vector3 lookAtPos = new Vector3(startPos.x, startPos.y, startPos.z); //new Vector3(winRectEnd.x + (winRectEnd.width * 0.5f), winRectEnd.y + (winRectEnd.height * 0.5f), 0); mtx.LookAt(lookAtPos); Vector3[] arrowHeadWorld = new Vector3[arrowHeadSize]; for (int i = 0; i < arrowHeadWorld.Length; i++) { arrowHeadWorld[i] = new Vector3(); arrowHeadWorld[i] = mtx.Transform(arrowHead[i]); } float slice = 0.05f; for (float i = slice; i < 1.0f - slice; i += slice) { Vector3 lerpVect = Vector3.Lerp(arrowHeadWorld[1], arrowHeadWorld[2], i); Handles.DrawBezier(arrowHeadWorld[0], lerpVect, lerpVect, arrowHeadWorld[0], bodyColor, null, 3); } Handles.DrawBezier(arrowHeadWorld[0], arrowHeadWorld[1], arrowHeadWorld[1], arrowHeadWorld[0], shadowColor, null, 3); Handles.DrawBezier(arrowHeadWorld[0], arrowHeadWorld[2], arrowHeadWorld[2], arrowHeadWorld[0], shadowColor, null, 3); Handles.DrawBezier(arrowHeadWorld[1], arrowHeadWorld[2], arrowHeadWorld[2], arrowHeadWorld[1], shadowColor, null, 3); Handles.color = lineColor; Handles.DrawLine(arrowHeadWorld[0], arrowHeadWorld[1]); Handles.DrawLine(arrowHeadWorld[0], arrowHeadWorld[2]); Handles.DrawLine(arrowHeadWorld[1], arrowHeadWorld[2]); }
/// <summary> /// returns the position of the window with the scroll/pan mtx transform. /// </summary> /// <returns></returns> public Vector3 GetTransformedPos(utlMatrix34 mtx) { return(mtx.Transform(GetPos())); }
/* * public static void DrawArrowTranformed(utlMatrix34 mtx, Vector3 startPos, Vector3 endPos, Rect winRectStart, Rect winRectEnd, int lineWidth, Color lineColor, int shadowWidth, Color shadowColor, Color bodyColor) * { * Vector3 startPosTrans = new Vector3(); * startPosTrans = mtx.Transform(startPos); * * Vector3 endPosTrans = new Vector3(); * endPosTrans = mtx.Transform(endPos); * * Rect transStartRect = new Rect(winRectStart); * Rect transEndRect = new Rect(winRectEnd); * * transStartRect.position = mtx.Transform(transStartRect.position); * transEndRect.position = mtx.Transform(transEndRect.position); * * DrawArrow(startPosTrans, * endPosTrans, * transStartRect, * transEndRect, * lineWidth, * lineColor, shadowWidth, shadowColor, bodyColor); * * }*/ public static void DrawArrow(Vector2 startPos, Vector2 endPos, Rect winRectStart, Rect winRectEnd, float lineWidth, Color lineColor, Color bodyColor) { Vector2 colPos = new Vector2(); if (LineRectIntersection(startPos, endPos, winRectStart, ref colPos)) { startPos = colPos; } if (LineRectIntersection(startPos, endPos, winRectEnd, ref colPos)) { endPos = colPos; } //Handles.DrawBezier(startPos, endPos, endPos, startPos, lineColor, null, lineWidth); DrawLine(startPos, endPos, lineWidth, lineColor); artGUIUtils.DrawRect(new Rect(startPos.x - 5, startPos.y - 5, 10, 10), lineWidth, lineColor, bodyColor); //arrow head draw const int arrowHeadSize = 3; Vector3[] arrowHead = new Vector3[arrowHeadSize]; float arrowSize = 15; arrowHead[0] = new Vector3(0, 0, 0); arrowHead[1] = new Vector3(0, arrowSize * 0.5f, arrowSize); arrowHead[2] = new Vector3(0, -arrowSize * 0.5f, arrowSize); utlMatrix34 mtx = new utlMatrix34(endPos); Vector3 lookAtPos = new Vector3(startPos.x, startPos.y, 0); //new Vector3(winRectEnd.x + (winRectEnd.width * 0.5f), winRectEnd.y + (winRectEnd.height * 0.5f), 0); mtx.LookAt(lookAtPos); Vector3[] arrowHeadWorld = new Vector3[arrowHeadSize]; for (int i = 0; i < arrowHeadWorld.Length; i++) { arrowHeadWorld[i] = new Vector3(); arrowHeadWorld[i] = mtx.Transform(arrowHead[i]); } float slice = 0.05f; for (float i = slice; i < 1.0f - slice; i += slice) { Vector3 lerpVect = Vector3.Lerp(arrowHeadWorld[1], arrowHeadWorld[2], i); //Handles.DrawBezier(arrowHeadWorld[0], lerpVect, lerpVect, arrowHeadWorld[0], bodyColor, null, 3); DrawLine(arrowHeadWorld[0], lerpVect, 3, bodyColor); } Handles.color = lineColor; artGUIUtils.DrawLine(arrowHeadWorld[0], arrowHeadWorld[1], lineWidth, lineColor); artGUIUtils.DrawLine(arrowHeadWorld[0], arrowHeadWorld[2], lineWidth, lineColor); artGUIUtils.DrawLine(arrowHeadWorld[1], arrowHeadWorld[2], lineWidth, lineColor); }