Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }