void PhysicsBodyComponent::setRestrictMovement(float x, float y, float z) {
    setRestrictMovement(btVector3(x, y, z));
}
Ejemplo n.º 2
0
Node::NodeSP SceneLoader::__loadPhysics(const QDomElement& og_component, Node::NodeSP dt_node)
{
    Node::NodeSP node = dt_node;
    if ( !og_component.isNull() )
    {
        QString name = og_component.attribute(SL_NAME);

        if ( node == nullptr )
        {
            node = mScene->addChildNode(new Node(name + "_node"));

            QDomElement pos = og_component.firstChildElement(SL_POS);

            node->setPosition(pos.attribute(SL_X).toFloat(), pos.attribute(SL_Y).toFloat(),
                pos.attribute(SL_Z).toFloat());
        }

        //get necessary attributes before initialize physics component
        QString shape = og_component.attribute(SL_PHYSICS_SHAPE);
        auto type = PhysicsBodyComponent::CONVEX;

        if ( shape == SL_PHYSICS_SHAPE_BOX )
        {
            type = PhysicsBodyComponent::BOX;
        }
        else if ( shape == SL_PHYSICS_SHAPE_CYLINDER )
        {
            type = PhysicsBodyComponent::CYLINDER;
        }
        else if ( shape == SL_PHYSICS_SHAPE_SPHERE )
        {
            type = PhysicsBodyComponent::SPHERE;
        }
        else if ( shape == SL_PHYSICS_SHAPE_TRIMESH )
        {
            type = PhysicsBodyComponent::TRIMESH;
        }

        //add physics component
        auto physics = node->addComponent<PhysicsBodyComponent>(
            new PhysicsBodyComponent(og_component.attribute(SL_PHYSICS_MESH_COM_NAME), name, type)
            );

        //set physics attributes
        QDomElement res_move = og_component.firstChildElement(SL_PHYSICS_RESMOVE);
        QDomElement res_rotate = og_component.firstChildElement(SL_PHYSICS_RESROTATE);
        QDomElement gravity = og_component.firstChildElement(SL_PHYSICS_GRAVITY);

        physics->setRestrictMovement(res_move.attribute(SL_X).toFloat(), res_move.attribute(SL_Y).toFloat(),
            res_move.attribute(SL_Z).toFloat());
        physics->setRestrictRotation(res_rotate.attribute(SL_X).toFloat(), res_move.attribute(SL_Y).toFloat(),
            res_move.attribute(SL_Z).toFloat());
        physics->setMass(og_component.attribute(SL_PHYSICS_MASS).toFloat());
        physics->setGravity(gravity.attribute(SL_X).toFloat(), gravity.attribute(SL_Y).toFloat(),
            gravity.attribute(SL_Z).toFloat());

        QString enable = og_component.attribute(SL_COMPONENT_ENABLED);
        if ( enable == SL_TRUE )
        {
            physics->enable();
        }
        else if ( enable == SL_FALSE )
        {
            physics->disable();
        }
    }

    return node;
}