Exemplo n.º 1
0
// Create a valley (similar to the Anti-Pointy test in the Testbed) and
// attach to the ground body.
void BodyContactTests::CreateValley()
{
	b2Assert(m_groundBody);
	float32 i;
	const float32 step = 1.0f;
	for (i = -10.0f; i < 10.0f; i+=step)
	{
		b2PolygonShape shape;
		const b2Vec2 vertices[] = {
			b2Vec2(i, -10.0f),
			b2Vec2(i+step, -10.0f),
			b2Vec2(0.0f, 15.0f)
		};
		shape.Set(vertices, B2_ARRAY_SIZE(vertices));
		m_groundBody->CreateFixture(&shape, 0.0f);
	}
	for (i = -10.0f; i < 35.0f; i+=step)
	{
		b2PolygonShape shape;
		const b2Vec2 vertices[] = {
			b2Vec2(-10.0f, i),
			b2Vec2(-10.0f, i+step),
			b2Vec2(0.0f, 15.0f)
		};
		shape.Set(vertices, B2_ARRAY_SIZE(vertices));
		m_groundBody->CreateFixture(&shape, 0.0f);

		const b2Vec2 vertices2[] = {
			b2Vec2(10.0f, i),
			b2Vec2(10.0f, i+step),
			b2Vec2(0.0f, 15.0f)
		};
		shape.Set(vertices2, B2_ARRAY_SIZE(vertices2));
		m_groundBody->CreateFixture(&shape, 0.0f);
	}
}
Exemplo n.º 2
0
// Draw a colored arrow rotated by angle, scaled by scale and at
// the viewport relative position using DebugDraw.
// With no transformation matrix applied, the arrow is drawn in box
// area (3.5f, 3.5f) (see Arrow::k_size) and the overall bounding box
// of the arrow is (-1.75f, -1.75f) to (1.75f, 1.75f).
void Arrow::DrawArrow(const b2Color &color, const float32 angle,
					  const float32 scale, const b2Vec2 &position)
{
	static const b2Vec2 square[] =
	{
		b2Vec2(0.25f, 1.0f), b2Vec2(0.25f, -1.0f),
		b2Vec2(-1.75f, -1.0f), b2Vec2(-1.75f, 1.0f)
	};
	static const b2Vec2 triangle[] =
	{
		b2Vec2(0.25f, 1.75f), b2Vec2(1.75f, 0.0f),
		b2Vec2(0.25f, -1.75f)
	};
	// Build the transformation matrix.
	glPushMatrix();
	glTranslatef(position.x, position.y, 0.0f);
	glRotatef(angle, 0.0f, 0.0f, 1.0f);
	glScalef(scale, scale, 1.0f);
	// Draw the arrow.
	DebugDraw dbgDraw;
	dbgDraw.DrawFlatPolygon(square, B2_ARRAY_SIZE(square), color);
	dbgDraw.DrawFlatPolygon(triangle, B2_ARRAY_SIZE(triangle), color);
	glPopMatrix();
}
Exemplo n.º 3
0
// Add a set of items to a free list, allocate a couple and free them.
TEST_F(FreeListTests, AllocateAndFree)
{
	b2FreeList freeList;
	b2IntrusiveListNode nodes[10];
	b2IntrusiveListNode *allocated[B2_ARRAY_SIZE(nodes) / 2];
	// Add nodes to the free list.
	for (uint32 i = 0; i < B2_ARRAY_SIZE(nodes); ++i)
	{
		freeList.AddToFreeList(&nodes[i]);
	}

	// Allocate nodes.
	std::set<const b2IntrusiveListNode*> allocatedSet;
	for (uint32 i = 0; i < B2_ARRAY_SIZE(allocated); ++i)
	{
		allocated[i] = freeList.Allocate();
		EXPECT_TRUE(NULL != allocated[i]);
		// Make sure each allocated node is unique.
		std::pair<std::set<const b2IntrusiveListNode*>::iterator, bool> it =
			allocatedSet.insert(allocated[i]);
		EXPECT_TRUE(it.second);
	}

	// Verify the allocated nodes are tracked by the free list.
	const b2IntrusiveListNode& allocatedList = freeList.GetAllocatedList();
	const b2IntrusiveListNode* allocatedTerminator =
		allocatedList.GetTerminator();
	for (const b2IntrusiveListNode *allocatedNode = allocatedList.GetNext();
		 allocatedNode != allocatedTerminator;
		 allocatedNode = allocatedNode->GetNext())
	{
		EXPECT_EQ(1U, allocatedSet.count(allocatedNode));
	}

	EXPECT_EQ(B2_ARRAY_SIZE(nodes) - B2_ARRAY_SIZE(allocated),
			  freeList.GetFreeList().GetLength());

	// Free nodes.
	for (uint32 i = 0; i < B2_ARRAY_SIZE(allocated); ++i)
	{
		freeList.Free(allocated[i]);
	}

	EXPECT_TRUE(freeList.GetAllocatedList().IsEmpty());
	EXPECT_FALSE(freeList.GetFreeList().IsEmpty());
}
// Reset to the default state.
void ParticleParameter::Reset(){
	m_restartOnChange = true;
	m_index = 0;
	SetDefinition(k_defaultDefinition, B2_ARRAY_SIZE(k_defaultDefinition));
	Set(0);
}
const ParticleParameter::Value ParticleParameter::k_particleTypes[] ={
	{ b2_waterParticle, ParticleParameter::k_DefaultOptions, "water" },
	{ b2_waterParticle, ParticleParameter::k_DefaultOptions | ParticleParameter::OptionStrictContacts, "water (strict)" },
	{ b2_springParticle, ParticleParameter::k_DefaultOptions, "spring" },
	{ b2_elasticParticle, ParticleParameter::k_DefaultOptions, "elastic" },
	{ b2_viscousParticle, ParticleParameter::k_DefaultOptions, "viscous" },
	{ b2_powderParticle, ParticleParameter::k_DefaultOptions, "powder" },
	{ b2_tensileParticle, ParticleParameter::k_DefaultOptions, "tensile" },
	{ b2_wallParticle, ParticleParameter::k_DefaultOptions, "wall" },
	{ b2_barrierParticle | b2_wallParticle, ParticleParameter::k_DefaultOptions, "barrier" },
	{ b2_staticPressureParticle, ParticleParameter::k_DefaultOptions, "static pressure" },
	{ b2_waterParticle, ParticleParameter::k_DefaultOptions | ParticleParameter::OptionDrawAABBs, "water (bounding boxes)" },
};
const ParticleParameter::Value *ParticleParameter::k_particleTypesPtr =	ParticleParameter::k_particleTypes;
const uint32 ParticleParameter::k_particleTypesCount = B2_ARRAY_SIZE(ParticleParameter::k_particleTypes);
const ParticleParameter::Definition ParticleParameter::k_defaultDefinition[] ={
	{ParticleParameter::k_particleTypes,	ParticleParameter::k_particleTypesCount },
};

