void RagdollDemo::initPhysics() { //ASSIGNMENT 8 ragdolldemo = this; //ASSIGNMENT 9 srand(time(NULL)); //ASSIGNMENT 10 pause = false; //ragdolldemo->touches = new btVector3* // Setup the basic world //setTexturing(true); //setShadows(true); setCameraDistance(btScalar(5.)); m_collisionConfiguration = new btDefaultCollisionConfiguration(); m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); btVector3 worldAabbMin(-10000,-10000,-10000); btVector3 worldAabbMax(10000,10000,10000); m_broadphase = new btAxisSweep3 (worldAabbMin, worldAabbMax); m_solver = new btSequentialImpulseConstraintSolver; m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); //m_dynamicsWorld->getDispatchInfo().m_useConvexConservativeDistanceUtil = true; //m_dynamicsWorld->getDispatchInfo().m_convexConservativeDistanceThreshold = 0.01f; //ASSIGNMENT 10 string line; ifstream myfile("../../RAGDOLL_DATA/weights.txt"); cout << "NORMAL SYNAPSE" << endl; for(int i = 0; i < 4; i++) { for(int k = 0; k < 8; k++) { getline(myfile,line); stringstream convert(line); convert >> synapseWeights[i][k]; cout << synapseWeights[i][k] << " | "; } cout << endl; } myfile.close(); //GET RECURRENT SYNAPSE line = ""; ifstream myfile3("../../RAGDOLL_DATA/recurrent.txt"); cout << "RECURRNT SYNAPSE" << endl; for(int i = 0; i < 4; i++) { for(int k = 0; k < 8; k++) { getline(myfile3,line); stringstream convert(line); convert >> synapseRecurrent[i][k]; cout << synapseRecurrent[i][k] << " | "; } cout << endl; } myfile.close(); // GET MASK recurrentOn = false; line = ""; cout << "PRINTING RECURRENT" << endl; ifstream myfile2("../../RAGDOLL_DATA/mask.txt"); for(int i = 0; i < 4; i++) { for(int k = 0; k < 8; k++) { getline(myfile2,line); stringstream convert(line); convert >> mask[i][k]; cout << mask[i][k] << " | "; if(mask[i][k] == 1) { recurrentOn = true; } } cout << endl; } myfile2.close(); cout << "INITIAL PEVIOUS TOUCH" << endl; //INITIAL PREVIOUS STEP = 0 for(int i = 0; i < 4; i++) { previousTouch[i] = 0; cout << previousTouch[i] << " | "; } cout << endl; // Setup a big ground box { btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(10.),btScalar(200.))); m_collisionShapes.push_back(groundShape); btTransform groundTransform; groundTransform.setIdentity(); groundTransform.setOrigin(btVector3(0,-10,0)); #define CREATE_GROUND_COLLISION_OBJECT 1 #ifdef CREATE_GROUND_COLLISION_OBJECT //ASSIGNMENT 8 /* btTransform offset; offset.setIdentity(); offset.setOrigin(btVector3(btScalar(0),btScalar(-10),btScalar(0))); btRigidBody* fixedGround = localCreateRigidBody(btScalar(1.0),offset, groundShape); fixedGround->setCollisionFlags(3); */ btCollisionObject* fixedGround = new btCollisionObject(); fixedGround->setFriction(btScalar(10000.0)); fixedGround->setCollisionShape(groundShape); fixedGround->setWorldTransform(groundTransform); m_dynamicsWorld->addCollisionObject(fixedGround); currentIndex = 0; /* fixedGround->setCollisionFlags(fixedGround->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); fixedGround->setCenterOfMassTransform(offset); */ collisionID[currentIndex] = new collisionObject(currentIndex, (btRigidBody *)groundShape); fixedGround->setUserPointer(collisionID[currentIndex]); cout << "OBJECT ID: " << collisionID[currentIndex]->id; cout << " | POINTER ID: " << ((collisionObject*)fixedGround->getUserPointer())->id; cout << " | ADDRESS " << collisionID[currentIndex]; cout << " | FLAGS " << collisionID[currentIndex]->body->getCollisionFlags() << endl; currentIndex++; #else localCreateRigidBody(btScalar(0.),groundTransform,groundShape); #endif //CREATE_GROUND_COLLISION_OBJECT } gContactAddedCallback = callBackFunc; //BODY ------------------------------------------------------------------ //(index, x, y, z, length, width, height) RagdollDemo::CreateBox(0, 0.0, 1.8, 0.0, 1.0, 0.2, 1.0);//WORKING //FEET RagdollDemo::CreateCylinder(3, 3.2, 0, 0, 1, .2, 0, M_PI_2, 0); //WORKING -> NORMAL RagdollDemo::CreateCylinder(4, -3.2, 0, 0, 1, .2, 0, -M_PI_2, 0); //WORKING -> NORMAL RagdollDemo::CreateCylinder(8, 0, 0, -3.2, 1, .2, 0, M_PI_2, 0); //WORKING -> ROTATED RagdollDemo::CreateCylinder(6, 0, 0, 3.2, 1, .2, 0, M_PI_2, 0); //WORKING -> NORMAL -> //ARM RagdollDemo::CreateCylinder(5, 0.0, 0.8, 2.0, 1.0, 0.2, M_PI_2, 0.0, 0.0);//WORKING -> ROTATED RagdollDemo::CreateCylinder(7, 0.0, 0.8, -2.0, 1.0, 0.2, M_PI_2, 0.0, 0.0);//WORKIN G-> ROTATED RagdollDemo::CreateCylinder(1, 2.0, .8, 0.0, 1.0, 0.2, 0.0, 0.0, M_PI_2);//WORKING -> NORMAL RagdollDemo::CreateCylinder(2, -2.0, .8, 0.0, 1.0, 0.2, 0, M_PI_2, M_PI_2);//WORKING -> NORMAL //FEET HINGE RagdollDemo::CreateHinge(2,3,1, btVector3(0.0, 0.0, 1.0), btVector3(0.0, 0.0, 1.0),btVector3(0.0, 1.0, 0.0), btVector3(0, -1.0, 0.0));//WORKING RagdollDemo::CreateHinge(3,4,2, btVector3(1.0, 0.0, 0.0), btVector3(0.0, 0.0, 1.0),btVector3(0.0, 1.0, 0.0), btVector3(0, 1.0, 0.0)); //WORKIN RagdollDemo::CreateHinge(6,7,8, btVector3(1.0, 0.0, 0.0), btVector3(1.0, 0.0, 0.0),btVector3(0.0, -1.0, 0.0), btVector3(0, 1.0, 0.0));//WORKING -> ROTATED RagdollDemo::CreateHinge(5,5,6, btVector3(1.0, 0.0, 0.0), btVector3(1.0, 0.0, 0.0),btVector3(0.0, 1.0, 0.0), btVector3(0, 1.0, 0.0));//WORKING -> ROTATED // //ARM HINGE RagdollDemo::CreateHinge(4,0,5, btVector3(1.0, 0.0, 0.0), btVector3(1.0, 0.0, 0.0),btVector3(0.0, 0.0, 1.0), btVector3(0, -1.0, 0.0));//WORKING -> ROTATED RagdollDemo::CreateHinge(7,0,7, btVector3(1.0, 0.0, 0.0), btVector3(1.0, 0.0, 0.0),btVector3(0.0, 0.0, -1.0), btVector3(0, 1.0, 0.0));//WORKING -> ROTATED RagdollDemo::CreateHinge(0,0,1, btVector3(0.0, 0.0, 1.0), btVector3(0.0, 0.0, 1.0), btVector3(1.0, 0.0, 0.0), btVector3(0.0, 1.0, 0.0));//WORKING RagdollDemo::CreateHinge(1,0,2, btVector3(0.0, 0.0, 1.0), btVector3(0.0, 0.0, 1.0),btVector3(-1.0, 0.0, 0.0), btVector3(0.0, -1.0, 0.0));//WORKING clientResetScene(); }
void MC::MCRUN() { Cells s(c,r); stringstream st; double addordel; // the prob to decide either add or del; // double probd;//,proba; // the acceptance prob of addition; proba = min(1.0,aaccp); double prob; // the prob to decide either accept add/del; double aaccp,daccp; double Q; // the fraction of hor and ver particle; double tho; // the density double AD;// addition and deletion fraction double size; srand(time(NULL)); long int i = 0; // Histogram his(0, r*c/length, 1); // the histogram of nv //================================Start my MC simulation================================= while (i<step) { i++; // generate a random probability to decide either add or del; addordel = rand()%2; size = av+ah-dv-dh; // *****************define the probabilities ***********************************// I HAVE TO CHANGE IT FOR LATTICE GAS CASE!!! prob = ((double) rand() / (RAND_MAX)); tho = double(length*size)/double(r*c); aaccp = z*double(r*c)/(double(nh+nv+1.0)*double(length)); daccp = (double(nh+nv)*double(length))/(z*double(r*c)); // proba = min(1.0,aaccp); // probd = min(1.0,daccp); // ===========================Addition =================================== if(addordel == 0) { //Do Addition; Add(s,prob,aaccp); } // ============================Deletion============================= else { if (size != 0) // make sure there are rods to be del; { //Do deletion; Del(s,prob,daccp,size); } } // ======================= Record the datas ============================================= Q = (nv - nh)/(nh + nv); AD = (av+ah-dv-dh)/(av+ah+dv+dh); if (i%(step/10000) == 0) { // his.record(nv); st << i << " " << Q <<" "<< nv << " "<< nh << " "<< tho << " "<< AD<< " "<< endl; cout <<"Process: "<< ((10000*i)/step)/100.00 <<"%"<<" "<<"SIZE: "<<av+ah-dv-dh<<" "<<"# of Ver Rod: "<<nv<<" "<<"# of Hor Rod: "<< nh <<" "<<"Qis "<<Q <<" "<<"tho is: "<<tho << endl; } } // Record the data into a txt file ofstream myfile3 ("dataplot.dat"); string data = st.str(); myfile3 << data; myfile3.close(); // his.plot(0); }