void box2dDrawWorld(b2World* pWorld, float viewScale, float x, float y){ box2dDrawBegin(viewScale, x, y); for (b2Body* b = pWorld->GetBodyList(); b; b = b->GetNext()) { const b2Transform& xf = b->GetTransform(); for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) { if (b->IsActive() == false) { box2dDrawShape(f, xf, b2Color(0.5f, 0.5f, 0.3f)); } else if (b->GetType() == b2_staticBody) { box2dDrawShape(f, xf, b2Color(0.5f, 0.9f, 0.5f)); } else if (b->GetType() == b2_kinematicBody) { box2dDrawShape(f, xf, b2Color(0.5f, 0.5f, 0.9f)); } else if (b->IsAwake() == false) { box2dDrawShape(f, xf, b2Color(0.6f, 0.6f, 0.6f)); } else { box2dDrawShape(f, xf, b2Color(0.9f, 0.7f, 0.7f)); } } } box2dDrawEnd(); }
void Entity::draw() { b2Vec2 position = body->GetPosition(); glBegin(GL_POINTS); glVertex2f(position.x, position.y); glEnd(); b2Color color; if( body->IsAwake() ) color = b2Color(1,0,0); else color = b2Color(0,0,1); auto transform = body->GetTransform(); b2Vec2 vertices[b2_maxPolygonVertices]; for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext()) { b2PolygonShape* polygonShape = (b2PolygonShape*)f->GetShape(); for(int32 i=0; i<polygonShape->m_vertexCount; i++) vertices[i] = b2Mul( transform, polygonShape->m_vertices[i] ); DrawPolygon( vertices, polygonShape->m_vertexCount, color ); } }
void Box2DDebugDraw::DrawTransform(const b2Transform& xf) { b2Vec2 p1 = xf.p, p2; const float32 k_axisScale = 0.8f; p2 = p1 + b2Vec2(k_axisScale * xf.q.c, k_axisScale * xf.q.s); DrawSegment(p1, p2, b2Color(1.0f, 0.0f, 0.0f)); p2 = p1 + b2Vec2(-k_axisScale * xf.q.s, k_axisScale * xf.q.c); DrawSegment(p1, p2, b2Color(0.0f, 1.0f, 0.0f)); /*b2Vec2 p1 = xf.position, p2; const float32 k_axisScale = 0.4f; glBegin(GL_LINES); glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(p1.x, p1.y); p2 = p1 + k_axisScale * xf.R.col1; glVertex2f(p2.x, p2.y); glColor3f(0.0f, 1.0f, 0.0f); glVertex2f(p1.x, p1.y); p2 = p1 + k_axisScale * xf.R.col2; glVertex2f(p2.x, p2.y); glEnd();*/ }
void Level::render(Drawer& drawer) { b2Transform trans = mTop->GetTransform(); drawer.DrawShape(trans, mTop->GetFixtureList(), b2Color(1, 1, 1)); trans = mBot->GetTransform(); drawer.DrawShape(trans, mTop->GetFixtureList(), b2Color(1, 1, 1)); }
void GLESDebugDraw::DrawTransform(const b2Transform& xf) { b2Vec2 p1 = xf.p, p2; const float32 k_axisScale = 0.4f; p2 = p1 + k_axisScale * xf.q.GetXAxis(); DrawSegment(p1, p2, b2Color(1,0,0)); p2 = p1 + k_axisScale * xf.q.GetYAxis(); DrawSegment(p1,p2,b2Color(0,1,0)); }
void GLESDebugDraw::DrawTransform(const b2Transform& xf) { b2Vec2 p1 = xf.p, p2; const float32 k_axisScale = 0.4f; p2=b2Vec2(0,0); //p2 = p1 + k_axisScale * xf.R.col1; DrawSegment(p1,p2,b2Color(1,0,0)); //p2 = p1 + k_axisScale * xf.R.col2; DrawSegment(p1,p2,b2Color(0,1,0)); }
void DebugRenderer::DrawTransform (const b2Transform& xf) { const b2Vec2& p1 = xf.p; const float32 k_axisScale = 0.4f; const b2Vec2 p2 = p1 + k_axisScale * xf.q.GetXAxis(); DrawSegment(p1, p2, b2Color(1.0f, 0.0f, 0.0f)); const b2Vec2 p3 = p1 + k_axisScale * xf.q.GetYAxis(); DrawSegment(p1, p3, b2Color(0.0f, 1.0f, 0.0f)); }
DebugRenderer::~DebugRenderer () { #ifndef NO_DEBUG_RENDERER const float32 k_impulseScale = 0.1f; const float32 k_axisScale = 0.3f; const bool drawFrictionImpulse = true; const bool drawContactNormals = true; const bool drawContactImpulse = true; for (int i = 0; i < _pointCount; ++i) { const ContactPoint* point = &_points[i]; if (point->state == b2_addState) { DrawPoint(point->position, 0.2f, b2Color(0.3f, 0.95f, 0.3f)); } else if (point->state == b2_persistState) { DrawPoint(point->position, 0.1f, b2Color(0.3f, 0.3f, 0.95f)); } if (drawContactNormals) { const b2Vec2& p1 = point->position; const b2Vec2 p2 = p1 + k_axisScale * point->normal; DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.9f)); } if (drawContactImpulse) { const b2Vec2& p1 = point->position; const b2Vec2 p2 = p1 + k_impulseScale * point->normalImpulse * point->normal; DrawSegmentWithAlpha(p1, p2, b2Color(0.9f, 0.9f, 0.3f), 0.5f); } if (drawFrictionImpulse) { const b2Vec2 tangent = b2Cross(point->normal, 1.0f); const b2Vec2& p1 = point->position; const b2Vec2 p2 = p1 + k_impulseScale * point->tangentImpulse * tangent; DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } } for (int i = 0; i < _traceCount; ++i) { const TraceData* data = &_traceData[i]; DrawSegment(data->start, data->end, b2Color(0.9f, 0.0f, 0.0f)); DrawPoint(data->start, 0.2f, b2Color(0.0f, 0.95f, 0.3f)); DrawPoint(data->end, 0.2f, b2Color(0.3f, 0.7f, 0.0f)); } if (!_waterIntersectionPoints.empty()) DrawPolygon(&_waterIntersectionPoints[0], _waterIntersectionPoints.size(), b2Color(0.0f, 1.0f, 1.0f)); if (_enableTextureArray) glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D); glPopMatrix(); GL_checkError(); if (_activeProgram != 0) GLContext::get().ctx_glUseProgram(_activeProgram); #endif }
void DebugDraw::DrawTransform(const b2Transform& xf) { float lineProportion = 0.4f; b2Vec2 p1 = xf.p, p2; //red (X axis) p2 = p1 + (lineProportion * xf.q.GetXAxis()); this->DrawSegment(p1, p2, b2Color(255, 0, 0)); //green (Y axis) p2 = p1 + (lineProportion * xf.q.GetYAxis()); this->DrawSegment(p1, p2, b2Color(0, 255, 0)); }
ForceDef() : pos(b2Vec2_zero), force(0), radius(0), lifeTime(0), faction(0), sides(false), shapes(true), projectiles(true), pickups(false), primary(b2Color(1.f, 0.5f, 0.25f)), secondary(b2Color(0.5f, 0.5f, 0.25f)), tertiary(b2Color(1.f, 1.f, 1.f)) {}
static EnemyDef squDef() { //Blue square EnemyDef squ = EnemyDef(); squ.verticesMin = 4; squ.vertices = 4; squ.verticesMax = 4; squ.colPrim = b2Color(0, 0, 0.4f); squ.colSecn = b2Color(0, 0, 0.7f); squ.colTert = b2Color(0, 0.9f, 0); squ.faction = 1; squ.hpScale = 4; squ.upgradeSides = false; squ.size = 0.75f; return squ; }
static EnemyDef octDef() { //Black Octagon EnemyDef oct = EnemyDef(); oct.verticesMin = 8; oct.vertices = 8; oct.verticesMax = 8; oct.colPrim = b2Color(0, 0, 0); oct.colSecn = b2Color(0.9f, 0.9f, 0.9f); oct.colTert = b2Color(0, 1, 0); oct.faction = 1; oct.hpScale = 8; oct.upgradeSides = false; oct.size = 1.75f; return oct; }
static EnemyDef hepDef() { //Cyan Heptagon EnemyDef hep = EnemyDef(); hep.verticesMin = 7; hep.vertices = 7; hep.verticesMax = 7; hep.colPrim = b2Color(0, 0.4f, 0.4f); hep.colSecn = b2Color(0, 0.9f, 0.9f); hep.colTert = b2Color(1, 1, 1); hep.faction = 1; hep.hpScale = 7; hep.upgradeSides = false; hep.size = 1.5f; return hep; }
static EnemyDef hexDef() { //Red Hexagon EnemyDef hex = EnemyDef(); hex.verticesMin = 6; hex.vertices = 6; hex.verticesMax = 6; hex.colPrim = b2Color(0.4f, 0, 0); hex.colSecn = b2Color(0.9f, 0, 0); hex.colTert = b2Color(0, 0, 0); hex.faction = 1; hex.hpScale = 6; hex.upgradeSides = false; hex.size = 1.25f; return hex; }
static EnemyDef penDef() { //Yellow Pentagon EnemyDef pen = EnemyDef(); pen.verticesMin = 5; pen.vertices = 5; pen.verticesMax = 5; pen.colPrim = b2Color(0.3f, 0.3f, 0); pen.colSecn = b2Color(0.6f, 0.6f, 0); pen.colTert = b2Color(0, 0, 0.9f); pen.faction = 1; pen.hpScale = 5; pen.upgradeSides = false; pen.size = 1.f; return pen; }
static EnemyDef triDef() { //Pink triangle EnemyDef tri = EnemyDef(); tri.verticesMin = 3; tri.vertices = 3; tri.verticesMax = 3; tri.colPrim = b2Color(0.4f, 0.3f, 0.3f); tri.colSecn = b2Color(0.7f, 0.5f, 0.5f); tri.colTert = b2Color(0.9f, 1, 0); tri.faction = 1; tri.hpScale = 3; tri.upgradeSides = false; tri.size = 0.5f; return tri; }
void RaceManager::loadRaceFromTOML(const char *filename) { std::ifstream ifs(filename); toml::Parser parser(ifs); toml::Value documentRoot = parser.parse(); toml::Value* raceSettings = documentRoot.find("RaceSettings"); const toml::Array& racers = raceSettings->find("racers")->as<toml::Array>(); m_numRacers = racers.size(); m_controllers = new IController*[m_numRacers]; unsigned int i = 0; for (const toml::Value& racer : racers) { // To be used :) std::string racer_name = racer.find("name")->as<std::string>(); std::string racer_type = racer.find("type")->as<std::string>(); const toml::Value *color = racer.find("color"); TopdownCar * car = new TopdownCar(i, b2Color(color->find("r")->as<double>(), color->find("g")->as<double>(), color->find("b")->as<double>())); car->setPosition(TRACK->getSectorPoint(0).center); if (racer_type.compare("basic_ai") == 0) { m_controllers[i] = new BasicAIController(); } else if (racer_type.compare("player") == 0) { m_controllers[i] = new PlayerController(); } // link controller to car; m_controllers[i]->initController(car); // get Params if any const toml::Value * params = racer.find("params"); if (params) { const toml::Array vparams = params->as<toml::Array>(); ((BasicAIController*)m_controllers[i])->setParams( vparams.at(0).as<double>(), vparams.at(1).as<double>(), vparams.at(2).as<double>(), vparams.at(3).as<double>(), vparams.at(4).as<double>()); } i++; } m_numLaps = raceSettings->find("lap_number")->as<int>(); m_maxRaceTime = raceSettings->find("max_race_time")->as<int>(); }
ShapeDef() : position(b2Vec2_zero), heading(b2Vec2_zero), size(1), upgradeSides(true), dropSides(true), spawnProtection(1.f), hpScale(1), speedScale(1), damageScale(1), vertices(0), verticesMin(3), verticesMax(8), faction(0), colPrim(b2Color(.5f, .5f, .5f)), colSecn(b2Color(.75f, .75f, .75f)), colTert(b2Color(0.f, 0.f, 0.f)) {}
void GHDebugDrawLayer::DebugDrawBody(b2Body* body, CCGLProgram* shaderProgram, GLint colorLocation) { const b2Transform& xf = body->GetTransform(); for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext()) { b2Color color = b2Color(0.5f, 0.5f, 0.3f); if (body->IsActive() == false) { color = b2Color(0.5f, 0.5f, 0.3f); } else if (body->GetType() == b2_staticBody) { color = b2Color(0.5f, 0.9f, 0.5f); } else if (body->GetType() == b2_kinematicBody) { color = b2Color(0.5f, 0.5f, 0.9f); } else if (body->IsAwake() == false) { color = b2Color(0.6f, 0.6f, 0.6f); } else { color = b2Color(0.9f, 0.7f, 0.7f); } GHDebugDrawLayer::DrawShape(f, body, xf, color, shaderProgram, colorLocation, GH_METER_RATIO()); } }
void CTrack::loadSettingsFromTOML(const char *filename) { std::ifstream ifs(filename); toml::Parser parser(ifs); toml::Value documentRoot = parser.parse(); toml::Value* trackSettings = documentRoot.find("tracksettings"); m_trackSize = trackSettings->find("track_size")->as<int>(); m_downStep = trackSettings->find("down_step")->as<int>(); m_sectorStep = trackSettings->find("sector_step")->as<int>(); m_trackWidth = trackSettings->find("track_width")->as<int>(); m_radiusOffsetCurvature = trackSettings->find("radius_offset_curvature")->as<int>(); m_hardCurvatureValue = trackSettings->find("hard_curvature_value")->as<int>(); m_smoothIterations = trackSettings->find("smooth_iterations")->as<int>(); const toml::Array& radius_curvature = trackSettings->find("radius_curvature")->as<toml::Array>(); const toml::Array& hard_curvature_probability = trackSettings->find("hard_curvature_probability")->as<toml::Array>(); const toml::Array& physics_wall_size_inner = trackSettings->find("physics_wall_size_inner")->as<toml::Array>(); const toml::Array& physics_wall_size_outer = trackSettings->find("physics_wall_size_outer")->as<toml::Array>(); m_radiusCurvature[0] = radius_curvature.at(0).as<int>(); m_radiusCurvature[1] = radius_curvature.at(1).as<int>(); m_hardCurvatureProbability[0] = hard_curvature_probability.at(0).as<int>(); m_hardCurvatureProbability[1] = hard_curvature_probability.at(1).as<int>(); m_hardCurvatureProbability[2] = hard_curvature_probability.at(2).as<int>(); m_physicsWallSizeInner[0] = physics_wall_size_inner.at(0).as<double>(); m_physicsWallSizeInner[1] = physics_wall_size_inner.at(1).as<double>(); m_physicsWallSizeOuter[0] = physics_wall_size_outer.at(0).as<double>(); m_physicsWallSizeOuter[1] = physics_wall_size_outer.at(1).as<double>(); const toml::Value * colorSector = trackSettings->find("color_sectors"); const toml::Value * colorWall = trackSettings->find("color_wall"); m_debugColorSectors = b2Color(colorSector->find("r")->as<double>(), colorSector->find("g")->as<double>(), colorSector->find("b")->as<double>()) ; m_debugColorWall = b2Color(colorWall->find("r")->as<double>(), colorWall->find("g")->as<double>(), colorWall->find("b")->as<double>()); }
STARTDECL(ph_createparticlecircle) (Value &position, Value &radius, Value &color, Value &type) { CheckParticles(); b2ParticleGroupDef pgd; b2CircleShape shape; shape.m_radius = radius.fval; pgd.shape = &shape; pgd.flags = type.ival; pgd.position = ValueDecToB2(position); auto c = ValueDecTo<float3>(color); pgd.color.Set(b2Color(c.x(), c.y(), c.z())); particlesystem->CreateParticleGroup(pgd); return Value(); }
Weight::Weight(World* world, b2Vec2 position, float32 weight, b2BodyDef def) { this->position = position; this->weight = weight; def.userData = this; def.type = b2_dynamicBody; this->world = world; this->body = world->createBody(&def); b2CircleShape shape; shape.m_radius = 1.5f; shape.m_p = position; b2FixtureDef fDef; fDef.shape = &shape; fDef.density = 15.0f; fDef.friction=1.0f; this->body->CreateFixture(&fDef, b2Color(0.1f,0.5f,0.9f)); this->world->createWeight(this); }
SupportSpotCalculator::SupportSpotCalculator(int numX, int numY, Team* team) :bestSupportSpot(NULL), team(team), frameCounter(0), noOfFramesBeforeUpdate(100) { const PitchRegion* PlayingField = team->match->pitch->PitchArea(); //calculate the positions of each sweet spot, create them and //store them in m_Spots double HeightOfSSRegion = PlayingField->rect.h * 1; double WidthOfSSRegion = PlayingField->rect.w * 0.5; double SliceX = WidthOfSSRegion / numX ; double SliceY = HeightOfSSRegion / numY; double left = PlayingField->rect.x + (PlayingField->rect.w-WidthOfSSRegion)/2.0 + SliceX/2.0; double right = (PlayingField->rect.x + PlayingField->rect.w) - (PlayingField->rect.w-WidthOfSSRegion)/2.0 - SliceX/2.0; double top = PlayingField->rect.y + (PlayingField->rect.h-HeightOfSSRegion)/2.0 + SliceY/2.0; double bottom = (PlayingField->rect.y + PlayingField->rect.h) - (PlayingField->rect.h - HeightOfSSRegion) / 2.0 - SliceY/2.0; for (int y=0; y< (numY / 2) -1; ++y) { for (int x=0; x< numX; ++x) { if (team->Home()) { spots.push_back(SupportSpot(b2Vec2(left + x * SliceX, top + y * SliceY), 0.0)); } else { spots.push_back(SupportSpot(b2Vec2(left + x * SliceX, bottom - y * SliceY), 0.0)); } } } color = b2Color(1, 0, 0); }
void __fastcall TTestBedForm::PaintBoxPaint(TObject *Sender, TCanvas *Canvas) { Canvas->BeginScene(); __try { Canvas->Fill->Color = b2Color2TColor(b2Color(0.3, 0.3, 0.3, 1)); TRectF rect = PaintBox->BoundsRect; Canvas->FillRect(rect, 0, 0, TCorners(), DEFAULT_OPACITY); if (test) { g_debugDraw.Canvas = Canvas; g_debugDraw.Canvas->Fill->Color = TAlphaColorRec::Yellow; test->DrawTitle(entry->name); g_debugDraw.Canvas->Fill->Color = TAlphaColorRec::Aqua; test->Step(&settings); } } __finally { Canvas->EndScene(); } }
void b2World::DrawDebugData() { if (m_debugDraw == NULL) { return; } uint32 flags = m_debugDraw->GetFlags(); if (flags & b2Draw::e_shapeBit) { for (b2Body* b = m_bodyList; b; b = b->GetNext()) { const b2Transform& xf = b->GetTransform(); for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) { if (b->IsActive() == false) { DrawShape(f, xf, b2Color(0.5f, 0.5f, 0.3f)); } else if (b->GetType() == b2_staticBody) { DrawShape(f, xf, b2Color(0.5f, 0.9f, 0.5f)); } else if (b->GetType() == b2_kinematicBody) { DrawShape(f, xf, b2Color(0.5f, 0.5f, 0.9f)); } else if (b->IsAwake() == false) { DrawShape(f, xf, b2Color(0.6f, 0.6f, 0.6f)); } else { DrawShape(f, xf, b2Color(0.9f, 0.7f, 0.7f)); } } } } if (flags & b2Draw::e_jointBit) { for (b2Joint* j = m_jointList; j; j = j->GetNext()) { DrawJoint(j); } } if (flags & b2Draw::e_pairBit) { b2Color color(0.3f, 0.9f, 0.9f); for (b2Contact* c = m_contactManager.m_contactList; c; c = c->GetNext()) { //b2Fixture* fixtureA = c->GetFixtureA(); //b2Fixture* fixtureB = c->GetFixtureB(); //b2Vec2 cA = fixtureA->GetAABB().GetCenter(); //b2Vec2 cB = fixtureB->GetAABB().GetCenter(); //m_debugDraw->DrawSegment(cA, cB, color); } } if (flags & b2Draw::e_aabbBit) { b2Color color(0.9f, 0.3f, 0.9f); b2BroadPhase* bp = &m_contactManager.m_broadPhase; for (b2Body* b = m_bodyList; b; b = b->GetNext()) { if (b->IsActive() == false) { continue; } for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) { for (int32 i = 0; i < f->m_proxyCount; ++i) { b2FixtureProxy* proxy = f->m_proxies + i; b2AABB aabb = bp->GetFatAABB(proxy->proxyId); b2Vec2 vs[4]; vs[0].Set(aabb.lowerBound.x, aabb.lowerBound.y); vs[1].Set(aabb.upperBound.x, aabb.lowerBound.y); vs[2].Set(aabb.upperBound.x, aabb.upperBound.y); vs[3].Set(aabb.lowerBound.x, aabb.upperBound.y); m_debugDraw->DrawPolygon(vs, 4, color); } } } } if (flags & b2Draw::e_centerOfMassBit) { for (b2Body* b = m_bodyList; b; b = b->GetNext()) { b2Transform xf = b->GetTransform(); xf.p = b->GetWorldCenter(); m_debugDraw->DrawTransform(xf); } } }
void b2World::DrawDebugData() { if (m_debugDraw == NULL) { return; } uint32 flags = m_debugDraw->GetFlags(); if (flags & b2DebugDraw::e_shapeBit) { bool core = (flags & b2DebugDraw::e_coreShapeBit) == b2DebugDraw::e_coreShapeBit; for (b2Body* b = m_bodyList; b; b = b->GetNext()) { const b2XForm& xf = b->GetXForm(); for (b2Shape* s = b->GetShapeList(); s; s = s->GetNext()) { if (b->IsStatic()) { DrawShape(s, xf, b2Color(0.5f, 0.9f, 0.5f), core); } else if (b->IsSleeping()) { DrawShape(s, xf, b2Color(0.5f, 0.5f, 0.9f), core); } else { DrawShape(s, xf, b2Color(0.9f, 0.9f, 0.9f), core); } } } } if (flags & b2DebugDraw::e_jointBit) { for (b2Joint* j = m_jointList; j; j = j->GetNext()) { if (j->GetType() != e_mouseJoint) { DrawJoint(j); } } } if (flags & b2DebugDraw::e_controllerBit) { for (b2Controller* c = m_controllerList; c; c= c->GetNext()) { c->Draw(m_debugDraw); } } if (flags & b2DebugDraw::e_pairBit) { b2BroadPhase* bp = m_broadPhase; b2Vec2 invQ; invQ.Set(1.0f / bp->m_quantizationFactor.x, 1.0f / bp->m_quantizationFactor.y); b2Color color(0.9f, 0.9f, 0.3f); for (int32 i = 0; i < b2_tableCapacity; ++i) { uint16 index = bp->m_pairManager.m_hashTable[i]; while (index != b2_nullPair) { b2Pair* pair = bp->m_pairManager.m_pairs + index; b2Proxy* p1 = bp->m_proxyPool + pair->proxyId1; b2Proxy* p2 = bp->m_proxyPool + pair->proxyId2; b2AABB b1, b2; b1.lowerBound.x = bp->m_worldAABB.lowerBound.x + invQ.x * bp->m_bounds[0][p1->lowerBounds[0]].value; b1.lowerBound.y = bp->m_worldAABB.lowerBound.y + invQ.y * bp->m_bounds[1][p1->lowerBounds[1]].value; b1.upperBound.x = bp->m_worldAABB.lowerBound.x + invQ.x * bp->m_bounds[0][p1->upperBounds[0]].value; b1.upperBound.y = bp->m_worldAABB.lowerBound.y + invQ.y * bp->m_bounds[1][p1->upperBounds[1]].value; b2.lowerBound.x = bp->m_worldAABB.lowerBound.x + invQ.x * bp->m_bounds[0][p2->lowerBounds[0]].value; b2.lowerBound.y = bp->m_worldAABB.lowerBound.y + invQ.y * bp->m_bounds[1][p2->lowerBounds[1]].value; b2.upperBound.x = bp->m_worldAABB.lowerBound.x + invQ.x * bp->m_bounds[0][p2->upperBounds[0]].value; b2.upperBound.y = bp->m_worldAABB.lowerBound.y + invQ.y * bp->m_bounds[1][p2->upperBounds[1]].value; b2Vec2 x1 = 0.5f * (b1.lowerBound + b1.upperBound); b2Vec2 x2 = 0.5f * (b2.lowerBound + b2.upperBound); m_debugDraw->DrawSegment(x1, x2, color); index = pair->next; } } } if (flags & b2DebugDraw::e_aabbBit) { b2BroadPhase* bp = m_broadPhase; b2Vec2 worldLower = bp->m_worldAABB.lowerBound; b2Vec2 worldUpper = bp->m_worldAABB.upperBound; b2Vec2 invQ; invQ.Set(1.0f / bp->m_quantizationFactor.x, 1.0f / bp->m_quantizationFactor.y); b2Color color(0.9f, 0.3f, 0.9f); for (int32 i = 0; i < b2_maxProxies; ++i) { b2Proxy* p = bp->m_proxyPool + i; if (p->IsValid() == false) { continue; } b2AABB b; b.lowerBound.x = worldLower.x + invQ.x * bp->m_bounds[0][p->lowerBounds[0]].value; b.lowerBound.y = worldLower.y + invQ.y * bp->m_bounds[1][p->lowerBounds[1]].value; b.upperBound.x = worldLower.x + invQ.x * bp->m_bounds[0][p->upperBounds[0]].value; b.upperBound.y = worldLower.y + invQ.y * bp->m_bounds[1][p->upperBounds[1]].value; b2Vec2 vs[4]; vs[0].Set(b.lowerBound.x, b.lowerBound.y); vs[1].Set(b.upperBound.x, b.lowerBound.y); vs[2].Set(b.upperBound.x, b.upperBound.y); vs[3].Set(b.lowerBound.x, b.upperBound.y); m_debugDraw->DrawPolygon(vs, 4, color); } b2Vec2 vs[4]; vs[0].Set(worldLower.x, worldLower.y); vs[1].Set(worldUpper.x, worldLower.y); vs[2].Set(worldUpper.x, worldUpper.y); vs[3].Set(worldLower.x, worldUpper.y); m_debugDraw->DrawPolygon(vs, 4, b2Color(0.3f, 0.9f, 0.9f)); } if (flags & b2DebugDraw::e_obbBit) { b2Color color(0.5f, 0.3f, 0.5f); for (b2Body* b = m_bodyList; b; b = b->GetNext()) { const b2XForm& xf = b->GetXForm(); for (b2Shape* s = b->GetShapeList(); s; s = s->GetNext()) { if (s->GetType() != e_polygonShape) { continue; } b2PolygonShape* poly = (b2PolygonShape*)s; const b2OBB& obb = poly->GetOBB(); b2Vec2 h = obb.extents; b2Vec2 vs[4]; vs[0].Set(-h.x, -h.y); vs[1].Set( h.x, -h.y); vs[2].Set( h.x, h.y); vs[3].Set(-h.x, h.y); for (int32 i = 0; i < 4; ++i) { vs[i] = obb.center + b2Mul(obb.R, vs[i]); vs[i] = b2Mul(xf, vs[i]); } m_debugDraw->DrawPolygon(vs, 4, color); } } } if (flags & b2DebugDraw::e_centerOfMassBit) { for (b2Body* b = m_bodyList; b; b = b->GetNext()) { b2XForm xf = b->GetXForm(); xf.position = b->GetWorldCenter(); m_debugDraw->DrawXForm(xf); } } }
void Test::Step(Settings* settings) { float32 timeStep = settings->hz > 0.0f ? 1.0f / settings->hz : float32(0.0f); if (settings->pause) { if (settings->singleStep) { settings->singleStep = 0; } else { timeStep = 0.0f; } m_debugDraw.DrawString(5, m_textLine, "****PAUSED****"); m_textLine += 15; } uint32 flags = 0; flags += settings->drawShapes * b2Draw::e_shapeBit; flags += settings->drawJoints * b2Draw::e_jointBit; flags += settings->drawAABBs * b2Draw::e_aabbBit; flags += settings->drawPairs * b2Draw::e_pairBit; flags += settings->drawCOMs * b2Draw::e_centerOfMassBit; m_debugDraw.SetFlags(flags); m_world->SetWarmStarting(settings->enableWarmStarting > 0); m_world->SetContinuousPhysics(settings->enableContinuous > 0); m_world->SetSubStepping(settings->enableSubStepping > 0); m_pointCount = 0; m_world->Step(timeStep, settings->velocityIterations, settings->positionIterations); m_world->DrawDebugData(); if (timeStep > 0.0f) { ++m_stepCount; } if (settings->drawStats) { int32 bodyCount = m_world->GetBodyCount(); int32 contactCount = m_world->GetContactCount(); int32 jointCount = m_world->GetJointCount(); m_debugDraw.DrawString(5, m_textLine, "bodies/contacts/joints = %d/%d/%d", bodyCount, contactCount, jointCount); m_textLine += 15; int32 proxyCount = m_world->GetProxyCount(); int32 height = m_world->GetTreeHeight(); int32 balance = m_world->GetTreeBalance(); float32 quality = m_world->GetTreeQuality(); m_debugDraw.DrawString(5, m_textLine, "proxies/height/balance/quality = %d/%d/%d/%g", proxyCount, height, balance, quality); m_textLine += 15; } // Track maximum profile times { const b2Profile& p = m_world->GetProfile(); m_maxProfile.step = b2Max(m_maxProfile.step, p.step); m_maxProfile.collide = b2Max(m_maxProfile.collide, p.collide); m_maxProfile.solve = b2Max(m_maxProfile.solve, p.solve); m_maxProfile.solveInit = b2Max(m_maxProfile.solveInit, p.solveInit); m_maxProfile.solveVelocity = b2Max(m_maxProfile.solveVelocity, p.solveVelocity); m_maxProfile.solvePosition = b2Max(m_maxProfile.solvePosition, p.solvePosition); m_maxProfile.solveTOI = b2Max(m_maxProfile.solveTOI, p.solveTOI); m_maxProfile.broadphase = b2Max(m_maxProfile.broadphase, p.broadphase); m_totalProfile.step += p.step; m_totalProfile.collide += p.collide; m_totalProfile.solve += p.solve; m_totalProfile.solveInit += p.solveInit; m_totalProfile.solveVelocity += p.solveVelocity; m_totalProfile.solvePosition += p.solvePosition; m_totalProfile.solveTOI += p.solveTOI; m_totalProfile.broadphase += p.broadphase; } if (settings->drawProfile) { const b2Profile& p = m_world->GetProfile(); b2Profile aveProfile; memset(&aveProfile, 0, sizeof(b2Profile)); if (m_stepCount > 0) { float32 scale = 1.0f / m_stepCount; aveProfile.step = scale * m_totalProfile.step; aveProfile.collide = scale * m_totalProfile.collide; aveProfile.solve = scale * m_totalProfile.solve; aveProfile.solveInit = scale * m_totalProfile.solveInit; aveProfile.solveVelocity = scale * m_totalProfile.solveVelocity; aveProfile.solvePosition = scale * m_totalProfile.solvePosition; aveProfile.solveTOI = scale * m_totalProfile.solveTOI; aveProfile.broadphase = scale * m_totalProfile.broadphase; } m_debugDraw.DrawString(5, m_textLine, "step [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.step, aveProfile.step, m_maxProfile.step); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "collide [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.collide, aveProfile.collide, m_maxProfile.collide); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solve [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solve, aveProfile.solve, m_maxProfile.solve); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solve init [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveInit, aveProfile.solveInit, m_maxProfile.solveInit); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solve velocity [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveVelocity, aveProfile.solveVelocity, m_maxProfile.solveVelocity); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solve position [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solvePosition, aveProfile.solvePosition, m_maxProfile.solvePosition); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solveTOI [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.solveTOI, aveProfile.solveTOI, m_maxProfile.solveTOI); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "broad-phase [ave] (max) = %5.2f [%6.2f] (%6.2f)", p.broadphase, aveProfile.broadphase, m_maxProfile.broadphase); m_textLine += 15; } if (m_mouseJoint) { b2Vec2 p1 = m_mouseJoint->GetAnchorB(); b2Vec2 p2 = m_mouseJoint->GetTarget(); b2Color c; c.Set(0.0f, 1.0f, 0.0f); m_debugDraw.DrawPoint(p1, 4.0f, c); m_debugDraw.DrawPoint(p2, 4.0f, c); c.Set(0.8f, 0.8f, 0.8f); m_debugDraw.DrawSegment(p1, p2, c); } if (m_bombSpawning) { b2Color c; c.Set(0.0f, 0.0f, 1.0f); m_debugDraw.DrawPoint(m_bombSpawnPoint, 4.0f, c); c.Set(0.8f, 0.8f, 0.8f); m_debugDraw.DrawSegment(m_mouseWorld, m_bombSpawnPoint, c); } if (settings->drawContactPoints) { //const float32 k_impulseScale = 0.1f; const float32 k_axisScale = 0.3f; for (int32 i = 0; i < m_pointCount; ++i) { ContactPoint* point = m_points + i; if (point->state == b2_addState) { // Add m_debugDraw.DrawPoint(point->position, 10.0f, b2Color(0.3f, 0.95f, 0.3f)); } else if (point->state == b2_persistState) { // Persist m_debugDraw.DrawPoint(point->position, 5.0f, b2Color(0.3f, 0.3f, 0.95f)); } if (settings->drawContactNormals == 1) { b2Vec2 p1 = point->position; b2Vec2 p2 = p1 + k_axisScale * point->normal; m_debugDraw.DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.9f)); } else if (settings->drawContactForces == 1) { //b2Vec2 p1 = point->position; //b2Vec2 p2 = p1 + k_forceScale * point->normalForce * point->normal; //DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } if (settings->drawFrictionForces == 1) { //b2Vec2 tangent = b2Cross(point->normal, 1.0f); //b2Vec2 p1 = point->position; //b2Vec2 p2 = p1 + k_forceScale * point->tangentForce * tangent; //DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } } } }
void Test::Step(Settings* settings) { float32 timeStep = settings->hz > 0.0f ? 1.0f / settings->hz : float32(0.0f); if (settings->pause) { if (settings->singleStep) { settings->singleStep = 0; } else { timeStep = 0.0f; } m_debugDraw.DrawString(5, m_textLine, "****PAUSED****"); m_textLine += 15; } uint32 flags = 0; flags += settings->drawShapes * b2DebugDraw::e_shapeBit; flags += settings->drawJoints * b2DebugDraw::e_jointBit; flags += settings->drawAABBs * b2DebugDraw::e_aabbBit; flags += settings->drawPairs * b2DebugDraw::e_pairBit; flags += settings->drawCOMs * b2DebugDraw::e_centerOfMassBit; m_debugDraw.SetFlags(flags); m_world->SetWarmStarting(settings->enableWarmStarting > 0); m_world->SetContinuousPhysics(settings->enableContinuous > 0); m_pointCount = 0; m_world->Step(timeStep, settings->velocityIterations, settings->positionIterations); m_world->DrawDebugData(); if (timeStep > 0.0f) { ++m_stepCount; } if (settings->drawStats) { m_debugDraw.DrawString(5, m_textLine, "bodies/contacts/joints/proxies = %d/%d/%d", m_world->GetBodyCount(), m_world->GetContactCount(), m_world->GetJointCount(), m_world->GetProxyCount()); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "heap bytes = %d", b2_byteCount); m_textLine += 15; } if (m_mouseJoint) { b2Body* body = m_mouseJoint->GetBody2(); b2Vec2 p1 = body->GetWorldPoint(m_mouseJoint->m_localAnchor); b2Vec2 p2 = m_mouseJoint->m_target; glPointSize(4.0f); glColor3f(0.0f, 1.0f, 0.0f); glBegin(GL_POINTS); glVertex2f(p1.x, p1.y); glVertex2f(p2.x, p2.y); glEnd(); glPointSize(1.0f); glColor3f(0.8f, 0.8f, 0.8f); glBegin(GL_LINES); glVertex2f(p1.x, p1.y); glVertex2f(p2.x, p2.y); glEnd(); } if (m_bombSpawning) { glPointSize(4.0f); glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_POINTS); glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(m_bombSpawnPoint.x, m_bombSpawnPoint.y); glEnd(); glColor3f(0.8f, 0.8f, 0.8f); glBegin(GL_LINES); glVertex2f(m_mouseWorld.x, m_mouseWorld.y); glVertex2f(m_bombSpawnPoint.x, m_bombSpawnPoint.y); glEnd(); } if (settings->drawContactPoints) { //const float32 k_impulseScale = 0.1f; const float32 k_axisScale = 0.3f; for (int32 i = 0; i < m_pointCount; ++i) { ContactPoint* point = m_points + i; if (point->state == b2_addState) { // Add m_debugDraw.DrawPoint(point->position, 10.0f, b2Color(0.3f, 0.95f, 0.3f)); } else if (point->state == b2_persistState) { // Persist m_debugDraw.DrawPoint(point->position, 5.0f, b2Color(0.3f, 0.3f, 0.95f)); } if (settings->drawContactNormals == 1) { b2Vec2 p1 = point->position; b2Vec2 p2 = p1 + k_axisScale * point->normal; m_debugDraw.DrawSegment(p1, p2, b2Color(0.4f, 0.9f, 0.4f)); } else if (settings->drawContactForces == 1) { //b2Vec2 p1 = point->position; //b2Vec2 p2 = p1 + k_forceScale * point->normalForce * point->normal; //DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } if (settings->drawFrictionForces == 1) { //b2Vec2 tangent = b2Cross(point->normal, 1.0f); //b2Vec2 p1 = point->position; //b2Vec2 p2 = p1 + k_forceScale * point->tangentForce * tangent; //DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } } } }
b2Color b2ParticleColor::GetColor() const { return b2Color(k_inverseMaxValue * r, k_inverseMaxValue * g, k_inverseMaxValue * b); }
void Test::Step(Settings* settings) { float32 timeStep = settings->hz > 0.0f ? 1.0f / settings->hz : float32(0.0f); if (settings->pause) { if (settings->singleStep) { settings->singleStep = 0; } else { timeStep = 0.0f; } DrawString(5, m_textLine, "****PAUSED****"); m_textLine += 15; } uint32 flags = 0; flags += settings->drawShapes * b2DebugDraw::e_shapeBit; flags += settings->drawJoints * b2DebugDraw::e_jointBit; flags += settings->drawCoreShapes * b2DebugDraw::e_coreShapeBit; flags += settings->drawAABBs * b2DebugDraw::e_aabbBit; flags += settings->drawOBBs * b2DebugDraw::e_obbBit; flags += settings->drawPairs * b2DebugDraw::e_pairBit; flags += settings->drawCOMs * b2DebugDraw::e_centerOfMassBit; m_debugDraw.SetFlags(flags); m_world->SetWarmStarting(settings->enableWarmStarting > 0); m_world->SetPositionCorrection(settings->enablePositionCorrection > 0); m_world->SetContinuousPhysics(settings->enableTOI > 0); m_pointCount = 0; m_world->Step(timeStep, settings->iterationCount); m_world->Validate(); if (m_bomb != NULL && m_bomb->IsFrozen()) { m_world->DestroyBody(m_bomb); m_bomb = NULL; } if (settings->drawStats) { DrawString(5, m_textLine, "proxies(max) = %d(%d), pairs(max) = %d(%d)", m_world->GetProxyCount(), b2_maxProxies, m_world->GetPairCount(), b2_maxPairs); m_textLine += 15; DrawString(5, m_textLine, "bodies/contacts/joints = %d/%d/%d", m_world->GetBodyCount(), m_world->GetContactCount(), m_world->GetJointCount()); m_textLine += 15; DrawString(5, m_textLine, "heap bytes = %d", b2_byteCount); m_textLine += 15; } if (m_mouseJoint) { b2Body* body = m_mouseJoint->GetBody2(); b2Vec2 p1 = body->GetWorldPoint(m_mouseJoint->m_localAnchor); b2Vec2 p2 = m_mouseJoint->m_target; glPointSize(4.0f); glColor3f(0.0f, 1.0f, 0.0f); glBegin(GL_POINTS); glVertex2f(p1.x, p1.y); glVertex2f(p2.x, p2.y); glEnd(); glPointSize(1.0f); glColor3f(0.8f, 0.8f, 0.8f); glBegin(GL_LINES); glVertex2f(p1.x, p1.y); glVertex2f(p2.x, p2.y); glEnd(); } if (settings->drawContactPoints) { //const float32 k_impulseScale = 0.1f; const float32 k_axisScale = 0.3f; for (int32 i = 0; i < m_pointCount; ++i) { ContactPoint* point = m_points + i; if (point->state == 0) { // Add DrawPoint(point->position, 10.0f, b2Color(0.3f, 0.95f, 0.3f)); } else if (point->state == 1) { // Persist DrawPoint(point->position, 5.0f, b2Color(0.3f, 0.3f, 0.95f)); } else { // Remove DrawPoint(point->position, 10.0f, b2Color(0.95f, 0.3f, 0.3f)); } if (settings->drawContactNormals == 1) { b2Vec2 p1 = point->position; b2Vec2 p2 = p1 + k_axisScale * point->normal; DrawSegment(p1, p2, b2Color(0.4f, 0.9f, 0.4f)); } else if (settings->drawContactForces == 1) { //b2Vec2 p1 = point->position; //b2Vec2 p2 = p1 + k_forceScale * point->normalForce * point->normal; //DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } if (settings->drawFrictionForces == 1) { //b2Vec2 tangent = b2Cross(point->normal, 1.0f); //b2Vec2 p1 = point->position; //b2Vec2 p2 = p1 + k_forceScale * point->tangentForce * tangent; //DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } } } }