// Render scene helpers.
void CViewerScene::RenderHelpers()
{
    glUseProgram(0);
    m_pRenderer->GetProjectionMatrix(m_mProjection);
    m_pRenderer->GetViewMatrix(m_mView);
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf(m_mProjection.f);

    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf(m_mView.f);
    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);

    if (m_bShowAABB)
    {
        if (m_pCurActor)
        {
            DrawOBB(m_pCurActor->GetPhysicalObject()->GetOBB());
        }
    }

    if (m_bShowGrid)
    {
        DrawCoordGrid(50, 2, 10);
    }

    glEnable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
}
void BipartiteBoxPruningTest::PerformTest()
{
	UpdateBoxes();

	// We pretend that half the boxes belong to first group, and the other half to the second group.
	udword Nb0 = mNbBoxes/2;
	udword Nb1 = mNbBoxes - Nb0;

	mPairs.ResetPairs();
	mProfiler.Start();
	BipartiteBoxPruning(Nb0, mBoxPtrs, Nb1, mBoxPtrs+Nb0, mPairs, Axes(AXES_XZY));
	mProfiler.End();
	mProfiler.Accum();

//	printf("%d pairs colliding\r     ", mPairs.GetNbPairs());

	bool* Flags = (bool*)_alloca(sizeof(bool)*mNbBoxes);
	ZeroMemory(Flags, sizeof(bool)*mNbBoxes);
	const Pair* P = mPairs.GetPairs();
	for(udword i=0;i<mPairs.GetNbPairs();i++)
	{
		// A colliding pair is (i,j) where 0 <= i < Nb0 and 0 <= j < Nb1
		Flags[P[i].id0] = true;
		Flags[P[i].id1+Nb0] = true;
	}

	// Render boxes
	OBB CurrentBox;
	CurrentBox.mRot.Identity();
	for(udword i=0;i<mNbBoxes;i++)
	{
		if(Flags[i])	glColor3f(1.0f, 0.0f, 0.0f);
		else
		{
			if(i<Nb0)
				glColor3f(0.0f, 1.0f, 0.0f);
			else
				glColor3f(0.0f, 0.0f, 1.0f);
		}
		mBoxes[i].GetCenter(CurrentBox.mCenter);
		mBoxes[i].GetExtents(CurrentBox.mExtents);
		DrawOBB(CurrentBox);
	}

	char Buffer[4096];
	sprintf(Buffer, "BipartiteBoxPruning - %5.1f us (%d cycles) - %d pairs\n", mProfiler.mMsTime, mProfiler.mCycles, mPairs.GetNbPairs());
	GLFontRenderer::print(10.0f, 10.0f, 0.02f, Buffer);
}
void OBBMeshQuery::PerformTest()
{
	RenderTerrain();

	Matrix3x3 MX,MY,MZ;
	RotX(MX, mAngleX);
	RotY(MY, mAngleY);
	RotY(MZ, mAngleZ);
	mBox.mRot = MX * MY * MZ;

	DrawOBB(mBox);

	const Model* TM = GetTerrainModel();
	if(TM)
	{
		OBBCollider Collider;
		mSettings.SetupCollider(Collider);

		mProfiler.Start();
		bool Status = Collider.Collide(mCache, mBox, *TM, null, null);
		mProfiler.End();
		mProfiler.Accum();

		if(Status)
		{
			if(Collider.GetContactStatus())
			{
				udword NbTris = Collider.GetNbTouchedPrimitives();
				const udword* Indices = Collider.GetTouchedPrimitives();

				RenderTerrainTriangles(NbTris, Indices);
			}
		}
	}

	// Raycast hit
	if(mValidHit)
	{
		Point wp = mLocalHit + mBox.mCenter;
		DrawLine(wp, wp + Point(1.0f, 0.0f, 0.0f), Point(1,0,0), 1.0f);
		DrawLine(wp, wp + Point(0.0f, 1.0f, 0.0f), Point(0,1,0), 1.0f);
		DrawLine(wp, wp + Point(0.0f, 0.0f, 1.0f), Point(0,0,1), 1.0f);
	}

	char Buffer[4096];
	sprintf(Buffer, "OBB-mesh query = %5.1f us (%d cycles)\n", mProfiler.mMsTime, mProfiler.mCycles);
	GLFontRenderer::print(10.0f, 10.0f, 0.02f, Buffer);
}
void CompleteBoxPruningTest::PerformTest()
{
    int numBoxes = (mNbBoxes*percentUpdate)/100;
    if (m_firstTime)
    {
        numBoxes = mNbBoxes;
        m_firstTime = false;
    }

    mProfiler.Start();
    UpdateBoxes(numBoxes);

    mPairs.ResetPairs();



    CompleteBoxPruning(mNbBoxes, mBoxPtrs, mPairs, Axes(AXES_XZY));
    mProfiler.End();
    mProfiler.Accum();

//	printf("%d pairs colliding\r     ", mPairs.GetNbPairs());

    bool* Flags = (bool*)_alloca(sizeof(bool)*mNbBoxes);
    ZeroMemory(Flags, sizeof(bool)*mNbBoxes);
    const Pair* P = mPairs.GetPairs();
    for(udword i=0; i<mPairs.GetNbPairs(); i++)
    {
        Flags[P[i].id0] = true;
        Flags[P[i].id1] = true;
    }

    // Render boxes
    OBB CurrentBox;
    CurrentBox.mRot.Identity();
    for(udword i=0; i<mNbBoxes; i++)
    {
        if(Flags[i])	glColor3f(1.0f, 0.0f, 0.0f);
        else			glColor3f(0.0f, 1.0f, 0.0f);
        mBoxes[i].GetCenter(CurrentBox.mCenter);
        mBoxes[i].GetExtents(CurrentBox.mExtents);
        DrawOBB(CurrentBox);
    }

    char Buffer[4096];
    sprintf(Buffer, "CompleteBoxPruning:  %5.1f us (%d cycles) : %d pairs\n", mProfiler.mMsTime, mProfiler.mCycles, mPairs.GetNbPairs());
    GLFontRenderer::print(10.0f, 10.0f, 0.02f, Buffer);
}
示例#5
0
void BatchRenderer::DrawViewFrustum( const ViewFrustum& frustum, const FColor& color )
{
	Vec3D	frustumCorners[8];
	frustum.CalculateCornerPoints( frustumCorners );

#if 1

#define DBG_DRAW_LINE(pointA,pointB)	\
	DrawLine3D( pointA, pointB, color, color );

	DBG_DRAW_LINE(frustumCorners[0],frustumCorners[1]);
	DBG_DRAW_LINE(frustumCorners[2],frustumCorners[3]);
	DBG_DRAW_LINE(frustumCorners[4],frustumCorners[5]);
	DBG_DRAW_LINE(frustumCorners[6],frustumCorners[7]);


	// far plane
	DBG_DRAW_LINE(frustumCorners[0],frustumCorners[4]);
	DBG_DRAW_LINE(frustumCorners[0],frustumCorners[2]);
	DBG_DRAW_LINE(frustumCorners[2],frustumCorners[6]);
	DBG_DRAW_LINE(frustumCorners[4],frustumCorners[6]);

	// near plane
	DBG_DRAW_LINE(frustumCorners[1],frustumCorners[5]);
	DBG_DRAW_LINE(frustumCorners[3],frustumCorners[7]);
	DBG_DRAW_LINE(frustumCorners[3],frustumCorners[1]);
	DBG_DRAW_LINE(frustumCorners[7],frustumCorners[5]);

#undef DBG_DRAW_LINE

#else

	rxOOBB	obb;
	XNA::ComputeBoundingOrientedBoxFromPoints(
		&obb,
		8,
		&as_float3(frustumCorners[0]),
		sizeof(frustumCorners[0])
	);
	mxSTATIC_ASSERT(sizeof(frustumCorners[0]) == sizeof(XMFLOAT3));

	DrawOBB(obb,color);
#endif
}
示例#6
0
void PhysicsWorld::Render()
{
	const u32 kNumParticles = mParticles.size();
	for (u32 i = 0; i < kNumParticles; ++i)
	{
		mParticles[i]->Render();
	}

	const u32 kNumConstraints = mConstraints.size();
	for (u32 i = 0; i < kNumConstraints; ++i)
	{
		mConstraints[i]->Render();
	}

	const u32 kNumOBBs = mOBBs.size();
	for (u32 i = 0; i < kNumOBBs; ++i)
	{
		DrawOBB(mOBBs[i]);
	}
}
// Render scene helpers.
void CEffectViewerScene::RenderHelpers()
{
	glUseProgram(0);
    m_pRenderer->GetProjectionMatrix(m_mProjection);
	m_pRenderer->GetViewMatrix(m_mView);
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(m_mProjection.f);

    glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(m_mView.f);
    glDisable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);

	if (m_bShowAABB)
	{
        if (m_pCurNode)
        {
			DrawOBB(m_pCurNode->GetOBB());
        }
	}

	if (m_bShowGrid)
	{
		if (m_pCurPhysics)
		{
			glMatrixMode(GL_MODELVIEW);
			OGMatrix mWorld = m_pCurPhysics->GetWorldTransform();
			MatrixMultiply(mWorld, mWorld, m_mView);
			glLoadMatrixf(mWorld.f);
		}
		DrawCoordGrid(50, 2, 10);
	}

    glEnable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
}