// Reset to the default state.
void ParticleParameter::Reset(){
	m_restartOnChange = true;
	m_index = 0;
	SetDefinition(k_defaultDefinition, B2_ARRAY_SIZE(k_defaultDefinition));
	Set(0);
}

// Set the parameter definition.
void ParticleParameter::SetDefinition(const Definition *definition, uint32 definitionCount){
	m_definition = definition;
Exemplo n.º 6
0
    // Test selection arrows.
    Arrow(Arrow::e_angleRight, FullscreenUI::k_arrowScale,
    b2Vec2(1.0f - FullscreenUI::k_arrowTestX, 0.0f),
    e_SelectionTestNext, &b2Vec2_zero, &b2Vec2_zero),
    Arrow(Arrow::e_angleLeft, FullscreenUI::k_arrowScale,
    b2Vec2(-1.0f + FullscreenUI::k_arrowTestX, 0.0f),
    e_SelectionTestPrevious, &b2Vec2_zero, &b2Vec2_zero),
    // Particle parameter selection arrows.
    Arrow(Arrow::e_angleRight, FullscreenUI::k_arrowScaleSmall,
    b2Vec2(1.0f - FullscreenUI::k_arrowParticleParameterX, 0.0f),
    e_SelectionParameterNext, &b2Vec2_zero, &b2Vec2_zero),
    Arrow(Arrow::e_angleLeft, FullscreenUI::k_arrowScaleSmall,
    b2Vec2(-1.0f + FullscreenUI::k_arrowParticleParameterX, 0.0f),
    e_SelectionParameterPrevious, &b2Vec2_zero, &b2Vec2_zero),
};
const uint32 FullscreenUI::k_numArrows = B2_ARRAY_SIZE(FullscreenUI::s_arrows);

