public SoftRigidDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache, ConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration, SoftBodySolver softBodySolver)
            : base(IntPtr.Zero)
        {
            if (softBodySolver != null)
            {
                _softBodySolver = softBodySolver;
                _ownsSolver     = false;
            }
            else
            {
                _softBodySolver = new DefaultSoftBodySolver();
                _ownsSolver     = true;
            }

            _native = btSoftRigidDynamicsWorld_new2(dispatcher._native, pairCache._native,
                                                    (constraintSolver != null) ? constraintSolver._native : IntPtr.Zero,
                                                    collisionConfiguration._native, _softBodySolver._native);

            _collisionObjectArray = new AlignedCollisionObjectArray(btCollisionWorld_getCollisionObjectArray(_native), this);

            _dispatcher           = dispatcher;
            _broadphase           = pairCache;
            _constraintSolver     = constraintSolver;
            _worldInfo            = new SoftBodyWorldInfo(btSoftRigidDynamicsWorld_getWorldInfo(_native), true);
            _worldInfo.Dispatcher = dispatcher;
            _worldInfo.Broadphase = pairCache;
            _native2ManagedMap.Add(_native, this);
        }
		public SoftRigidDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache,
			ConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration,
			SoftBodySolver softBodySolver)
            : base(IntPtr.Zero)
		{
            if (softBodySolver != null) {
                _softBodySolver = softBodySolver;
                _ownsSolver = false;
            } else {
                _softBodySolver = new DefaultSoftBodySolver();
                _ownsSolver = true;
            }

            _native = btSoftRigidDynamicsWorld_new2(dispatcher._native, pairCache._native,
                (constraintSolver != null) ? constraintSolver._native : IntPtr.Zero,
                collisionConfiguration._native, _softBodySolver._native);

            _collisionObjectArray = new AlignedCollisionObjectArray(btCollisionWorld_getCollisionObjectArray(_native), this);

            _broadphase = pairCache;
			_constraintSolver = constraintSolver;
			_dispatcher = dispatcher;
            _worldInfo = new SoftBodyWorldInfo(btSoftRigidDynamicsWorld_getWorldInfo(_native), true);
            _worldInfo.Dispatcher = dispatcher;
            _worldInfo.Broadphase = pairCache;
		}
        public SoftRigidDynamicsWorld(Dispatcher dispatcher, BroadphaseInterface pairCache,
                                      ConstraintSolver constraintSolver, CollisionConfiguration collisionConfiguration,
                                      SoftBodySolver softBodySolver = null)
        {
            if (softBodySolver != null)
            {
                _softBodySolver = softBodySolver;
                _ownsSolver     = false;
            }
            else
            {
                _softBodySolver = new DefaultSoftBodySolver();
                _ownsSolver     = true;
            }

            IntPtr native = btSoftRigidDynamicsWorld_new(dispatcher.Native, pairCache.Native,
                                                         (constraintSolver != null) ? constraintSolver.Native : IntPtr.Zero,
                                                         collisionConfiguration.Native, _softBodySolver.Native);

            InitializeUserOwned(native);
            InitializeMembers(dispatcher, pairCache, constraintSolver);

            WorldInfo = new SoftBodyWorldInfo(btSoftRigidDynamicsWorld_getWorldInfo(Native), this)
            {
                Dispatcher = dispatcher,
                Broadphase = pairCache
            };
        }
Ejemplo n.º 4
0
        public Physics()
        {
            CLStuff.InitCL();

            cloths = new Cloth[numFlags];
            for (int flagIndex = 0; flagIndex < numFlags; ++flagIndex)
            {
                cloths[flagIndex] = new Cloth();
                cloths[flagIndex].CreateBuffers(clothWidth, clothHeight);
            }

            gSolver = new OpenCLSoftBodySolver(CLStuff.commandQueue, CLStuff.cxMainContext);
            softBodyOutput = new SoftBodySolverOutputCLToCpu();

            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new SoftBodyRigidBodyCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            Broadphase = new DbvtBroadphase();
            Solver = new SequentialImpulseConstraintSolver();

            World = new SoftRigidDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf, gSolver);
            World.Gravity = new Vector3(0, -10, 0);

            // create the ground
            CollisionShape groundShape = new BoxShape(50, 50, 50);
            CollisionShapes.Add(groundShape);
            CollisionObject ground = LocalCreateRigidBody(0, Matrix.Translation(0, -60, 0), groundShape);
            ground.UserObject = "Ground";

            SoftWorld.WorldInfo.AirDensity = 1.2f;
            SoftWorld.WorldInfo.WaterDensity = 0;
            SoftWorld.WorldInfo.WaterOffset = 0;
            SoftWorld.WorldInfo.WaterNormal = Vector3.Zero;
            SoftWorld.WorldInfo.Gravity = new Vector3(0, -10, 0);

            CreateFlag(clothWidth, clothHeight, out flags);

            // Create output buffer descriptions for ecah flag
            // These describe where the simulation should send output data to
            for (int flagIndex = 0; flagIndex < flags.Count; ++flagIndex)
            {
                // flags[flagIndex].WindVelocity = new Vector3(0, 0, 15.0f);

                // In this case we have a DX11 output buffer with a vertex at index 0, 8, 16 and so on as well as a normal at 3, 11, 19 etc.
                // Copies will be performed GPU-side directly into the output buffer

                CpuVertexBufferDescriptor vertexBufferDescriptor = new CpuVertexBufferDescriptor(cloths[flagIndex].CpuBuffer, 0, 8, 3, 8);
                cloths[flagIndex].VertexBufferDescriptor = vertexBufferDescriptor;
            }

            gSolver.Optimize(SoftWorld.SoftBodyArray);

            World.StepSimulation(1.0f / 60.0f, 0);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// gRally
        /// </summary>
        /// <param name="worldCreated"></param>
        /// <param name="dispatcher"></param>
        /// <param name="pairCache"></param>
        /// <param name="constraintSolver"></param>
        public SoftRigidDynamicsWorld(IntPtr worldCreated, Dispatcher dispatcher, BroadphaseInterface pairCache, ConstraintSolver constraintSolver)
            : base(IntPtr.Zero)
        {
            _softBodySolver = new DefaultSoftBodySolver();
            _ownsSolver     = true;
            _native         = worldCreated;

            _collisionObjectArray = new AlignedCollisionObjectArray(btCollisionWorld_getCollisionObjectArray(_native), this);

            _dispatcher           = dispatcher;
            _broadphase           = pairCache;
            _constraintSolver     = constraintSolver;
            _worldInfo            = new SoftBodyWorldInfo(btSoftRigidDynamicsWorld_getWorldInfo(_native), true);
            _worldInfo.Dispatcher = dispatcher;
            _worldInfo.Broadphase = pairCache;
            _native2ManagedMap.Add(_native, this);
        }