public ConvexPointCloudShape()
	    {
            m_localScaling = new IndexedVector3(1);
		    m_shapeType = BroadphaseNativeTypes.CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
		    m_unscaledPoints = null;
		    m_numPoints = 0;
	    }
Esempio n. 2
0
		protected virtual int SetAngularLimits(ConstraintInfo2 info, int row_offset, ref IndexedMatrix transA, ref IndexedMatrix transB, ref IndexedVector3 linVelA, ref IndexedVector3 linVelB, ref IndexedVector3 angVelA, ref IndexedVector3 angVelB)
		{
			Generic6DofConstraint d6constraint = this;
			int row = row_offset;
			//solve angular limits
			for (int i = 0; i < 3; i++)
			{
				if (d6constraint.GetRotationalLimitMotor(i).NeedApplyTorques())
				{
					IndexedVector3 axis = d6constraint.GetAxis(i);
					int tempFlags = ((int)m_flags) >> ((i + 3) * BT_6DOF_FLAGS_AXIS_SHIFT);
					SixDofFlags flags = (SixDofFlags)tempFlags;
					if (0 == (flags & SixDofFlags.BT_6DOF_FLAGS_CFM_NORM))
					{
						m_angularLimits[i].m_normalCFM = info.m_solverConstraints[0].m_cfm;
					}
					if (0 == (flags & SixDofFlags.BT_6DOF_FLAGS_CFM_STOP))
					{
						m_angularLimits[i].m_stopCFM = info.m_solverConstraints[0].m_cfm;
					}
					if (0 == (flags & SixDofFlags.BT_6DOF_FLAGS_ERP_STOP))
					{
						m_angularLimits[i].m_stopERP = info.erp;
					}
					row += GetLimitMotorInfo2(d6constraint.GetRotationalLimitMotor(i),
														ref transA, ref transB, ref linVelA, ref linVelB, ref angVelA, ref angVelB, info, row, ref axis, 1, false);
				}
			}

			return row;
		}
Esempio n. 3
0
	    public BU_Simplex1to4(ref IndexedVector3 pt0,ref IndexedVector3 pt1,ref IndexedVector3 pt2)
        {
            m_shapeType = BroadphaseNativeTypes.TETRAHEDRAL_SHAPE_PROXYTYPE;
            AddVertex(ref pt0);
            AddVertex(ref pt1);
            AddVertex(ref pt2);
        }
        public override IndexedVector3 LocalGetSupportingVertexWithoutMargin(ref IndexedVector3 vec0)
        {
	        IndexedVector3 supVec = IndexedVector3.Zero;

	        IndexedVector3 vec = vec0;
	        float lenSqr = vec.LengthSquared();
	        if (lenSqr < 0.0001f)
	        {
                vec = new IndexedVector3(1, 0, 0);
	        } 
            else
	        {
                float rlen = (1.0f) / (float)Math.Sqrt(lenSqr);
                vec *= rlen;
                //vec.Normalize();
            }

	        LocalSupportVertexCallback supportCallback = new LocalSupportVertexCallback(ref vec);
	        IndexedVector3 aabbMax = new IndexedVector3(float.MaxValue);
            IndexedVector3 aabbMin = -aabbMax;
	        m_stridingMesh.InternalProcessAllTriangles(supportCallback,ref aabbMin,ref aabbMax);
	        supVec = supportCallback.GetSupportVertexLocal();

	        return supVec;

        }
Esempio n. 5
0
	    public virtual IndexedVector3 GetHalfExtentsWithMargin()
	    {
		    IndexedVector3 halfExtents = GetHalfExtentsWithoutMargin();
		    IndexedVector3 margin = new IndexedVector3(GetMargin());
		    halfExtents += margin;
		    return halfExtents;
	    }
