本文整理汇总了C++中b2Body类的典型用法代码示例。如果您正苦于以下问题:C++ b2Body类的具体用法?C++ b2Body怎么用?C++ b2Body使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了b2Body类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: keyDown
bool keyDown (int keyCode) {
if (keyCode == gdx_cpp::Input::Keys::COMMA) {
if (m_bullet != NULL) {
world->DestroyBody(m_bullet);
m_bullet = NULL;
}
{
b2CircleShape * shape = new b2CircleShape();
shape->m_radius = 0.25f;
b2FixtureDef fd;
fd.shape = shape;
fd.density = 20.0f;
fd.restitution = 0.05f;
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.bullet = true;
bd.position.Set(-31, 5);
m_bullet = world->CreateBody(&bd);
m_bullet->CreateFixture(&fd);
m_bullet->SetLinearVelocity(b2Vec2(400, 0));
}
}
return false;
}
开发者ID:henviso,项目名称:libgdx-cpp,代码行数:30,代码来源:VerticalStack.cpp
示例2: Car
//constructor
Car(b2World* world){
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
w_body = world->CreateBody(&bodyDef);
b2PolygonShape polygonShape;
polygonShape.SetAsBox(0.5f, 1.25f);
b2Fixture* fixture = w_body->CreateFixture(&polygonShape, 1);//shape, density
fixture->SetUserData(new CarTireFUD());
w_body->SetUserData(this);
currentTraction = 1;
}
开发者ID:Bryans91,项目名称:Box2DSFML,代码行数:16,代码来源:Car.cpp
示例3: Pelota
Pelota(b2World* _world ,RenderWindow *_wnd){
//guardamos puntero a ventana para dibujar luego
wnd=_wnd;
_image= new Image();
_image->LoadFromFile("pelota.jpg");
//cargamos el sprite
_sprite= new Sprite(*_image);
//definimos el body y lo creamos
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(100.0f, 0.0f);
_body = _world->CreateBody(&bodyDef);
//creamos su figura de colisión
//en este caso suponemos que la figura de
//colision es una caja cuadrada
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(20.0f, 20.0f);
//creamos el fixture, le seteamos
//la figura de colision
//y agregamos el fixture al body
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 10.0f;
fixtureDef.friction = 0.3f;
fixtureDef.restitution=1.0f;
_body->CreateFixture(&fixtureDef);
}
开发者ID:dexter1986,项目名称:unli,代码行数:31,代码来源:Box2dEmptyApp.cpp
示例4: CreateFixture
Value CreateFixture(b2Body &body, b2Shape &shape)
{
auto fixture = body.CreateFixture(&shape, 1.0f);
auto r = new Renderable("color");
fixture->SetUserData(r);
return Value((int)fixtures->Add(fixture));
}
开发者ID:DawidvC,项目名称:lobster,代码行数:7,代码来源:physics.cpp
示例5: generateId
void Box2dContainer::assignNode(b2Body& body, cocos2d::Node& node)
{
if (!nodeToId.count(&node)) {
auto newId = generateId();
nodeToId[&node] = newId;
idToNode[newId] = &node;
}
body.SetUserData(static_cast<void*>(nodeToId[&node]));
}
开发者ID:Ratel13,项目名称:avalon,代码行数:10,代码来源:Box2dContainer.cpp
示例6: Ball
Ball(b2World* world, float radius) {
m_body = NULL;
m_radius = radius;
b2BodyDef myBodyDef;
myBodyDef.type = b2_dynamicBody;
myBodyDef.position.Set(0, 20);
m_body = world->CreateBody(&myBodyDef);
m_contacting = false;
//add circle fixture
b2CircleShape circleShape;
circleShape.m_p.Set(0, 0);
circleShape.m_radius = m_radius; //use class variable
b2FixtureDef myFixtureDef;
myFixtureDef.shape = &circleShape;
myFixtureDef.density = 1;
m_body->CreateFixture(&myFixtureDef);
m_body->SetUserData( this );
}
开发者ID:ChanukyaVardhan,项目名称:Project,代码行数:20,代码来源:cs251_base+collision.hpp
示例7: CreateFixture
Value CreateFixture(VM &vm, b2Body &body, b2Shape &shape) {
auto fixture = body.CreateFixture(&shape, 1.0f);
auto po = new PhysicsObject(Renderable("color"), fixture);
fixture->SetUserData(po);
return Value(vm.NewResource(po, &physics_type));
}
开发者ID:aardappel,项目名称:treesheets,代码行数:6,代码来源:physics.cpp
示例8:
const b2Vec2 Box2dService::retrieveTopLeftVertex(const b2Body &objectBody) {
return objectBody.GetWorldPoint(dynamic_cast<const b2PolygonShape*>(findNonSensorFixture(*objectBody.GetFixtureList()).GetShape())->GetVertex(3));
}
开发者ID:edwardrowens,项目名称:jimmyjump,代码行数:3,代码来源:Box2dService.cpp
示例9: CreateGroundBox
// Create a horizontal box fixture attached to the ground body.
b2Fixture* BodyContactTests::CreateGroundBox()
{
b2Assert(m_groundBody);
b2PolygonShape shape;
shape.SetAsBox(10.0f * m_particleDiameter, m_particleDiameter);
return m_groundBody->CreateFixture(&shape, 0.0f);
}
开发者ID:3rd3,项目名称:liquidfun,代码行数:8,代码来源:BodyContactsTests.cpp
示例10: CreateValley
// 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);
}
}
开发者ID:3rd3,项目名称:liquidfun,代码行数:38,代码来源:BodyContactsTests.cpp
示例11: block
block(float w,float h,float x,float y,int a, b2World* m_world,int s_d=0, float friction =1.0f,float density=1.0f)
{
b2PolygonShape shape;
shape.SetAsBox(w, h);
bd.angle = a; //set the starting angle
bd.position.Set(x, y);
if(s_d==1)bd.type = b2_dynamicBody;
if(s_d==0)bd.type = b2_staticBody;
body = m_world->CreateBody(&bd);
b2FixtureDef *fd = new b2FixtureDef;
fd->density = density;
fd->shape = new b2PolygonShape;
fd->shape = &shape;
fd->friction = friction;
fd->restitution = 0.0f;
body->CreateFixture(fd);
}
开发者ID:Pushyarag,项目名称:Box2D,代码行数:21,代码来源:dominos.cpp
示例12: updateDrive
void updateDrive(int controlState) {
//find desired speed
float desiredSpeed = 0;
switch (controlState & (TDC_UP | TDC_DOWN)) {
case TDC_UP: desiredSpeed = maxForwardSpeed; break;
case TDC_DOWN: desiredSpeed = maxBackwardSpeed; break;
default: return;//do nothing
}
//find current speed in forward direction
b2Vec2 currentForwardNormal = w_body->GetWorldVector(b2Vec2(0, 1));
float currentSpeed = b2Dot(getForwardVelocity(), currentForwardNormal);
//apply necessary force
float force = 0;
if (desiredSpeed > currentSpeed)
force = maxDriveForce;
else if (desiredSpeed < currentSpeed)
force = -maxDriveForce;
else
return;
//w_body->ApplyForce(currentTraction * force * currentForwardNormal, w_body->GetWorldCenter());
}
开发者ID:Bryans91,项目名称:Box2DSFML,代码行数:24,代码来源:Car.cpp
示例13: getLateralVelocity
b2Vec2 getLateralVelocity() {
b2Vec2 currentRightNormal = w_body->GetWorldVector(b2Vec2(1, 0));
return b2Dot(currentRightNormal, w_body->GetLinearVelocity()) * currentRightNormal;
}
开发者ID:Bryans91,项目名称:Box2DSFML,代码行数:4,代码来源:Car.cpp
示例14: ActualizarPosiciones
//metodo que posiciona el sprites
//segun la posicion del body
void ActualizarPosiciones(){
b2Vec2 pos=_body->GetPosition();
_sprite->SetPosition(pos.x,pos.y);
}
开发者ID:dexter1986,项目名称:unli,代码行数:6,代码来源:Box2dEmptyApp.cpp
示例15:
//destructor
~Car(){
w_body->GetWorld()->DestroyBody(w_body);
}
开发者ID:Bryans91,项目名称:Box2DSFML,代码行数:4,代码来源:Car.cpp
示例16: applyForceToCenter
/// Apply a force to the center of the rigid body
virtual void applyForceToCenter(Vector2D force)
{
_body->ApplyLinearImpulse(b2Vec2(force.x, force.y), _body->GetLocalCenter());
}
开发者ID:GrimshawA,项目名称:Nephilim,代码行数:5,代码来源:Box2DSystem.cpp
示例17: applyAngularImpulse
/// Apply a angular impulse to the object (2D)
virtual void applyAngularImpulse(float impulse2d)
{
_body->ApplyAngularImpulse(impulse2d);
}
开发者ID:GrimshawA,项目名称:Nephilim,代码行数:5,代码来源:Box2DSystem.cpp
示例18: operator
b2Fixture * operator()(const CollisionPolygonDef & aDef) const
{
b2Fixture *fixture = mBody->CreateFixture(&aDef.mFixture);
fixture->SetUserData(mBody->GetUserData());
return fixture;
}
开发者ID:Fissuras,项目名称:videoventure,代码行数:6,代码来源:Collidable.cpp
示例19: geometry
sf::FloatRect geometry() {
sf::Vector2f bod_pos = vHelper::toSF(m_box_body->GetPosition());
sf::Vector2f position(bod_pos.x - (m_size.x / 2), bod_pos.y - (m_size.y / 2));
return sf::FloatRect{ position.x, position.y, (float)m_size.x, (float)m_size.y };
}
开发者ID:Joshmoo2009,项目名称:FYP_1516_JoshMooney,代码行数:5,代码来源:XYPlatform.hpp
示例20:
virtual float getRotation2D()
{
return _body->GetAngle();
}
开发者ID:GrimshawA,项目名称:Nephilim,代码行数:4,代码来源:Box2DSystem.cpp
注:本文中的b2Body类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论