Ejemplo n.º 1
0
//----------------------------------------------------------------------------
void IntersectTriangleCylinder::OnIdle ()
{
    MeasureTime();

    if (MoveCamera())
    {
        mCuller.ComputeVisibleSet(mScene);
    }

    if (MoveObject())
    {
        mScene->Update();
        mCuller.ComputeVisibleSet(mScene);
        TestIntersection();
    }

    if (mRenderer->PreDraw())
    {
        mRenderer->ClearBuffers();
        mRenderer->Draw(mCuller.GetVisibleSet());
        //DrawFrameRate(8, GetHeight()-8, mTextColor);
        mRenderer->PostDraw();
        mRenderer->DisplayColorBuffer();
    }

    UpdateFrameCount();
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------------
void TestTriTri::GetIntersecting ()
{
    Vector2 akV0[3], akV1[3];
    for (int i = 0; i < 3; i++)
    {
        akV0[i].x = (Real) m_aiX0[i];
        akV0[i].y = (Real) m_aiY0[i];
        akV1[i].x = (Real) m_aiX1[i];
        akV1[i].y = (Real) m_aiY1[i];
    }

    Vector2 kW0, kW1;
    Real fTLast, fTMax = 1.0;
    m_iQuantity = 0;

    switch ( m_eType )
    {
    case TT_TEST:
        m_bIntersecting = TestIntersection(akV0,akV1);
        break;
    case TT_FIND:
        m_bIntersecting = FindIntersection(akV0,akV1,m_iQuantity,
            m_akVertex);
        break;
    case TT_TEST_VEL:
        kW0 = GetVelocity(m_uiSpeed0,m_uiAngle0);
        kW1 = GetVelocity(m_uiSpeed1,m_uiAngle1);
        m_bIntersecting = TestIntersection(fTMax,akV0,kW0,akV1,kW1,
            m_fTFirst,fTLast);
        break;
    case TT_FIND_VEL:
        kW0 = GetVelocity(m_uiSpeed0,m_uiAngle0);
        kW1 = GetVelocity(m_uiSpeed1,m_uiAngle1);
        m_bIntersecting = FindIntersection(fTMax,akV0,kW0,akV1,kW1,
            m_fTFirst,fTLast,m_iQuantity,m_akVertex);
        break;
    }

    InvalidateRect(GetWindowHandle(),NULL,TRUE);
}
//Checks for line intersections and adjusts color accordingly
void update()
{
	//Each update we must be sure to update the convex hulls with the current orientation of the polygons
	convexHull1.rotation = poly1.rotation;
	convexHull2.rotation = poly2.rotation;

	//test if they are intersection. If so, change the color of the line segment.
	if (TestIntersection(convexHull1, poly1.center, convexHull2, poly2.center))
	{
		//Decouple
		DecoupleObjects(poly1, poly2, minimumTranslationVector, overlap);
	}
}
Ejemplo n.º 4
0
bool Rect< TReal >::SetIntersect( const Rect& A, const Rect& B )
{
	bool intersects = TestIntersection( A, B );

	if ( intersects )
	{
		Set( 
			Math< TReal >::Max( A.Left,   B.Left   ),
			Math< TReal >::Max( A.Top,    B.Top    ),
			Math< TReal >::Min( A.Right,  B.Right  ),
			Math< TReal >::Min( A.Bottom, B.Bottom )
		);
	}

	return intersects;
}
Ejemplo n.º 5
0
bool Rect< TReal >::Intersect( TReal left, TReal top, TReal right, TReal bottom )
{
	bool intersects = TestIntersection( left, top, right, bottom );

	if ( intersects )
	{
		Set( 
			Math< TReal >::Max( Left,   left   ),
			Math< TReal >::Max( Top,    top    ),
			Math< TReal >::Min( Right,  right  ),
			Math< TReal >::Min( Bottom, bottom )
		);
	}

	return intersects;
}
Ejemplo n.º 6
0
int main( int argc, char **argv )
{
  int num_sample=100000;
  int t0=clock();
  InitRandom(100000);
  int t1=clock();

  ///Initialization performance
  printf("** Time elapsed for initialization of %d sample is %d\n \n",num_sample,t1-t0);
  Hash2D.Set(Allocated.begin(),Allocated.end());

  ///Box Query performance
  t0=clock();
  MyScalarType avg_test=TestBox(num_sample);
  t1=clock();
  printf("** Time elapsed for %d BOX queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_test);
  

  ///Intersecting segment performance
  t0=clock();
  MyScalarType avg_int=TestIntersection(num_sample);
  t1=clock();
  printf("** Time elapsed for %d INTERSECTION queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_int);
	
  ///closest test
  t0=clock();
  MyScalarType avg_clos=TestClosest(num_sample);
  t1=clock();
  printf("** Time elapsed for %d CLOSEST queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_clos);
	
 ///reinitialize structure
  MyMark.mark=0;
  Hash2D.Clear();
  int n_test=1000;
  InitRandom(n_test,100,0.1);
  Hash2D.Set(Allocated.begin(),Allocated.end());

  int tested_int=TestCorrectIntersect(n_test);
  printf("** Correct Intersect on %d test are %d \n",n_test,tested_int);
	
  int tested_clos=TestCorrectClosest(n_test);
  printf("** Correct Closest on %d test are %d \n",n_test,tested_clos);

  return 0;
}
bool ApplicationClass::HandleInput()
{
	bool result;
	int mouseX, mouseY;


	// Do the input frame processing.
	result = m_Input->Frame();
	if(!result)
	{
		return false;
	}

	// Check if the user pressed escape and wants to exit the application.
	if(m_Input->IsEscapePressed() == true)
	{
		return false;
	}

	// Check if the left mouse button has been pressed.
	if(m_Input->IsLeftMouseButtonDown() == true)
	{
		// If they have clicked on the screen with the mouse then perform an intersection test.
		if(m_beginCheck == false)
		{
			m_beginCheck = true;
			m_Input->GetMouseLocation(mouseX, mouseY);
			TestIntersection(mouseX, mouseY);
		}
	}

	// Check if the left mouse button has been released.
	if(m_Input->IsLeftMouseButtonDown() == false)
	{
		m_beginCheck = false;
	}

	return true;
}
Ejemplo n.º 8
0
//	ProximityCheck()
//	this function will take the pieces close enough to be
//	attached to another and checks if this linkage is possible
//	this function is used in the PutOn/Below function
//	the boolean variable will indicate an above or a below connection
//	this function will restore the original location of the block before returning
bool VDSBuildingBlock::ProximityCheck( VDSBuildingBlock& Parent, bool above )
{
    /// this is added to make old files work
    // some double wheels weren't added after the modification which was made there
    // maybe that was because i changed the way the
   // return true;
	//	i will store its current position to restore in case of failure
	//	before making the AABB test
	//	i will change a little in the bounding box data (shrinking a little)
	//	to make the check more reliable
	//	first i will calculate the store the y location and change it
	//	as if the pieces are attached
	//	in case of failure..i will restore it
	//	also..i will shrink the dimensions a little for better handling

	//	we need 2 boxes..a box here and a box at the parent
	//	these boxes changes if above or not
	VDSGeom*	pThisBox;
	VDSGeom*	pParentBox;


	//	get the y position of the parent..to move the bounding box just above it
	float	OldY;			//	old y position of bounding box (restored in case of failure)
	TSRMatrix4 ParentMat;		//	Get The parent matrix here


	//	set the pointers according to the above boolean variable
	if ( above )
	{
		pThisBox	=	m_pLowerBox;
		pParentBox	=	Parent.m_pUpperBox;
	}
	else
	{
		pThisBox	=	m_pUpperBox;
		pParentBox	=	Parent.m_pLowerBox;
	}

	//	get the matrix of the end of the parent
	//	(the part where we will put)
	pParentBox->GetWorldMatrix( ParentMat );

	//	make the matrix y in the bounding box here just above it
	//	as if it is there
	OldY = pThisBox->m_Transform._42;

	//	above or below will determine the y position to bring the block to
	if ( above )
    {
	    pThisBox->m_Transform._42 = ParentMat._42 + ( ( pThisBox->m_Dimensions.y + pParentBox->m_Dimensions.y ) / 2.0f );
    }
	else
    {
		pThisBox->m_Transform._42 = ParentMat._42 - ( ( pThisBox->m_Dimensions.y + pParentBox->m_Dimensions.y ) / 2.0f );
    }

	//	shrink it a little..
	TSRVector3 olddims;
	olddims = pThisBox->m_Dimensions;
	pThisBox->m_Dimensions = 0.95f * pThisBox->m_Dimensions;

	//	make the AABB test now
	if ( TestIntersection( Parent ) == false )
	{
		//	failure..restore data..
		pThisBox->m_Transform._42 = OldY;
		pThisBox->m_Dimensions    = olddims;
		return false;
	}
	pThisBox->m_Dimensions = olddims;
	return true;
}
Ejemplo n.º 9
0
void CQuadTree::AddReference( Box3f box, CEntity * pEntity, CQuadNode * node )  {

    assert( m_iLevels > 1 ); 

    int iNumInside = 0;

    Box3f boxTemp =  box;
    Box3f boxEnt = *pEntity->GetBoundingBox();

    // move box to the entity's height
    boxTemp.Center().Y() = boxEnt.Center().Y();
    boxTemp.Extent(1) = 100.0f; //extend this box infinitely

    bool bEntInQuad = false;

    Vector3f vBoxVerts[8];
    bool abValid[8] = { 1,1,1,1,1,1,1,1 };//{ 0,0,0,0,0,0,0,0 };
    bool bEntBoxInNode = false;
    bool bNodeInEntBox = false;

    //switch(TestIntersection( boxTemp,  boxEnt ) ) 
    switch(TestIntersection( boxEnt, boxTemp ) ) 
    {
        case true:  // box intersects
            node->m_EntMap[pEntity->GetId()] = pEntity; 
            bEntInQuad = true;  // find if the children intersect too
            break;

        case false:  // ent box is INSIDE or OUTSIDE the node
            // get vertices for the bounding box                
            boxEnt.ComputeVertices(vBoxVerts);

            // if entities box is contained in node box
            for (int j=0; j<8; j++ ) {
                if (InBox( vBoxVerts[j], boxTemp))  {
                    bEntBoxInNode = true;
                }
            }

            if (bEntBoxInNode == true)  {
            //if (ContOrientedBox (8, vBoxVerts, abValid, node->m_BBox))  {
                node->m_EntMap[pEntity->GetId()] = pEntity; //entity is in this node
                bEntInQuad = true;  // find out what child quads also contain this
                iNumInside++;                
            }
            else { // OUTSIDE or entities box contains the bounding box!
                boxTemp.ComputeVertices(vBoxVerts);
                
                // if node box  is contained in entities box
                for (int j=0; j<8; j++ ) {
                    if (InBox( vBoxVerts[j], boxEnt))  {
                        bNodeInEntBox = true;
                    }
                }

                if (bNodeInEntBox == true)  {
                //if (ContOrientedBox (8, vBoxVerts, abValid, boxTemp))  {
                    node->m_EntMap[pEntity->GetId()] = pEntity; //entity is in this node
                    bEntInQuad = true;  // find out what child quads also contain this

                }
                else {
                    // entity is outside, so don't add
                    bEntInQuad = false;
                    return;
                }
            }
            break;
    }

    // now this box will also intersect/be contained in the children as well
    if (bEntInQuad == true )  {
        //check if we need to subdivide even further
        if (iNumInside >= MAX_ENTS_PER_NODE)  {
            m_iLevels++;  //increase the number of levels
            SubDivide(node, m_iLevels-1);
        }

        if (node->m_pChildNode[NE] != NULL)  {
            AddReference( node->m_pChildNode[NE]->m_BBox, pEntity, node->m_pChildNode[NE]);
            //node->m_pChildNode[NE]->m_EntMap[pEntity->GetId()] = pEntity;
        }
        if (node->m_pChildNode[NW] != NULL)  {
            AddReference( node->m_pChildNode[NW]->m_BBox, pEntity, node->m_pChildNode[NW]);
            //node->m_pChildNode[NW]->m_EntMap[pEntity->GetId()] = pEntity;
        }
        if (node->m_pChildNode[SE] != NULL)  {
            AddReference( node->m_pChildNode[SE]->m_BBox, pEntity, node->m_pChildNode[SE]);
            //node->m_pChildNode[SE]->m_EntMap[pEntity->GetId()] = pEntity;
        }
        if (node->m_pChildNode[SW] != NULL)  {
            AddReference( node->m_pChildNode[SW]->m_BBox, pEntity, node->m_pChildNode[SW]);
            //node->m_pChildNode[SW]->m_EntMap[pEntity->GetId()] = pEntity;
        }        
    }

    return;
}
Ejemplo n.º 10
0
bool Rect< TReal >::TestIntersection( const Rect& r ) const
{
	return TestIntersection( r.Left, r.Top, r.Right, r.Bottom );
}