Esempio n. 6
0
        //----------------------------------------------------------------------------------------------

        public void SetupWorldObjects()
        {
            IndexedVector3 halfExtents = new IndexedVector3(10, 5, 10);
            CollisionShape groundShape = new BoxShape(ref halfExtents);

            IndexedVector3 world1Center = new IndexedVector3(-20, -5, 0);
            IndexedVector3 world2Center = new IndexedVector3(20, -5, 0);

            IndexedMatrix groundTransform1 = IndexedMatrix.CreateTranslation(world1Center);
            IndexedMatrix groundTransform2 = IndexedMatrix.CreateTranslation(world2Center);

            IndexedVector3 halfExtents2 = new IndexedVector3(0.5f);
            CollisionShape smallBoxShape = new BoxShape(ref halfExtents2);

            //IndexedMatrix groundTransform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,-10,0));
            float mass = 0f;

            LocalCreateRigidBodyMultiWorld(mass, ref groundTransform1, groundShape ,m_worlds[0]);
            LocalCreateRigidBodyMultiWorld(mass, ref groundTransform2, groundShape, m_worlds[1]);

            mass = 1f;
            for (int i = 0; i < 5; ++i)
            {
                IndexedVector3 offset = new IndexedVector3(0, halfExtents.Y + halfExtents2.Y + (2 * i), 0);

                IndexedMatrix boxTransform1 = IndexedMatrix.CreateTranslation(world1Center+offset);
                IndexedMatrix boxTransform2 = IndexedMatrix.CreateTranslation(world2Center + offset);

                LocalCreateRigidBodyMultiWorld(mass, ref boxTransform1, smallBoxShape, m_worlds[0]);
                LocalCreateRigidBodyMultiWorld(mass, ref boxTransform2, smallBoxShape, m_worlds[1]);
            }

        }
Esempio n. 7
0
        public void Reset()
        {
            m_relpos1CrossNormal = IndexedVector3.Zero;
            m_contactNormal = IndexedVector3.Zero;
            m_relpos2CrossNormal = IndexedVector3.Zero;
            m_angularComponentA = IndexedVector3.Zero;
            m_angularComponentB = IndexedVector3.Zero;
            m_appliedPushImpulse = 0f;
            m_appliedImpulse = 0f;
            m_friction = 0f;
            m_jacDiagABInv = 0f;
            m_numConsecutiveRowsPerKernel = 0;
            m_frictionIndex = 0;
            m_solverBodyA = null;
            m_companionIdA = 0;
            m_solverBodyB = null;
            m_companionIdB = 0;
            m_originalContactPoint = null;
            //m_originalContactPointConstraint = null;
            m_rhs = 0f;
            m_cfm = 0;
            m_lowerLimit = 0f;
            m_upperLimit = 0f;
            m_rhsPenetration = 0f;
            m_overrideNumSolverIterations = -1;

        }
	    ///btActionInterface interface
        public virtual void DebugDraw(IDebugDraw debugDrawer)
        {
	        for (int v=0;v<GetNumWheels();v++)
	        {
		        IndexedVector3 wheelColor = new IndexedVector3(0,1,1);
		        if (GetWheelInfo(v).m_raycastInfo.m_isInContact)
		        {
			        wheelColor = new IndexedVector3(0,0,1);
		        } else
		        {
			        wheelColor= new IndexedVector3(1,0,1);
		        }

		        IndexedVector3 wheelPosWS = GetWheelInfo(v).m_worldTransform._origin;

                IndexedMatrix temp = GetWheelInfo(v).m_worldTransform;
                IndexedVector3 axle = new IndexedVector3(
        GetWheelInfo(v).m_worldTransform._basis._el0[GetRightAxis()],
        GetWheelInfo(v).m_worldTransform._basis._el1[GetRightAxis()],
        GetWheelInfo(v).m_worldTransform._basis._el2[GetRightAxis()]);

		        //debug wheels (cylinders)
		        debugDrawer.DrawLine(wheelPosWS,wheelPosWS+axle,wheelColor);
		        debugDrawer.DrawLine(wheelPosWS,GetWheelInfo(v).m_raycastInfo.m_contactPointWS,wheelColor);

	        }
        }
Esempio n. 9
0
 public static bool	Distance(ConvexShape shape0,ref IndexedMatrix wtrs0,ConvexShape shape1,ref IndexedMatrix wtrs1,ref IndexedVector3 guess,ref GjkEpaSolver2Results results)
 {
     using (GjkEpaSolver2MinkowskiDiff shape = BulletGlobals.GjkEpaSolver2MinkowskiDiffPool.Get())
     using (GJK gjk = BulletGlobals.GJKPool.Get())
     {
         Initialize(shape0, ref wtrs0, shape1, ref wtrs1, ref results, shape, false);
         gjk.Initialise();
         GJKStatus gjk_status = gjk.Evaluate(shape, ref guess);
         if (gjk_status == GJKStatus.Valid)
         {
             IndexedVector3 w0 = IndexedVector3.Zero;
             IndexedVector3 w1 = IndexedVector3.Zero;
             for (uint i = 0; i < gjk.m_simplex.rank; ++i)
             {
                 float p = gjk.m_simplex.p[i];
                 w0 += shape.Support(ref gjk.m_simplex.c[i].d, 0) * p;
                 IndexedVector3 temp = -gjk.m_simplex.c[i].d;
                 w1 += shape.Support(ref temp, 1) * p;
             }
             results.witnesses0 = wtrs0 * w0;
             results.witnesses1 = wtrs0 * w1;
             results.normal = w0 - w1;
             results.distance = results.normal.Length();
             results.normal /= results.distance > GJK_MIN_DISTANCE ? results.distance : 1;
             return (true);
         }
         else
         {
             //GjkEpaSolver2Status
             results.status = (gjk_status == GJKStatus.Inside) ? GjkEpaSolver2Status.Penetrating : GjkEpaSolver2Status.GJK_Failed;
             return (false);
         }
     }
 }
Esempio n. 10
0
 public IndexedVector4(IndexedVector3 v,float w)
 {
     X = v.X;
     Y = v.Y;
     Z = v.Z;
     W = w;
 }
Esempio n. 11
0
        //notice that the vectors should be unit length
		public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(IndexedVector3[] vectors, IndexedVector4[] supportVerticesOut, int numVectors) 
        {
	        for (int i=0;i<numVectors;i++)
	        {
		        supportVerticesOut[i] = IndexedVector4.Zero;
	        }
        }
 public void DrawArc(ref IndexedVector3 center, ref IndexedVector3 normal, ref IndexedVector3 axis, float radiusA, float radiusB, float minAngle, float maxAngle, ref IndexedVector3 color, bool drawSect, float stepDegrees)
 {
     IndexedVector3 vx = axis;
     IndexedVector3 vy = IndexedVector3.Cross(normal, axis);
     float step = stepDegrees * MathUtil.SIMD_RADS_PER_DEG;
     int nSteps = (int)((maxAngle - minAngle) / step);
     if (nSteps == 0)
     {
         nSteps = 1;
     }
     IndexedVector3 prev = center + radiusA * vx * (float)Math.Cos(minAngle) + radiusB * vy * (float)Math.Sin(minAngle);
     if (drawSect)
     {
         DrawLine(ref center, ref prev, ref color);
     }
     for (int i = 1; i <= nSteps; i++)
     {
         float angle = minAngle + (maxAngle - minAngle) * i / nSteps;
         IndexedVector3 next = center + radiusA * vx * (float)Math.Cos(angle) + radiusB * vy * (float)Math.Sin(angle);
         DrawLine(ref prev, ref next, ref color);
         prev = next;
     }
     if (drawSect)
     {
         DrawLine(ref center, ref prev, ref color);
     }
 }
        public GjkEpaPenetrationDepthSolver() { } // for pool

        public virtual bool CalcPenDepth(ISimplexSolverInterface simplexSolver, ConvexShape convexA, ConvexShape convexB, ref IndexedMatrix transA, ref IndexedMatrix transB,
                ref IndexedVector3 v, ref IndexedVector3 wWitnessOnA, ref IndexedVector3 wWitnessOnB, IDebugDraw debugDraw)
        {
            //float radialmargin = 0f;

            IndexedVector3 guessVector = (transA._origin - transB._origin);
            GjkEpaSolver2Results results = new GjkEpaSolver2Results();
            if (GjkEpaSolver2.Penetration(convexA, ref transA,
                                        convexB, ref transB,
                                        ref guessVector, ref results))
            {
                //	debugDraw->drawLine(results.witnesses[1],results.witnesses[1]+results.normal,btVector3(255,0,0));
                //resultOut->addContactPoint(results.normal,results.witnesses[1],-results.depth);
                wWitnessOnA = results.witnesses0;
                wWitnessOnB = results.witnesses1;
                v = results.normal;
                return true;
            }
            else
            {
                if (GjkEpaSolver2.Distance(convexA, ref transA, convexB, ref transB, ref guessVector, ref results))
                {
                    wWitnessOnA = results.witnesses0;
                    wWitnessOnB = results.witnesses1;
                    v = results.normal;
                    return false;
                }
            }
            return false;
        }
        public void MergePoints(ref IndexedVector4 plane, float margin, IndexedVector3[] points, int point_count)
        {
            m_point_count = 0;
            m_penetration_depth = -1000.0f;

            int _k;

            for (_k = 0; _k < point_count; _k++)
            {
                float _dist = -ClipPolygon.DistancePointPlane(ref plane, ref points[_k]) + margin;

                if (_dist >= 0.0f)
                {
                    if (_dist > m_penetration_depth)
                    {
                        m_penetration_depth = _dist;
                        point_indices[0] = _k;
                        m_point_count = 1;
                    }
                    else if ((_dist + MathUtil.SIMD_EPSILON) >= m_penetration_depth)
                    {
                        point_indices[m_point_count] = _k;
                        m_point_count++;
                    }
                }
            }

            for (_k = 0; _k < m_point_count; _k++)
            {
                m_points[_k] = points[point_indices[_k]];
            }
        }
