//** Debug Methods **// private void drawDebug() { //Draw line from this cam to the observed object Debug.DrawLine(transform.position, observedObject.position, Color.gray); //Draw the hide obstruction Ray //hideRayCamToPlayer.draw(Color.black); //Draw the ZoomClip Ray, this isnt up to date since the cam has already lerped before this is called clipZoomRayPlayerToCam.draw(Color.white); DebugShapes.DrawRay(clipZoomRayPlayerToCam.getOrigin(), clipZoomRayPlayerToCam.getDirection(), clipZoomMinDistanceFactor * maxCameraDistance, Color.blue); DebugShapes.DrawRay(clipZoomRayPlayerToCam.getEnd(), -clipZoomRayPlayerToCam.getDirection(), clipZoomPaddingFactor * maxCameraDistance, Color.red); //Draw the angle restrictions Vector3 zeroOrientation = getHorizontalRotationAxis(); Vector3 up = Quaternion.AngleAxis(-camUpperAngleMargin, camTarget.right) * zeroOrientation; Vector3 down = Quaternion.AngleAxis(-camLowerAngleMargin, camTarget.right) * zeroOrientation; #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { UnityEditor.Handles.color = Color.white; UnityEditor.Handles.DrawSolidArc(observedObject.position, camTarget.right, down, Vector3.SignedAngle(down, up, camTarget.right), maxCameraDistance / 4); } #endif //Draw Target Transform DebugShapes.DrawPoint(camTarget.position, Color.magenta, 0.1f); DebugShapes.DrawRay(camTarget.position, camTarget.forward, Color.blue); DebugShapes.DrawRay(camTarget.position, camTarget.right, Color.red); DebugShapes.DrawRay(camTarget.position, camTarget.up, Color.green); }
public static void DrawRect(Rect rect, Color col) { Vector3 pos = new Vector3(rect.x + rect.width / 2, rect.y + rect.height / 2, 0.0f); Vector3 scale = new Vector3(rect.width, rect.height, 0.0f); DebugShapes.DrawRect(pos, col, scale); }
/// <summary> /// Draw the <see cref="Text"/> with given <see cref="SpriteBatch"/>. /// </summary> /// <param name="spriteBatch"><see cref="SpriteBatch"/> to draw with.</param> public void Draw(SpriteBatch spriteBatch) { spriteBatch.DrawString(this.font, this.Contents, this.Position, this.Clr * this.Alpha, this.Rotation, Vector2.Zero, this.Scale, SpriteEffects.None, 0); #if DEBUG DebugShapes.DrawRectagnle(spriteBatch, this.Position, this.Size, 1f, Color.Red); #endif }
protected void DrawTileSelection(int tileX, int tileY) { Color fillColor = new Color(80, 100, 150, 150); Vector2 pos = new Vector2(tileX * TileGrid.TileSize.X * TileGrid.Scale.X, tileY * TileGrid.TileSize.Y * TileGrid.Scale.Y); Vector2 size = new Vector2(TileGrid.TileSize.X * TileGrid.Scale.X, TileGrid.TileSize.Y * TileGrid.Scale.Y); DrawingManager.DrawFilledRectangle(TileGrid.Layer, pos, size, fillColor, TileGrid.BlendingType); DebugShapes.DrawRectangle(new Rectangle((int)(pos.X + 1), (int)(pos.Y + 1), (int)size.X - 2, (int)size.Y - 2), Color.Aquamarine); }
protected void DrawBoneSceneItemBoundingRect(String boneTransformRef, Color color) { CompositeBoneTransform boneTransform = ParentEditor.SelectedCompositeKeyFrame.GetBoneTransformFromKeyFrame( ParentEditor.SelectedCompositeKeyFrame, boneTransformRef); SceneItem boneTransformSceneItem = boneTransform.GetSceneItem(); if (boneTransform.IsVisible == true && boneTransformSceneItem != null) { Rectangle boundingRect = boneTransformSceneItem.BoundingRect; DebugShapes.DrawRectangle(boundingRect, color); } }
/// <summary> /// Render the polygon using debug lines /// </summary> /// <param name="position"></param> /// <param name="verticesColor"></param> public void Draw(Vector2 position, Color verticesColor) { for (int i = 0; i < _vertices.Count; i++) { Color tint = OutlineColor; DebugShapes.DrawLine(_transformedVertices[i] + position, _transformedVertices[(i + 1) % _transformedVertices.Count] + position, tint); } int centerLineSize = 3; DebugShapes.DrawLine(new Vector2(_center.X - centerLineSize, _center.Y - centerLineSize) + position, new Vector2(_center.X + centerLineSize, _center.Y + centerLineSize) + position, verticesColor); DebugShapes.DrawLine(new Vector2(_center.X - centerLineSize, _center.Y + centerLineSize) + position, new Vector2(_center.X + centerLineSize, _center.Y - centerLineSize) + position, verticesColor); }
protected void DrawGridLines() { Color lineColor = Color.White; for (int i = 1; i < TileGrid.TileCols; i++) { float x = i * _tileGrid.TileSize.X * _tileGrid.Scale.X; DebugShapes.DrawLine(new Vector2(x, 0), new Vector2(x, _tileGrid.BoundingRect.Height), lineColor); } for (int i = 1; i < TileGrid.TileRows; i++) { float y = i * _tileGrid.TileSize.Y * _tileGrid.Scale.Y; DebugShapes.DrawLine(new Vector2(0, y), new Vector2(_tileGrid.BoundingRect.Width, y), lineColor); } }
//** Debug Methods **// private void drawDebug() { //Draw the two Sphere Rays downRay.draw(Color.green); forwardRay.draw(Color.blue); //Draw the Gravity off distance Vector3 borderpoint = getColliderBottomPoint(); Debug.DrawLine(borderpoint, borderpoint + getGravityOffDistance() * -transform.up, Color.magenta); //Draw the current transform.up and the bodys current Y orientation Debug.DrawLine(transform.position, transform.position + 2f * getColliderRadius() * transform.up, new Color(1, 0.5f, 0, 1)); Debug.DrawLine(transform.position, transform.position + 2f * getColliderRadius() * body.TransformDirection(bodyY), Color.blue); //Draw the Centroids DebugShapes.DrawPoint(getDefaultCentroid(), Color.magenta, 0.1f); DebugShapes.DrawPoint(getLegsCentroid(), Color.red, 0.1f); DebugShapes.DrawPoint(getColliderBottomPoint(), Color.cyan, 0.1f); }
protected override void Draw() { Update(1f / 60f); if (CurrentScene != null) { DrawingManager.ViewPortSize = new Microsoft.Xna.Framework.Point(this.Width, this.Height); SquidCore.DrawSquidEngineScene(GraphicsDevice, 0.16f, SceneManager.ActiveScene); if (_highlightedItem != null) { Microsoft.Xna.Framework.Rectangle re = _highlightedItem.BoundingRect; if (_highlightedItem.IgnoreCameraPosition) { Vector2 offset = CurrentScene.ActiveCameras[0].Position; //offset *= -1; re.Offset((int)offset.X, (int)offset.Y); } DebugShapes.DrawRectangle(re, Color.Yellow); } foreach (SceneItem item in _selectedItems) { Microsoft.Xna.Framework.Rectangle re = item.BoundingRect; if (item.IgnoreCameraPosition) { Vector2 offset = CurrentScene.ActiveCameras[0].Position; //offset *= -1; re.Offset((int)offset.X, (int)offset.Y); } DebugShapes.DrawRectangle(re, Color.White); } if (PreviewedItem != null) { Vector2 oldPosition = PreviewedItem.Position; Vector2 oldPivot = PreviewedItem.Pivot; int oldLayer = PreviewedItem.Layer; PreviewedItem.Position = Vector2.Zero; PreviewedItem.Layer = 1; PreviewedItem.Pivot = new Vector2(PreviewedItem.BoundingRect.Width / 2f, PreviewedItem.BoundingRect.Height / 2f); PreviewedItem.Update(1f / 60f); PreviewedItem.Draw(1f / 60f); PreviewedItem.Position = oldPosition; PreviewedItem.Layer = oldLayer; PreviewedItem.Pivot = oldPivot; } if (Preferences.ShowCameraBounds == true) { Point size = SceneManager.GlobalDataHolder.NativeResolution; Point safeSize = Point.Zero; safeSize.X = (int)(size.X * 0.8f); safeSize.Y = (int)(size.Y * 0.8f); SquidEngine.Drawing.DebugShapes.DrawRectangle( new Microsoft.Xna.Framework.Rectangle(-size.X / 2, -size.Y / 2, size.X, size.Y), new Color(255, 0, 255, 200)); SquidEngine.Drawing.DebugShapes.DrawRectangle( new Microsoft.Xna.Framework.Rectangle(-safeSize.X / 2, -safeSize.Y / 2, safeSize.X, safeSize.Y), new Color(255, 255, 255, 100)); } if (Preferences.ShowGrid == true) { Point gridSize = Preferences.GridSizes[Preferences.SelectedGrid - 1]; Microsoft.Xna.Framework.Rectangle screenBounds = SceneManager.ActiveScene.ActiveCameras[0].BoundingRect; Point start = new Point((int)Math.Floor((double)screenBounds.X / (double)gridSize.X), (int)Math.Floor((double)screenBounds.Y / (double)gridSize.X)); Point end = new Point(1 + (int)Math.Floor((double)screenBounds.Right / (double)gridSize.X), 1 + (int)Math.Floor((double)screenBounds.Bottom / (double)gridSize.Y)); for (int x = start.X; x <= end.X; x++) { SquidEngine.Drawing.DebugShapes.DrawLine(new Vector2(x * gridSize.X, start.Y * gridSize.Y), new Vector2(x * gridSize.X, end.Y * gridSize.Y), (x == 0) ? Color.Black : Preferences.GridColor); } for (int y = start.Y; y <= end.Y; y++) { SquidEngine.Drawing.DebugShapes.DrawLine(new Vector2(start.X * gridSize.X, y * gridSize.Y), new Vector2(end.X * gridSize.X, y * gridSize.Y), (y == 0) ? Color.Black : Preferences.GridColor); } } SquidCore.RenderSquidEngine(); } }
public override void draw(Color col, float duration = 0) { DebugShapes.DrawSphereRay(getOrigin(), getEnd(), getRadius(), 5, col, duration); }
/* * This function will perform debug drawing using Gizmos. */ private void drawDebug(bool points = true, bool steppingProcess = true, bool rayCasts = true, bool DOFArc = true) { float scale = spider.getScale() * 0.0001f * debugIconScale; if (points) { // Default Position DebugShapes.DrawPoint(getDefault(), Color.magenta, scale); // Last Resort Position DebugShapes.DrawPoint(getLastResortTarget().position, Color.cyan, scale); //Draw the top and bottom ray points DebugShapes.DrawPoint(getTopFocalPoint(), Color.green, scale); DebugShapes.DrawPoint(getBottomFocalPoint(), Color.green, scale); //Target Point if (isStepping) { DebugShapes.DrawPoint(ikChain.getTarget().position, Color.cyan, scale, 0.2f); } else { DebugShapes.DrawPoint(ikChain.getTarget().position, Color.cyan, scale); } } if (steppingProcess) { //Draw the prediction process DebugShapes.DrawPoint(lastEndEffectorPos, Color.white, scale); DebugShapes.DrawPoint(projPrediction, Color.grey, scale); DebugShapes.DrawPoint(overshootPrediction, Color.green, scale); DebugShapes.DrawPoint(prediction, Color.yellow, scale); Debug.DrawLine(lastEndEffectorPos, projPrediction, Color.white); Debug.DrawLine(projPrediction, overshootPrediction, Color.grey); Debug.DrawLine(overshootPrediction, prediction, Color.green); } if (rayCasts) { Color col = Color.black; foreach (var cast in casts) { if (cast.Key.Contains("Default")) { col = Color.magenta; } else if (cast.Key.Contains("Prediction")) { col = Color.yellow; } if (cast.Key != lastHitRay) { col = Color.Lerp(col, Color.white, 0.5f); } cast.Value.draw(col); } } if (DOFArc) { Vector3 v = spider.transform.TransformDirection(minOrient); Vector3 w = spider.transform.TransformDirection(maxOrient); Vector3 p = spider.transform.InverseTransformPoint(rootJoint.getRotationPoint()); p.y = defaultPositionLocal.y; p = spider.transform.TransformPoint(p); DebugShapes.DrawCircleSection(p, v, w, rootJoint.getRotationAxis(), minDistance, chainLength, Color.red); } }
/* * This coroutine is a copy paste of the original CCD solver above. It exists due to debug reasons. * It allows me to go through the iterations steps frame by frame and pause the editor. * This will be deleted once i dont need the frame by frame debuging anymore. */ public static IEnumerator solveChainCCDFrameByFrame(JointHinge[] joints, Transform endEffector, TargetInfo target, float tolerance, float minimumChangePerIteration = 0, float singularityRadius = 0, bool hasFoot = false, bool printDebugLogs = false) { int iteration = 0; float error = Vector3.Distance(target.position, endEffector.position); float oldError; float errorDelta; if (printDebugLogs) { Debug.Log(endEffector.gameObject.name + " is starting the CCD solving process."); } Debug.Break(); yield return(null); while (iteration < maxIterations && error > tolerance) { if (printDebugLogs) { Debug.Log("Starting iteration " + iteration + " with an error of " + error); } Debug.Break(); yield return(null); for (int i = 0; i < joints.Length; i++) { int k = mod((i - 1), joints.Length); // start: Not clean but for now just initialize variables again and draw stuff here Vector3 rotPoint = joints[k].getRotationPoint(); Vector3 rotAxis = joints[k].getRotationAxis(); Vector3 toEnd = Vector3.ProjectOnPlane((endEffector.position - rotPoint), rotAxis); Vector3 toTarget = Vector3.ProjectOnPlane(target.position - rotPoint, rotAxis); DebugShapes.DrawPlane(rotPoint, rotAxis, toTarget, 1.0f, Color.yellow); Debug.DrawLine(rotPoint, rotPoint + toTarget, Color.blue); Debug.DrawLine(rotPoint, rotPoint + toEnd, Color.red); // end if (printDebugLogs) { Debug.Log("Iteration " + iteration + ", joint " + joints[k].gameObject.name + " gonna happen now."); } Debug.Break(); yield return(null); solveJointCCD(ref joints[k], ref endEffector, ref target, singularityRadius, hasFoot && k == joints.Length - 1); // start: Not clean but for now just initialize variables again and draw stuff here toEnd = Vector3.ProjectOnPlane((endEffector.position - rotPoint), rotAxis); DebugShapes.DrawPlane(rotPoint, rotAxis, toTarget, 1.0f, Color.yellow); Debug.DrawLine(rotPoint, rotPoint + toTarget, Color.blue); Debug.DrawLine(rotPoint, rotPoint + toEnd, Color.red); // end if (printDebugLogs) { Debug.Log("Iteration " + iteration + ", joint " + joints[k].gameObject.name + " done."); } Debug.Break(); yield return(null); } iteration++; oldError = error; error = Vector3.Distance(target.position, endEffector.position); errorDelta = Mathf.Abs(oldError - error); if (errorDelta < minimumChangePerIteration) { if (printDebugLogs) { Debug.Log("Only moved " + errorDelta + ". Therefore i give up solving"); } Debug.Break(); break; } } if (printDebugLogs) { if (error > tolerance) { Debug.Log(endEffector.gameObject.name + " could not solve with " + iteration + " iterations. The error is " + error); } else { Debug.Log(endEffector.gameObject.name + " completed solving with " + iteration + " iterations and an error of " + error); } } Debug.Break(); yield return(null); }