Ejemplo n.º 1
0
        public override void DebugDrawWorld()
        {
            BulletGlobals.StartProfile("debugDrawWorld");

            base.DebugDrawWorld();

            if (GetDebugDrawer() != null)
            {
                DebugDrawModes mode = GetDebugDrawer().GetDebugMode();
                if ((mode & (DebugDrawModes.DBG_DrawConstraints | DebugDrawModes.DBG_DrawConstraintLimits)) != 0)
                {
                    for (int i = GetNumConstraints() - 1; i >= 0; i--)
                    {
                        TypedConstraint constraint = GetConstraint(i);
                        DrawHelper.DebugDrawConstraint(constraint, GetDebugDrawer());
                    }
                }
                if (mode != 0)
                {
                    int actionsCount = m_actions.Count;
                    for (int i = 0; i < actionsCount; ++i)
                    {
                        m_actions[i].DebugDraw(m_debugDrawer);
                    }
                }
            }

            BulletGlobals.StopProfile();
        }
        public void Evaluate(int SpreadMax)
        {
            if (this.currentWorld != this.worldPin[0])
            {
                if (this.currentWorld != null)
                {
                    this.currentWorld.World.DebugDrawer = null;
                }
                this.currentWorld = this.worldPin[0];
            }

            if (this.currentWorld != null)
            {
                if (this.enabled[0])
                {
                    this.mode = DebugDrawModes.None;
                    for (int i = 0; i < this.drawMode.SliceCount; i++)
                    {
                        mode |= this.drawMode[i];
                    }
                }
                else
                {
                    this.currentWorld.World.DebugDrawer = null;
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="device">グラフィックデバイス</param>
 public PhysicsDebugDraw(GraphicsDevice device)
 {
     effect = new BasicEffect(device);
     effect.VertexColorEnabled = true;
     effect.World = Matrix.Identity;
     vertexDec = VertexPositionColor.VertexDeclaration;//new VertexDeclaration(device, VertexPositionColor.VertexElements);
     vertex = new VertexPositionColor[50];
     DebugMode=(DebugDrawModes.DBG_DrawWireframe | DebugDrawModes.DBG_DrawConstraints);
 }
Ejemplo n.º 4
0
    /*
     *  public virtual void syncPhysicsToGraphics()
     *  {
     *          if (m_dynamicsWorld)
     *          {
     *                  m_guiHelper.syncPhysicsToGraphics(m_dynamicsWorld);
     *          }
     *  }
     */
    /*
     *  public virtual void renderScene()
     *  {
     *  if (m_dynamicsWorld)
     *  {
     *          m_guiHelper.syncPhysicsToGraphics(m_dynamicsWorld);
     *
     *          m_guiHelper.render(m_dynamicsWorld);
     *  }
     *
     *  }
     */

    public virtual void    physicsDebugDraw(DebugDrawModes debugDrawFlags)
    {
        if (m_dynamicsWorld != null)
        {
            if (m_dynamicsWorld.DebugDrawer != null)
            {
                m_dynamicsWorld.DebugDrawer.DebugMode = (debugDrawFlags);
            }
            m_dynamicsWorld.DebugDrawWorld();
        }
    }
Ejemplo n.º 5
0
        private void DebugDrawFlags_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            DebugDrawModes drawModes = _demo.DebugDrawMode;

            if (e.NewValue == CheckState.Checked)
            {
                drawModes |= _debugDrawModesList[e.Index];
            }
            else
            {
                drawModes &= (DebugDrawModes.All ^ _debugDrawModesList[e.Index]);
            }
            _demo.DebugDrawMode = drawModes;
        }
Ejemplo n.º 6
0
        private static void UpdateDisplay()
        {
            DebugDrawModes drawModes = DebugDrawModes.None;

            if (_areAabbsShown)
            {
                drawModes |= DebugDrawModes.DrawAabb;
            }
            if (_areConstraintLimitsShown)
            {
                drawModes |= DebugDrawModes.DrawConstraintLimits;
            }
            if (_areConstraintsShown)
            {
                drawModes |= DebugDrawModes.DrawConstraints;
            }
            if (_areContactPointsShown)
            {
                drawModes |= DebugDrawModes.DrawContactPoints;
            }
            if (_areNormalsShown)
            {
                drawModes |= DebugDrawModes.DrawNormals;
            }
            if (_showWireframe)
            {
                drawModes |= DebugDrawModes.DrawWireframe;
            }

            DebugDrawModes = drawModes;

            if (Game.IsInitialized)
            {
                Game.Workspace.Physics.UpdateDebugDrawModes();
            }
            else
            {
                Game.Initialized += (sender, args) =>
                {
                    Game.Workspace.Physics.UpdateDebugDrawModes();
                };
            }
        }
Ejemplo n.º 7
0
		public override void setDebugMode( DebugDrawModes debugMode )
		{
			mode = debugMode;
		}
Ejemplo n.º 8
0
 public override void SetDebugMode(DebugDrawModes debugMode)
 {
     m_debugDrawModes = debugMode;
 }
Ejemplo n.º 9
0
        public void DrawXNA(ref IndexedMatrix m, CollisionShape shape, ref IndexedVector3 color, DebugDrawModes debugMode, ref IndexedVector3 worldBoundsMin, ref IndexedVector3 worldBoundsMax, ref IndexedMatrix view, ref IndexedMatrix projection)
        {
            //btglMultMatrix(m);
            if (shape == null)
            {
                return;
            }

            if (shape.GetShapeType() == BroadphaseNativeTypes.UNIFORM_SCALING_SHAPE_PROXYTYPE)
            {
                UniformScalingShape scalingShape = (UniformScalingShape)shape;
                ConvexShape convexShape = scalingShape.GetChildShape();
                float scalingFactor = scalingShape.GetUniformScalingFactor();
                IndexedMatrix scaleMatrix = IndexedMatrix.CreateScale(scalingFactor);
                IndexedMatrix finalMatrix = scaleMatrix * m;
                DrawXNA(ref finalMatrix, convexShape, ref color, debugMode, ref worldBoundsMin, ref worldBoundsMax,ref view,ref projection);
                return;
            }
            if (shape.GetShapeType() == BroadphaseNativeTypes.COMPOUND_SHAPE_PROXYTYPE)
            {
                CompoundShape compoundShape = (CompoundShape)shape;
                for (int i = compoundShape.GetNumChildShapes() - 1; i >= 0; i--)
                {
                    IndexedMatrix childTrans = compoundShape.GetChildTransform(i);
                    CollisionShape colShape = compoundShape.GetChildShape(i);
                    IndexedMatrix childMat = childTrans;

					//childMat = MathUtil.bulletMatrixMultiply(m, childMat);
                    //childMat = childMat * m;
                    childMat = m * childMat;

                    
					
					DrawXNA(ref childMat, colShape, ref color, debugMode, ref worldBoundsMin, ref worldBoundsMax,ref view,ref projection);
                }
            }
            else
            {

                bool useWireframeFallback = true;

                if ((debugMode & DebugDrawModes.DBG_DrawWireframe) == 0)
                {
                    ///you can comment out any of the specific cases, and use the default
                    ///the benefit of 'default' is that it approximates the actual collision shape including collision margin
                    //BroadphaseNativeTypes shapetype = m_textureEnabled ? BroadphaseNativeTypes.MAX_BROADPHASE_COLLISION_TYPES : shape.getShapeType();
                    BroadphaseNativeTypes shapetype = shape.GetShapeType();
                    switch (shapetype)
                    {
                        case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE:
                            {
                                BoxShape boxShape = shape as BoxShape;
                                IndexedVector3 halfExtents = boxShape.GetHalfExtentsWithMargin();

                                DrawSolidCube(ref halfExtents, ref m, ref view, ref projection,ref color);
                                //drawSolidSphere(halfExtents.X, 10, 10, ref m, ref view, ref projection);
                                //drawCylinder(halfExtents.X, halfExtents.Y, 1, ref m, ref view, ref projection);
                                //drawSolidCone(halfExtents.Y, halfExtents.X, ref m, ref view, ref projection);

                                //DrawText("Hello World", new IndexedVector3(20, 20, 0), new IndexedVector3(255, 255, 255));
                                useWireframeFallback = false;
                                break;
                            }


                        case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE:
                            {
                                SphereShape sphereShape = shape as SphereShape;
                                float radius = sphereShape.GetMargin();//radius doesn't include the margin, so draw with margin
								DrawSolidSphere(radius, 10, 10, ref m, ref view, ref projection, ref color);
                                //glutSolidSphere(radius,10,10);
                                useWireframeFallback = false;
                                break;
                            }
                        case BroadphaseNativeTypes.CAPSULE_SHAPE_PROXYTYPE:
		                    {
                                CapsuleShape capsuleShape = shape as CapsuleShape;

			                    float radius = capsuleShape.GetRadius();
			                    float halfHeight = capsuleShape.GetHalfHeight();

			                    int upAxis = capsuleShape.GetUpAxis();

			                    IndexedVector3 capStart = IndexedVector3.Zero;
			                    capStart[upAxis] = -halfHeight;

                                IndexedVector3 capEnd = IndexedVector3.Zero;
                                capEnd[upAxis] = halfHeight;

			                    // Draw the ends
			                    {

				                    IndexedMatrix childTransform = IndexedMatrix.Identity;
                                    childTransform._origin = m * capStart;
									DrawSolidSphere(radius, 5, 5, ref childTransform, ref view, ref projection, ref color);
			                    }

			                    {
                                    IndexedMatrix childTransform = IndexedMatrix.Identity;
                                    childTransform._origin = m * capEnd;
									DrawSolidSphere(radius, 5, 5, ref childTransform, ref view, ref projection, ref color);
                                }

                                DrawCylinder(radius, halfHeight, upAxis, ref m, ref view, ref projection,ref color);
                                break;
		                    }
                        case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE:
                            {
                                ConeShape coneShape = (ConeShape)(shape);
                                int upIndex = coneShape.GetConeUpIndex();
                                float radius = coneShape.GetRadius();//+coneShape.getMargin();
                                float height = coneShape.GetHeight();//+coneShape.getMargin();
                                IndexedMatrix rotateMatrix = IndexedMatrix.Identity;


                                switch (upIndex)
                                {
                                    case 0:
                                        rotateMatrix = IndexedMatrix.CreateRotationX(-MathUtil.SIMD_HALF_PI);
                                        break;
                                    case 1:
                                        break;
                                    case 2:
                                        rotateMatrix = IndexedMatrix.CreateRotationX(MathUtil.SIMD_HALF_PI);
                                        break;
                                    default:
                                        {
                                            break;
                                        }
                                };

                                IndexedMatrix translationMatrix = IndexedMatrix.CreateTranslation(0f, 0f, -0.5f * height);

                                IndexedMatrix resultant = m * rotateMatrix * translationMatrix;

                                DrawSolidCone(height, radius, ref resultant, ref view, ref projection, ref color);
                                useWireframeFallback = false;
                                break;

                            }


                        case BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE:
                            {
                                StaticPlaneShape staticPlaneShape = shape as StaticPlaneShape;
                                float planeConst = staticPlaneShape.GetPlaneConstant();
                                IndexedVector3 planeNormal = staticPlaneShape.GetPlaneNormal();
                                IndexedVector3 planeOrigin = planeNormal * planeConst;
                                IndexedVector3 vec0, vec1;
                                TransformUtil.PlaneSpace1(ref planeNormal, out vec0, out vec1);
                                float vecLen = 100f;
                                IndexedVector3 pt0 = planeOrigin + vec0 * vecLen;
                                IndexedVector3 pt1 = planeOrigin - vec0 * vecLen;
                                IndexedVector3 pt2 = planeOrigin + vec1 * vecLen;
                                IndexedVector3 pt3 = planeOrigin - vec1 * vecLen;

                                // Fallback to debug draw - needs tidying
                                IndexedVector3 colour = new IndexedVector3(255, 255, 255);
                                DrawLine(ref pt0, ref pt1, ref colour);
                                DrawLine(ref pt1, ref pt2, ref colour);
                                DrawLine(ref pt2, ref pt3, ref colour);
                                DrawLine(ref pt3, ref pt1, ref colour);

                                break;

                            }

                        case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE:
                            {
                                CylinderShape cylinder = (CylinderShape)(shape);
                                int upAxis = cylinder.GetUpAxis();

                                float radius = cylinder.GetRadius();
                                float halfHeight = cylinder.GetHalfExtentsWithMargin()[upAxis];
								DrawCylinder(radius, halfHeight, upAxis, ref m, ref view, ref projection, ref color);
                                break;
                            }

                        default:
                            {
                                if (shape.IsConvex())
                                {
                                    ShapeCache	sc=Cache(shape as ConvexShape);

                                    //if (shape.getUserPointer())
                                    {
                                        //glutSolidCube(1.0);
                                        ShapeHull hull = sc.m_shapehull/*(btShapeHull*)shape.getUserPointer()*/;

                                        int numTriangles = hull.NumTriangles();
                                        int numIndices = hull.NumIndices();
                                        int numVertices = hull.NumVertices(); 
                                        if (numTriangles > 0)
                                        {
                                            int index = 0;
                                            IList<int> idx = hull.m_indices;
                                            IList<IndexedVector3> vtx = hull.m_vertices;

                                            for (int i = 0; i < numTriangles; i++)
                                            {
                                                int i1 = index++;
                                                int i2 = index++;
                                                int i3 = index++;
                                                Debug.Assert(i1 < numIndices &&
                                                    i2 < numIndices &&
                                                    i3 < numIndices);

                                                int index1 = idx[i1];
                                                int index2 = idx[i2];
                                                int index3 = idx[i3];
                                                Debug.Assert(index1 < numVertices &&
                                                    index2 < numVertices &&
                                                    index3 < numVertices);

                                                IndexedVector3 v1 = m * vtx[index1];
                                                IndexedVector3 v2 = m * vtx[index2];
                                                IndexedVector3 v3 = m * vtx[index3];
                                                IndexedVector3 normal = IndexedVector3.Cross((v3-v1),(v2-v1));
                                                normal.Normalize();

                                                Vector2 tex = new Vector2(0,0);
                                                AddVertex(ref v1, ref normal,ref tex);
                                                AddVertex(ref v2, ref normal, ref tex);
                                                AddVertex(ref v3, ref normal, ref tex);
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }

                    /// for polyhedral shapes
                    if (debugMode == DebugDrawModes.DBG_DrawFeaturesText && (shape.IsPolyhedral()))
                    {
                        PolyhedralConvexShape polyshape = (PolyhedralConvexShape)shape;
                        {
                            //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape.getExtraDebugInfo());

                            IndexedVector3 colour = new IndexedVector3(255, 255, 255);
                            for (int i = 0; i < polyshape.GetNumVertices(); i++)
                            {
                                IndexedVector3 vtx;
                                polyshape.GetVertex(i, out vtx);
                                String buf = " " + i;
                                DrawText(buf, ref vtx, ref colour);
                            }

                            for (int i = 0; i < polyshape.GetNumPlanes(); i++)
                            {
                                IndexedVector3 normal;
                                IndexedVector3 vtx;
                                polyshape.GetPlane(out normal, out vtx, i);
                                float d = IndexedVector3.Dot(vtx, normal);
                                vtx *= d;

                                String buf = " plane " + i;
                                DrawText(buf, ref vtx, ref colour);
                            }
                        }
                    }

                    if (shape.IsConcave() && !shape.IsInfinite())//>getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape.getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
                    //		if (shape.getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
                    {
                        ConcaveShape concaveMesh = shape as ConcaveShape;

                        XNADrawcallback drawCallback = new XNADrawcallback(this,ref m);
                        drawCallback.m_wireframe = (debugMode & DebugDrawModes.DBG_DrawWireframe) != 0;

                        concaveMesh.ProcessAllTriangles(drawCallback, ref worldBoundsMin, ref worldBoundsMax);

                    }

                    //glDisable(GL_DEPTH_TEST);
                    //glRasterPos3f(0,0,0);//mvtx.x(),  vtx.y(),  vtx.z());
                    if ((debugMode & DebugDrawModes.DBG_DrawText) != 0)
                    {
                        IndexedVector3 position = IndexedVector3.Zero;
                        IndexedVector3 colour = new IndexedVector3(255, 255, 255);
                        DrawText(shape.GetName(), ref position, ref colour);
                    }

                    if ((debugMode & DebugDrawModes.DBG_DrawFeaturesText) != 0)
                    {
                        //drawText(shape.getEx]
                        //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),shape.getExtraDebugInfo());
                    }
                    //glEnable(GL_DEPTH_TEST);

                    ////	glPopMatrix();	
                    //if(m_textureenabled) glDisable(GL_TEXTURE_2D);
                    //  }
                    //    glPopMatrix();
            }
        }
Ejemplo n.º 10
0
 public void DrawXNA(IndexedMatrix m, CollisionShape shape, IndexedVector3 color, DebugDrawModes debugMode, IndexedVector3 worldBoundsMin, IndexedVector3 worldBoundsMax, IndexedMatrix view, IndexedMatrix projection)
 {
     DrawXNA(ref m, shape, ref color, debugMode, ref worldBoundsMin, ref worldBoundsMax, ref view, ref projection);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// デバッグ描画
 /// </summary>
 /// <param name="MaxLine">確保する最大ライン数</param>
 public PhysicsDebugDraw(int MaxLine)
 {
     lines = new PDDVertex[MaxLine * 2];
     DebugMode = DebugDrawModes.DBG_DrawWireframe;
     
 }
Ejemplo n.º 12
0
 public static void disableGlobalDebugMode(DebugDrawModes debugMode)
 {
     BulletDebugDraw_disableGlobalDebugMode((int)debugMode);
     Log.Default.debug("Disabled {0}", debugMode);
 }
Ejemplo n.º 13
0
 public abstract void SetDebugMode(DebugDrawModes debugMode);
Ejemplo n.º 14
0
 public void SetDebugMode(DebugDrawModes debugMode)
 {
     m_debugDrawModes = debugMode;
 }
Ejemplo n.º 15
0
		public abstract void setDebugMode( DebugDrawModes debugMode );
Ejemplo n.º 16
0
 public static void setGlobalDebugMode(DebugDrawModes debugMode)
 {
     BulletDebugDraw_setGlobalDebugMode((int)debugMode);
     Log.Default.debug("Enabled {0}", debugMode);
 }
Ejemplo n.º 17
0
 public void DrawXNA(IndexedMatrix m, CollisionShape shape, IndexedVector3 color, DebugDrawModes debugMode, IndexedVector3 worldBoundsMin, IndexedVector3 worldBoundsMax, IndexedMatrix view, IndexedMatrix projection)
 {
     DrawXNA(ref m, shape, ref color, debugMode, ref worldBoundsMin, ref worldBoundsMax, ref view, ref projection);
 }
Ejemplo n.º 18
0
        private void SetDebugDrawFlag(int index, DebugDrawModes drawMode)
        {
            bool isChecked = (_demo.DebugDrawMode & drawMode) != 0;

            debugDrawFlags.SetItemChecked(index, isChecked);
        }
Ejemplo n.º 19
0
        public void DrawXNA(ref IndexedMatrix m, CollisionShape shape, ref IndexedVector3 color, DebugDrawModes debugMode, ref IndexedVector3 worldBoundsMin, ref IndexedVector3 worldBoundsMax, ref IndexedMatrix view, ref IndexedMatrix projection)
        {
            //btglMultMatrix(m);
            if (shape == null)
            {
                return;
            }

            if (shape.GetShapeType() == BroadphaseNativeTypes.UNIFORM_SCALING_SHAPE_PROXYTYPE)
            {
                UniformScalingShape scalingShape = (UniformScalingShape)shape;
                ConvexShape         convexShape  = scalingShape.GetChildShape();
                float         scalingFactor      = scalingShape.GetUniformScalingFactor();
                IndexedMatrix scaleMatrix        = IndexedMatrix.CreateScale(scalingFactor);
                IndexedMatrix finalMatrix        = scaleMatrix * m;
                DrawXNA(ref finalMatrix, convexShape, ref color, debugMode, ref worldBoundsMin, ref worldBoundsMax, ref view, ref projection);
                return;
            }
            if (shape.GetShapeType() == BroadphaseNativeTypes.COMPOUND_SHAPE_PROXYTYPE)
            {
                CompoundShape compoundShape = (CompoundShape)shape;
                for (int i = compoundShape.GetNumChildShapes() - 1; i >= 0; i--)
                {
                    IndexedMatrix  childTrans = compoundShape.GetChildTransform(i);
                    CollisionShape colShape   = compoundShape.GetChildShape(i);
                    IndexedMatrix  childMat   = childTrans;

                    //childMat = MathUtil.bulletMatrixMultiply(m, childMat);
                    //childMat = childMat * m;
                    childMat = m * childMat;



                    DrawXNA(ref childMat, colShape, ref color, debugMode, ref worldBoundsMin, ref worldBoundsMax, ref view, ref projection);
                }
            }
            else
            {
                bool useWireframeFallback = true;

                if ((debugMode & DebugDrawModes.DBG_DrawWireframe) == 0)
                {
                    ///you can comment out any of the specific cases, and use the default
                    ///the benefit of 'default' is that it approximates the actual collision shape including collision margin
                    //BroadphaseNativeTypes shapetype = m_textureEnabled ? BroadphaseNativeTypes.MAX_BROADPHASE_COLLISION_TYPES : shape.getShapeType();
                    BroadphaseNativeTypes shapetype = shape.GetShapeType();
                    switch (shapetype)
                    {
                    case BroadphaseNativeTypes.BOX_SHAPE_PROXYTYPE:
                    {
                        BoxShape       boxShape    = shape as BoxShape;
                        IndexedVector3 halfExtents = boxShape.GetHalfExtentsWithMargin();

                        DrawSolidCube(ref halfExtents, ref m, ref view, ref projection, ref color);
                        //drawSolidSphere(halfExtents.X, 10, 10, ref m, ref view, ref projection);
                        //drawCylinder(halfExtents.X, halfExtents.Y, 1, ref m, ref view, ref projection);
                        //drawSolidCone(halfExtents.Y, halfExtents.X, ref m, ref view, ref projection);

                        //DrawText("Hello World", new IndexedVector3(20, 20, 0), new IndexedVector3(255, 255, 255));
                        useWireframeFallback = false;
                        break;
                    }


                    case BroadphaseNativeTypes.SPHERE_SHAPE_PROXYTYPE:
                    {
                        SphereShape sphereShape = shape as SphereShape;
                        float       radius      = sphereShape.GetMargin();//radius doesn't include the margin, so draw with margin
                        DrawSolidSphere(radius, 10, 10, ref m, ref view, ref projection, ref color);
                        //glutSolidSphere(radius,10,10);
                        useWireframeFallback = false;
                        break;
                    }

                    case BroadphaseNativeTypes.CAPSULE_SHAPE_PROXYTYPE:
                    {
                        CapsuleShape capsuleShape = shape as CapsuleShape;

                        float radius     = capsuleShape.GetRadius();
                        float halfHeight = capsuleShape.GetHalfHeight();

                        int upAxis = capsuleShape.GetUpAxis();

                        IndexedVector3 capStart = IndexedVector3.Zero;
                        capStart[upAxis] = -halfHeight;

                        IndexedVector3 capEnd = IndexedVector3.Zero;
                        capEnd[upAxis] = halfHeight;

                        // Draw the ends
                        {
                            IndexedMatrix childTransform = IndexedMatrix.Identity;
                            childTransform._origin = m * capStart;
                            DrawSolidSphere(radius, 5, 5, ref childTransform, ref view, ref projection, ref color);
                        }

                        {
                            IndexedMatrix childTransform = IndexedMatrix.Identity;
                            childTransform._origin = m * capEnd;
                            DrawSolidSphere(radius, 5, 5, ref childTransform, ref view, ref projection, ref color);
                        }

                        DrawCylinder(radius, halfHeight, upAxis, ref m, ref view, ref projection, ref color);
                        break;
                    }

                    case BroadphaseNativeTypes.CONE_SHAPE_PROXYTYPE:
                    {
                        ConeShape     coneShape    = (ConeShape)(shape);
                        int           upIndex      = coneShape.GetConeUpIndex();
                        float         radius       = coneShape.GetRadius(); //+coneShape.getMargin();
                        float         height       = coneShape.GetHeight(); //+coneShape.getMargin();
                        IndexedMatrix rotateMatrix = IndexedMatrix.Identity;


                        switch (upIndex)
                        {
                        case 0:
                            rotateMatrix = IndexedMatrix.CreateRotationX(-MathUtil.SIMD_HALF_PI);
                            break;

                        case 1:
                            break;

                        case 2:
                            rotateMatrix = IndexedMatrix.CreateRotationX(MathUtil.SIMD_HALF_PI);
                            break;

                        default:
                        {
                            break;
                        }
                        }
                        ;

                        IndexedMatrix translationMatrix = IndexedMatrix.CreateTranslation(0f, 0f, -0.5f * height);

                        IndexedMatrix resultant = m * rotateMatrix * translationMatrix;

                        DrawSolidCone(height, radius, ref resultant, ref view, ref projection, ref color);
                        useWireframeFallback = false;
                        break;
                    }


                    case BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE:
                    {
                        StaticPlaneShape staticPlaneShape = shape as StaticPlaneShape;
                        float            planeConst = staticPlaneShape.GetPlaneConstant();
                        IndexedVector3   planeNormal = staticPlaneShape.GetPlaneNormal();
                        IndexedVector3   planeOrigin = planeNormal * planeConst;
                        IndexedVector3   vec0, vec1;
                        TransformUtil.PlaneSpace1(ref planeNormal, out vec0, out vec1);
                        float          vecLen = 100f;
                        IndexedVector3 pt0 = planeOrigin + vec0 * vecLen;
                        IndexedVector3 pt1 = planeOrigin - vec0 * vecLen;
                        IndexedVector3 pt2 = planeOrigin + vec1 * vecLen;
                        IndexedVector3 pt3 = planeOrigin - vec1 * vecLen;

                        // Fallback to debug draw - needs tidying
                        IndexedVector3 colour = new IndexedVector3(255, 255, 255);
                        DrawLine(ref pt0, ref pt1, ref colour);
                        DrawLine(ref pt1, ref pt2, ref colour);
                        DrawLine(ref pt2, ref pt3, ref colour);
                        DrawLine(ref pt3, ref pt1, ref colour);

                        break;
                    }

                    case BroadphaseNativeTypes.CYLINDER_SHAPE_PROXYTYPE:
                    {
                        CylinderShape cylinder = (CylinderShape)(shape);
                        int           upAxis   = cylinder.GetUpAxis();

                        float radius     = cylinder.GetRadius();
                        float halfHeight = cylinder.GetHalfExtentsWithMargin()[upAxis];
                        DrawCylinder(radius, halfHeight, upAxis, ref m, ref view, ref projection, ref color);
                        break;
                    }

                    default:
                    {
                        if (shape.IsConvex())
                        {
                            ShapeCache sc = Cache(shape as ConvexShape);

                            //if (shape.getUserPointer())
                            {
                                //glutSolidCube(1.0);
                                ShapeHull hull = sc.m_shapehull /*(btShapeHull*)shape.getUserPointer()*/;

                                int numTriangles = hull.NumTriangles();
                                int numIndices   = hull.NumIndices();
                                int numVertices  = hull.NumVertices();
                                if (numTriangles > 0)
                                {
                                    int                    index = 0;
                                    IList <int>            idx   = hull.m_indices;
                                    IList <IndexedVector3> vtx   = hull.m_vertices;

                                    for (int i = 0; i < numTriangles; i++)
                                    {
                                        int i1 = index++;
                                        int i2 = index++;
                                        int i3 = index++;
                                        Debug.Assert(i1 < numIndices &&
                                                     i2 < numIndices &&
                                                     i3 < numIndices);

                                        int index1 = idx[i1];
                                        int index2 = idx[i2];
                                        int index3 = idx[i3];
                                        Debug.Assert(index1 < numVertices &&
                                                     index2 < numVertices &&
                                                     index3 < numVertices);

                                        IndexedVector3 v1     = m * vtx[index1];
                                        IndexedVector3 v2     = m * vtx[index2];
                                        IndexedVector3 v3     = m * vtx[index3];
                                        IndexedVector3 normal = IndexedVector3.Cross((v3 - v1), (v2 - v1));
                                        normal.Normalize();

                                        Vector2 tex = new Vector2(0, 0);
                                        AddVertex(ref v1, ref normal, ref tex);
                                        AddVertex(ref v2, ref normal, ref tex);
                                        AddVertex(ref v3, ref normal, ref tex);
                                    }
                                }
                            }
                        }
                        break;
                    }
                    }
                }

                /// for polyhedral shapes
                if (debugMode == DebugDrawModes.DBG_DrawFeaturesText && (shape.IsPolyhedral()))
                {
                    PolyhedralConvexShape polyshape = (PolyhedralConvexShape)shape;
                    {
                        //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape.getExtraDebugInfo());

                        IndexedVector3 colour = new IndexedVector3(255, 255, 255);
                        for (int i = 0; i < polyshape.GetNumVertices(); i++)
                        {
                            IndexedVector3 vtx;
                            polyshape.GetVertex(i, out vtx);
                            String buf = " " + i;
                            DrawText(buf, ref vtx, ref colour);
                        }

                        for (int i = 0; i < polyshape.GetNumPlanes(); i++)
                        {
                            IndexedVector3 normal;
                            IndexedVector3 vtx;
                            polyshape.GetPlane(out normal, out vtx, i);
                            float d = IndexedVector3.Dot(vtx, normal);
                            vtx *= d;

                            String buf = " plane " + i;
                            DrawText(buf, ref vtx, ref colour);
                        }
                    }
                }

                if (shape.IsConcave() && !shape.IsInfinite())    //>getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape.getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
                //		if (shape.getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
                {
                    ConcaveShape concaveMesh = shape as ConcaveShape;

                    XNADrawcallback drawCallback = new XNADrawcallback(this, ref m);
                    drawCallback.m_wireframe = (debugMode & DebugDrawModes.DBG_DrawWireframe) != 0;

                    concaveMesh.ProcessAllTriangles(drawCallback, ref worldBoundsMin, ref worldBoundsMax);
                }

                //glDisable(GL_DEPTH_TEST);
                //glRasterPos3f(0,0,0);//mvtx.x(),  vtx.y(),  vtx.z());
                if ((debugMode & DebugDrawModes.DBG_DrawText) != 0)
                {
                    IndexedVector3 position = IndexedVector3.Zero;
                    IndexedVector3 colour   = new IndexedVector3(255, 255, 255);
                    DrawText(shape.GetName(), ref position, ref colour);
                }

                if ((debugMode & DebugDrawModes.DBG_DrawFeaturesText) != 0)
                {
                    //drawText(shape.getEx]
                    //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),shape.getExtraDebugInfo());
                }
                //glEnable(GL_DEPTH_TEST);

                ////	glPopMatrix();
                //if(m_textureenabled) glDisable(GL_TEXTURE_2D);
                //  }
                //    glPopMatrix();
            }
        }
Ejemplo n.º 20
0
 public override void SetDebugMode(DebugDrawModes debugMode)
 {
     m_debugDrawModes = debugMode;
 }
Ejemplo n.º 21
0
 public BulletDebugEntry(String text, DebugDrawModes mode)
 {
     this.text = text;
     this.mode = mode;
 }