예제 #1
0
        public static void DebugDrawClusters()
        {
            if (Clusters == null)
            {
                return;
            }

            double  previewScale  = 2000;
            MatrixD previewMatrix = MatrixD.CreateWorld(DebugDrawClustersMatrix.Translation + previewScale * DebugDrawClustersMatrix.Forward, Vector3D.Forward, Vector3D.Up);

            m_resultWorlds.Clear();

            Clusters.GetAll(m_resultWorlds);

            BoundingBoxD totalBox = BoundingBoxD.CreateInvalid();

            foreach (var res in m_resultWorlds)
            {
                totalBox = totalBox.Include(res.AABB);
            }

            double maxAxis = totalBox.Size.AbsMax();
            //double scaleAxis = 0.057142857142857141;
            double scaleAxis = previewScale / maxAxis;

            //Vector3D scale = new Vector3D(totalBox.Size.X * scaleAxis, totalBox.Size.Y * scaleAxis, totalBox.Size.Z * scaleAxis);

            Vector3D center = totalBox.Center;

            totalBox.Min -= center;
            totalBox.Max -= center;

            {
                BoundingBoxD           scaledBox = new BoundingBoxD(totalBox.Min * scaleAxis * 1.02f, totalBox.Max * scaleAxis * 1.02f);
                MyOrientedBoundingBoxD oriented  = new MyOrientedBoundingBoxD(scaledBox, previewMatrix);
                MyRenderProxy.DebugDrawOBB(oriented, Vector3.Up, 1, false, false);

                MyRenderProxy.DebugDrawAxis(previewMatrix, 50, false);

                if (MySession.Static != null)
                {
                    foreach (var player in Sandbox.Game.Multiplayer.Sync.Players.GetOnlinePlayers())
                    {
                        if (player.Character != null)
                        {
                            var playerPos = Vector3D.Transform((player.Character.PositionComp.GetPosition() - center) * scaleAxis, previewMatrix);
                            MyRenderProxy.DebugDrawSphere(playerPos, 10, Vector3.One, 1, false);
                        }
                    }
                }
            }

            Clusters.GetAllStaticObjects(m_clusterStaticObjects);
            foreach (var staticBB in m_clusterStaticObjects)
            {
                BoundingBoxD scaledBox = new BoundingBoxD((staticBB.Min - center) * scaleAxis, (staticBB.Max - center) * scaleAxis);

                MyOrientedBoundingBoxD oriented = new MyOrientedBoundingBoxD(scaledBox, previewMatrix);

                MyRenderProxy.DebugDrawOBB(oriented, Color.Blue, 1, false, false);
            }

            foreach (var res in m_resultWorlds)
            {
                BoundingBoxD scaledBox = new BoundingBoxD((res.AABB.Min - center) * scaleAxis, (res.AABB.Max - center) * scaleAxis);

                MyOrientedBoundingBoxD oriented = new MyOrientedBoundingBoxD(scaledBox, previewMatrix);

                MyRenderProxy.DebugDrawOBB(oriented, Vector3.One, 1, false, false);

                foreach (var rb in ((HkWorld)res.UserData).CharacterRigidBodies)
                {
                    Vector3D rbCenter = res.AABB.Center + rb.Position;
                    rbCenter = (rbCenter - center) * scaleAxis;
                    rbCenter = Vector3D.Transform(rbCenter, previewMatrix);

                    Vector3D velocity = rb.LinearVelocity;
                    velocity = Vector3D.TransformNormal(velocity, previewMatrix) * 10;
                    MyRenderProxy.DebugDrawLine3D(rbCenter, rbCenter + velocity, Color.Blue, Color.White, false);
                }

                foreach (var rb in ((HkWorld)res.UserData).RigidBodies)
                {
                    MyOrientedBoundingBoxD rbbb = new MyOrientedBoundingBoxD((BoundingBoxD)rb.GetEntity().LocalAABB, rb.GetEntity().WorldMatrix);
                    rbbb.Center      = (rbbb.Center - center) * scaleAxis;
                    rbbb.HalfExtent *= scaleAxis;
                    rbbb.Transform(previewMatrix);
                    MyRenderProxy.DebugDrawOBB(rbbb, Color.Yellow, 1, false, false);

                    //BoundingBoxD rbaa = rb.GetEntity().WorldAABB;
                    //rbaa.Min = (rbaa.Min - center) * scaleAxis;
                    //rbaa.Max = (rbaa.Max - center) * scaleAxis;
                    //MyRenderProxy.DebugDrawAABB(rbaa, new Vector3(0.8f, 0.8f, 0.8f), 1, 1, false);

                    Vector3D velocity = rb.LinearVelocity;
                    velocity = Vector3D.TransformNormal(velocity, previewMatrix) * 10;
                    MyRenderProxy.DebugDrawLine3D(rbbb.Center, rbbb.Center + velocity, Color.Red, Color.White, false);

                    if (velocity.Length() > 1)
                    {
                        BoundingBoxD           ideal    = new BoundingBoxD(rb.GetEntity().WorldAABB.Center - MyHavokCluster.IdealClusterSize / 2, rb.GetEntity().WorldAABB.Center + MyHavokCluster.IdealClusterSize / 2);
                        MyOrientedBoundingBoxD idealObb = new MyOrientedBoundingBoxD(ideal, MatrixD.Identity);
                        idealObb.Center      = (ideal.Center - center) * scaleAxis;
                        idealObb.HalfExtent *= scaleAxis;
                        idealObb.Transform(previewMatrix);
                        MyRenderProxy.DebugDrawOBB(idealObb, new Vector3(0, 0, 1), 1, false, false);
                    }
                }
            }
        }
        private new void FixSnapTransformationBase6()
        {
            Debug.Assert(CopiedGrids.Count > 0);
            if (CopiedGrids.Count == 0)
            {
                return;
            }

            var hitGrid = m_hitEntity as MyCubeGrid;

            if (hitGrid == null)
            {
                return;
            }

            // Fix rotation of the first pasted grid
            Matrix rotationDelta = GetRotationDeltaMatrixToHitGrid(hitGrid);

            foreach (var grid in PreviewGrids)
            {
                Matrix rotation = grid.WorldMatrix.GetOrientation();
                rotation = rotation * rotationDelta;

                Vector3D position = m_pastePosition;

                MatrixD newWorld = MatrixD.CreateWorld(position, rotation.Forward, rotation.Up);
                Debug.Assert(newWorld.GetOrientation().IsRotation());
                grid.PositionComp.SetWorldMatrix(newWorld);
            }

            bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && PreviewGrids[0].GridSizeEnum == MyCubeSize.Small;

            if (smallOnLargeGrid)
            {
                Vector3 pasteOffset = MyCubeBuilder.TransformLargeGridHitCoordToSmallGrid(m_hitPos, hitGrid.PositionComp.WorldMatrixNormalizedInv, hitGrid.GridSize);
                m_pastePosition = hitGrid.GridIntegerToWorld(pasteOffset);
            }
            else
            {
                // Find a collision-free position for the first paste grid along the raycast normal
                Vector3I collisionTestStep        = Vector3I.Round(m_hitNormal);
                Vector3I pasteOffset              = hitGrid.WorldToGridInteger(m_pastePosition);
                Vector3I previewGridMin           = PreviewGrids[0].Min;
                Vector3I previewGridMax           = PreviewGrids[0].Max;
                Vector3I previewGridSize          = previewGridMax - previewGridMin + Vector3I.One;
                Vector3D previewGridSizeInWorld   = Vector3D.TransformNormal((Vector3D)previewGridSize, PreviewGrids[0].WorldMatrix);
                Vector3I previewGridSizeInHitGrid = Vector3I.Abs(Vector3I.Round(Vector3D.TransformNormal(previewGridSizeInWorld, hitGrid.PositionComp.WorldMatrixNormalizedInv)));

                int attemptsCount = Math.Abs(Vector3I.Dot(ref collisionTestStep, ref previewGridSizeInHitGrid));
                Debug.Assert(attemptsCount > 0);
                int i;

                for (i = 0; i < attemptsCount; ++i)
                {
                    if (hitGrid.CanMergeCubes(PreviewGrids[0], pasteOffset))
                    {
                        break;
                    }
                    pasteOffset += collisionTestStep;
                }

                if (i == attemptsCount)
                {
                    pasteOffset = hitGrid.WorldToGridInteger(m_pastePosition);
                }

                m_pastePosition = hitGrid.GridIntegerToWorld(pasteOffset);
            }

            // Move all the grids according to the collision-free position of the first one
            for (int i = 0; i < PreviewGrids.Count; ++i)
            {
                var     grid   = PreviewGrids[i];
                MatrixD matrix = grid.WorldMatrix;
                matrix.Translation = m_pastePosition + Vector3.Transform(m_copiedGridOffsets[i], rotationDelta);
                grid.PositionComp.SetWorldMatrix(matrix);
            }

            if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE)
            {
                MyRenderProxy.DebugDrawLine3D(m_hitPos, m_hitPos + m_hitNormal, Color.Red, Color.Green, false);
            }
        }
 public override void DebugDraw()
 {
     MyRenderProxy.DebugDrawLine3D(m_origin, FrontPoint, Color.Red, Color.Blue, false);
 }
