本文整理汇总了C++中Body::addCollider方法的典型用法代码示例。如果您正苦于以下问题:C++ Body::addCollider方法的具体用法?C++ Body::addCollider怎么用?C++ Body::addCollider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body::addCollider方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addFloor
Entity* Test::addFloor(World* world, Material* material, vec3 pos)
{
if (!gFloor)
{
ShapeDescription descr;
descr.constructionType = ShapeConstruction::HULL_FROM_BOX;
descr.hullFromBox.c = vec3(0, 0, 0);
descr.hullFromBox.e = vec3(30, 1, 30);
gFloor = world->createShape(descr);
}
ColliderDescription colliderDescr;
colliderDescr.material = material;
colliderDescr.transform.p = vec3(0.0f, 0.0f, 0.0f);
colliderDescr.transform.q = QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f);
colliderDescr.shape = gFloor;
colliderDescr.isSensor = false;
Collider* collider = world->createCollider(colliderDescr);
BodyDescription bodyDescr;
bodyDescr.type = BodyType::Static;
bodyDescr.transform.p= vec3(0.0f, -2.0f, 0.0f) + pos;
bodyDescr.transform.q = QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f);
bodyDescr.linearMomentum = vec3(0.0f, 0.0f, 0.0f);
bodyDescr.angularMomentum = vec3(0.0f, 0.0f, 0.0f);
Body* body = world->createBody(bodyDescr);
body->addCollider(collider);
return new Entity(body, vec3(1,0,0));
}
示例2: addBox
Entity* Test::addBox(World* world, BodyDescription descr, Material* material)
{
if (!gBox)
{
ShapeDescription descr;
descr.constructionType = ShapeConstruction::HULL_FROM_BOX;
descr.hullFromBox.c = vec3(0, 0, 0);
descr.hullFromBox.e = vec3(1, 1, 1);
gBox = world->createShape(descr);
}
ColliderDescription colliderDescr;
colliderDescr.material = material;
colliderDescr.transform.p = vec3(0.0f, 0.0f, 0.0f);
colliderDescr.transform.q = QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f);
colliderDescr.shape = gBox;
colliderDescr.isSensor = false;
Collider* collider = world->createCollider(colliderDescr);
//BodyDescription bodyDescr;
//bodyDescr.type = BodyType::Dynamic;
//bodyDescr.transform = transform;
//bodyDescr.linearMomentum = vec3(0.0f, 0.0f, 0.0f);
//bodyDescr.angularMomentum = vec3(0.0f, 0.0f, 0.0f);
Body* body = world->createBody(descr);
body->addCollider(collider);
return new Entity(body, vec3(0,0,1));
}
示例3: addSlope
Entity* Test::addSlope(World* world, Transform t, Material* material)
{
if (!gSlope)
{
vec3 slope[6] =
{
vec3(-8, -1, -4),
vec3(-8, 1, -4),
vec3(8, -1, -4),
vec3(8, 1, -4),
vec3(-8, -1, 4),
vec3(8, -1, 4),
};
ShapeDescription descr;
descr.constructionType = ShapeConstruction::HULL_FROM_POINTS;
descr.hullFromPoints.points = slope;
descr.hullFromPoints.numPoints = 6;
gSlope = world->createShape(descr);
}
ColliderDescription colliderDescr;
colliderDescr.material = material;
colliderDescr.transform.p = vec3(0.0f, 0.0f, 0.0f);
colliderDescr.transform.q = QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f);
colliderDescr.shape = gSlope;
colliderDescr.isSensor = false;
Collider* collider = world->createCollider(colliderDescr);
BodyDescription bodyDescr;
bodyDescr.type = BodyType::Static;
bodyDescr.transform = t;
bodyDescr.linearMomentum = vec3(0.0f, 0.0f, 0.0f);
bodyDescr.angularMomentum = vec3(0.0f, 0.0f, 0.0f);
Body* body = world->createBody(bodyDescr);
body->addCollider(collider);
return new Entity(body, vec3(1,0,0));
}
示例4: init
void Test::init()
{
m_world = new World(vec3(0.0f, -10.0f, 0.0f));
//m_world = new World(vec3(0.0f, 0.0f, 0.0f));
gBox = ShapePtr();
gCapsule = ShapePtr();
gFloor = ShapePtr();
gSlope = ShapePtr();
gSphere = ShapePtr();
Material m;
m.density = 10.0f;
m.friction = 1.0f;
m.restitution = 0.0f;
Material* material = m_world->createMaterial(m);
BodyDescription descr;
descr.type = BodyType::Dynamic;
descr.transform = Transform(vec3(0.0f, 5.0f, -4.0f), QuatFromAxisAngle(vec3(1.0f, 2.0f, 3.0f), 1.0f));
descr.linearMomentum = vec3(0.0f, 0.0f, 0.0f);
descr.angularMomentum = vec3(0.0f, 0.0f, 0.0f);
m_entities.push_back(addBox(m_world, descr, material));
ShapeDescription shapeDescr;
shapeDescr.shapeType = ShapeType::CAPSULE;
shapeDescr.capsule.r = 0.5f;
shapeDescr.capsule.c1 = vec3(0.0f, 0.5f, 0.0f);
shapeDescr.capsule.c2 = vec3(0.0f, -0.5f, 0.0f);
gCapsule = m_world->createShape(shapeDescr);
ColliderDescription colliderDescr;
colliderDescr.material = material;
colliderDescr.transform = Transform(vec3(0, 0, 0), QuatFromAxisAngle(vec3(1, 0, 0), 0));
colliderDescr.shape = gCapsule;
colliderDescr.isSensor = false;
descr.transform.p.x += 3.0f;
Collider* c = m_world->createCollider(colliderDescr);
Body* b = m_world->createBody(descr);
b->addCollider(c);
m_entities.push_back(new Entity(b, vec3(0, 0, 1)));
// spherestack
{
shapeDescr.shapeType = ShapeType::SPHERE;
shapeDescr.sphere.r = 1.0f;
shapeDescr.sphere.c = vec3(0, 0, 0);
gSphere = m_world->createShape(shapeDescr);
colliderDescr.shape = gSphere;
descr.transform.p.x += 3.0f;
Collider* c = m_world->createCollider(colliderDescr);
Body* b = m_world->createBody(descr);
b->addCollider(c);
m_entities.push_back(new Entity(b, vec3(0, 0, 1)));
descr.transform = Transform(vec3(-10.0f, 3.0f, -10.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
for (int i = 0; i < 4; ++i)
{
Collider* c = m_world->createCollider(colliderDescr);
Body* b = m_world->createBody(descr);
b->addCollider(c);
m_entities.push_back(new Entity(b, vec3(0, 0, 1)));
descr.transform.p.y += 3.0f;
}
}
colliderDescr.shape = gCapsule;
descr.transform = Transform(vec3(-10.0f, 3.0f, 10.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
for (int i = 0; i < 4; ++i)
{
Collider* c = m_world->createCollider(colliderDescr);
Body* b = m_world->createBody(descr);
b->addCollider(c);
m_entities.push_back(new Entity(b, vec3(0, 0, 1)));
descr.transform.p.y += 3.0f;
}
//pyramid
descr.transform = Transform(vec3(10.0f, 0.0f, 0.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
//.........这里部分代码省略.........
示例5: addPlayer
Player* Test::addPlayer(World* world, const Transform& transform)
{
Material m;
m.friction = 0.1f;
m.density = 200.0f;
m.restitution = 0.5f;
Material* material = world->createMaterial(m);
vec3 jetHull[8] =
{
vec3( -0.25f, -0.25f, 0.5f),
vec3( -0.25f, -0.25f, -0.5f),
vec3( 0.25f, -0.25f, -0.5f),
vec3( 0.25f, -0.25f, 0.5f),
vec3( -0.25f, 0.25f, 0.5f),
vec3( -0.25f, 0.25f, -0.5f),
vec3( 0.25f, 0.25f, -0.5f),
vec3( 0.25f, 0.25f, 0.5f)
};
ShapeDescription shapeDescr;
shapeDescr.constructionType = ShapeConstruction::HULL_FROM_BOX;
shapeDescr.hullFromBox.c = vec3(0, 0, 0);
shapeDescr.hullFromBox.e = vec3(0.25f, 0.25f, 0.5f);
ShapePtr shape = world->createShape(shapeDescr);
ColliderDescription colliderDescr;
colliderDescr.material = material;
colliderDescr.transform.p = vec3(0.75f, 0.0f, 0.0f);
colliderDescr.transform.q = QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f);
colliderDescr.shape = shape;
colliderDescr.isSensor = false;
Collider* jet1 = world->createCollider(colliderDescr);
colliderDescr.transform.p = vec3(-0.75f, 0.0f, 0.0f);
Collider* jet2 = world->createCollider(colliderDescr);
shapeDescr.hullFromBox.e = vec3(0.5, 0.5, 1.0f);
shape = world->createShape(shapeDescr);
colliderDescr.transform.p = vec3(0.0f, 0.0f, 1.0f);
colliderDescr.shape = shape;
Collider* bodyC = world->createCollider(colliderDescr);
BodyDescription bodyDescr;
bodyDescr.linearMomentum = vec3(0.0f, 0.0f, 0.0f);
bodyDescr.angularMomentum = vec3(0.0f, 0.0f, 0.0f);
bodyDescr.transform = transform;
bodyDescr.type = BodyType::Dynamic;
Body* body = world->createBody(bodyDescr);
body->addCollider(jet1);
body->addCollider(jet2);
body->addCollider(bodyC);
return new Player(body, vec3(0.0f, 1.0f, 0.0f), m_window, &m_toAdd);
}
示例6: destroy
void Entity::destroy(std::vector<Entity*>& entities)
{
World* world = m_body->getWorld();
Collider* c = m_body->getCollider();
ShapeDescription sDescr;
sDescr.constructionType = ShapeConstruction::HULL_FROM_BOX;
ColliderDescription cDescr;
cDescr.transform.q = Quaternion(vec3(0, 0, 0), 1);
cDescr.transform.p = vec3(0, 0, 0);
cDescr.isSensor = false;
BodyDescription bDescr;
bDescr.type = BodyType::Dynamic;
bDescr.transform.q = Quaternion(vec3(0, 0, 0), 1);
bDescr.linearMomentum = 0.5f*m_body->getLinearMomentum();
bDescr.angularMomentum = 0.5f*m_body->getAngularMomentum();
for (; c != 0; c = c->getNext())
{
float chunkSize = 0;
for (int i = 0; i < 3; ++i)
chunkSize += c->getAABB().e[i];
chunkSize /= 6.0f;
sDescr.hullFromBox.c = vec3(0, 0, 0);
sDescr.hullFromBox.e = vec3(chunkSize, chunkSize, chunkSize);
cDescr.material = c->getMaterial();
cDescr.shape = world->createShape(sDescr);
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
for (int i = 0; i < 3; ++i)
{
bDescr.transform.p[i] = (fmodf((float)rand(), (2.0f * c->getAABB().e.x)) - c->getAABB().e[i]) * 2.0f;
}
bDescr.transform.p += c->getAABB().c;
bDescr.transform = transformTransform(bDescr.transform, m_body->getTransform());
ARGS args;
args.body = m_body;
auto callback = [](Collider* collider, void* userData)->bool
{
if (collider->getBody() != ((ARGS*)userData)->body)
((ARGS*)userData)->valid = false;
return 1;
};
world->queryShape(cDescr.shape, bDescr.transform, callback, &args);
if (args.valid)
{
Body* body = world->createBody(bDescr);
body->addCollider(world->createCollider(cDescr));
entities.push_back(new Entity(body, m_color));
break;
}
}
}
}
}