CollisionBoxComponent::CollisionBoxComponent(GameObject& aGameObject, eCollisionGroup aCollisionGroup, const Vector2<float>& someDimensions) : CollisionComponent(aGameObject, aCollisionGroup) { myDimensions = someDimensions; Line<float> aLine; Vector2<float> position1(-myDimensions.myX / 2, -myDimensions.myY / 2); Vector2<float> position2(-myDimensions.myX / 2, myDimensions.myY / 2); Vector2<float> position3(myDimensions.myX / 2, myDimensions.myY / 2); Vector2<float> position4(myDimensions.myX / 2, -myDimensions.myY / 2); aLine.InitWith2Points(position1, position2); myLineVolume.AddLine(aLine); aLine.InitWith2Points(position2, position3); myLineVolume.AddLine(aLine); aLine.InitWith2Points(position3, position4); myLineVolume.AddLine(aLine); aLine.InitWith2Points(position4, position1); myLineVolume.AddLine(aLine); myParent->SetValue<CollisionBoxComponent*>("CollisionBoxComponent", this); //mySprite = ResourceManager::GetInstance()->GetSprite("../Data/Gfx/debugBox.png", { someDimensions.x, someDimensions.y }, { someDimensions.x / 2.f, someDimensions.y / 2.f }); }
void CSimPetriDoc::AdjustElementsOnGrid(const std::vector<CElement*>& selection, CElement* mouseObject, const Point& pointer) { Point position1(mouseObject->GetBoundRect().X, mouseObject->GetBoundRect().Y); //Ajustement de l'objet en déplacement sur la grille //suivant la position du pointeur mouseObject->AdjustOnGrid(&pointer); Point position2(mouseObject->GetBoundRect().X, mouseObject->GetBoundRect().Y); //Déplacement de tous les éléments Size size(position2.X - position1.X, position2.Y - position1.Y); for(auto it = selection.begin(); it!=selection.end(); ++it) if(*it != mouseObject) (*it)->Move(size); }
void CWsGraphicShareBase::DoTestDrawGraphicCompareL(TPtrC aShare) { // UID of the shared graphic TUid uid1 = {0x12000021}; TWsGraphicId twsGraphicId1(uid1); _LIT8(KTestData,"HelloWorld"); CFbsBitmap bitmap1; CFbsBitmap mask1; TSize screenSize = iScreen->SizeInPixels(); User::LeaveIfError(bitmap1.Load(MY_TEST_BITMAP,0)); mask1.Create(bitmap1.SizeInPixels(),iScreen->DisplayMode()); CWsGraphicBitmap* bTest = CWsGraphicBitmap::NewL(&bitmap1,&mask1); // divide the screen into two equal rectangles TRect position1(0,0,screenSize.iWidth/2,screenSize.iHeight); TRect position2(screenSize.iWidth/2,0,screenSize.iWidth,screenSize.iHeight); // draw the new graphic and attempt to draw the shared graphic iGc->Activate(*iWin); iWin->Invalidate(); iWin->BeginRedraw(); iGc->Clear(position1); iGc->Clear(position2); iGc->DrawWsGraphic(bTest->Id(),position1,KTestData); iGc->DrawWsGraphic(twsGraphicId1.Uid(),position2,KTestData); iGc->Deactivate(); iWin->EndRedraw(); iWs.Flush(); iWs.Finish(); // compare the graphic in both positions if (aShare==_L("false")) Test(!iScreen->RectCompare(position1,position2)); else Test(iScreen->RectCompare(position1,position2)); delete bTest; }
CollisionBoxComponent::CollisionBoxComponent(GameObject& aGameObject, eCollisionGroup aCollisionGroup, const Vector2<float>& someDimensions, const Vector2<float>& aCenterPosition) : CollisionComponent(aGameObject, aCollisionGroup, aCenterPosition) { myDimensions = someDimensions; Line<float> aLine; Vector2<float> position1(-myDimensions.myX / 2, -myDimensions.myY / 2); Vector2<float> position2(-myDimensions.myX / 2, myDimensions.myY / 2); Vector2<float> position3(myDimensions.myX / 2, myDimensions.myY / 2); Vector2<float> position4(myDimensions.myX / 2, -myDimensions.myY / 2); aLine.InitWith2Points(position1, position2); myLineVolume.AddLine(aLine); aLine.InitWith2Points(position2, position3); myLineVolume.AddLine(aLine); aLine.InitWith2Points(position3, position4); myLineVolume.AddLine(aLine); aLine.InitWith2Points(position4, position1); myLineVolume.AddLine(aLine); myParent->SetValue<CollisionBoxComponent*>("CollisionBoxComponent", this); }
//========================================= // Main Program //========================================= task main() { initializeRobot(); waitForStart(); // wait for FCS to tell us to go! if(done) { StartTask(lightDiagnostic); } if(calibrate != 2) // GYRO calibration hasn't been run during the wait time { gyroCalTime = 3; // so setup the default calibrate time calibrate = 1; // start the calibration going while(calibrate != 2) // and wait for it to complete before moving the robot { EndTimeSlice(); } } constHeading = 0; // reset the GYRO headings to eliminate any drift while we waited relHeading = 0; // same thing for relative heading wait1Msec(Start_Delay*1000); // implement the user configurable delay before moving PlaySound(soundBeepBeep); // tell everyone we're about to start going step = MissionNumber*100; // this records the actual mission number that we ran within the data log file LogData=true; // start saving data to the log file servo[wrist] = WRIST_CLOSED; servo[shoulder] = SHOULDER_DOWN; servo[right_servo] = RIGHT_GRIPPER_START; servo[left_servo] = LEFT_GRIPPER_START; switch(MissionNumber) // now go run whichever mission we have been asked to run { //================================================ // start on the right side of the blue dispenser delivers to IR //================================================ case 1: IRside = position1();//go here if(IRside < -75) column = 1; else if(IRside < -25) column = 2; else column = 3; wait1Msec(800); switch(column) { case 1://left diagnosticBeeps(1); leftPeg(); break; case 2://center diagnosticBeeps(2); centerPeg(); break; case 3://right diagnosticBeeps(3); rightPeg(); break; } switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // CENTER PEG //================================================ case 2: position1(); centerPeg(); switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // LEFT PEG //================================================ case 3: position1(); leftPeg(); switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // RIGHT PEG //================================================ case 4: position1(); rightPeg(); switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // IR SECOND POSITION //================================================ case 5: IRside = position2();//go here if(IRside < -75) column = 1; else if(IRside < -25) column = 2; else column = 3; wait1Msec(800); switch(column) { case 1://left diagnosticBeeps(1); leftPeg(); break; case 2://center diagnosticBeeps(2); centerPeg(); break; case 3://right diagnosticBeeps(3); rightPeg(); break; } switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // CENTER PED SECOND POSITION //================================================ case 6: position2(); centerPeg(); break; //================================================ // LEFT PEG SECOND POSITION //================================================ case 7: position2(); leftPeg(); break; //================================================ // RIGHT PED SECOND POSITION //================================================ case 8: position2(); rightPeg(); break; //================================================ // DEFENSE RIGHT //================================================ case 9: GyroSonar_moveV2(0, BACK, 100, 124, -60,true, true, CONSTANT); GyroTime_moveV2(700,-50,true,true,REL); GyroTimeS_moveV2(1800,40,true,true,false,true); break; //================================================ // DEFENSE LEFT //================================================ case 10: GyroSonar_moveV2(0, BACK, 100, 124, -60,true, true, CONSTANT); GyroTime_moveV2(700,-50,true,true,REL); GyroTimeS_moveV2(1800,-40,true,true,false,true); break; //================================================ // OPPONENT IR //================================================ case 11: for (int i=0;i<90;i++) {SetDrive(i,50,i); wait1Msec(30); } StopRobot(); wait1Msec(30000); break; //================================================ // OPPONENT CENTER //================================================ case 12: opponentRight(); centerPeg(); break; //================================================ // OPPONENT LEFT //================================================ case 13: opponentRight(); rightPeg(); break; //================================================ // OPPONENT RIGHT //================================================ case 14: opponentRight(); leftPeg(); break; //================================================ // OPPONENTL IR //================================================ case 15: opponentLeft(); leftPeg(); break; //================================================ // OPPONENTL CENTER //================================================ case 16: opponentLeft(); centerPeg(); break; //================================================ // OPPONENTL LEFT //================================================ case 17: opponentLeft(); rightPeg(); break; //================================================ // OPPONENTL RIGHT //================================================ case 18: opponentLeft(); leftPeg(); break; //================================================ // See Opponent test //================================================ case 19: sawOpponent = GyroSonar_moveV2(0, BACK, 100, 112, -50,true, true, CONSTANT); StopRobot(); if(sawOpponent) diagnosticBeeps(6); break; //================================================ // See Opponent test2 //================================================ case 20: sawOpponent = GyroSonar_moveV2(0, BACK, 100, 112, -50,true, true, CONSTANT); StopRobot(); if(sawOpponent) diagnosticBeeps(6); break; } LogData=false; // stop logging IR data and close the file StopRobot(); }
double System::maxTimestep(int i) { Distance d; const Object mainObject = objectlist[i]; int k; if (i == 0) { k=1; } else { k=0; } Object tempObject = objectlist[k]; arma::Col<double> position1(3), position2(3); arma::Col<double> mainVel = mainObject.getVelocity(); position1 = mainObject.getPosition(); position2 = tempObject.getPosition(); double R = d.twoObjects(position1, position2); arma::Col<double> tempVel = tempObject.getVelocity()-mainVel; double V = std::sqrt(arma::dot(tempVel,tempVel)); double maxTime; if (V>1e-16) { maxTime = R/V; } else { maxTime = R/1e-16; } double temptime; for (int j = 1; j < numberOfObject; ++j) { if (j!=i) { tempObject = objectlist[j]; position2 = tempObject.getPosition(); R = d.twoObjects(position1, position2); tempVel = tempObject.getVelocity()-mainVel; V = std::sqrt(arma::dot(tempVel,tempVel)); if (V>1e-16) { maxTime = R/V; } else { maxTime = R/1e-16; } temptime = R/V; if (temptime<maxTime) { maxTime = temptime; } } //end if } //end for return maxTime; }
//========================================= // Main Program //========================================= task main() { initializeRobot(); waitForStart(); // wait for FCS to tell us to go! if(done) { StartTask(lightDiagnostic); } if(calibrate != 2) // GYRO calibration hasn't been run during the wait time { gyroCalTime = 3; // so setup the default calibrate time calibrate = 1; // start the calibration going while(calibrate != 2) // and wait for it to complete before moving the robot { EndTimeSlice(); } } constHeading = 0; // reset the GYRO headings to eliminate any drift while we waited relHeading = 0; // same thing for relative heading wait1Msec(Start_Delay*1000); // implement the user configurable delay before moving PlaySound(soundBeepBeep); // tell everyone we're about to start going step = MissionNumber*100; // this records the actual mission number that we ran within the data log file LogData=true; // start saving data to the log file servo[wrist] = WRIST_CLOSED; servo[shoulder] = SHOULDER_DOWN; servo[right_servo] = RIGHT_GRIPPER_START; servo[left_servo] = LEFT_GRIPPER_START; switch(MissionNumber) // now go run whichever mission we have been asked to run { //================================================ // start on the right side of the blue dispenser delivers to IR //================================================ case 1: int IRside = position1();//go here if(IRside < -75) column = 1; else if(IRside < -25) column = 2; else column = 3; wait1Msec(800); switch(column) { case 1://left diagnosticBeeps(1); leftPeg(); break; case 2://center diagnosticBeeps(2); centerPeg(); break; case 3://right diagnosticBeeps(3); rightPeg(); break; } switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // CENTER PEG //================================================ case 2: position1(); centerPeg(); switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // LEFT PEG //================================================ case 3: position1(); leftPeg(); switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // RIGHT PEG //================================================ case 4: position1(); switch(fieldRed) { case STOP: StopRobot(); break; case RED: redReturn(); break; case BLUE: blueReturn(); break; } break; //================================================ // CENTER PED SECOND POSITION //================================================ case 5: GyroSonar_moveV2(0, BACK, 100, 114, -48,true, true, CONSTANT); GyroTime_moveV2(400,-30,true,false,false); GyroTimeS_moveV2(750,-40,false,true,true,CONSTANT); Gyro_TurnV2(40,15,CONSTANT); wait1Msec(800); GyroTime_moveV2(1200,-30,true,false,false); moveLightServo(DOWN); //GyroTimeS_moveV2(8000,15,true,true,false,false); GyroTimeS_moveV2(8000,-15,true,true,false,false); GyroTimeS_moveV2(8000,18,true,true,false,false); GyroTimeS_moveV2(8000,-15,true,true,false,false); //GyroTimeS_moveV2(90,10,true,false,false,false); GyroTime_moveV2(1200,-30,true,false,false); wait1Msec(1500); servo[shoulder] = SHOULDER_UP; wait1Msec(2000); servo[wrist] = WRIST_OPEN; wait1Msec(1000); GyroTime_moveV2(400,25,true,false,false); wait1Msec(1000); servo[shoulder] = SHOULDER_DOWN; switch(fieldRed) { case STOP: StopRobot(); break; case RED: Gyro_TurnV2(42,-15,REL); GyroTime_moveV2(1200,50,true,false,REL); GyroTime45_V2(490,50,false, true, REL, true); GyroTime_moveV2(400,50,true,false,REL); break; case BLUE: Gyro_TurnV2(42,15,REL); GyroTime_moveV2(1600,45,true,false,false); break; } break; //================================================ // LEFT PEG SECOND POSITION //================================================ case 6: /* GyroSonar_moveV2(0, BACK, 100, 114, -48,true, true, CONSTANT); // was this GyroTime_moveV2(400,-30,true,false,false); GyroTimeS_moveV2(750,-40,true,true,false,CONSTANT); Gyro_TurnV2(40,15,CONSTANT); */ GyroSonar_moveV2(0, BACK, 100, 114, -48,true, true, CONSTANT); //trying this GyroTime_moveV2(400,-30,true,false,false); GyroTimeS_moveV2(750,-40,false,true,true,CONSTANT); Gyro_TurnV2(40,15,CONSTANT); wait1Msec(800); GyroTime_moveV2(1200,-30,true,false,false); moveLightServo(DOWN); //GyroTimeS_moveV2(8000,15,true,true,false,false); GyroTimeS_moveV2(8000,-15,true,true,false,false); GyroTimeS_moveV2(8000,18,true,true,false,false); GyroTimeS_moveV2(8000,-15,true,true,false,false); Gyro_TurnV2(36,-15,CONSTANT); GyroTime_moveV2(1300,-30,true,false,false); GyroTime_moveV2(120,30,true,false,false); GyroTimeS_moveV2(500,25,true,false,false,false); GyroTimeS_moveV2(2000,15,true,true,false,false); GyroTimeS_moveV2(8000,-10,true,true,false,false); Gyro_TurnV2(36,-15,CONSTANT); //GyroTimeS_moveV2(80,15,true,false,false,false); GyroTimeS_moveV2(8000,-25,true,true,false,false); GyroTimeS_moveV2(50,-20,true,false,false,false); GyroTime_moveV2(400,-30,true,false,false); wait1Msec(1500); servo[shoulder] = SHOULDER_UP; wait1Msec(2000); servo[wrist] = WRIST_OPEN; wait1Msec(1000); GyroTime_moveV2(600,25,true,false,false); wait1Msec(3000); servo[shoulder] = SHOULDER_DOWN; switch(fieldRed) { case STOP: StopRobot(); break; case RED: break; case BLUE: wait1Msec(1000); Gyro_TurnV2(30,15,CONSTANT); GyroTime_moveV2(800,50,true,false,false); break; } break; //================================================ // RIGHT PED SECOND POSITION //================================================ case 7: /* GyroSonar_moveV2(0, BACK, 100, 114, -48,true, true, CONSTANT); //was this GyroTime_moveV2(400,-30,true,false,false); GyroTimeS_moveV2(750,-40,false,true,true,CONSTANT); Gyro_TurnV2(40,15,CONSTANT); */ GyroSonar_moveV2(0, BACK, 100, 114, -48,true, true, CONSTANT); //trying this GyroTime_moveV2(400,-30,true,false,false); GyroTimeS_moveV2(750,-40,false,true,true,CONSTANT); Gyro_TurnV2(40,15,CONSTANT); break; wait1Msec(800); GyroTime_moveV2(1200,-30,true,false,false); moveLightServo(DOWN); //GyroTimeS_moveV2(8000,-15,true,true,false,false); GyroTimeS_moveV2(8000,18,true,true,false,false); GyroTimeS_moveV2(8000,-15,true,true,false,false); Gyro_TurnV2(36,-15,CONSTANT); GyroTime_moveV2(1300,-30,true,false,false); GyroTime_moveV2(120,30,true,false,false); GyroTimeS_moveV2(260,20,true,false,false,false); GyroTimeS_moveV2(8000,15,true,true,false,false); GyroTimeS_moveV2(8000,-15,true,true,false,false); Gyro_TurnV2(36,-15,CONSTANT); GyroTimeS_moveV2(80,-18,true,false,false,false); GyroTime_moveV2(400,-30,true,false,false); wait1Msec(1500); servo[shoulder] = SHOULDER_UP; wait1Msec(2000); servo[wrist] = WRIST_OPEN; wait1Msec(1000); GyroTime_moveV2(600,25,true,false,false); wait1Msec(3000); servo[shoulder] = SHOULDER_DOWN; switch(fieldRed) { case STOP: StopRobot(); break; case RED: wait1Msec(3000); Gyro_TurnV2(42,-15,REL); GyroTime_moveV2(1200,50,true,false,REL); GyroTime45_V2(490,50,false, true, REL, true); GyroTime_moveV2(400,50,true,false,REL); break; case BLUE: wait1Msec(3000); Gyro_TurnV2(42,15,REL); GyroTime_moveV2(1600,45,true,false,false); break; } break; //================================================ // DEFENSE RIGHT //================================================ case 8: GyroSonar_moveV2(0, BACK, 100, 124, -60,true, true, CONSTANT); GyroTime_moveV2(700,-50,true,true,REL); GyroTimeS_moveV2(1800,40,true,true,false,true); break; //================================================ // DEFENSE LEFT //================================================ case 9: GyroSonar_moveV2(0, BACK, 100, 124, -60,true, true, CONSTANT); GyroTime_moveV2(700,-50,true,true,REL); GyroTimeS_moveV2(1800,-40,true,true,false,true); break; //================================================ // OPPONENTS SIDE //================================================ case 10: for (int i=0;i<360;i++) {SetDrive(i,50); wait1Msec(10); } StopRobot(); wait1Msec(30000); break; //================================================ // TEST ORBIT //================================================ case 11: for (int i=0;i<360;i++) {SetDrive(i,50,i); wait1Msec(10); } StopRobot(); wait1Msec(30000); break; //================================================ // HIGH LIGHT OPPONENTS //================================================ case 12: for (int i=0;i<50;i++) { moveLightServo(UP); wait1Msec(1000); moveLightServo(DOWN); wait1Msec(1000); } break; //================================================ // ROBOT EVADE //================================================ case 13: wait1Msec(30000); break; } LogData=false; // stop logging IR data and close the file StopRobot(); }
PointToPlaneDemo::PointToPlaneDemo(hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env) { // // Setup the camera // { hkVector4 from(5.0f, 2.0f, 10.0f); hkVector4 to (2.0f, 0.0f, 0.0f); hkVector4 up (0.0f, 1.0f, 0.0f); setupDefaultCameras( env, from, to, up ); } // // Create the world // { hkpWorldCinfo info; info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); info.setBroadPhaseWorldSize( 100.0f ); info.m_enableDeactivation = false; m_world = new hkpWorld( info ); m_world->lock(); // Register the single agent required (a hkpBoxBoxAgent) hkpAgentRegisterUtil::registerAllAgents( m_world->getCollisionDispatcher() ); // // Create constraint viewer // m_debugViewerNames.pushBack( hkpConstraintViewer::getName() ); hkpConstraintViewer::m_scale = 1.0f; setupGraphics(); } // // Create vectors to be used for setup // hkVector4 halfSize (0.5f, 0.5f, 0.5f); hkVector4 position1(0.f,0.f,0.f); hkVector4 position2(3.0f,-0.5f,0.f); // // Create Box Shape // hkpBoxShape* boxShape; { boxShape = new hkpBoxShape( halfSize , 0 ); } // // Create fixed rigid body // hkpRigidBody* fixedBody; { hkpRigidBodyCinfo info; info.m_position = position1; info.m_shape = boxShape; info.m_motionType = hkpMotion::MOTION_FIXED; fixedBody = new hkpRigidBody(info); m_world->addEntity(fixedBody); fixedBody->removeReference(); } // // Create movable rigid body // hkpRigidBody* moveableBody; { hkpRigidBodyCinfo info; info.m_position = position2; info.m_shape = boxShape; // Compute the box inertia tensor hkpMassProperties massProperties; info.m_mass = 10.0f; hkpInertiaTensorComputer::computeBoxVolumeMassProperties(halfSize, info.m_mass, massProperties); info.m_inertiaTensor = massProperties.m_inertiaTensor; info.m_centerOfMass = massProperties.m_centerOfMass; info.m_motionType = hkpMotion::MOTION_BOX_INERTIA; moveableBody = new hkpRigidBody(info); m_world->addEntity(moveableBody); moveableBody->removeReference(); } // // Cleanup shared shape references // boxShape->removeReference(); boxShape = HK_NULL; // // Create point to plane constraint // { hkpPointToPlaneConstraintData* plane = new hkpPointToPlaneConstraintData(); hkVector4 up(0.0f, 1.0f, 0.0f); // Create constraint hkVector4 pivotW; pivotW.setAdd4(position2, hkVector4(-0.5f, 0.5f, 0.5f)); plane->setInWorldSpace(moveableBody->getTransform(), fixedBody->getTransform(), pivotW, up); // // Create and add the constraint // { hkpConstraintInstance* constraint = new hkpConstraintInstance( moveableBody, fixedBody, plane ); m_world->addConstraint(constraint); constraint->removeReference(); } plane->removeReference(); } m_world->unlock(); }