public static bool TestInternalObjects( ref IndexedMatrix trans0, ref IndexedMatrix trans1, ref IndexedVector3 delta_c, ref IndexedVector3 axis, ConvexPolyhedron convex0, ConvexPolyhedron convex1, float dmin)
{
	float dp = delta_c.Dot(ref axis);

	IndexedVector3 localAxis0;
	InverseTransformPoint3x3(out localAxis0, ref axis,ref trans0);
	IndexedVector3 localAxis1;
	InverseTransformPoint3x3(out localAxis1, ref axis,ref trans1);

	IndexedVector3 p0;
    BoxSupport(ref convex0.m_extents, ref localAxis0, out p0);
    IndexedVector3 p1;
    BoxSupport(ref convex1.m_extents, ref localAxis1, out p1);

	float Radius0 = p0.X*localAxis0.X + p0.Y*localAxis0.Y + p0.Z*localAxis0.Z;
	float Radius1 = p1.X*localAxis1.X + p1.Y*localAxis1.Y + p1.Z*localAxis1.Z;

	float MinRadius = Radius0>convex0.m_radius ? Radius0 : convex0.m_radius;
	float MaxRadius = Radius1>convex1.m_radius ? Radius1 : convex1.m_radius;

	float MinMaxRadius = MaxRadius + MinRadius;
	float d0 = MinMaxRadius + dp;
	float d1 = MinMaxRadius - dp;

	float depth = d0<d1 ? d0:d1;
    if (depth > dmin)
    {
        return false;
    }
	return true;
}
Esempio n. 16
0
        public override void InitializeDemo()
        {
            m_maxIterations = 10;
            SetCameraDistance(50f);

            //string filename = @"E:\users\man\bullet\xna-basic-output-1.txt";
            //FileStream filestream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read);
            //BulletGlobals.g_streamWriter = new StreamWriter(filestream);

            ///collision configuration contains default setup for memory, collision setup
            m_collisionConfiguration = new DefaultCollisionConfiguration();

            ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
            m_dispatcher = new CollisionDispatcher(m_collisionConfiguration);

            m_broadphase = new DbvtBroadphase();
            IOverlappingPairCache pairCache = null;
            //pairCache = new SortedOverlappingPairCache();

            //m_broadphase = new SimpleBroadphase(1000, pairCache);

            ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
            SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver();
            m_constraintSolver = sol;

            m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_constraintSolver, m_collisionConfiguration);

            IndexedVector3 gravity = new IndexedVector3(0, -10, 0);
            m_dynamicsWorld.SetGravity(ref gravity);

            m_dynamicsWorld.SetForceUpdateAllAabbs(false);

            BuildLevelMap();
        }
 public StaticPlaneShape(ref IndexedVector3 planeNormal,float planeConstant)
 {
     m_shapeType = BroadphaseNativeTypes.STATIC_PLANE_PROXYTYPE;
     m_planeNormal = planeNormal;
     m_planeConstant = planeConstant;
     m_localScaling = IndexedVector3.Zero;
 }
        public override void ProcessAllTriangles(ITriangleCallback callback, ref IndexedVector3 aabbMin, ref IndexedVector3 aabbMax)
        {
	        IndexedVector3 halfExtents = (aabbMax - aabbMin) * .5f;
	        float radius = halfExtents.Length();
	        IndexedVector3 center = (aabbMax + aabbMin) * 0.5f;
        	
	        //this is where the triangles are generated, given AABB and plane equation (normal/constant)

	        IndexedVector3 tangentDir0;
            IndexedVector3 tangentDir1;

	        //tangentDir0/tangentDir1 can be precalculated
	        TransformUtil.PlaneSpace1(ref m_planeNormal, out tangentDir0, out tangentDir1);

            IndexedVector3 supVertex0 = IndexedVector3.Zero;
            IndexedVector3 supVertex1 = IndexedVector3.Zero;

	        IndexedVector3 projectedCenter = center - (IndexedVector3.Dot(m_planeNormal,center) - m_planeConstant)*m_planeNormal;

            IndexedVector3[] triangle = new IndexedVector3[3];
	        triangle[0] = (projectedCenter + tangentDir0*radius + tangentDir1*radius);
            triangle[1] = (projectedCenter + tangentDir0 * radius - tangentDir1 * radius);
            triangle[2] = (projectedCenter - tangentDir0 * radius - tangentDir1 * radius);

	        callback.ProcessTriangle(triangle,0,0);

	        triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
	        triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
	        triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;

	        callback.ProcessTriangle(triangle,0,1);

        }
        public override void InitializeDemo()
        {
        //	std::cerr << "initializing...\n";

            m_nearClip = 1f;
            m_farClip = 1000f;

            m_aspect = m_glutScreenWidth / m_glutScreenHeight;
            m_perspective = IndexedMatrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(40.0f), m_aspect, m_nearClip, m_farClip);


	        // set up basic state
	        m_upAxis = 1;		// start with Y-axis as "up"
	        m_type = PHY_ScalarType.PHY_FLOAT;
	        m_model = eTerrainModel.eRadial;//eFractal;
	        m_isDynamic = true;

	        // set up the physics world
	        m_collisionConfiguration = new DefaultCollisionConfiguration();
	        m_dispatcher = new CollisionDispatcher(m_collisionConfiguration);
	        IndexedVector3 worldMin = new IndexedVector3(-1000,-1000,-1000);
            IndexedVector3 worldMax = new IndexedVector3(1000, 1000, 1000);
            //m_broadphase = new AxisSweep3Internal(ref worldMin,ref worldMax);
            m_broadphase = new AxisSweep3Internal(ref worldMin, ref worldMax, 0xfffe, 0xffff, 16384, null, false);

	        m_constraintSolver = new SequentialImpulseConstraintSolver();
	        m_dynamicsWorld = new DiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_constraintSolver,m_collisionConfiguration);

	        // initialize axis- or type-dependent physics from here
            ClientResetScene();
        }