FullscreenUI::FullscreenUI()
{
    Reset();
    m_enabled = k_enabledDefault;
}

// Reset the UI to it's initial state.
void FullscreenUI::Reset()
{
    m_selection = e_SelectionNone;
    m_particleParameterSelectionEnabled = false;
    m_aspectRatio = 1;
}
Exemplo n.º 7
0
void DestructionListener::SayGoodbye(b2ParticleGroup* group){
	test->ParticleGroupDestroyed(group);
}

const b2ParticleColor Test::k_ParticleColors[] = {
	b2ParticleColor(0xff, 0x00, 0x00, 0xff), // red
	b2ParticleColor(0x00, 0xff, 0x00, 0xff), // green
	b2ParticleColor(0x00, 0x00, 0xff, 0xff), // blue
	b2ParticleColor(0xff, 0x8c, 0x00, 0xff), // orange
	b2ParticleColor(0x00, 0xce, 0xd1, 0xff), // turquoise
	b2ParticleColor(0xff, 0x00, 0xff, 0xff), // magenta
	b2ParticleColor(0xff, 0xd7, 0x00, 0xff), // gold
	b2ParticleColor(0x00, 0xff, 0xff, 0xff), // cyan
};
const uint32 Test::k_ParticleColorsCount = B2_ARRAY_SIZE(Test::k_ParticleColors);

Test::Test(){
	const b2ParticleSystemDef particleSystemDef;
	b2Vec2 gravity;
	gravity.Set(0.0f, -10.0f);
	m_world = new b2World(gravity);
	m_particleSystem = m_world->CreateParticleSystem(&particleSystemDef);
	m_bomb = NULL;
	m_textLine = 30;
	m_mouseJoint = NULL;
	m_pointCount = 0;

	m_destructionListener.test = this;
	m_world->SetDestructionListener(&m_destructionListener);
	m_world->SetContactListener(this);
Exemplo n.º 8
0
{
	test->ParticleGroupDestroyed(group);
}

const b2ParticleColor Test::k_ParticleColors[] = {
	b2ParticleColor(0xff, 0x00, 0x00, 0xff), // red
	b2ParticleColor(0x00, 0xff, 0x00, 0xff), // green
	b2ParticleColor(0x00, 0x00, 0xff, 0xff), // blue
	b2ParticleColor(0xff, 0x8c, 0x00, 0xff), // orange
	b2ParticleColor(0x00, 0xce, 0xd1, 0xff), // turquoise
	b2ParticleColor(0xff, 0x00, 0xff, 0xff), // magenta
	b2ParticleColor(0xff, 0xd7, 0x00, 0xff), // gold
	b2ParticleColor(0x00, 0xff, 0xff, 0xff), // cyan
};
const uint32 Test::k_ParticleColorsCount =
	B2_ARRAY_SIZE(Test::k_ParticleColors);

Test::Test()
{
	const b2ParticleSystemDef particleSystemDef;
	b2Vec2 gravity;
	gravity.Set(0.0f, -10.0f);
	m_world = new b2World(gravity);
	m_particleSystem = m_world->CreateParticleSystem(&particleSystemDef);

	m_bomb = NULL;
	m_textLine = 30;
	m_mouseJoint = NULL;
	m_pointCount = 0;

	m_destructionListener.test = this;