INTERSECTION_RESULT CROUNDSEGMENT2D::IsBBoxInside( const CBBOX2D &aBBox ) const
{
    if( !m_bbox.Intersects( aBBox ) )
        return INTR_MISSES;

    SFVEC2F v[4];

    v[0] = aBBox.Min();
    v[1] = aBBox.Max();
    v[2] = SFVEC2F( aBBox.Min().x, aBBox.Max().y );
    v[3] = SFVEC2F( aBBox.Max().x, aBBox.Min().y );

    bool isInside[4];

    isInside[0] = IsPointInside( v[0] );
    isInside[1] = IsPointInside( v[1] );
    isInside[2] = IsPointInside( v[2] );
    isInside[3] = IsPointInside( v[3] );

    // Check if all points are inside the circle
    if( isInside[0] &&
        isInside[1] &&
        isInside[2] &&
        isInside[3] )
        return INTR_FULL_INSIDE;

    // Check if any point is inside the circle
    if( isInside[0] ||
        isInside[1] ||
        isInside[2] ||
        isInside[3] )
        return INTR_INTERSECTS;

    return INTR_MISSES;
}
// Not tested, and there may be a better way...
bool IsOverlapping( Circle * pCirc, OBB * pOBB )
{
	for ( int i = 0; i < 4; i++ )
		if ( IsPointInside( GetVert( pOBB, i ), pCirc ) )
			return true;
	return IsPointInside( pCirc->v2Center, pOBB );
}
Beispiel #3
0
BOOL CImageWnd::OnLButtonDown(CPoint point)
{
   if (m_pAppWnd == NULL)
      return FALSE;

   if (IsPointInside(point))
   {
      CPoint pt = point - m_ViewRect.TopLeft();
      CWnd *pViewWnd;

      pViewWnd = m_pViewWnd != NULL ? m_pViewWnd : m_pAppWnd;

      // TrackRubberBand and Track methods capture the mouse and return when user releases left mouse button,
      // presses right mouse button or escape key.
      if (m_RectTracker.HitTest(pt) == CRectTracker::hitNothing)
      {
         m_RectTracker.m_nStyle = CRectTracker::resizeInside | CRectTracker::dottedLine;
         m_RectTracker.TrackRubberBand(pViewWnd, pt);
      }
      else
      {
         m_RectTracker.Track(pViewWnd, pt, FALSE, pViewWnd);
      }

      // normalize m_rect for 4th quadrant coordinates and limit according to scroll position
      m_RectTracker.m_rect.NormalizeRect();

      m_roi.TopLeft() = TranslatePos(m_RectTracker.m_rect.TopLeft());
      m_roi.BottomRight() = TranslatePos(m_RectTracker.m_rect.BottomRight());

      return TRUE;
   }

   return FALSE;
}
Beispiel #4
0
CPoint CImageWnd::TranslateMousePos(CPoint point)
{
   // Check that the position is inside the view rectangle
   if (!IsPointInside(point))
      return CPoint(0, 0);

   CPoint translatedPoint = point - m_ViewRect.TopLeft();

   return TranslatePos(translatedPoint);
}
Beispiel #5
0
bool UIList::SystemInput(UIEvent *currentInput)
{
	if(!inputEnabled || !visible || controlState & STATE_DISABLED)
	{
		return false;
	}

	if(currentInput->touchLocker != this)
	{
		if(currentInput->phase == UIEvent::PHASE_BEGAN)
		{
			if(IsPointInside(currentInput->point))
			{
				PerformEvent(EVENT_TOUCH_DOWN);
				Input(currentInput);
			}
		}
		else if(currentInput->tid == mainTouch && currentInput->phase == UIEvent::PHASE_DRAG)
		{
			if(orientation == ORIENTATION_HORIZONTAL)
			{
				if(abs(currentInput->point.x - newPos) > touchHoldSize)
				{
					UIControlSystem::Instance()->SwitchInputToControl(mainTouch, this);
					newPos = currentInput->point.x;
					return TRUE;
				}
			}
			else 
			{
				if(abs(currentInput->point.y - newPos) > touchHoldSize)
				{
					UIControlSystem::Instance()->SwitchInputToControl(mainTouch, this);
					newPos = currentInput->point.y;
					return TRUE;
				}
			}
		}
		else if(currentInput->tid == mainTouch && currentInput->phase == UIEvent::PHASE_ENDED)
		{
			mainTouch = 0;
			lockTouch = false;
		}

		

	}

	return UIControl::SystemInput(currentInput);
}
Beispiel #6
0
bool CUIChatText::OnTextClick(CCPoint touchPos)
{
	int index = 0;
	bool isfound = false;

	std::vector<NDNode*> vChildren = this->GetChildren();
	for (std::vector<NDNode*>::iterator it = vChildren.begin(); it != vChildren.end(); it++)
	{
		NDUINode* uinode = dynamic_cast<NDUINode*> (*it);
		if (uinode && IsPointInside(touchPos, uinode->GetScreenRect()))
		{
			//NDLog(@"click on chat ui node");
			isfound=true;
			break;
		}
		index++;
	}

	if(!isfound)
	{
		return false;
	}

	ChatNode cnode = this->textNodeList[index];

	if (cnode.textType==ChatSpeaker)
	{
		//NDLog(@"click on chat speaker:%d",cnode.content_id);
		BaseScriptMgrObj.excuteLuaFunc<bool>("OnChatNodeClick", "ChatDataFunc",
			(int)cnode.textType,cnode.content_id,this->speakerName);
	}
	else if(cnode.textType==ChatItem)
	{
		//NDLog(@"click on chat item:%d",cnode.content_id);
		BaseScriptMgrObj.excuteLuaFunc<bool>("OnChatNodeClick", "ChatDataFunc",
			(int)cnode.textType,cnode.content_id,"");
	}
	else if (cnode.textType==ChatRole)
	{
		//NDLog(@"click on chat Role:%d",cnode.content_id);
		BaseScriptMgrObj.excuteLuaFunc<bool>("OnChatNodeClick", "ChatDataFunc",
			(int)cnode.textType,cnode.content_id,cnode.content_str);
	}
	else
	{
		//NDLog(@"click nothing");
	}
	return true;
}
Beispiel #7
0
bool UIHierarchy::SystemInput(UIEvent *currentInput)
{
    if(!inputEnabled || !visible || controlState & STATE_DISABLED)
    {
        return false;
    }
    
    if(currentInput->touchLocker != this)
    {
        if(currentInput->phase == UIEvent::PHASE_BEGAN)
        {
            if(IsPointInside(currentInput->point))
            {
                PerformEvent(EVENT_TOUCH_DOWN);
                Input(currentInput);
            }
        }
        else if(currentInput->tid == mainTouch && currentInput->phase == UIEvent::PHASE_DRAG)
        {
            bool isCommandPressed =     InputSystem::Instance()->GetKeyboard()->IsKeyPressed(DVKEY_CTRL) 
                                    ||  InputSystem::Instance()->GetKeyboard()->IsKeyPressed(DVKEY_SHIFT);
            if(!isCommandPressed)
            {
                if(abs(currentInput->point.y - newPos) > touchHoldSize)
                {
                    UIControlSystem::Instance()->SwitchInputToControl(mainTouch, this);
                    newPos = currentInput->point.y;
                    return true;
                }
            }
            else
            {
                UIControlSystem::Instance()->SwitchInputToControl(mainTouch, this);
            }
        }
        else if(currentInput->tid == mainTouch && currentInput->phase == UIEvent::PHASE_ENDED)
        {
            mainTouch = 0;
            lockTouch = false;
        }
    }
    
    return UIControl::SystemInput(currentInput);
}
Beispiel #8
0
//do two AABBs intersect?
bool AA_BOUNDING_BOX::IsAABoundingBoxInside(const AA_BOUNDING_BOX & box) const
{
	//loop through vertices of the other box
	for(int i=0; i<8; ++i)
	{
		//if this vertex is in this box, return true
		if(IsPointInside(box.vertices[i]))
			return true;
	}

	//now see if any of our vertices are in the other box
	for(int i=0; i<8; ++i)
	{
		//if this vertex is in this box, return true
		if(box.IsPointInside(vertices[i]))
			return true;
	}

	return false;
}
Beispiel #9
0
CString CImageWnd::GetPixelString(CPoint point)
{
   if (!m_pView || !*m_pView || m_pView->GetBuffer() == NULL || !*m_pView->GetBuffer() || !m_pView->GetBuffer()->IsMapped() || !IsPointInside(point))
      return CImageWnd::GetPixelString(NULL, CPoint(0, 0));

   CPoint pt = TranslateMousePos(point);
   return CImageWnd::GetPixelString(m_pView->GetBuffer(), pt, m_PixelStringFormatDecimal);
}
bool CROUNDSEGMENT2D::Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const
{
    wxASSERT( aOutT );
    wxASSERT( aNormalOut );

    bool start_is_inside = IsPointInside( aSegRay.m_Start );
    bool end_is_inside = IsPointInside( aSegRay.m_End );

    // If segment if inside there are no hits
    if( start_is_inside && end_is_inside )
        return false;

    bool hitted = false;

    float closerHitT = FLT_MAX;
    float farHitT = FLT_MAX;

    SFVEC2F closerHitNormal;
    SFVEC2F farHitNormal;

    float leftSegT;
    bool leftSegmentHit = aSegRay.IntersectSegment( m_leftStart, m_leftEnd_minus_start, &leftSegT );

    if( leftSegmentHit )
    {
        hitted = true;
        closerHitT = leftSegT;
        farHitT    = leftSegT;

        closerHitNormal = SFVEC2F( -m_leftDir.y,  m_leftDir.x );
        farHitNormal    = SFVEC2F( -m_leftDir.y,  m_leftDir.x );
    }

    float rightSegT;
    bool rightSegmentHit = aSegRay.IntersectSegment( m_rightStart, m_rightEnd_minus_start, &rightSegT );

    if( rightSegmentHit )
    {
        if( !start_is_inside )
        if( (hitted == false) || (rightSegT < closerHitT) )
        {
            closerHitT = rightSegT;
            closerHitNormal = SFVEC2F( -m_rightDir.y,  m_rightDir.x );
        }

        if( start_is_inside )
        if( (hitted == false) || (rightSegT > farHitT) )
        {
            farHitT = rightSegT;
            farHitNormal = SFVEC2F( -m_rightDir.y,  m_rightDir.x );
        }

        hitted = true;
    }

    float   circleStart_T0;
    float   circleStart_T1;
    SFVEC2F circleStart_N0;
    SFVEC2F circleStart_N1;

    bool startCircleHit = aSegRay.IntersectCircle( m_segment.m_Start, m_radius,
                                                   &circleStart_T0, &circleStart_T1,
                                                   &circleStart_N0, &circleStart_N1 );

    if( startCircleHit )
    {
        if( circleStart_T0 > 0.0f )
        {
            if( !start_is_inside )
            if( (hitted == false) || (circleStart_T0 < closerHitT) )
            {
                closerHitT = circleStart_T0;
                closerHitNormal = circleStart_N0;
            }

            if( start_is_inside )
            if( (hitted == false) || (circleStart_T1 > farHitT) )
            {
                farHitT = circleStart_T1;
                farHitNormal = circleStart_N1;
            }
        }
        else
        {
            // This can only happen if the ray starts inside
            if( (hitted == false) || (circleStart_T1 > farHitT) )
            {
                farHitT = circleStart_T1;
                farHitNormal = circleStart_N1;
            }
        }

        hitted = true;
    }

    float   circleEnd_T0;
    float   circleEnd_T1;
    SFVEC2F circleEnd_N0;
    SFVEC2F circleEnd_N1;

    bool rightCircleHit = aSegRay.IntersectCircle( m_segment.m_End, m_radius,
                                                   &circleEnd_T0, &circleEnd_T1,
                                                   &circleEnd_N0, &circleEnd_N1 );
    if( rightCircleHit )
    {
        if( circleEnd_T0 > 0.0f )
        {
            if( !start_is_inside )
            if( (hitted == false) || (circleEnd_T0 < closerHitT) )
            {
                closerHitT = circleEnd_T0;
                closerHitNormal = circleEnd_N0;
            }

            if( start_is_inside )
            if( (hitted == false) || (circleEnd_T1 > farHitT) )
            {
                farHitT = circleEnd_T1;
                farHitNormal = circleEnd_N1;
            }
        }
        else
        {
            // This can only happen if the ray starts inside
            if( (hitted == false) || (circleEnd_T1 > farHitT) )
            {
                farHitT = circleEnd_T1;
                farHitNormal = circleEnd_N1;
            }
        }

        hitted = true;
    }

    if( hitted )
    {
        if( !start_is_inside )
        {
            *aOutT = closerHitT;
            //wxASSERT( (closerHitT > 0.0f) && (closerHitT <= 1.0f) );
            *aNormalOut = closerHitNormal;
        }
        else
        {
            wxASSERT( (farHitT > 0.0f) && (farHitT <= 1.0f) );
            *aOutT = farHitT;
            *aNormalOut = farHitNormal;
        }
    }

    return hitted;
}
CString CImageWnd::GetPixelString(CPoint point) 
{
   CString str = _T("[ Pixel data not available ]");

   // if there is no buffer to display, return right away
   if (m_pView == NULL || !(*m_pView) || m_pView->GetBuffer() == NULL || !m_pView->GetBuffer()->IsMapped())
      return str;

   if (IsPointInside(point) && *m_pView->GetBuffer())
	{
		CPoint pt = TranslateMousePos(point);

		// Get pixel value at cursor's position and create string according to pixel format
		CString text;
		SapFormat format = m_pView->GetBuffer()->GetFormat();

		if (format == SapFormatHSI || format == SapFormatHSIP8)
      {
         SapDataHSI data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld H:0x%04x S:0x%04x I:0x%04x ]"), pt.x, pt.y, data.H(), data.S(), data.I());
      }
		else if (format == SapFormatLAB || format == SapFormatLAB101010)
      {
         SapDataLAB data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld L:0x%04x A:0x%04x B:0x%04x ]"), pt.x, pt.y, data.L(), data.A(), data.B());
      }
		else if (format == SapFormatLAB16161616)
      {
         SapDataLABA data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld L:0x%04x A:0x%04x B:0x%04x ]"), pt.x, pt.y, data.L(), data.A(), data.B());
      }
		else if (format == SapFormatHSV)
      {
         SapDataHSV data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld H:0x%04x S:0x%04x V:0x%04x ]"), pt.x, pt.y, data.H(), data.S(), data.V());
      }
		else if (CORDATA_FORMAT_IS_YUV(format))
      {
         SapDataYUV data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld Y:0x%04x U:0x%04x V:0x%04x ]"), pt.x, pt.y, data.Y(), data.U(), data.V());
      }
		else if (CORDATA_FORMAT_IS_RGB(format))
      {
         if(format==SapFormatRGB16161616)
         {
            SapDataRGBA data;
            m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
            text.Format(_T("[ x:%03ld y:%03ld R:0x%04x G:0x%04x B:0x%04x ]"), pt.x, pt.y, data.Red(), data.Green(), data.Blue());
         }
         else
         {
            SapDataRGB data;
            m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
            text.Format(_T("[ x:%03ld y:%03ld R:0x%04x G:0x%04x B:0x%04x ]"), pt.x, pt.y, data.Red(), data.Green(), data.Blue());
         }
      }
		else if (format == SapFormatRGBP8 || format == SapFormatLABP8 || format == SapFormatRGBP16 || format == SapFormatLABP16)
      {

         SapData data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         SapDataRGB dataRGB = data;

         TCHAR fmtStr8[] = _T("[ x:%03ld y:%03ld value:%03d ]");
         TCHAR fmtStr16[] = _T("[ x:%03ld y:%03ld value:0x%04x ]");
         TCHAR* pFmtStr;

         if (format == SapFormatRGBP8 || format == SapFormatLABP8)
            pFmtStr = fmtStr8;
         else 
            pFmtStr = fmtStr16;

         int page;
         m_pView->GetBuffer()->GetParameter(CORBUFFER_PRM_PAGE,&page);

         if(page==0)
            text.Format(CString(pFmtStr), pt.x, pt.y, dataRGB.Red());
         else if(page==1)
            text.Format(CString(pFmtStr), pt.x, pt.y, dataRGB.Green());
         else if(page==2)
            text.Format(CString(pFmtStr), pt.x, pt.y, dataRGB.Blue());
      }
      else
      {
         SapDataMono data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld value:0x%04x ]"), pt.x, pt.y, data.Mono());
      }

		// Append string to application title
		str = _T("  ") + CString(text);
	}

	return str;
}