Esempio n. 20
0
        public override IndexedVector3 LocalGetSupportingVertexWithoutMargin(ref IndexedVector3 vec)
        {
	        IndexedVector3 supVec = IndexedVector3.Zero;
	        float newDot,maxDot = float.MinValue;
#if DEBUG
			if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugConvexHull)
			{
				BulletGlobals.g_streamWriter.WriteLine("localGetSupportingVertexWithoutMargin");
				MathUtil.PrintVector3(BulletGlobals.g_streamWriter, "vec", vec);
				for (int i = 0; i < m_unscaledPoints.Count; ++i)
				{
					MathUtil.PrintVector3(BulletGlobals.g_streamWriter, m_unscaledPoints[i]);
				}
			}
#endif

	        for (int i=0;i<m_unscaledPoints.Count;i++)
	        {
		        IndexedVector3 vtx = m_unscaledPoints[i] * m_localScaling;

		        newDot = IndexedVector3.Dot(vec,vtx);
		        if (newDot > maxDot)
		        {
			        maxDot = newDot;
			        supVec = vtx;
		        }
	        }
	        return supVec;
        }
        public override void GetAabb(ref IndexedMatrix t,out IndexedVector3 aabbMin,out IndexedVector3 aabbMax)
        {
            float fmargin = GetMargin();
            IndexedVector3 margin = new IndexedVector3(fmargin);
	        aabbMin = t._origin - margin;
	        aabbMax = t._origin + margin;
        }
