Пример #1
0
void PlatformDemoState::addPlayer()
{
    auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic);
    xy::Physics::CollisionRectangleShape cs({ 120.f, 240.f });
    cs.setFriction(0.6f);
    cs.setDensity(0.9f);

    body->fixedRotation(true);
    body->addCollisionShape(cs);

    auto controller = xy::Component::create<Plat::PlayerController>(m_messageBus);

    auto camera = xy::Component::create<xy::Camera>(m_messageBus, getContext().defaultView);
    camera->lockTransform(xy::Camera::TransformLock::AxisY);
    camera->lockBounds({ 0.f,0.f, 2816.f, 1080.f });

    auto model = m_meshRenderer.createModel(MeshID::Batcat, m_messageBus);
    model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::BatcatMat));
    model->rotate(xy::Model::Axis::X, 90.f);
    model->rotate(xy::Model::Axis::Z, -90.f);
    model->setPosition({ 60.f, 240.f, 0.f });
    model->playAnimation(1, 0.2f);

    auto entity = xy::Entity::create(m_messageBus);
    entity->setPosition(960.f, 540.f);
    entity->addComponent(body);
    entity->addComponent(model);
    playerController = entity->addComponent(controller);
    playerCamera = entity->addComponent(camera);
    m_scene.setActiveCamera(playerCamera);
    m_scene.addEntity(entity, xy::Scene::Layer::FrontMiddle);

    body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic);
    body->fixedRotation(true);
    cs.setRect({ 200.f, 300.f });
    body->addCollisionShape(cs);
    cs.setRect({ 80.f, 80.f }, { 60.f, -80.f });
    body->addCollisionShape(cs);

    model = m_meshRenderer.createModel(MeshID::Fixit, m_messageBus);
    model->setSubMaterial(m_meshRenderer.getMaterial(MatId::MrFixitBody), 0);
    model->setSubMaterial(m_meshRenderer.getMaterial(MatId::MrFixitHead), 1);
    model->rotate(xy::Model::Axis::X, 90.f);
    model->rotate(xy::Model::Axis::Z, 90.f);
    model->setScale({ 50.f, 50.f, 50.f });
    model->setPosition({ 100.f, 300.f, 0.f });

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1320.f, 40.f);
    entity->addComponent(model);
    entity->addComponent(body);
    m_scene.addEntity(entity, xy::Scene::Layer::FrontMiddle);
}
Пример #2
0
/**
 * @brief Body::applyAngularImpulse
 * @param f
 */
void Body::applyAngularImpulse(float impulse)
{
	if (!fixedRotation())
	{
		m_fAngularVelocity += (impulse * m_fInvAngularMass);
		m_flags &= ~SLEEPING;
	}
}
Пример #3
0
/**
 * @brief Body::applyTorque
 * @param torque
 */
void Body::applyTorque(float torque)
{
	if (!fixedRotation())
	{
		m_fTorque += (torque * m_fInvAngularMass);
		m_flags &= ~SLEEPING;
	}
}
Пример #4
0
void Box2DBody::setFixedRotation(bool _fixedRotation)
{
    if (fixedRotation() == _fixedRotation)
        return;
    if (mBody)
        mBody->SetFixedRotation(_fixedRotation);
    else
        mBodyDef.fixedRotation = _fixedRotation;

    emit fixedRotationChanged();
}
Пример #5
0
/**
 * @brief Body::Body
 * @param v
 */
Body::Body(const BodyModel & model, Shape * pShape)
: m_vPosition(model.position)
, m_fRotation(model.rotation)
, m_vLinearVelocity(0.0f, 0.0f)
, m_fAngularVelocity(0.0f)
, m_vAcceleration(0.0f, 0.0f)
, m_fTorque(0.0f)
, m_fInvLinearMass(1.0f)
, m_fInvAngularMass(1.0f)
, m_flags(0)
, m_pShape(pShape)
, m_pNextBody(nullptr)
{
	assert(nullptr != m_pShape);

	fixedPosition(!model.dynamic);
	fixedRotation(!model.dynamic);
}