bool CBox2D::Intersects( const CCircle& Circle ) const { CFVec2 vOffset = (Circle.Centre() - m_vCentre); vOffset.SetAbs(); vOffset -= m_vExtents; return ( vOffset.X() < Circle.Radius() && vOffset.Y() < Circle.Radius() ); }
void CMole::Update(FLOAT32 _fTimeDelta) { m_pMoleAgent->Update(_fTimeDelta); // Turn. m_fHeading += m_pMoleAgent->GetRotationalSpeed() * _fTimeDelta; // Update position. CFVec2 vHeading; vHeading.SetToRotationZ(m_fHeading); CFVec2 vVelocity = vHeading * m_pMoleAgent->GetSpeed() * _fTimeDelta; m_vPosition += vVelocity; if ((m_vDestination - m_vPosition).Magnitude() < fMOLE_RADIUS) { Messages::send(DESTINATION_REACHED_EVENT, this); } // finally check if that pesky rodent got caught: CCircle Bounds; Bounds.Initialise( m_vPosition, fMOLE_RADIUS ); if ( CMMMContext::GetInstance().GetSquirrel()->Intersects( Bounds ) ) { CMMMContext::GetInstance().GetSquirrel()->LoseLife(); Messages::send(DESTINATION_REACHED_EVENT, this); } }
void CMole::DrawTargetAcorn(const CAcorn* _kpAcorn) const { GDE::CRenderer* pRenderer = CMMMContext::GetInstance().GetRenderer(); GDE::SVertex FirstLine[2]; FirstLine[0].m_uColour = 0xFFFFFF00; FirstLine[1].m_uColour = 0xFFFFFF00; FirstLine[0].m_fX = m_vPosition.X(); FirstLine[0].m_fY = m_vPosition.Y(); FirstLine[0].m_fZ = 0.0f; FirstLine[1].m_fX = _kpAcorn->GetPosition().X(); FirstLine[1].m_fY = _kpAcorn->GetPosition().Y(); FirstLine[1].m_fZ = 0.0f; pRenderer->DrawPrimitives(GDE::PT_LineList, 1, FirstLine); CCircle AcornCircle; AcornCircle.Initialise(_kpAcorn->GetPosition(), 14.0f); AcornCircle.Draw(0xAAFFFF00, true); }
void CSquirrel::LoseLife( void ) { if ( m_uNumLives ) { // do not lose a life if over a tunnel: CTunnel* pTunnels; UINT32 uNumTunnels; CMMMContext::GetInstance().GetTunnels( pTunnels, uNumTunnels ); CCircle Bounds; Bounds.Initialise( m_vPosition, m_fRadius ); for ( UINT32 i=0; i<uNumTunnels; i++ ) { if ( pTunnels[i].Intersects( Bounds ) ) { return; // immune, over a tunnel! } } for ( UINT32 i=0; i<m_uNumAcorns; i++ ) { m_ppAcorns[i]->SetState( CAcorn::ES_Available ); } m_uNumAcorns = 0; m_uNumLives--; if ( m_uNumLives ) { Spawn(); } else { CMMMContext::GetInstance().NotifySquirrelDeath(); } } }
bool suken::CCollisionManager::CollisionCircle(CCircle &A , CCircle &B) { // 前位置及び到達位置におけるパーティクル間のベクトルを算出 suken::Vector2D C0 = B.center.prePosition - A.center.prePosition; suken::Vector2D C1 = B.center.position - A.center.position; suken::Vector2D D = C1 - C0; // 衝突判定用の2次関数係数の算出 float P = VSquareSize( D ); // 同じ方向に移動 if(P==0){ return false; } float Q = VDot( C0, D ); float R = VSquareSize( C0 ); // 距離 float r = A.radius + B.radius; // 衝突判定式 float Judge = Q*Q - P*(R-r*r); if( Judge < 0 ){ // 衝突していない return false; } // 衝突時間の算出 float t_plus = (-Q + sqrt( Judge ) ) / P; float t_minus = ( -Q - sqrt( Judge ) ) / P; // 衝突位置の決定 suken::Vector2D pOut_colli_A = A.center.prePosition + ( A.center.position - A.center.prePosition) * t_minus; suken::Vector2D pOut_colli_B = B.center.prePosition + ( B.center.position - B.center.prePosition) * t_minus; // 衝突時間の決定(t_minus側が常に最初の衝突) float pOut_t0 = t_minus; float pOut_t1 = t_plus; // 時間内衝突できるか? // t_minusが1より大きいと届かず衝突していない // t_plus、t_minusが両方ともマイナスだと反対方向なので衝突しない if( (t_minus > 1) || (t_minus < 0 && t_plus < 0) ){ return false; } //衝突処理 A.SetCollisionState(true); B.SetCollisionState(true); A.OnCollisionFunc(); B.OnCollisionFunc(); #ifdef DEBUG_DRAW DxLib::DrawCircle((int)(A.center.position.x +0.5), (int)(A.center.position.y+0.5) , (int)(A.radius+0.5) ,GREEN ,true ); DxLib::DrawCircle((int)(B.center.position.x +0.5), (int)(B.center.position.y+0.5) , (int)(B.radius+0.5) ,GREEN ,true ); #endif CollisionCircleCalc(A ,B ,( 1.0f - abs(pOut_t0) ) / 60.0f ); return true; // 衝突報告 }
bool CMinSquareRecognizing::checkIfCircle( CCircle& circle, std::vector< cv::Point >& contour ) { if( circle.GetAccuracy() < accuracyThreshold && circle.GetRadius() > 50 ) { return true; } return false; }
bool CMole::Intersects(const CCircle& _krCircle) const { CCircle Bounds; Bounds.Initialise(m_vPosition, m_fRadius); return (_krCircle.Overlaps(Bounds)); }
bool CMole::Intersects(const CBox2D& _krBox) const { CCircle Bounds; Bounds.Initialise(m_vPosition, m_fRadius); return (_krBox.Intersects(Bounds)); }
//////////////////////////////////////////////////////////////////////////////// /// /// \brief Clones circle /// /// \return Pointer to cloned circle /// //////////////////////////////////////////////////////////////////////////////// CCircle* CCircle::clone() const { METHOD_ENTRY("CCircle::clone"); CCircle* pClone = new CCircle(); MEM_ALLOC("IShape") pClone->copy(this); return pClone; }
void CMole::NotifyDisturbance(const CCircle& _krCircle) { _krCircle.Radius(); #ifndef _EDITOR // Check disterbance within range if (sqrt(_krCircle.Centre().SquareDistance(m_vPosition)) - _krCircle.Radius() - m_fRadius <= 0.0f) { AppendHuntTask(_krCircle.Centre()); } #endif }
void CMole::DrawKnownAcorns() const { std::map<CAcorn*, bool>::iterator Current = s_mKnownAcorns.begin(); std::map<CAcorn*, bool>::iterator End = s_mKnownAcorns.end(); for (Current; Current != End; ++ Current) { // Draw known unbags acorns if ((*Current).second == false) { CCircle AcornCircle; AcornCircle.Initialise((*Current).first->GetPosition(), 14.0f); AcornCircle.Draw(0xAAFA00FF, true); } } }
int main () { CPolygon* polygons[4]; polygons[0] = new CRectangle(20,30); polygons[1] = new CTriangle(20,25); polygons[2] = new CCircle(25,25); polygons[3] = new CSquare(18,18); for(int i = 0; i < 4; i++) { CTriangle* trin = dynamic_cast <CTriangle *> (polygons[i]); if (trin != 0) { trin->set_values(10, 10); assert(trin->area() != 50); } CCircle* circ = dynamic_cast <CCircle *> (polygons[i]); if (circ != 0) { circ->set_values(10, 10); assert(circ->area() != 78); } CSquare* sqrr = dynamic_cast <CSquare *> (polygons[i]); if (sqrr != 0) { sqrr->set_values(10, 10); assert(sqrr->area() != 100); } CRectangle* rect = dynamic_cast <CRectangle *> (polygons[i]); if (rect != 0) { rect->set_values(10, 20); assert(rect->area() != 200); } } /* */ return 0; }
/** * Draw the board. * Should be properly decoupled, oops. */ void CGameBoard::Draw( void ) { CCircle Circle; UINT32 colCurrent; bool bHighlighted = false; for ( int y=0; y<m_iHeight; y++ ) { for ( int x=0; x<m_iWidth; x++ ) { switch( GetBoardPos( x, y ) ) { default: case BOARD_ERROR: assert_now( "Error with board" ); case EMPTY: colCurrent = colEMPTY; break; case PLAYER1: colCurrent = colPLAYER_ONE; break; case PLAYER2: colCurrent = colPLAYER_TWO; break; } const FLOAT32 fXPos = fPIECE_RADIUS+fPIECE_SPACING+(fPIECE_SPACING + fPIECE_RADIUS*2)*x; const FLOAT32 fYPos = fPIECE_RADIUS+fPIECE_SPACING+(fPIECE_SPACING + fPIECE_RADIUS*2)*y; Circle.Initialise( SFVec2( fXPos, fYPos ), fPIECE_RADIUS ); CConnect4Context::GetInstance().DrawFilledCircle( Circle, colCurrent ); if ( false == bHighlighted ) { if ( m_iColumnHighlighted == x ) { CConnect4Context::GetInstance().DrawCircle( Circle, colHIGHLIGHT ); } } } } }
void CMole::Draw( void ) { m_pSprite->RenderEx( m_vPosition.X(), m_vPosition.Y(), m_fHeading, 1.0f, 1.0f ); if ( m_bHighlighted ) { CCircle Bounds; Bounds.Initialise( m_vPosition, fMOLE_RADIUS ); CMMMContext::GetInstance().DrawCircle( Bounds, 0xFFFF0000 ); } #ifndef _EDITOR if (CMMMContext::GetInstance().IsDrawingMoleState()) { CCircle radiusCircle; radiusCircle.Initialise(m_vPosition, fMOLE_RADIUS); CMMMContext::GetInstance().DrawCircle(radiusCircle, 0xFF00FF00); CCircle destinationCircle; destinationCircle.Initialise(m_vDestination, 5.0f ); CMMMContext::GetInstance().DrawCircle(destinationCircle, 0xFF8800FF); } m_pMoleAgent->Draw(); #endif }
void CMole::Draw(bool _bDrawKnownAcorns) { _bDrawKnownAcorns; m_pSprite->RenderEx( m_vPosition.X(), m_vPosition.Y(), m_fHeading, 1.0f, 1.0f ); //if ( m_bHighlighted ) { CCircle Bounds; Bounds.Initialise( m_vPosition, m_fRadius ); CMMMContext::GetInstance().DrawCircle( Bounds, 0xFFFF0000 ); } #ifndef _EDITOR DrawWhiskers(); DrawTaskPathTarget(m_Tasks.top()); if (m_Tasks.top().GetType() == CTask::TYPE_PATROL) { DrawTargetAcorn(m_Tasks.top().GetAcorn()); } DrawTaskType(); m_Repulsor.Draw(); DrawSteeringForce(); if (_bDrawKnownAcorns) { DrawKnownAcorns(); } #endif }
int main() { CCircle circle; double input_radius; cout << "CS138 C++ Final Project" << endl; cout << "Cameron Carroll --- Fall 2012" << endl; cout << endl; cout << "Please enter a circle radius: "; cin >> input_radius; circle.setRadius(input_radius); cout << "Your circle radius is: " << circle.getRadius() << endl; cout << "Area: " << circle.getArea() << endl; cout << "Diameter: " << circle.getDiameter() << endl; cout << "Circumference: " << circle.getCircumference() << endl; }
void CPathFindingAgent::Draw() const { if (m_path.size() > 1) { for (UINT32 uiIndex = 0; uiIndex < m_path.size() - 1; uiIndex++) { CCircle waypointCircle; waypointCircle.Initialise(m_path[uiIndex]->GetPosition(), 5.0f); CMMMContext::GetInstance().DrawCircle(waypointCircle, 0xFFBFBD2B); CMMMContext::GetInstance().DrawLine(m_path[uiIndex]->GetPosition(), m_path[uiIndex + 1]->GetPosition(), 0xFFBFBD2B); } CCircle waypointCircle; waypointCircle.Initialise(m_path.back()->GetPosition(), 5.0f); CMMMContext::GetInstance().DrawCircle(waypointCircle, 0xFFBFBD2B); CCircle destinationCircle; destinationCircle.Initialise(m_vDestination, fGRID_SIZE); CMMMContext::GetInstance().DrawCircle(destinationCircle, 0xFFBFBD2B); } }
void CMole::Update(float _fTimeDelta, CSquirrel& _rSquirrel) { // Check interection with squirrel CCircle Bounds; Bounds.Initialise( m_vPosition, m_fRadius ); if (_rSquirrel.Intersects(Bounds)) { _rSquirrel.LoseLife(); } if (!m_Tasks.empty()) { ProcessStuckManager(_fTimeDelta); CTask& rCurrentTask = m_Tasks.top(); // Check if mole is not patrolling if (!m_bHasPatrolTask && rCurrentTask.GetType() != CTask::TYPE_PATROL || rCurrentTask.GetType() != CTask::TYPE_SNOOZE) { // Try and bags an acorn to patrol, if any BagsAcorn(); } switch (rCurrentTask.GetType()) { case CTask::TYPE_EXPLORE: ProcessExplore(_fTimeDelta, rCurrentTask); break; case CTask::TYPE_PATROL: ProcessPatrol(_fTimeDelta, rCurrentTask); break; case CTask::TYPE_SNOOZE: ProcessSnooze(_fTimeDelta, rCurrentTask); break; case CTask::TYPE_HUNT: ProcessHunt(_fTimeDelta, rCurrentTask); break; case CTask::TYPE_STUCK: ProcessStuck(_fTimeDelta, rCurrentTask); break; } } else { assert_now("Mole has no assignments"); } s_pSharedPath->NotifyAccessablePosition(m_vPosition, m_fRadius); UpdateWhiskers(); m_Repulsor.Initialise(m_vPosition, fMOLE_RADIUS, 40.0f); }
bool CSquirrel::Intersects( const CCircle& Circle ) const { CCircle Bounds; Bounds.Initialise( m_vPosition, m_fRadius ); return Circle.Overlaps( Bounds ); }
bool CMole::Intersects( const CBox2D& Box ) const { CCircle Bounds; Bounds.Initialise( m_vPosition, fMOLE_RADIUS ); return Box.Intersects( Bounds ); }
void CSquirrel::Update( FLOAT32 fTimeDelta ) { if ( 0 == m_uNumLives ) { return; } const static CFVec2 s_vMoveOffsets[] = { SFVec2( -1.0f, 0.0f ), //"Left", SFVec2( 1.0f, 0.0f ), //"Right", SFVec2( 0.0f, -1.0f ), //"Up", SFVec2( 0.0f, 1.0f ), //"Down" }; _COMPILE_ASSERT( _ARRAY_SIZE( s_vMoveOffsets ) == EMove_COUNT ); CFVec2 vMove = SFVec2( 0.0f, 0.0f ); for ( UINT32 i=0; i< EMove_COUNT; i++ ) { if ( m_Movements[i].m_bValue ) { vMove += s_vMoveOffsets[i]; } } // great, now we have the movement direction. if ( vMove.SquareMagnitude() != 0.0f ) { m_fDistTimeMoving += fTimeDelta; vMove.Normalise(); FLOAT32 fStep = 1.0f; CFVec2 vTestedMove = vMove * fTimeDelta * m_fSpeed * fStep; // now check the target position - is it embedded in any walls? CCircle TargetBounds; while ( fStep > 0.0f ) { TargetBounds.Initialise( m_vPosition + vTestedMove, m_fRadius ); if ( false == CMMMContext::GetInstance().CircleIntersectsGeometry( TargetBounds ) ) { break; // found a valid, allowable movement. } fStep -= 0.2f; vTestedMove = vMove * fTimeDelta * m_fSpeed * fStep; } // now update to the new position m_vPosition += vTestedMove; // finally what happens at the new position // is an acorn collected? if ( m_uNumAcorns != m_uMaxAcorns ) { CAcorn* pLevelAcorns; UINT32 uNumLevelAcorns; CMMMContext::GetInstance().GetAcorns( pLevelAcorns, uNumLevelAcorns ); for ( UINT32 i=0; i<uNumLevelAcorns; i++ ) { if ( pLevelAcorns[i].GetState() == CAcorn::ES_Available ) { if ( pLevelAcorns[i].Intersects( TargetBounds ) ) { pLevelAcorns[i].SetState( CAcorn::ES_Carried ); m_ppAcorns[m_uNumAcorns++] = pLevelAcorns+i; if ( m_uNumAcorns == m_uMaxAcorns ) { break; // cannont collect any more! } } } } } // is a tunnel reached? if ( m_uNumAcorns > 0 ) { CTunnel* pTunnels; UINT32 uNumTunnels; CMMMContext::GetInstance().GetTunnels( pTunnels, uNumTunnels ); for ( UINT32 i=0; i<uNumTunnels; i++ ) { if ( pTunnels[i].Intersects( TargetBounds ) ) { // reached the tunnel. for ( UINT32 i=0; i<m_uNumAcorns; i++ ) { m_ppAcorns[i]->SetState( CAcorn::ES_Collected ); m_uScore++; } m_uNumAcorns = 0; } } } } m_fTimeToDisturbance -= fTimeDelta; if ( m_fTimeToDisturbance <= 0.0f ) { // schedule the next disturbance. m_fTimeToDisturbance = FLOAT32(rand())/FLOAT32(RAND_MAX); m_fTimeToDisturbance *= m_fMaxDistSep-m_fMinDistSep; m_fTimeToDisturbance += m_fMinDistSep; // create this disturbance: FLOAT32 fRad = m_fLastDistDelay=0.0f?0.0f:m_fDistTimeMoving/m_fLastDistDelay; // DbgPrint( "Creating Disturbance strength %0.2f, next delay %0.2f\n", fRad,m_fTimeToDisturbance ); fRad *= m_fMaxDistRad-m_fMinDistRad; fRad += m_fMinDistRad; if ( fRad >= 0.0f ) { CCircle Dist; Dist.Initialise( m_vPosition, fRad ); CMMMContext::GetInstance().CreateDisturbance( Dist ); } m_fDistTimeMoving = 0.0f; m_fLastDistDelay = m_fTimeToDisturbance; } }
void CMole::UpdatePosition(float _fTimeDelta) { CCircle SelfCircle; CWall* pWalls = 0; CAcorn* pAcorns = 0; CMole* pMoles = 0; int iNumWalls = 0; int iNumAcorns = 0; int iNumMoles = 0; bool bCollision = false; // Create heading vector CFVec2 vHeading(0.0f, -1.0f); vHeading.RotateZ(m_fHeading); float fMovementVelocity = m_fMovementVelocity + (DIFFICULTY_MOVEMENT_VELOCITY_INCR * m_iDifficultyLevel); CFVec2 vNextPosition = m_vPosition; vNextPosition += vHeading * (fMovementVelocity * _fTimeDelta); SelfCircle.Initialise(vNextPosition, m_fRadius); CMMMContext& rMMMContext = CMMMContext::GetInstance(); rMMMContext.GetWalls(pWalls, iNumWalls); rMMMContext.GetAcorns(pAcorns, iNumAcorns); rMMMContext.GetMoles(pMoles, iNumMoles); CCircle EntityCircle; SelfCircle.Initialise(vNextPosition, m_fRadius); // Check collision against other moles for (int i = 0; i < iNumMoles; ++ i) { if (&pMoles[i] != this) { EntityCircle.Initialise(pMoles[i].GetPosition(), pMoles[i].GetRadius()); if (SelfCircle.Overlaps(EntityCircle)) { bCollision = true; break; } else { // Do nothing } } } if (!bCollision) { // Check collision against walls for (int i = 0; i < iNumWalls; ++ i) { if (SelfCircle.OverlapsLineSegment(pWalls[i].GetEnd0(), pWalls[i].GetEnd1())) { bCollision = true; break; } } } if (!bCollision) { m_vPosition = vNextPosition; } }
bool CMole::Intersects( const CCircle& Circle ) const { CCircle Bounds; Bounds.Initialise( m_vPosition, fMOLE_RADIUS ); return Circle.Overlaps( Bounds ); }
/** * @param Circle A circle to evaluate to see if it intersects the wall. * @return true if the circle intersects the wall. */ bool CWall::Intersects( const CCircle& Circle ) const { return Circle.OverlapsLineSegment( m_vEnd[0], m_vEnd[1] ); }
void CGetShapeInfo::Visit(CCircle& shape) { m_val = "CIRCLE: P=" + shape.GetPerimeter().ToString() + "; S=" + shape.GetSquare().ToString(); }