Esempio n. 22
0
 public static IndexedVector3 GimGetPointInertia(ref IndexedVector3 point, float mass)
 {
     float x2 = point.X * point.X;
     float y2 = point.Y * point.Y;
     float z2 = point.Z * point.Z;
     return new IndexedVector3(mass * (y2 + z2), mass * (x2 + z2), mass * (x2 + y2));
 }
Esempio n. 23
0
	    public TriangleShape(ref IndexedVector3 p0,ref IndexedVector3 p1,ref IndexedVector3 p2) : base ()
        {
		    m_shapeType = BroadphaseNativeTypes.TRIANGLE_SHAPE_PROXYTYPE;
            m_vertices1[0] = p0;
            m_vertices1[1] = p1;
            m_vertices1[2] = p2;
        }
Esempio n. 24
0
 public void Initialize(ref IndexedVector3 p0,ref IndexedVector3 p1,ref IndexedVector3 p2)
 {
     m_shapeType = BroadphaseNativeTypes.TRIANGLE_SHAPE_PROXYTYPE;
     m_vertices1[0] = p0;
     m_vertices1[1] = p1;
     m_vertices1[2] = p2;
 }
        public override void CalculateLocalInertia(float mass, out IndexedVector3 inertia)
        {
	        ///this linear upscaling is not realistic, but we don't deal with large mass ratios...
	        IndexedVector3 tmpInertia;
	        m_childConvexShape.CalculateLocalInertia(mass, out tmpInertia);
	        inertia = tmpInertia * m_uniformScalingFactor;
        }
        public void Initialise(ref IndexedVector3 pointA, ref IndexedVector3 pointB, ref IndexedVector3 normal, float distance)
        {
            /* Don't initialize default values twice in C# */
            m_lateralFrictionDir1 = IndexedVector3.Zero;
            m_lateralFrictionDir2 = IndexedVector3.Zero;
            m_lifeTime = 0;
            m_appliedImpulseLateral1 = 0f;
            m_appliedImpulseLateral2 = 0f;
            m_contactMotion1 = 0f;
            m_contactMotion2 = 0f;
            m_contactCFM1 = 0f;
            m_contactCFM2 = 0f;

            m_lateralFrictionInitialized = false;
            m_userPersistentData = null;
            m_appliedImpulse = 0f;
            m_partId0 = 0;
            m_partId1 = 0;
            m_index0 = 0;
            m_index1 = 0;
            m_combinedRestitution = 0f;
            m_combinedFriction = 0f;
            m_positionWorldOnA = IndexedVector3.Zero;
            m_positionWorldOnB = IndexedVector3.Zero;

            m_localPointA = pointA;
            m_localPointB = pointB;
            m_normalWorldOnB = normal;
            m_distance1 = distance;

            m_constraintRow[0].Reset();
            m_constraintRow[1].Reset();
            m_constraintRow[2].Reset();
        }
Esempio n. 27
0
 public TriangleRaycastCallback() { } // for pool
 public TriangleRaycastCallback(ref IndexedVector3 from, ref IndexedVector3 to, EFlags flags)
 {
     m_from = from;
     m_to = to;
     m_flags = flags;
     m_hitFraction = 1f;
 }
 public static void DebugDrawLine(ref IndexedVector3 from, ref IndexedVector3 to, ref IndexedVector3 color)
 {
     if (BulletGlobals.gDebugDraw != null)
     {
         BulletGlobals.gDebugDraw.DrawLine(ref from, ref to, ref color);
     }
 }
