bool SOFM2D::initGrid(const dmatrix& data) { bool b=true; int i,j; const parameters& param=getParameters(); if (param.initType == parameters::Linear) { //eigenvalues already calculated? if (eva1==0.) { varianceFunctor<double> varFunc; dmatrix cov; varFunc.covarianceMatrixOfRows(data, cov); jacobi<double> eigenFunc; jacobi<double>::parameters jp; jp.sort=true; eigenFunc.setParameters(jp); dvector eva; dmatrix eve; b = eigenFunc.apply(cov, eva, eve); if (b) { eva1=eva.at(0); eva2=eva.at(1); eve1=eve.getColumnCopy(0); eve2=eve.getColumnCopy(1); } else { setStatusString("could not find eigenvalues using random points\n"); selectRandomPoints(data, sizeX*sizeY, grid); return false; } } meansFunctor<double> meanFunc; dvector mean; meanFunc.meanOfRows(data, mean); double x,y; dvector deltaX(eve1); deltaX.multiply(eva1/sizeX); dvector deltaY(eve2); deltaY.multiply(eva2/sizeY); dvector delta; for (i=0, y=-(double(sizeY-1)); i<sizeY; i++, y++) { for (j=0, x=-(double(sizeX-1)); j<sizeX; j++, x++) { delta.addScaled(x,deltaX,y,deltaY); grid.getRow(i*sizeX+j).add(mean,delta); } } } else { selectRandomPoints(data, sizeX*sizeY, grid); } return b; }
void dmz::QtModuleCanvasBasic::_handle_mouse_event (QMouseEvent *me, QWheelEvent *we) { if (_inputModule && _canvas) { InputEventMouse event (_mouseEvent); QPoint pointOnCanvas (event.get_mouse_x (), event.get_mouse_y ()); QPoint pointOnScreen (event.get_mouse_screen_x (), event.get_mouse_screen_y ()); Qt::MouseButtons buttons; if (me) { pointOnCanvas = _canvas->mapFrom (this, me->pos ()); pointOnScreen = me->globalPos (); buttons = me->buttons (); } else if (we) { pointOnCanvas = _canvas->mapFrom (this, we->pos ()); pointOnScreen = we->globalPos (); buttons = we->buttons (); } event.set_mouse_position (pointOnCanvas.x (), pointOnCanvas.y ()); event.set_mouse_screen_position (pointOnScreen.x (), pointOnScreen.y ()); UInt32 mask (0); if (buttons & Qt::LeftButton) { mask |= 0x01 << 0; } if (buttons & Qt::RightButton) { mask |= 0x01 << 1; } if (buttons & Qt::MidButton) { mask |= 0x01 << 2; } event.set_button_mask (mask); Int32 deltaX (0), deltaY (0); if (we) { if (we->orientation () == Qt::Vertical) { deltaY = we->delta (); } else if (we->orientation () == Qt::Horizontal) { deltaX = we->delta (); } } event.set_scroll_delta (deltaX, deltaY); event.set_window_size (width (), height ()); if (_mouseEvent.update (event)) { _inputModule->send_mouse_event (_mouseEvent); } } }
Pyramid() { { b2::BodyDef bd; b2::Body* ground = m_world->CreateBody(&bd); b2::EdgeShape shape; shape.Set(b2::Vec2(-40.0f, 0.0f), b2::Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } { b2::float32 a = 0.5f; b2::PolygonShape shape; shape.SetAsBox(a, a); b2::Vec2 x(-7.0f, 0.75f); b2::Vec2 y; b2::Vec2 deltaX(0.5625f, 1.25f); b2::Vec2 deltaY(1.125f, 0.0f); for (b2::int32 i = 0; i < e_count; ++i) { y = x; for (b2::int32 j = i; j < e_count; ++j) { b2::BodyDef bd; bd.type = b2::dynamicBody; bd.position = y; b2::Body* body = m_world->CreateBody(&bd); body->CreateFixture(&shape, 5.0f); y += deltaY; } x += deltaX; } } }
void ZViewpoint::zviewpointHandleMsgFly( ZMsg *msg ) { static float viewpointMouseLast[2]; static int dragging = 0; float newzviewpointScale = 0.f; int scaleChange = 0; if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && (zmsgIs(which,R) || zmsgIs(which,M)) && zmsgI(shift) && zmsgI(ctrl) && zmsgI(alt) ) { // RESET memset( &zviewpointTrans, 0, sizeof(zviewpointTrans) ); zviewpointRotQuat.fromAxisAngle( FVec3::XAxis, 0.f ); zviewpointScale = 1.f; } char button = msg->getS( "which", "X" ) [0]; // if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && zmsgIs(which,M) ) { if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && button==zviewpointRotateButton ) { dragging = zMouseMsgRequestExclusiveDrag( "type=Viewpoint_MouseDrag" ); } if( zmsgIs(type,Viewpoint_MouseDrag) ) { if( zmsgI(releaseDrag) ) { zMouseMsgCancelExclusiveDrag(); } else { int _deltaX = zMouseMsgX - zMouseMsgLastX; int _deltaY = zMouseMsgY - zMouseMsgLastY; FQuat deltaX( FVec3::XAxis, -0.01f * _deltaX ); FQuat deltaY( FVec3::YAxis, +0.01f * _deltaY ); FQuat deltaZ; deltaX.mul( zviewpointRotQuat ); deltaY.mul( deltaX ); deltaZ.mul( deltaY ); zviewpointRotQuat = deltaZ; } } }
void ZViewpoint::zviewpointRotateTrackball( float dx, float dy, float side ) { // ROTATE: this was originally in the message handler for trackball mode // reponse to mouse drag. I factored out to here so that I can call this // code in response to arrow keys to step-rotate the object about a given // axis. (tfb) // COMPUTE the world axises about which we are spinning (i.e. the screen axis) FMat4 ref( zviewpointReferenceModel.m ); FMat4 rot = zviewpointRotQuat.mat(); rot.transpose(); ref.cat( rot ); ref.setTrans( FVec3::Origin ); ref.orthoNormalize(); ref.inverse(); // ref is now the transform that will take a point in eye-coordinates and // transform it to its original pre-viewing-transform world coordinates. tfb FVec3 xEye = ref.mul( FVec3::XAxis ); FVec3 yEye = ref.mul( FVec3::YAxis ); FVec3 zEye = ref.mul( FVec3::ZAxis ); FQuat deltaX( xEye, dy ); if( !zviewpointPermitRotX ) deltaX.identity(); FQuat deltaY( yEye, dx ); if( !zviewpointPermitRotY ) deltaY.identity(); FQuat deltaZ; if( side != 0 ) { deltaX.identity(); deltaY.identity(); deltaZ.fromAxisAngle( zEye, side * -dy ); } if( !zviewpointPermitRotZ ) deltaZ.identity(); // QUATERNION multiply the delta by the origial to get the new deltaX.mul( zviewpointRotQuat ); deltaY.mul( deltaX ); deltaZ.mul( deltaY ); zviewpointRotQuat = deltaZ; }
void Planar2D::initPhysics() { m_guiHelper->setUpAxis(1); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new btDefaultCollisionConfiguration(); //m_collisionConfiguration->setConvexConvexMultipointIterations(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); m_simplexSolver = new btVoronoiSimplexSolver(); m_pdSolver = new btMinkowskiPenetrationDepthSolver(); m_convexAlgo2d = new btConvex2dConvex2dAlgorithm::CreateFunc(m_simplexSolver,m_pdSolver); m_box2dbox2dAlgo = new btBox2dBox2dCollisionAlgorithm::CreateFunc(); m_dispatcher->registerCollisionCreateFunc(CONVEX_2D_SHAPE_PROXYTYPE,CONVEX_2D_SHAPE_PROXYTYPE,m_convexAlgo2d); m_dispatcher->registerCollisionCreateFunc(BOX_2D_SHAPE_PROXYTYPE,CONVEX_2D_SHAPE_PROXYTYPE,m_convexAlgo2d); m_dispatcher->registerCollisionCreateFunc(CONVEX_2D_SHAPE_PROXYTYPE,BOX_2D_SHAPE_PROXYTYPE,m_convexAlgo2d); m_dispatcher->registerCollisionCreateFunc(BOX_2D_SHAPE_PROXYTYPE,BOX_2D_SHAPE_PROXYTYPE,m_box2dbox2dAlgo); m_broadphase = new btDbvtBroadphase(); //m_broadphase = new btSimpleBroadphase(); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver; m_solver = sol; m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); //m_dynamicsWorld->getSolverInfo().m_erp = 1.f; //m_dynamicsWorld->getSolverInfo().m_numIterations = 4; m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); m_dynamicsWorld->setGravity(btVector3(0,-10,0)); ///create a few basic rigid bodies btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(150.),btScalar(50.),btScalar(150.))); // btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50); m_collisionShapes.push_back(groundShape); btTransform groundTransform; groundTransform.setIdentity(); groundTransform.setOrigin(btVector3(0,-43,0)); //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here: { btScalar mass(0.); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) groundShape->calculateLocalInertia(mass,localInertia); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia); btRigidBody* body = new btRigidBody(rbInfo); //add the body to the dynamics world m_dynamicsWorld->addRigidBody(body); } { //create a few dynamic rigidbodies // Re-using the same collision is better for memory usage and performance btScalar u= btScalar(1*SCALING-0.04); btVector3 points[3] = {btVector3(0,u,0),btVector3(-u,-u,0),btVector3(u,-u,0)}; btConvexShape* childShape0 = new btBoxShape(btVector3(btScalar(SCALING*1),btScalar(SCALING*1),btScalar(0.04))); btConvexShape* colShape= new btConvex2dShape(childShape0); //btCollisionShape* colShape = new btBox2dShape(btVector3(SCALING*1,SCALING*1,0.04)); btConvexShape* childShape1 = new btConvexHullShape(&points[0].getX(),3); btConvexShape* colShape2= new btConvex2dShape(childShape1); btConvexShape* childShape2 = new btCylinderShapeZ(btVector3(btScalar(SCALING*1),btScalar(SCALING*1),btScalar(0.04))); btConvexShape* colShape3= new btConvex2dShape(childShape2); m_collisionShapes.push_back(colShape); m_collisionShapes.push_back(colShape2); m_collisionShapes.push_back(colShape3); m_collisionShapes.push_back(childShape0); m_collisionShapes.push_back(childShape1); m_collisionShapes.push_back(childShape2); //btUniformScalingShape* colShape = new btUniformScalingShape(convexColShape,1.f); colShape->setMargin(btScalar(0.03)); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); /// Create Dynamic Objects btTransform startTransform; startTransform.setIdentity(); btScalar mass(1.f); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) colShape->calculateLocalInertia(mass,localInertia); // float start_x = START_POS_X - ARRAY_SIZE_X/2; // float start_y = START_POS_Y; // float start_z = START_POS_Z - ARRAY_SIZE_Z/2; btVector3 x(-ARRAY_SIZE_X, 8.0f,-20.f); btVector3 y; btVector3 deltaX(SCALING*1, SCALING*2,0.f); btVector3 deltaY(SCALING*2, 0.0f,0.f); for (int i = 0; i < ARRAY_SIZE_X; ++i) { y = x; for (int j = i; j < ARRAY_SIZE_Y; ++j) { startTransform.setOrigin(y-btVector3(-10,0,0)); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(0,0,0); switch (j%3) { #if 1 case 0: rbInfo = btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,colShape,localInertia); break; case 1: rbInfo = btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,colShape3,localInertia); break; #endif default: rbInfo = btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,colShape2,localInertia); } btRigidBody* body = new btRigidBody(rbInfo); //body->setContactProcessingThreshold(colShape->getContactBreakingThreshold()); body->setActivationState(ISLAND_SLEEPING); body->setLinearFactor(btVector3(1,1,0)); body->setAngularFactor(btVector3(0,0,1)); m_dynamicsWorld->addRigidBody(body); body->setActivationState(ISLAND_SLEEPING); // y += -0.8*deltaY; y += deltaY; } x += deltaX; } } m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); }
/** * Update all object positions. Process object 'local' events * including boundary events and collisions */ void ObjectHandler_v1d::moveObjects() { debugC(4, kDebugObject, "moveObjects"); // Added to DOS version in order to handle mouse properly // Do special route processing _vm->_route->processRoute(); // Perform any adjustments to velocity based on special path types // and store all (visible) object baselines into the boundary file. // Don't store foreground or background objects for (int i = 0; i < _numObj; i++) { object_t *obj = &_objects[i]; // Get pointer to object seq_t *currImage = obj->currImagePtr; // Get ptr to current image if (obj->screenIndex == *_vm->_screen_p) { switch (obj->pathType) { case kPathChase: { // Allowable motion wrt boundary int dx = _vm->_hero->x + _vm->_hero->currImagePtr->x1 - obj->x - currImage->x1; int dy = _vm->_hero->y + _vm->_hero->currImagePtr->y2 - obj->y - currImage->y2 - 1; if (abs(dx) <= 1) obj->vx = 0; else obj->vx = (dx > 0) ? MIN(dx, obj->vxPath) : MAX(dx, -obj->vxPath); if (abs(dy) <= 1) obj->vy = 0; else obj->vy = (dy > 0) ? MIN(dy, obj->vyPath) : MAX(dy, -obj->vyPath); // Set first image in sequence (if multi-seq object) if (obj->seqNumb == 4) { if (!obj->vx) { // Got 4 directions if (obj->vx != obj->oldvx) {// vx just stopped if (dy > 0) obj->currImagePtr = obj->seqList[DOWN].seqPtr; else obj->currImagePtr = obj->seqList[_UP].seqPtr; } } else if (obj->vx != obj->oldvx) { if (dx > 0) obj->currImagePtr = obj->seqList[RIGHT].seqPtr; else obj->currImagePtr = obj->seqList[LEFT].seqPtr; } } if (obj->vx || obj->vy) { if (obj->seqNumb > 1) obj->cycling = kCycleForward; } else { obj->cycling = kCycleNotCycling; boundaryCollision(obj); // Must have got hero! } obj->oldvx = obj->vx; obj->oldvy = obj->vy; currImage = obj->currImagePtr; // Get (new) ptr to current image break; } case kPathWander: if (!_vm->_rnd->getRandomNumber(3 * _vm->_normalTPS)) { // Kick on random interval obj->vx = _vm->_rnd->getRandomNumber(obj->vxPath << 1) - obj->vxPath; obj->vy = _vm->_rnd->getRandomNumber(obj->vyPath << 1) - obj->vyPath; // Set first image in sequence (if multi-seq object) if (obj->seqNumb > 1) { if (!obj->vx && (obj->seqNumb > 2)) { if (obj->vx != obj->oldvx) { // vx just stopped if (obj->vy > 0) obj->currImagePtr = obj->seqList[DOWN].seqPtr; else obj->currImagePtr = obj->seqList[_UP].seqPtr; } } else if (obj->vx != obj->oldvx) { if (obj->vx > 0) obj->currImagePtr = obj->seqList[RIGHT].seqPtr; else obj->currImagePtr = obj->seqList[LEFT].seqPtr; } if (obj->vx || obj->vy) obj->cycling = kCycleForward; else obj->cycling = kCycleNotCycling; } obj->oldvx = obj->vx; obj->oldvy = obj->vy; currImage = obj->currImagePtr; // Get (new) ptr to current image } break; default: ; // Really, nothing } // Store boundaries if ((obj->cycling > kCycleAlmostInvisible) && (obj->priority == kPriorityFloating)) storeBoundary(obj->x + currImage->x1, obj->x + currImage->x2, obj->y + currImage->y2); } } // Move objects, allowing for boundaries for (int i = 0; i < _numObj; i++) { object_t *obj = &_objects[i]; // Get pointer to object if ((obj->screenIndex == *_vm->_screen_p) && (obj->vx || obj->vy)) { // Only process if it's moving // Do object movement. Delta_x,y return allowed movement in x,y // to move as close to a boundary as possible without crossing it. seq_t *currImage = obj->currImagePtr; // Get ptr to current image // object coordinates int x1 = obj->x + currImage->x1; // Left edge of object int x2 = obj->x + currImage->x2; // Right edge int y1 = obj->y + currImage->y1; // Top edge int y2 = obj->y + currImage->y2; // Bottom edge if ((obj->cycling > kCycleAlmostInvisible) && (obj->priority == kPriorityFloating)) clearBoundary(x1, x2, y2); // Clear our own boundary // Allowable motion wrt boundary int dx = deltaX(x1, x2, obj->vx, y2); if (dx != obj->vx) { // An object boundary collision! boundaryCollision(obj); obj->vx = 0; } int dy = deltaY(x1, x2, obj->vy, y2); if (dy != obj->vy) { // An object boundary collision! boundaryCollision(obj); obj->vy = 0; } if ((obj->cycling > kCycleAlmostInvisible) && (obj->priority == kPriorityFloating)) storeBoundary(x1, x2, y2); // Re-store our own boundary obj->x += dx; // Update object position obj->y += dy; // Don't let object go outside screen if (x1 < kEdge) obj->x = kEdge2; if (x2 > (kXPix - kEdge)) obj->x = kXPix - kEdge2 - (x2 - x1); if (y1 < kEdge) obj->y = kEdge2; if (y2 > (kYPix - kEdge)) obj->y = kYPix - kEdge2 - (y2 - y1); if ((obj->vx == 0) && (obj->vy == 0)) obj->cycling = kCycleNotCycling; } } // Clear all object baselines from the boundary file. for (int i = 0; i < _numObj; i++) { object_t *obj = &_objects[i]; // Get pointer to object seq_t *currImage = obj->currImagePtr; // Get ptr to current image if ((obj->screenIndex == *_vm->_screen_p) && (obj->cycling > kCycleAlmostInvisible) && (obj->priority == kPriorityFloating)) clearBoundary(obj->oldx + currImage->x1, obj->oldx + currImage->x2, obj->oldy + currImage->y2); } // If maze mode is enabled, do special maze processing if (_vm->_maze.enabledFl) { seq_t *currImage = _vm->_hero->currImagePtr;// Get ptr to current image // hero coordinates int x1 = _vm->_hero->x + currImage->x1; // Left edge of object int x2 = _vm->_hero->x + currImage->x2; // Right edge int y1 = _vm->_hero->y + currImage->y1; // Top edge int y2 = _vm->_hero->y + currImage->y2; // Bottom edge _vm->_scheduler->processMaze(x1, x2, y1, y2); } }
Real pixelAspectRatio() const { return deltaX() / deltaY(); }
auto distance(Point<PRECISION> p1, Point<PRECISION2> p2) { return sqrt(pow(deltaX(p1, p2), 2) + pow(deltaY(p1, p2), 2)); }
Point<PRECISION> delta(Point<PRECISION> p1, Point<PRECISION2> p2) { return {deltaX(p1, p2), deltaY(p1, p2)}; }
void Box2dDemo::initPhysics() { m_dialogDynamicsWorld = new GL_DialogDynamicsWorld(); //m_dialogDynamicsWorld->createDialog(100,110,200,50); //m_dialogDynamicsWorld->createDialog(100,00,100,100); //m_dialogDynamicsWorld->createDialog(0,0,100,100); GL_DialogWindow* settings = m_dialogDynamicsWorld->createDialog(50,0,200,120,"Settings"); GL_ToggleControl* toggle = m_dialogDynamicsWorld->createToggle(settings,"Toggle 1"); toggle = m_dialogDynamicsWorld->createToggle(settings,"Toggle 2"); toggle ->m_active = true; toggle = m_dialogDynamicsWorld->createToggle(settings,"Toggle 3"); //GL_SliderControl* slider = m_dialogDynamicsWorld->createSlider(settings,"Slider"); GL_DialogWindow* dialog = m_dialogDynamicsWorld->createDialog(0,200,420,300,"Help"); GL_TextControl* txt = new GL_TextControl; dialog->addControl(txt); txt->m_textLines.push_back("Mouse to move"); txt->m_textLines.push_back("Test 2"); txt->m_textLines.push_back("mouse to interact"); txt->m_textLines.push_back("ALT + mouse to move camera"); txt->m_textLines.push_back("space to reset"); txt->m_textLines.push_back("cursor keys and z,x to navigate"); txt->m_textLines.push_back("i to toggle simulation, s single step"); txt->m_textLines.push_back("q to quit"); txt->m_textLines.push_back(". to shoot box"); txt->m_textLines.push_back("d to toggle deactivation"); txt->m_textLines.push_back("g to toggle mesh animation (ConcaveDemo)"); txt->m_textLines.push_back("h to toggle help text"); txt->m_textLines.push_back("o to toggle orthogonal/perspective view"); //txt->m_textLines.push_back("+- shooting speed = %10.2f",m_ShootBoxInitialSpeed); setTexturing(true); setShadows(true); setCameraDistance(btScalar(SCALING*50.)); m_cameraTargetPosition.setValue(0,0,0);//0, ARRAY_SIZE_Y, 0); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new btDefaultCollisionConfiguration(); //m_collisionConfiguration->setConvexConvexMultipointIterations(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); btVoronoiSimplexSolver* simplex = new btVoronoiSimplexSolver(); btMinkowskiPenetrationDepthSolver* pdSolver = new btMinkowskiPenetrationDepthSolver(); btConvex2dConvex2dAlgorithm::CreateFunc* convexAlgo2d = new btConvex2dConvex2dAlgorithm::CreateFunc(simplex,pdSolver); m_dispatcher->registerCollisionCreateFunc(CONVEX_2D_SHAPE_PROXYTYPE,CONVEX_2D_SHAPE_PROXYTYPE,convexAlgo2d); m_dispatcher->registerCollisionCreateFunc(BOX_2D_SHAPE_PROXYTYPE,CONVEX_2D_SHAPE_PROXYTYPE,convexAlgo2d); m_dispatcher->registerCollisionCreateFunc(CONVEX_2D_SHAPE_PROXYTYPE,BOX_2D_SHAPE_PROXYTYPE,convexAlgo2d); m_dispatcher->registerCollisionCreateFunc(BOX_2D_SHAPE_PROXYTYPE,BOX_2D_SHAPE_PROXYTYPE,new btBox2dBox2dCollisionAlgorithm::CreateFunc()); m_broadphase = new btDbvtBroadphase(); //m_broadphase = new btSimpleBroadphase(); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver; m_solver = sol; m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); //m_dynamicsWorld->getSolverInfo().m_erp = 1.f; //m_dynamicsWorld->getSolverInfo().m_numIterations = 4; m_dynamicsWorld->setGravity(btVector3(0,-10,0)); ///create a few basic rigid bodies btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(150.),btScalar(50.),btScalar(150.))); // btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50); m_collisionShapes.push_back(groundShape); btTransform groundTransform; groundTransform.setIdentity(); groundTransform.setOrigin(btVector3(0,-43,0)); //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here: { btScalar mass(0.); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) groundShape->calculateLocalInertia(mass,localInertia); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia); btRigidBody* body = new btRigidBody(rbInfo); //add the body to the dynamics world m_dynamicsWorld->addRigidBody(body); } { //create a few dynamic rigidbodies // Re-using the same collision is better for memory usage and performance btScalar u= btScalar(1*SCALING-0.04); btVector3 points[3] = {btVector3(0,u,0),btVector3(-u,-u,0),btVector3(u,-u,0)}; btConvexShape* childShape0 = new btBoxShape(btVector3(btScalar(SCALING*1),btScalar(SCALING*1),btScalar(0.04))); btConvexShape* colShape= new btConvex2dShape(childShape0); //btCollisionShape* colShape = new btBox2dShape(btVector3(SCALING*1,SCALING*1,0.04)); btConvexShape* childShape1 = new btConvexHullShape(&points[0].getX(),3); btConvexShape* colShape2= new btConvex2dShape(childShape1); btConvexShape* childShape2 = new btCylinderShapeZ(btVector3(btScalar(SCALING*1),btScalar(SCALING*1),btScalar(0.04))); btConvexShape* colShape3= new btConvex2dShape(childShape2); m_collisionShapes.push_back(colShape); m_collisionShapes.push_back(colShape2); m_collisionShapes.push_back(colShape3); m_collisionShapes.push_back(childShape0); m_collisionShapes.push_back(childShape1); m_collisionShapes.push_back(childShape2); //btUniformScalingShape* colShape = new btUniformScalingShape(convexColShape,1.f); colShape->setMargin(btScalar(0.03)); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); /// Create Dynamic Objects btTransform startTransform; startTransform.setIdentity(); btScalar mass(1.f); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) colShape->calculateLocalInertia(mass,localInertia); // float start_x = START_POS_X - ARRAY_SIZE_X/2; // float start_y = START_POS_Y; // float start_z = START_POS_Z - ARRAY_SIZE_Z/2; btVector3 x(-ARRAY_SIZE_X, 8.0f,-20.f); btVector3 y; btVector3 deltaX(SCALING*1, SCALING*2,0.f); btVector3 deltaY(SCALING*2, 0.0f,0.f); for (int i = 0; i < ARRAY_SIZE_X; ++i) { y = x; for (int j = i; j < ARRAY_SIZE_Y; ++j) { startTransform.setOrigin(y-btVector3(-10,0,0)); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(0,0,0); switch (j%3) { #if 1 case 0: rbInfo = btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,colShape,localInertia); break; case 1: rbInfo = btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,colShape3,localInertia); break; #endif default: rbInfo = btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,colShape2,localInertia); } btRigidBody* body = new btRigidBody(rbInfo); //body->setContactProcessingThreshold(colShape->getContactBreakingThreshold()); body->setActivationState(ISLAND_SLEEPING); body->setLinearFactor(btVector3(1,1,0)); body->setAngularFactor(btVector3(0,0,1)); m_dynamicsWorld->addRigidBody(body); body->setActivationState(ISLAND_SLEEPING); // y += -0.8*deltaY; y += deltaY; } x += deltaX; } } clientResetScene(); }
//-------------------------------------------------------------------------- // //-------------------------------------------------------------------------- void AlgWspect::run() { #ifdef TIMING_ALG_W_SPECT int quark_b, quark_e; int meson_b, meson_m, meson_e, meson_bmp, meson_mmp, meson_emp; int nucleon_b, nucleon_m, nucleon_e; int total_b = clock(); int total_e; #endif CgArg cg = *cg_arg_p; char *fname = "run()"; VRB.Func(d_class_name,fname); // printf("in AlgWspect::run \n"); WspectOutput * output = (WspectOutput *)common_arg->results; // Set the Lattice pointer //------------------------------------------------------------------------ Lattice& lat = AlgLattice(); int src_slice = d_arg_p->aots_start; int src_slice_step = d_arg_p->aots_step; int src_slice_end = src_slice + src_slice_step * d_arg_p->aots_num; VRB.Result(d_class_name,fname,"%d %d %d \n",src_slice,src_slice_step, src_slice_end); for ( ; src_slice < src_slice_end; src_slice += src_slice_step) { // Calculate quark propagator //---------------------------------------------------------------------- // Ping: certainly more work here to be done about the desired // combinations of non-degenerate quarks. // Presumably, more arguments will have to be passed in. // One way: for three flavors, [100] means use only q1 // to caculate spectrum. // Also some care needed to get the scope (CTOR and DTOR) // of each quark propagator right. // const WspectQuark & q2 = q; // const WspectQuark & q3 = q; // Xiaodong & Thomas: // Modified to calculate also extended mesons // q1 is the usual propagator(no source operator), which can be // used to pass propagation direction and src_slice infomation // to spectrum class // there is a problem here --> check ! VRB.Result(d_class_name,fname,"prop_dir = %d , src_slice = %d \n",d_arg_p->prop_dir, src_slice); WspectHyperRectangle hyperRect(d_arg_p->prop_dir, src_slice); #ifdef TIMING_ALG_W_SPECT quark_b = clock(); #endif VRB.Result(d_class_name,fname,"created quark q1 \n"); // create local quark propagator WspectQuark q1(lat, output->cg, output->pbp, output->mid_point, output->a0_p, d_arg_p[0], cg,hyperRect); VRB.Result(d_class_name,fname,"finished quark q1 \n"); #ifdef TIMING_ALG_W_SPECT quark_e = clock(); #endif //Note: for ExtendedMesons, do only zero momentum projection WspectMomenta mom(hyperRect, q1.SourceCenter2(), d_arg_p->num_mom - 1); // mom.dumpData(); // Calculate LOCAL meson CORRELATOR // added control by Thomas and Xiaodong //---------------------------------------------------------------------- { #ifdef TIMING_ALG_W_SPECT meson_b = clock(); #endif if(d_arg_p->normal_mesons_on) { WspectMesons mes(q1, q1, hyperRect, mom); #if 0 q1.dumpData("qprop.dat"); #endif #ifdef TIMING_ALG_W_SPECT meson_m = clock(); #endif //write data to files mes.print(output); } #ifdef TIMING_ALG_W_SPECT meson_e = clock(); #endif } //end of normal mesons // Calculate <\Delta J^5 \bar q1 \gamma^5 q1> with middle point sink // changed //---------------------------------------------------------------------- if (lat.Fclass() == F_CLASS_DWF && output->mid_point) { #ifdef TIMING_ALG_W_SPECT meson_bmp = clock(); #endif WspectMesons mes(q1.Data_SP1(), q1.Data_SP2(), hyperRect, mom); #ifdef TIMING_ALG_W_SPECT meson_mmp = clock(); #endif mes.print_mp(output->mid_point); #ifdef TIMING_ALG_W_SPECT meson_emp = clock(); #endif } // Calculate nucleon and delta's //---------------------------------------------------------------------- if (d_arg_p->baryons_on) { { #ifdef TIMING_ALG_W_SPECT nucleon_b = clock(); #endif WspectBaryon nuc(q1, q1, q1, hyperRect, WspectBaryon::NUCLEON_CONSTI, WspectBaryon::NUCLEON_DIRAC); #ifdef TIMING_ALG_W_SPECT nucleon_m = clock(); #endif nuc.print(output->nucleon, output->fold); #ifdef TIMING_ALG_W_SPECT nucleon_e = clock(); #endif } { WspectBaryon nucPrime(q1, q1, q1, hyperRect, WspectBaryon::NUCLEON_CONSTI, WspectBaryon::UnitUnit); nucPrime.print(output->nucleon_prime, output->fold); } { WspectBaryon deltaX(q1, q1, q1, hyperRect, WspectBaryon::DELTA_CONSTI, WspectBaryon::DELTAX_DIRAC); deltaX.print(output->delta_x, output->fold); } { WspectBaryon deltaY(q1, q1, q1, hyperRect, WspectBaryon::DELTA_CONSTI, WspectBaryon::DELTAY_DIRAC); deltaY.print(output->delta_y, output->fold); } { WspectBaryon deltaZ(q1, q1, q1, hyperRect, WspectBaryon::DELTA_CONSTI, WspectBaryon::DELTAZ_DIRAC); deltaZ.print(output->delta_z, output->fold); } { WspectBaryon deltaT(q1, q1, q1, hyperRect, WspectBaryon::DELTA_CONSTI, WspectBaryon::DELTAT_DIRAC); deltaT.print(output->delta_t, output->fold); } } //end if(baryons_on) // Increment the counter d_counter += d_count_step; } // end of for(sc_slice,..) #ifdef TIMING_ALG_W_SPECT total_e = clock(); printf("Total: %d = [%d - %d]\n", total_e - total_b, total_e, total_b); printf("Quark: %d = [%d - %d]\n", quark_e - quark_b, quark_e, quark_b); printf("Meson: \t%d = [%d - %d] = \n\tcalc %d = [%d - %d] + \n\tprint %d = [%d - %d]\n", meson_e - meson_b, meson_e, meson_b, meson_m - meson_b, meson_m, meson_b, meson_e - meson_m, meson_e, meson_m); printf("Nucleon:\t%d = [%d - %d] = \n\tcalc %d = [%d - %d] + \n\tprint %d = [%d - %d]\n", nucleon_e - nucleon_b, nucleon_e, nucleon_b, nucleon_m - nucleon_b, nucleon_m, nucleon_b, nucleon_e - nucleon_m, nucleon_e, nucleon_m); #endif VRB.FuncEnd(d_class_name,fname); }