예제 #4
0
        /// <summary>
        /// Draws a frustum representing the valid scanning range, a line representing the last raycast,
        /// and a sphere representing the last raycast hit.
        /// </summary>
        private void DrawDebug()
        {
            MyRenderProxy.DebugDrawLine3D(m_lastRay.Start, m_lastRay.End, Color.Orange, Color.Orange, false);
            if (m_lastRay.Hit.HasValue)
            {
                MyRenderProxy.DebugDrawSphere(m_lastRay.Hit.Value, 1, Color.Orange, 1, false);
            }

            double distance = m_lastRay.Distance / Math.Cos(MathHelper.ToRadians(BlockDefinition.RaycastConeLimit));

            //calculate the extremes of the scan area and draw the thing manually
            Vector3D[] corners = new Vector3D[4];

            var startPos   = this.WorldMatrix.Translation;
            var forwardDir = this.WorldMatrix.Forward;

            float    pitch       = MathHelper.ToRadians(-BlockDefinition.RaycastConeLimit);
            float    yaw         = MathHelper.ToRadians(-BlockDefinition.RaycastConeLimit);
            var      pitchMatrix = MatrixD.CreateFromAxisAngle(this.WorldMatrix.Right, pitch);
            var      yawMatrix   = MatrixD.CreateFromAxisAngle(this.WorldMatrix.Down, yaw);
            Vector3D direction;
            Vector3D intermediateDirection;

            Vector3D.RotateAndScale(ref forwardDir, ref pitchMatrix, out intermediateDirection);
            Vector3D.RotateAndScale(ref intermediateDirection, ref yawMatrix, out direction);

            corners[0] = startPos + direction * distance;

            pitch       = MathHelper.ToRadians(-BlockDefinition.RaycastConeLimit);
            yaw         = MathHelper.ToRadians(BlockDefinition.RaycastConeLimit);
            pitchMatrix = MatrixD.CreateFromAxisAngle(this.WorldMatrix.Right, pitch);
            yawMatrix   = MatrixD.CreateFromAxisAngle(this.WorldMatrix.Down, yaw);
            Vector3D.RotateAndScale(ref forwardDir, ref pitchMatrix, out intermediateDirection);
            Vector3D.RotateAndScale(ref intermediateDirection, ref yawMatrix, out direction);

            corners[1] = startPos + direction * distance;

            pitch       = MathHelper.ToRadians(BlockDefinition.RaycastConeLimit);
            yaw         = MathHelper.ToRadians(BlockDefinition.RaycastConeLimit);
            pitchMatrix = MatrixD.CreateFromAxisAngle(this.WorldMatrix.Right, pitch);
            yawMatrix   = MatrixD.CreateFromAxisAngle(this.WorldMatrix.Down, yaw);
            Vector3D.RotateAndScale(ref forwardDir, ref pitchMatrix, out intermediateDirection);
            Vector3D.RotateAndScale(ref intermediateDirection, ref yawMatrix, out direction);

            corners[2] = startPos + direction * distance;

            pitch       = MathHelper.ToRadians(BlockDefinition.RaycastConeLimit);
            yaw         = MathHelper.ToRadians(-BlockDefinition.RaycastConeLimit);
            pitchMatrix = MatrixD.CreateFromAxisAngle(this.WorldMatrix.Right, pitch);
            yawMatrix   = MatrixD.CreateFromAxisAngle(this.WorldMatrix.Down, yaw);
            Vector3D.RotateAndScale(ref forwardDir, ref pitchMatrix, out intermediateDirection);
            Vector3D.RotateAndScale(ref intermediateDirection, ref yawMatrix, out direction);

            corners[3] = startPos + direction * distance;

            MyRenderProxy.DebugDrawLine3D(startPos, corners[0], Color.Blue, Color.Blue, false);
            MyRenderProxy.DebugDrawLine3D(startPos, corners[1], Color.Blue, Color.Blue, false);
            MyRenderProxy.DebugDrawLine3D(startPos, corners[2], Color.Blue, Color.Blue, false);
            MyRenderProxy.DebugDrawLine3D(startPos, corners[3], Color.Blue, Color.Blue, false);

            MyRenderProxy.DebugDrawLine3D(corners[0], corners[1], Color.Blue, Color.Blue, false);
            MyRenderProxy.DebugDrawLine3D(corners[1], corners[2], Color.Blue, Color.Blue, false);
            MyRenderProxy.DebugDrawLine3D(corners[2], corners[3], Color.Blue, Color.Blue, false);
            MyRenderProxy.DebugDrawLine3D(corners[3], corners[0], Color.Blue, Color.Blue, false);
        }
        public static void DebugDraw()
        {
            if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_ENTITY_COMPONENTS && MySector.MainCamera != null)
            {
                double fontSize = 1.5;
                double lineSize = fontSize * 0.045;
                double hoffset  = 0.5f;

                Vector3D playerPos   = MySector.MainCamera.Position;
                Vector3D upVector    = MySector.MainCamera.WorldMatrix.Up;
                Vector3D rightVector = MySector.MainCamera.WorldMatrix.Right;
                Vector3D fwVector    = MySector.MainCamera.ForwardVector;

                BoundingSphereD bSphere       = new BoundingSphereD(playerPos, 5.0f);
                var             entities      = MyEntities.GetEntitiesInSphere(ref bSphere);
                Vector3D        lastEntityPos = Vector3D.Zero;
                Vector3D        offset        = Vector3D.Zero;

                var mat = MySector.MainCamera.ViewProjectionMatrix;

                var   fullscreenRect = Sandbox.Graphics.MyGuiManager.GetSafeGuiRectangle();
                float aspect         = (float)fullscreenRect.Height / fullscreenRect.Width;
                float scaleX         = 600;
                float scaleY         = scaleX * aspect;

                Vector3D worldAxisPos = playerPos + 1.0f * fwVector;

                // Draw the world-space axis in the middle of the screen

                /*MyRenderProxy.DebugDrawArrow3D(worldAxisPos, worldAxisPos + Vector3D.Right * 0.1f, Color.Red, Color.Red, false, text: "World X");
                 * MyRenderProxy.DebugDrawArrow3D(worldAxisPos, worldAxisPos + Vector3D.Up * 0.1f, Color.Green, Color.Green, false, text: "World Y");
                 * MyRenderProxy.DebugDrawArrow3D(worldAxisPos, worldAxisPos + Vector3D.Backward * 0.1f, Color.Blue, Color.Blue, false, text: "World Z");*/

                Vector3D posView    = Vector3D.Transform(worldAxisPos, mat);
                Vector3D rtView     = Vector3D.Transform(worldAxisPos + Vector3D.Right * 0.1f, mat);
                Vector3D upView     = Vector3D.Transform(worldAxisPos + Vector3D.Up * 0.1f, mat);
                Vector3D bwView     = Vector3D.Transform(worldAxisPos + Vector3D.Backward * 0.1f, mat);
                var      center2D   = new Vector2((float)posView.X * scaleX, (float)posView.Y * -scaleY * aspect);
                var      right2D    = new Vector2((float)rtView.X * scaleX, (float)rtView.Y * -scaleY * aspect) - center2D;
                var      up2D       = new Vector2((float)upView.X * scaleX, (float)upView.Y * -scaleY * aspect) - center2D;
                var      backward2D = new Vector2((float)bwView.X * scaleX, (float)bwView.Y * -scaleY * aspect) - center2D;

                var frameSize   = 150.0f;
                var frameBR     = Sandbox.Graphics.MyGuiManager.GetScreenCoordinateFromNormalizedCoordinate(new Vector2(1.0f, 1.0f));
                var frameBL     = frameBR + new Vector2(-frameSize, 0.0f);
                var frameTR     = frameBR + new Vector2(0.0f, -frameSize);
                var frameTL     = frameBR + new Vector2(-frameSize, -frameSize);
                var frameCenter = (frameBR + frameTL) * 0.5f;

                // Draw frame around the world-space axis

                /*MyRenderProxy.DebugDrawLine2D(frameTL, frameTR, Color.White, Color.White);
                *  MyRenderProxy.DebugDrawLine2D(frameTR, frameBR, Color.White, Color.White);
                *  MyRenderProxy.DebugDrawLine2D(frameBR, frameBL, Color.White, Color.White);
                *  MyRenderProxy.DebugDrawLine2D(frameBL, frameTL, Color.White, Color.White);*/

                // Draw the world-space axis in the corner
                MyRenderProxy.DebugDrawLine2D(frameCenter, frameCenter + right2D, Color.Red, Color.Red);
                MyRenderProxy.DebugDrawLine2D(frameCenter, frameCenter + up2D, Color.Green, Color.Green);
                MyRenderProxy.DebugDrawLine2D(frameCenter, frameCenter + backward2D, Color.Blue, Color.Blue);
                MyRenderProxy.DebugDrawText2D(frameCenter + right2D, "World X", Color.Red, 0.5f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
                MyRenderProxy.DebugDrawText2D(frameCenter + up2D, "World Y", Color.Green, 0.5f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
                MyRenderProxy.DebugDrawText2D(frameCenter + backward2D, "World Z", Color.Blue, 0.5f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);

                MyComponentsDebugInputComponent.DetectedEntities.Clear();

                foreach (var entity in entities)
                {
                    if (entity.PositionComp == null)
                    {
                        continue;
                    }

                    Vector3D originalPos = entity.PositionComp.GetPosition();
                    Vector3D pos2        = originalPos + upVector * 0.1f;
                    Vector3D pos         = pos2 - rightVector * hoffset;
                    Vector3D viewVector  = Vector3D.Normalize(originalPos - playerPos);

                    double dot = Vector3D.Dot(viewVector, fwVector);
                    if (dot < 0.9995)
                    {
                        Vector3D rightObject    = entity.PositionComp.WorldMatrix.Right * 0.3f;
                        Vector3D upObject       = entity.PositionComp.WorldMatrix.Up * 0.3f;
                        Vector3D backwardObject = entity.PositionComp.WorldMatrix.Backward * 0.3f;

                        MyRenderProxy.DebugDrawSphere(originalPos, 0.01f, Color.White, 1.0f, false);
                        MyRenderProxy.DebugDrawArrow3D(originalPos, originalPos + rightObject, Color.Red, Color.Red, false, text: "X");
                        MyRenderProxy.DebugDrawArrow3D(originalPos, originalPos + upObject, Color.Green, Color.Green, false, text: "Y");
                        MyRenderProxy.DebugDrawArrow3D(originalPos, originalPos + backwardObject, Color.Blue, Color.Blue, false, text: "Z");
                        continue;
                    }

                    if (Vector3D.Distance(originalPos, lastEntityPos) < 0.01)
                    {
                        offset  += rightVector * 0.3f;
                        upVector = -upVector;
                        pos2     = originalPos + upVector * 0.1f;
                        pos      = pos2 - rightVector * hoffset;
                    }
                    lastEntityPos = originalPos;


                    double dist     = Vector3D.Distance(pos, playerPos);
                    double textSize = Math.Atan(fontSize / Math.Max(dist, 0.001));

                    float n = 0;
                    {
                        var             enumerator = entity.Components.GetEnumerator();
                        MyComponentBase component  = null;
                        while (enumerator.MoveNext())
                        {
                            component = enumerator.Current;
                            n        += GetComponentLines(component);
                        }
                        n += 1;
                        n -= GetComponentLines(component); // The last component should not make the line longer
                        enumerator.Dispose();
                    }

                    Vector3D topPos     = pos + (n + 0.5f) * upVector * lineSize;
                    Vector3D currentPos = pos + (n + 1) * upVector * lineSize + 0.01f * rightVector;

                    MyRenderProxy.DebugDrawLine3D(originalPos, pos2, Color.White, Color.White, false);
                    MyRenderProxy.DebugDrawLine3D(pos, pos2, Color.White, Color.White, false);
                    MyRenderProxy.DebugDrawLine3D(pos, topPos, Color.White, Color.White, false);
                    MyRenderProxy.DebugDrawLine3D(topPos, topPos + rightVector * 1.0f, Color.White, Color.White, false);
                    MyRenderProxy.DebugDrawText3D(currentPos, entity.GetType().ToString() + " - " + entity.DisplayName, Color.Orange, (float)textSize, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);

                    MyComponentsDebugInputComponent.DetectedEntities.Add(entity);

                    foreach (var component in entity.Components)
                    {
                        currentPos = pos + n * upVector * lineSize;
                        DebugDrawComponent(component, currentPos, rightVector, upVector, lineSize, (float)textSize);
                        var    entityComponent = component as MyEntityComponentBase;
                        string compType        = entityComponent == null ? "" : entityComponent.ComponentTypeDebugString;
                        MyRenderProxy.DebugDrawText3D(currentPos - 0.02f * rightVector, compType, Color.Yellow, (float)textSize, false, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER);
                        n -= GetComponentLines(component);
                    }
                }
                entities.Clear();
            }
        }
예제 #6
0
        public override void DebugDraw(ref Matrix drawMatrix)
        {
            if (!MyDebugDrawSettings.ENABLE_DEBUG_DRAW)
            {
                return;
            }

            base.DebugDraw(ref drawMatrix);

            if ((MyDebugDrawSettings.DEBUG_DRAW_NAVMESHES & MyWEMDebugDrawMode.EDGES) != 0)
            {
                if (m_connectionHelper != null)
                {
                    foreach (var edge in m_connectionHelper)
                    {
                        Vector3 A = Vector3.Transform(edge.Key.A / 256.0f, drawMatrix);
                        Vector3 B = Vector3.Transform(edge.Key.B / 256.0f, drawMatrix);
                        MyRenderProxy.DebugDrawLine3D(A, B, Color.Red, Color.Yellow, false);
                    }
                }
            }

            if ((MyDebugDrawSettings.DEBUG_DRAW_NAVMESHES & MyWEMDebugDrawMode.NORMALS) != 0)
            {
                foreach (var entry in m_smallTriangleRegistry)
                {
                    var list = entry.Value;
                    foreach (var triIndex in list)
                    {
                        var     tri    = GetTriangle(triIndex);
                        Vector3 normal = Vector3.Transform(tri.Center + tri.Normal * 0.2f, drawMatrix);
                        Vector3 center = Vector3.Transform(tri.Center, drawMatrix);
                        MyRenderProxy.DebugDrawLine3D(center, normal, Color.Blue, Color.Blue, true);
                    }
                }
            }

            if (MyFakes.DEBUG_DRAW_NAVMESH_HIERARCHY)
            {
                if (m_higherLevel != null)
                {
                    m_higherLevel.DebugDraw(lite: MyFakes.DEBUG_DRAW_NAVMESH_HIERARCHY_LITE);
                }
            }

            /*foreach (var entry in m_smallTriangleRegistry)
             * {
             *  var list = entry.Value;
             *  foreach (var triIndex in list)
             *  {
             *      var tri = GetTriangle(triIndex);
             *      Vector3 normal = Vector3.Transform(tri.Center + tri.Normal * 0.2f, drawMatrix);
             *      Vector3 center = Vector3.Transform(tri.Center, drawMatrix);
             *      MyRenderProxy.DebugDrawText3D(center, entry.Key.ToString(), Color.Blue, 0.7f, true);
             *  }
             * }*/

            /*
             * if (m_cubeSet != null)
             * {
             *  foreach (var entry in m_cubeSet)
             *  {
             *      Vector3 pos = Vector3.Transform(entry, drawMatrix);
             *      MyRenderProxy.DebugDrawSphere(pos, 0.1f, Color.Red, 1.0f, false);
             *      MyRenderProxy.DebugDrawText3D(pos, entry.ToString(), Color.Red, 1.0f, false);
             *  }
             * }*/
        }
예제 #7
0
        public override bool DebugDraw()
        {
            var minCorner = m_voxelMap.PositionLeftBottomCorner;

            if (MyDebugDrawSettings.DEBUG_DRAW_VOXEL_MAP_AABB)
            {
                MyRenderProxy.DebugDrawAABB(m_voxelMap.PositionComp.WorldAABB, Color.White, alpha: 0.2f);
                MyRenderProxy.DebugDrawLine3D(minCorner, minCorner + new Vector3(1f, 0f, 0f), Color.Red, Color.Red, true);
                MyRenderProxy.DebugDrawLine3D(minCorner, minCorner + new Vector3(0f, 1f, 0f), Color.Green, Color.Green, true);
                MyRenderProxy.DebugDrawLine3D(minCorner, minCorner + new Vector3(0f, 0f, 1f), Color.Blue, Color.Blue, true);

                MyRenderProxy.DebugDrawAxis(m_voxelMap.PositionComp.WorldMatrix, 2f, false);

                MyRenderProxy.DebugDrawSphere(m_voxelMap.PositionComp.GetPosition(), 1, Color.OrangeRed, 1, false);
            }

            m_voxelMap.Storage.DebugDraw(m_voxelMap, MyDebugDrawSettings.DEBUG_DRAW_VOXELS_MODE);
            if (m_voxelMap.Physics != null)
            {
                m_voxelMap.Physics.DebugDraw();
            }
            //if (MyDebugDrawSettings.DEBUG_DRAW_VOXEL_GEOMETRY_CELL)
            //{
            //    LineD worldLine;
            //    if (false)
            //    {
            //        var entityMatrix = MySession.Static.ControlledEntity.Entity.WorldMatrix;
            //        worldLine = new LineD(entityMatrix.Translation, entityMatrix.Translation + 25f * entityMatrix.Forward);
            //    }
            //    else
            //    {
            //        var camera = MySector.MainCamera;
            //        worldLine = new LineD(camera.Position, camera.Position + 25f * camera.ForwardVector);
            //    }
            //    VRage.Game.Models.MyIntersectionResultLineTriangleEx? result;
            //    bool depthRead = true;
            //    if (m_voxelMap.GetIntersectionWithLine(ref worldLine, out result))
            //    {
            //        var t = result.Value.Triangle.InputTriangle;
            //        MyRenderProxy.DebugDrawTriangle(
            //            t.Vertex0 + minCorner,
            //            t.Vertex1 + minCorner,
            //            t.Vertex2 + minCorner,
            //            Color.Red, true, false);
            //        Vector3I cellCoord, voxelCoord;
            //        var worldPosition = result.Value.IntersectionPointInWorldSpace;
            //        BoundingBoxD voxelAabb;
            //        MyVoxelCoordSystems.WorldPositionToVoxelCoord(minCorner, ref worldPosition, out voxelCoord);
            //        MyVoxelCoordSystems.VoxelCoordToWorldAABB(minCorner, ref voxelCoord, out voxelAabb);
            //        MyRenderProxy.DebugDrawAABB(voxelAabb, Vector3.UnitY, 1f, 1f, true);
            //        MyVoxelCoordSystems.WorldPositionToGeometryCellCoord(minCorner, ref worldPosition, out cellCoord);
            //        MyVoxelCoordSystems.GeometryCellCoordToWorldAABB(minCorner, ref cellCoord, out voxelAabb);
            //        MyRenderProxy.DebugDrawAABB(voxelAabb, Vector3.UnitZ, 1f, 1f, true);

            //        bool isEmpty;
            //        MyIsoMesh cell;
            //        if (m_voxelMap.Storage.Geometry.TryGetMesh(new MyCellCoord(0, cellCoord), out isEmpty, out cell) && !isEmpty)
            //        {
            //            MyVoxelVertex tmp;
            //            var triangleBatch = MyRenderProxy.PrepareDebugDrawTriangles();
            //            for (int i = 0; i < cell.VerticesCount; ++i)
            //            {
            //                cell.GetUnpackedVertex(i, out tmp);
            //                triangleBatch.AddVertex(tmp.Position);
            //                tmp.Position += minCorner;
            //                MyRenderProxy.DebugDrawLine3D(tmp.Position, tmp.Position + tmp.Normal * MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF, Color.Gray, Color.White, depthRead);
            //            }
            //            for (int i = 0; i < cell.TrianglesCount; ++i)
            //            {
            //                triangleBatch.AddIndex(cell.Triangles[i].VertexIndex2);
            //                triangleBatch.AddIndex(cell.Triangles[i].VertexIndex1);
            //                triangleBatch.AddIndex(cell.Triangles[i].VertexIndex0);
            //            }
            //            MyRenderProxy.DebugDrawTriangles(triangleBatch, Matrix.CreateTranslation(minCorner), Color.CornflowerBlue, depthRead, false);
            //        }
            //    }
            //}
            return(true);
        }
예제 #8
0
        private static void DrawMountPointsAxisHelpers(MyCubeBlockDefinition def, ref MatrixD drawMatrix, float cubeSize)
        {
            Vector3I centerGrid   = def.Center;
            Vector3  centerOffset = def.Size * 0.5f;

            MatrixD drawTransf = MatrixD.CreateTranslation(centerGrid - centerOffset) * MatrixD.CreateScale(cubeSize) * drawMatrix;

            // Draw axis helpers for the six mount point walls
            for (int i = 0; i < 6; ++i)
            {
                Base6Directions.Direction dir = (Base6Directions.Direction)i;

                Vector3D position = Vector3D.Zero;
                position.Z = -0.2f;

                Vector3D normal = Vector3.Forward;
                Vector3D right  = Vector3.Right;
                Vector3D up     = Vector3.Up;

                position = def.MountPointLocalToBlockLocal(position, dir);
                position = Vector3D.Transform(position, drawTransf);

                normal = def.MountPointLocalNormalToBlockLocal(normal, dir);
                normal = Vector3D.TransformNormal(normal, drawTransf);

                up = def.MountPointLocalNormalToBlockLocal(up, dir);
                up = Vector3D.TransformNormal(up, drawTransf);

                right = def.MountPointLocalNormalToBlockLocal(right, dir);
                right = Vector3D.TransformNormal(right, drawTransf);

                MatrixD rightMat = MatrixD.CreateWorld(position + right * 0.25f, normal, right);
                MatrixD upMat    = MatrixD.CreateWorld(position + up * 0.25f, normal, up);
                Vector4 rc       = Color.Red.ToVector4();
                Vector4 uc       = Color.Green.ToVector4();

                MyRenderProxy.DebugDrawSphere(position, 0.03f * cubeSize, Color.Red.ToVector3(), 1.0f, true);
                MySimpleObjectDraw.DrawTransparentCylinder(ref rightMat, 0.0f, 0.03f * cubeSize, 0.5f * cubeSize, ref rc, false, 16, 0.01f * cubeSize);
                MySimpleObjectDraw.DrawTransparentCylinder(ref upMat, 0.0f, 0.03f * cubeSize, 0.5f * cubeSize, ref uc, false, 16, 0.01f * cubeSize);
                MyRenderProxy.DebugDrawLine3D(position, position - normal * 0.2f, Color.Red, Color.Red, true);

                float textSizeX    = 0.5f * cubeSize;
                float textSizeY    = 0.5f * cubeSize;
                float textSizeDesc = 0.5f * cubeSize;
                if (MySector.MainCamera != null)
                {
                    float distX    = (float)(position + right * 0.55f - MySector.MainCamera.Position).Length();
                    float distY    = (float)(position + up * 0.55f - MySector.MainCamera.Position).Length();
                    float distDesc = (float)(position + normal * 0.1f - MySector.MainCamera.Position).Length();
                    textSizeX    = textSizeX * 6 / distX;
                    textSizeY    = textSizeY * 6 / distY;
                    textSizeDesc = textSizeDesc * 6 / distDesc;
                }

                MyRenderProxy.DebugDrawText3D(position + right * 0.55f, "X", Color.Red, textSizeX, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
                MyRenderProxy.DebugDrawText3D(position + up * 0.55f, "Y", Color.Green, textSizeY, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
                MyRenderProxy.DebugDrawText3D(position + normal * 0.1f, m_mountPointSideNames[i], Color.White, textSizeDesc, true, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
            }

            // If close enough, draw a black grid spaced by tenths of a mount point unit
            float        dist = (float)(drawTransf.Translation - MySector.MainCamera.Position).Length();
            BoundingBoxD bb   = new BoundingBoxD(-def.Size * cubeSize * 0.5f, def.Size * cubeSize * 0.5f);

            dist -= (float)bb.Size.Max() * 0.866f; // sqrt(3) * 0.5 - half of the solid diagonal of a cube
            Color black = Color.Black;

            if (dist < cubeSize * 3.0f)
            {
                MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix, ref bb, ref black, MySimpleObjectRasterizer.Wireframe, def.Size * 10, 0.005f / (float)bb.Size.Max() * cubeSize, onlyFrontFaces: true);
            }
        }
예제 #9
0
            private void Probe(Vector3D pos)
            {
                var ray = m_probedLine;

                ray.From += pos;
                ray.To   += pos;

                var entities = new List <MyLineSegmentOverlapResult <MyEntity> >();

                MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref ray, entities, MyEntityQueryType.Static);

                double closest = double.PositiveInfinity;

                foreach (var e in entities)
                {
                    var voxel = e.Element as MyVoxelBase;
                    if (voxel != null && e.Distance < closest)
                    {
                        m_probedVoxel = voxel;
                    }
                }

                if (m_probedVoxel is MyVoxelPhysics)
                {
                    m_probedVoxel = ((MyVoxelPhysics)m_probedVoxel).Parent;
                }

                if (m_probedVoxel != null && m_probedVoxel.Storage.DataProvider != null)
                {
                    MyRenderProxy.DebugDrawLine3D(ray.From, ray.To, Color.Green, Color.Green, true);

                    Vector3D start = Vector3D.Transform(ray.From, m_probedVoxel.PositionComp.WorldMatrixInvScaled);
                    start += m_probedVoxel.SizeInMetresHalf;
                    var end = Vector3D.Transform(ray.To, m_probedVoxel.PositionComp.WorldMatrixInvScaled);
                    end += m_probedVoxel.SizeInMetresHalf;
                    var voxRay = new LineD(start, end);

                    double startOffset;
                    double endOffset;
                    // Intersect provider for nau
                    var cont = m_probedVoxel.Storage.DataProvider.Intersect(ref voxRay, out startOffset, out endOffset);

                    var from = voxRay.From;
                    voxRay.From = from + voxRay.Direction * voxRay.Length * startOffset;
                    voxRay.To   = from + voxRay.Direction * voxRay.Length * endOffset;

                    if (m_probeCount == 1)
                    {
                        Text(Color.Yellow, 1.5f, "Probing voxel map {0}:{1}", m_probedVoxel.StorageName, m_probedVoxel.EntityId);
                        Text("Local Pos: {0}", start);
                        Text("Intersects: {0}", cont);
                    }

                    if (cont)
                    {
                        start = voxRay.From - m_probedVoxel.SizeInMetresHalf;
                        start = Vector3D.Transform(start, m_probedVoxel.PositionComp.WorldMatrix);
                        end   = voxRay.To - m_probedVoxel.SizeInMetresHalf;
                        end   = Vector3D.Transform(end, m_probedVoxel.PositionComp.WorldMatrix);

                        MyRenderProxy.DebugDrawLine3D(start, end, Color.Red, Color.Red, true);
                    }
                }
                else
                {
                    if (m_probeCount == 1)
                    {
                        Text(Color.Yellow, 1.5f, "No voxel found");
                    }

                    MyRenderProxy.DebugDrawLine3D(ray.From, ray.To, Color.Yellow, Color.Yellow, true);
                }
            }
예제 #10
0
        public void DebugDraw()
        {
            if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW == false)
            {
                return;
            }

            m_aiming.DebugDraw(m_aimingPositionAndOrientation);

            if (MyDebugDrawSettings.DEBUG_DRAW_BOT_STEERING)
            {
                foreach (var steering in m_steerings)
                {
                    steering.DebugDraw();
                }
            }

            if (MyDebugDrawSettings.DEBUG_DRAW_BOT_NAVIGATION)
            {
                Vector3 pos         = PositionAndOrientation.Translation;// + /*PositionAndOrientation.Up * 1.5f + */ForwardVector;
                Vector3 rightVector = Vector3.Cross(m_forwardVector, UpVector);

                if (Stuck)
                {
                    MyRenderProxy.DebugDrawSphere(pos, 1.0f, Color.Red.ToVector3(), 1.0f, false);
                }

                //MyRenderProxy.DebugDrawLine3D(pos, pos + ForwardVector, Color.Blue, Color.Blue, false);

                //var normalizedCorrection = Vector3D.Normalize(m_correction);
                //var normalizedCorrectedDirXZ = normalizedCorrection + m_forwardVector;
                //normalizedCorrectedDirXZ = Vector3D.Normalize(Vector3D.Reject(normalizedCorrectedDirXZ, Vector3D.Up));
                //MyRenderProxy.DebugDrawLine3D(pos, pos + normalizedCorrectedDirXZ * 3, Color.Lime, Color.Lime, false);
                MyRenderProxy.DebugDrawArrow3D(pos, pos + ForwardVector, Color.Blue, Color.Blue, false, text: "Nav. FW");
                MyRenderProxy.DebugDrawArrow3D(pos + ForwardVector, pos + ForwardVector + m_correction, Color.LightBlue, Color.LightBlue, false, text: "Correction");
                //MyRenderProxy.DebugDrawLine3D(pos + ForwardVector, pos + ForwardVector + m_correction, Color.Yellow, Color.Yellow, false);
                //MyRenderProxy.DebugDrawSphere(pos + ForwardVector + m_correction, 0.05f, Color.Yellow.ToVector3(), 1.0f, true);

                if (m_destinationSphere != null)
                {
                    m_destinationSphere.DebugDraw();
                }

                var character = this.BotEntity as MyCharacter;
                if (character != null)
                {
                    var viewMatrix  = character.GetViewMatrix();
                    var worldMatrix = MatrixD.Invert(viewMatrix);
                    var headMatrix  = character.GetHeadMatrix(true, true);

                    MyRenderProxy.DebugDrawLine3D(worldMatrix.Translation, Vector3D.Transform(Vector3D.Forward * 50, worldMatrix), Color.Yellow, Color.White, false);
                    MyRenderProxy.DebugDrawLine3D(headMatrix.Translation, Vector3D.Transform(Vector3D.Forward * 50, headMatrix), Color.Red, Color.Red, false);

                    if (character.CurrentWeapon != null)
                    {
                        var direction = character.CurrentWeapon.DirectionToTarget(character.AimedPoint);
                        var spos      = (character.CurrentWeapon as MyEntity).WorldMatrix.Translation;

                        MyRenderProxy.DebugDrawSphere(character.AimedPoint, 1.0f, Color.Yellow, 1.0f, false);
                        MyRenderProxy.DebugDrawLine3D(spos, spos + direction * 20, Color.Purple, Color.Purple, false);
                    }
                }
            }
        }
예제 #11
0
        // ------------------------------------------------------------------------------------
        /// <summary>
        /// Solve IK for chain of two bones + change rotation of end bone.
        /// </summary>
        /// <param name="characterBones">bone storage</param>
        /// <param name="ikChain">description of bone chain</param>
        /// <param name="finalPosition">desired position of end bone</param>
        /// <param name="finalNormal">desired normal of end bone - would be projected on plane first bone-second bone-third bone</param>
        /// <param name="fromBindPose">solve this starting from the bind pose</param>
        /// <returns>true on success</returns>
        public static bool SolveIkTwoBones(MyCharacterBone[] characterBones, MyAnimationIkChainExt ikChain, ref Vector3 finalPosition, ref Vector3 finalNormal, bool fromBindPose)
        {
            int     boneIndex            = ikChain.BoneIndex;
            float   finalMinRot          = MathHelper.ToRadians(ikChain.MinEndPointRotation);
            float   finalMaxRot          = MathHelper.ToRadians(ikChain.MaxEndPointRotation);
            Vector3 lastPoleVector       = ikChain.LastPoleVector;
            int     chainLength          = ikChain.ChainLength;
            bool    alignBoneWithTerrain = ikChain.AlignBoneWithTerrain;

            MyCharacterBone thirdBone = characterBones[boneIndex];

            if (thirdBone == null)
            {
                return(false);
            }
            MyCharacterBone secondBone = thirdBone.Parent;

            for (int i = 2; i < chainLength; i++)
            {
                secondBone = secondBone.Parent;
            }
            if (secondBone == null)
            {
                return(false);
            }
            MyCharacterBone firstBone = secondBone.Parent;

            if (firstBone == null)
            {
                return(false);
            }

            if (fromBindPose)
            {
                firstBone.SetCompleteBindTransform();
                secondBone.SetCompleteBindTransform();
                thirdBone.SetCompleteBindTransform();
                firstBone.ComputeAbsoluteTransform(true);
            }

            Matrix thirdBoneTransformBackup = thirdBone.AbsoluteTransform;

            //Vector3 firstBoneTransformRightDir = firstBone.AbsoluteTransform.Right;
            Vector3 firstBoneOrigin  = firstBone.AbsoluteTransform.Translation;
            Vector3 secondBoneOrigin = secondBone.AbsoluteTransform.Translation;
            Vector3 thirdBoneOrigin  = thirdBone.AbsoluteTransform.Translation;
            // Vector3D finalPosition comes from parameter
            Vector3 secondMinusFirst = secondBoneOrigin - firstBoneOrigin;
            Vector3 finalMinusFirst  = finalPosition - firstBoneOrigin;
            //Vector3 finalMinusSecond = finalPosition - secondBoneOrigin;

            Vector3 poleVectorNormalized;
            Vector3 thirdMinusFirst = thirdBoneOrigin - firstBoneOrigin;

            Vector3.Cross(ref secondMinusFirst, ref thirdMinusFirst, out poleVectorNormalized);

            // project to 2D (only vectors)
            poleVectorNormalized.Normalize();
            poleVectorNormalized = Vector3.Normalize(Vector3.Lerp(poleVectorNormalized, lastPoleVector, m_poleVectorChangeSmoothness));
            Vector3 planeDirY = Vector3.Normalize(finalMinusFirst); // finalMinusFirst? thirdMinusFirst?
            Vector3 planeDirX = Vector3.Normalize(Vector3.Cross(planeDirY, poleVectorNormalized));
            //Vector2 firstBoneOrigin2D = new Vector2(0, 0);
            Vector2 secondBoneOrigin2D = new Vector2(planeDirX.Dot(ref secondMinusFirst), planeDirY.Dot(ref secondMinusFirst));
            Vector2 thirdBoneOrigin2D  = new Vector2(planeDirX.Dot(ref thirdMinusFirst), planeDirY.Dot(ref thirdMinusFirst));
            Vector2 finalPosition2D    = new Vector2(planeDirX.Dot(ref finalMinusFirst), planeDirY.Dot(ref finalMinusFirst));
            Vector2 terrainNormal2D    = new Vector2(planeDirX.Dot(ref finalNormal), planeDirY.Dot(ref finalNormal));

            float firstBoneLength  = (secondBoneOrigin2D /* - 0*/).Length();
            float secondBoneLength = (thirdBoneOrigin2D - secondBoneOrigin2D).Length();
            float finalDistance    = finalPosition2D.Length();

            if (firstBoneLength + secondBoneLength <= finalDistance)
            {
                finalPosition2D = (firstBoneLength + secondBoneLength) * finalPosition2D / finalDistance;
                // too far
                //return false;
            }

            // mid-joint ->  wanted position in 2D
            Vector2 newSecondBoneOrigin2D;
            {
                newSecondBoneOrigin2D.Y = (finalPosition2D.Y * finalPosition2D.Y - secondBoneLength * secondBoneLength + firstBoneLength * firstBoneLength) / (2.0f * finalPosition2D.Y);
                float srqtArg = firstBoneLength * firstBoneLength - newSecondBoneOrigin2D.Y * newSecondBoneOrigin2D.Y;
                newSecondBoneOrigin2D.X = (float)Math.Sqrt(srqtArg > 0 ? srqtArg : 0);
            }

            // project back
            Vector3 newSecondBoneOrigin = firstBoneOrigin + planeDirX * newSecondBoneOrigin2D.X + planeDirY * newSecondBoneOrigin2D.Y;
            Vector3 newSecondMinusFirst = newSecondBoneOrigin - firstBoneOrigin;
            Vector3 newThirdMinusSecond = finalPosition - newSecondBoneOrigin;
            Vector3 newTerrainNormal    = planeDirX * terrainNormal2D.X + planeDirY * terrainNormal2D.Y;

            newTerrainNormal.Normalize();

            // set the rotations in the bones

            // first bone ---------------------------------
            Matrix     firstBoneAbsoluteFinal = firstBone.AbsoluteTransform;
            Quaternion rotFirstDelta          = Quaternion.CreateFromTwoVectors(secondMinusFirst, newSecondMinusFirst);

            firstBoneAbsoluteFinal.Right   = Vector3.Transform(firstBoneAbsoluteFinal.Right, rotFirstDelta);
            firstBoneAbsoluteFinal.Up      = Vector3.Transform(firstBoneAbsoluteFinal.Up, rotFirstDelta);
            firstBoneAbsoluteFinal.Forward = Vector3.Transform(firstBoneAbsoluteFinal.Forward, rotFirstDelta);

            firstBone.SetCompleteTransformFromAbsoluteMatrix(ref firstBoneAbsoluteFinal, true);
            firstBone.ComputeAbsoluteTransform();

            // second bone ---------------------------------
            Matrix     secondBoneAbsoluteFinal = secondBone.AbsoluteTransform;
            Quaternion rotSecondDelta          = Quaternion.CreateFromTwoVectors(thirdBone.AbsoluteTransform.Translation - secondBone.AbsoluteTransform.Translation, newThirdMinusSecond);

            secondBoneAbsoluteFinal.Right   = Vector3.Transform(secondBoneAbsoluteFinal.Right, rotSecondDelta);
            secondBoneAbsoluteFinal.Up      = Vector3.Transform(secondBoneAbsoluteFinal.Up, rotSecondDelta);
            secondBoneAbsoluteFinal.Forward = Vector3.Transform(secondBoneAbsoluteFinal.Forward, rotSecondDelta);

            secondBone.SetCompleteTransformFromAbsoluteMatrix(ref secondBoneAbsoluteFinal, true);
            secondBone.ComputeAbsoluteTransform();

            //// third bone ----------------------------------

            if (ikChain.EndBoneTransform.HasValue)
            {
                MatrixD localTransformRelated = ikChain.EndBoneTransform.Value * MatrixD.Invert((MatrixD)thirdBone.BindTransform * thirdBone.Parent.AbsoluteTransform);
                thirdBone.Rotation    = Quaternion.CreateFromRotationMatrix(Matrix.Normalize((Matrix)localTransformRelated.GetOrientation()));
                thirdBone.Translation = (Vector3)localTransformRelated.Translation;
                thirdBone.ComputeAbsoluteTransform();
            }
            else if (alignBoneWithTerrain)
            {
                Matrix  footRotation;
                Vector3 finalRotPoleVec;
                Vector3.Cross(ref newTerrainNormal, ref Vector3.Up, out finalRotPoleVec);
                float deltaAngle = MyUtils.GetAngleBetweenVectors(newTerrainNormal, Vector3.Up);
                if (finalRotPoleVec.Dot(poleVectorNormalized) > 0)
                {
                    deltaAngle = -deltaAngle;
                }
                deltaAngle = MathHelper.Clamp(deltaAngle, finalMinRot, finalMaxRot);

                Matrix.CreateFromAxisAngle(ref poleVectorNormalized, deltaAngle, out footRotation);
                ikChain.LastAligningRotationMatrix = Matrix.Lerp(ikChain.LastAligningRotationMatrix, footRotation, ikChain.AligningSmoothness);
                Matrix thirdBoneAbsoluteFinal = thirdBoneTransformBackup.GetOrientation() * ikChain.LastAligningRotationMatrix;
                thirdBoneAbsoluteFinal.Translation = thirdBone.AbsoluteTransform.Translation;

                thirdBone.SetCompleteTransformFromAbsoluteMatrix(ref thirdBoneAbsoluteFinal, true);
                thirdBone.ComputeAbsoluteTransform();
            }

            // Debugging of the solver.
            if (m_showDebugDrawings)
            {
                MyRenderProxy.DebugDrawLine3D(Vector3D.Transform(firstBoneOrigin, ref DebugTransform), Vector3D.Transform(secondBoneOrigin, ref DebugTransform),
                                              Color.Yellow, Color.Red, false);
                MyRenderProxy.DebugDrawLine3D(Vector3D.Transform(secondBoneOrigin, ref DebugTransform), Vector3D.Transform(thirdBoneOrigin, ref DebugTransform),
                                              Color.Yellow, Color.Red, false);
                MyRenderProxy.DebugDrawSphere(Vector3D.Transform(finalPosition, ref DebugTransform), 0.05f, Color.Cyan, 1.0f, false);
                MyRenderProxy.DebugDrawLine3D(Vector3D.Transform(secondBoneOrigin, ref DebugTransform), Vector3D.Transform(secondBoneOrigin + poleVectorNormalized, ref DebugTransform),
                                              Color.PaleGreen, Color.PaleGreen, false);

                MyRenderProxy.DebugDrawLine3D(Vector3D.Transform(firstBoneOrigin, ref DebugTransform), Vector3D.Transform(firstBoneOrigin + planeDirX, ref DebugTransform),
                                              Color.White, Color.White, false);
                MyRenderProxy.DebugDrawLine3D(Vector3D.Transform(firstBoneOrigin, ref DebugTransform), Vector3D.Transform(firstBoneOrigin + planeDirY, ref DebugTransform),
                                              Color.White, Color.White, false);

                MyRenderProxy.DebugDrawSphere(Vector3D.Transform(newSecondBoneOrigin, ref DebugTransform), 0.05f, Color.Green, 1.0f, false);
                MyRenderProxy.DebugDrawAxis(firstBone.AbsoluteTransform * DebugTransform, 0.5f, false);

                MyRenderProxy.DebugDrawLine3D(Vector3D.Transform(finalPosition, ref DebugTransform), Vector3D.Transform(finalPosition + newTerrainNormal, ref DebugTransform),
                                              Color.Black, Color.LightBlue, false);

                MyRenderProxy.DebugDrawArrow3D(Vector3D.Transform(secondBoneOrigin, ref DebugTransform), Vector3D.Transform(newSecondBoneOrigin, ref DebugTransform),
                                               Color.Green, Color.White, false);
            }

            ikChain.LastPoleVector = poleVectorNormalized;
            return(true);
        }
예제 #12
0
        public void DebugDraw()
        {
            var matrix = Sandbox.Game.World.MySector.MainCamera.ViewMatrix;

            Vector3D?prevPosition = null;

            foreach (var node in m_pathNodes)
            {
                Vector3D down = Sandbox.Game.GameSystems.MyGravityProviderSystem.CalculateTotalGravityInPoint(node.WorldPosition);
                if (Vector3D.IsZero(down, 0.001))
                {
                    down = Vector3D.Down;
                }
                down.Normalize();
                Vector3D position = node.WorldPosition + down * -10.0;
                MyRenderProxy.DebugDrawSphere(position, 1.0f, Color.IndianRed, 1.0f, false);
                MyRenderProxy.DebugDrawLine3D(node.WorldPosition, position, Color.IndianRed, Color.IndianRed, false);
                if (prevPosition.HasValue)
                {
                    MyRenderProxy.DebugDrawLine3D(position, prevPosition.Value, Color.IndianRed, Color.IndianRed, false);
                }

                prevPosition = position;
            }

            /*if (m_hlEnd != null)
             * {
             *  Vector3D position = m_hlEnd.WorldPosition + new Vector3D(0.0f, 10.0f, 0.0f);
             *  MyRenderProxy.DebugDrawSphere(position, 1.0f, Color.Crimson, 1.0f, false);
             *  MyRenderProxy.DebugDrawLine3D(m_hlEnd.WorldPosition, position, Color.Crimson, Color.Crimson, false);
             * }*/

            MyRenderProxy.DebugDrawSphere(m_startPoint, 0.5f, Color.HotPink, 1.0f, false);

            /*MyRenderProxy.DebugDrawSphere(m_endPoint, 0.5f, Color.HotPink, 1.0f, false);
             * MyRenderProxy.DebugDrawLine3D(m_startPoint, m_endPoint, Color.HotPink, Color.HotPink, false);*/

            if (m_goal != null)
            {
                m_goal.DebugDraw();
            }

            if (MyFakes.DEBUG_DRAW_FOUND_PATH)
            {
                Vector3D?prevPoint = null;
                for (int i = 0; i < m_expandedPath.Count; ++i)
                {
                    Vector3D point  = new Vector3D(m_expandedPath[i]);
                    float    radius = (float)m_expandedPath[i].W;
                    Color    col    = i == m_expandedPath.Count - 1 ? Color.OrangeRed : Color.Orange;
                    //VRageRender.MyRenderProxy.DebugDrawSphere(point, radius, col, 1.0f, false);
                    VRageRender.MyRenderProxy.DebugDrawPoint(point, col, false);
                    VRageRender.MyRenderProxy.DebugDrawText3D(point + matrix.Right * 0.1f, radius.ToString(), col, 0.7f, false);
                    if (prevPoint.HasValue)
                    {
                        VRageRender.MyRenderProxy.DebugDrawLine3D(prevPoint.Value, point, Color.Pink, Color.Pink, false);
                    }
                    prevPoint = point;
                }
            }
        }
예제 #13
0
        public static void DebugDraw()
        {
            if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW && MyDebugDrawSettings.DEBUG_DRAW_ENTITY_COMPONENTS && MySector.MainCamera != null)
            {
                double fontSize = 1.5;
                double lineSize = fontSize * 0.045;
                double hoffset  = 0.5f;

                Vector3D playerPos   = MySector.MainCamera.Position;
                Vector3D upVector    = MySector.MainCamera.WorldMatrix.Up;
                Vector3D rightVector = MySector.MainCamera.WorldMatrix.Right;
                Vector3D fwVector    = MySector.MainCamera.ForwardVector;

                BoundingSphereD bSphere  = new BoundingSphereD(playerPos, 5.0f);
                var             entities = MyEntities.GetEntitiesInSphere(ref bSphere);
                foreach (var entity in entities)
                {
                    if (entity.PositionComp == null)
                    {
                        continue;
                    }

                    Vector3D originalPos = entity.PositionComp.GetPosition();
                    Vector3D pos2        = originalPos + upVector * 0.1f;
                    Vector3D pos         = pos2 - rightVector * hoffset;
                    Vector3D viewVector  = Vector3D.Normalize(originalPos - playerPos);
                    double   dot         = Vector3D.Dot(viewVector, fwVector);
                    if (dot < 0.9995)
                    {
                        MyRenderProxy.DebugDrawSphere(originalPos, 0.01f, Color.White, 1.0f, false);
                        continue;
                    }

                    double dist     = Vector3D.Distance(pos, playerPos);
                    double textSize = Math.Atan(fontSize / Math.Max(dist, 0.001));

                    float n = 0;
                    {
                        var             enumerator = entity.Components.GetEnumerator();
                        MyComponentBase component  = null;
                        while (enumerator.MoveNext())
                        {
                            component = enumerator.Current;
                            n        += GetComponentLines(component);
                        }
                        n += 1;
                        n -= GetComponentLines(component); // The last component should not make the line longer
                        enumerator.Dispose();
                    }

                    Vector3D topPos     = pos + (n + 0.5f) * upVector * lineSize;
                    Vector3D currentPos = pos + (n + 1) * upVector * lineSize + 0.01f * rightVector;

                    MyRenderProxy.DebugDrawLine3D(originalPos, pos2, Color.White, Color.White, false);
                    MyRenderProxy.DebugDrawLine3D(pos, pos2, Color.White, Color.White, false);
                    MyRenderProxy.DebugDrawLine3D(pos, topPos, Color.White, Color.White, false);
                    MyRenderProxy.DebugDrawLine3D(topPos, topPos + rightVector * 1.0f, Color.White, Color.White, false);
                    MyRenderProxy.DebugDrawText3D(currentPos, entity.GetType().ToString() + " - " + entity.DisplayName, Color.Orange, (float)textSize, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);

                    foreach (var component in entity.Components)
                    {
                        currentPos = pos + n * upVector * lineSize;
                        DebugDrawComponent(component, currentPos, rightVector, upVector, lineSize, (float)textSize);
                        var    entityComponent = component as MyEntityComponentBase;
                        string compType        = entityComponent == null ? "" : entityComponent.ComponentTypeDebugString;
                        MyRenderProxy.DebugDrawText3D(currentPos - 0.02f * rightVector, compType, Color.Yellow, (float)textSize, false, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER);
                        n -= GetComponentLines(component);
                    }
                }
                entities.Clear();
            }
        }
예제 #14
0
 public virtual void DebugDraw(ref Matrix drawMatrix)
 {
     if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW)
     {
         if (MyDebugDrawSettings.DEBUG_DRAW_NAVMESHES != MyWEMDebugDrawMode.NONE)
         {
             this.m_mesh.DebugDraw(ref drawMatrix, MyDebugDrawSettings.DEBUG_DRAW_NAVMESHES);
             this.m_mesh.CustomDebugDrawFaces(ref drawMatrix, MyDebugDrawSettings.DEBUG_DRAW_NAVMESHES, obj => (obj as MyNavigationTriangle).Index.ToString());
         }
         if (MyFakes.DEBUG_DRAW_FUNNEL)
         {
             List <Vector3> .Enumerator enumerator;
             MyRenderProxy.DebugDrawSphere(Vector3.Transform(this.m_vertex, (Matrix)drawMatrix), 0.05f, Color.Yellow.ToVector3(), 1f, false, false, true, false);
             MyRenderProxy.DebugDrawSphere(Vector3.Transform(this.m_vertex + this.m_normal, (Matrix)drawMatrix), 0.05f, Color.Orange.ToVector3(), 1f, false, false, true, false);
             MyRenderProxy.DebugDrawSphere(Vector3.Transform(this.m_left, (Matrix)drawMatrix), 0.05f, Color.Red.ToVector3(), 1f, false, false, true, false);
             Color green = Color.Green;
             MyRenderProxy.DebugDrawSphere(Vector3.Transform(this.m_right, (Matrix)drawMatrix), 0.05f, green.ToVector3(), 1f, false, false, true, false);
             using (enumerator = m_debugPointsLeft.GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     green = Color.Red;
                     MyRenderProxy.DebugDrawSphere(Vector3.Transform(enumerator.Current, (Matrix)drawMatrix), 0.03f, green.ToVector3(), 1f, false, false, true, false);
                 }
             }
             using (enumerator = m_debugPointsRight.GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     green = Color.Green;
                     MyRenderProxy.DebugDrawSphere(Vector3.Transform(enumerator.Current, (Matrix)drawMatrix), 0.04f, green.ToVector3(), 1f, false, false, true, false);
                 }
             }
             Vector3?nullable = null;
             if (m_path != null)
             {
                 using (enumerator = m_path.GetEnumerator())
                 {
                     while (enumerator.MoveNext())
                     {
                         Vector3 vector = Vector3.Transform(enumerator.Current, (Matrix)drawMatrix);
                         MyRenderProxy.DebugDrawSphere(vector + (Vector3.Up * 0.2f), 0.02f, Color.Orange.ToVector3(), 1f, false, false, true, false);
                         if (nullable != null)
                         {
                             MyRenderProxy.DebugDrawLine3D(nullable.Value + (Vector3.Up * 0.2f), vector + (Vector3.Up * 0.2f), Color.Orange, Color.Orange, true, false);
                         }
                         nullable = new Vector3?(vector);
                     }
                 }
             }
             nullable = null;
             if (m_path2 != null)
             {
                 using (enumerator = m_path2.GetEnumerator())
                 {
                     while (enumerator.MoveNext())
                     {
                         Vector3 vector2 = Vector3.Transform(enumerator.Current, (Matrix)drawMatrix);
                         if (nullable != null)
                         {
                             MyRenderProxy.DebugDrawLine3D(nullable.Value + (Vector3.Up * 0.1f), vector2 + (Vector3.Up * 0.1f), Color.Violet, Color.Violet, true, false);
                         }
                         nullable = new Vector3?(vector2);
                     }
                 }
             }
             if (m_debugFunnel.Count > 0)
             {
                 FunnelState local2  = m_debugFunnel[m_debugFunnelIdx % m_debugFunnel.Count];
                 Vector3     vector3 = Vector3.Transform(local2.Apex, (Matrix)drawMatrix);
                 Vector3     vector4 = vector3 + ((Vector3.Transform(local2.Left, (Matrix)drawMatrix) - vector3) * 10f);
                 Vector3     vector5 = vector3 + ((Vector3.Transform(local2.Right, (Matrix)drawMatrix) - vector3) * 10f);
                 Color       cyan    = Color.Cyan;
                 MyRenderProxy.DebugDrawLine3D(vector3 + (Vector3.Up * 0.1f), vector4 + (Vector3.Up * 0.1f), cyan, cyan, true, false);
                 MyRenderProxy.DebugDrawLine3D(vector3 + (Vector3.Up * 0.1f), vector5 + (Vector3.Up * 0.1f), cyan, cyan, true, false);
             }
         }
     }
 }