Esempio n. 29
0
        public virtual IndexedVector3 LocalGetSupportingVertex(ref IndexedVector3 vec)
        {
	        IndexedVector3 supportVertex;

            IndexedMatrix ident = IndexedMatrix.Identity;

	        SupportVertexCallback supportCallback = new SupportVertexCallback(ref vec,ref ident);

	        IndexedVector3 aabbMax = MathUtil.MAX_VECTOR;
            IndexedVector3 aabbMin = MathUtil.MIN_VECTOR;

            // URGGHHH!
            if (m_inConstructor)
            {
                this.ProcessAllTrianglesCtor(supportCallback, ref aabbMin, ref aabbMax);
            }
            else
            {
                ProcessAllTriangles(supportCallback, ref aabbMin, ref aabbMax);
            }
            
	        supportVertex = supportCallback.GetSupportVertexLocal();
            supportCallback.Cleanup();
	        return supportVertex;

        }
        public virtual void DrawSphere(float radius, ref IndexedMatrix transform, ref IndexedVector3 color)
        {
            IndexedVector3 start = transform._origin;

            IndexedVector3 xoffs = transform._basis * new IndexedVector3(radius, 0, 0);
            IndexedVector3 yoffs = transform._basis * new IndexedVector3(0, radius, 0);
            IndexedVector3 zoffs = transform._basis * new IndexedVector3(0, 0, radius);

            // XY 
            DrawLine(start - xoffs, start + yoffs, color);
            DrawLine(start + yoffs, start + xoffs, color);
            DrawLine(start + xoffs, start - yoffs, color);
            DrawLine(start - yoffs, start - xoffs, color);

            // XZ
            DrawLine(start - xoffs, start + zoffs, color);
            DrawLine(start + zoffs, start + xoffs, color);
            DrawLine(start + xoffs, start - zoffs, color);
            DrawLine(start - zoffs, start - xoffs, color);

            // YZ
            DrawLine(start - yoffs, start + zoffs, color);
            DrawLine(start + zoffs, start + yoffs, color);
            DrawLine(start + yoffs, start - zoffs, color);
            DrawLine(start - zoffs, start - yoffs, color);
        }
        /// protected initialization

        /**
         * Handles the work of constructors so that public constructors can be
         * backwards-compatible without a lot of copy/paste.
         */
        protected void Initialize(int heightStickWidth, int heightStickLength,
                                  Object heightfieldData, float heightScale,
                                  float minHeight, float maxHeight, int upAxis,
                                  PHY_ScalarType hdt, bool flipQuadEdges)
        {
            // validation
            Debug.Assert(heightStickWidth > 1, "bad width");
            Debug.Assert(heightStickLength > 1, "bad length");
            Debug.Assert(heightfieldData != null, "null heightfield data");
            // Debug.Assert(heightScale) -- do we care?  Trust caller here
            Debug.Assert(minHeight <= maxHeight, "bad min/max height");
            Debug.Assert(upAxis >= 0 && upAxis < 3,
                         "bad upAxis--should be in range [0,2]");
            Debug.Assert(hdt != PHY_ScalarType.PHY_UCHAR || hdt != PHY_ScalarType.PHY_FLOAT || hdt != PHY_ScalarType.PHY_SHORT,
                         "Bad height data type enum");

            // initialize member variables
            m_shapeType         = BroadphaseNativeTypes.TERRAIN_SHAPE_PROXYTYPE;
            m_heightStickWidth  = heightStickWidth;
            m_heightStickLength = heightStickLength;
            m_minHeight         = minHeight;
            m_maxHeight         = maxHeight;
            m_width             = (heightStickWidth - 1);
            m_length            = (heightStickLength - 1);
            m_heightScale       = heightScale;
            // copy the data in
            m_heightFieldDataByte  = heightfieldData as byte[];
            m_heightFieldDataFloat = heightfieldData as float[];
            m_heightDataType       = hdt;

            m_flipQuadEdges         = flipQuadEdges;
            m_useDiamondSubdivision = false;
            m_upAxis       = upAxis;
            m_localScaling = new IndexedVector3(1f);

            // determine min/max axis-aligned bounding box (aabb) values
            switch (m_upAxis)
            {
            case 0:
            {
                m_localAabbMin = new IndexedVector3(m_minHeight, 0, 0);
                m_localAabbMax = new IndexedVector3(m_maxHeight, m_width, m_length);
                break;
            }

            case 1:
            {
                m_localAabbMin = new IndexedVector3(0, m_minHeight, 0);
                m_localAabbMax = new IndexedVector3(m_width, m_maxHeight, m_length);
                break;
            };

            case 2:
            {
                m_localAabbMin = new IndexedVector3(0, 0, m_minHeight);
                m_localAabbMax = new IndexedVector3(m_width, m_length, m_maxHeight);
                break;
            }

            default:
            {
                //need to get valid m_upAxis
                Debug.Assert(false, "Bad m_upAxis");
                break;
            }
            }

            // remember origin (defined as exact middle of aabb)
            m_localOrigin = 0.5f * (m_localAabbMin + m_localAabbMax);
        }