当前位置: 首页>>代码示例>>C++>>正文


C++ TStack::loadTranslation方法代码示例

本文整理汇总了C++中TStack::loadTranslation方法的典型用法代码示例。如果您正苦于以下问题:C++ TStack::loadTranslation方法的具体用法?C++ TStack::loadTranslation怎么用?C++ TStack::loadTranslation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TStack的用法示例。


在下文中一共展示了TStack::loadTranslation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: add_rigid_body

void add_rigid_body(OBJMESH *objmesh, float mass)
{
    /* Create a new Box collision shape for the current mesh. */
    /* Use half of the dimension XYZ to represent the extent of the box
     * relative to its pivot point, which is already centered in the middle of
     * its bounding box.
     */
    btCollisionShape *btcollisionshape = new btBoxShape(btVector3(objmesh->dimension->x * 0.5f,
                                                                  objmesh->dimension->y * 0.5f,
                                                                  objmesh->dimension->z * 0.5f));

    /* Declare a btTransform variable to be able to contain the transformation
     * matrix of the object in a form that Bullet will understand.
     */
    btTransform bttransform;

    TStack  l;
    l.loadTranslation(objmesh->location);
    // Convert angles to radians & divide by 2.
    float   alpha = objmesh->rotation->z*DEG_TO_RAD_DIV_2;
    float   cosAlpha(cosf(alpha)), sinAlpha(sinf(alpha));
    float   beta  = objmesh->rotation->y*DEG_TO_RAD_DIV_2;
    float   cosBeta(cosf(beta)), sinBeta(sinf(beta));
    float   gamma = objmesh->rotation->x*DEG_TO_RAD_DIV_2;
    float   cosGamma(cosf(gamma)), sinGamma(sinf(gamma));
    float   cAcB(cosAlpha*cosBeta);
    float   sAsB(sinAlpha*sinBeta);
    float   cAsB(cosAlpha*sinBeta);
    float   sAcB(sinAlpha*cosBeta);
    l.rotate(quaternion(cAcB*cosGamma+sAsB*sinGamma,
                        cAcB*sinGamma-sAsB*cosGamma,
                        cAsB*cosGamma+sAcB*sinGamma,
                        sAcB*cosGamma-cAsB*sinGamma));

    /* Assign the current transformation matrix that you create using the
     * standard "OpenGL way" and send it over to the Bullet transform variable.
     */
    bttransform.setFromOpenGLMatrix(l.back().m());

    /* Create a new motion state in order for Bullet to be able to
     * maintain and interpolate the object transformation.
     */
    btDefaultMotionState *btdefaultmotionstate = NULL;

    btdefaultmotionstate = new btDefaultMotionState(bttransform);

    /* Create a Bullet vector to be able to hold the local inertia of
     * the object.
     */
    btVector3 localinertia(0.0f, 0.0f, 0.0f);

    /* If a mass greater than 0 is passed in as a parameter to the function,
     * use it to calculate the local inertia.  If a mass is equal to 0, it means
     * that the object is static and you do not need to execute this calculation.
     */
    if (mass > 0.0f)
        btcollisionshape->calculateLocalInertia(mass, localinertia);

    /* Create a new rigid body and link the information that you have
     * calculated above.  Note that you are using the btRigidBody pointer already
     * contained in the OBJMESH structure to initialize the class.  This way, when
     * you're drawing, you can easily query the pointer in order to gain access to
     * its transformation matrix, which is from now on maintained by Bullet
     * internally.
     */
    objmesh->btrigidbody = new btRigidBody(mass,
                                           btdefaultmotionstate,
                                           btcollisionshape,
                                           localinertia);

    /* Built into the btRigidBody class is a "void *" variable that
     * allows you to associate a user-defined pointer with the rigid
     * body.  By associating the current objmesh pointer to this
     * variable, you will have direct access to the OBJMESH structure
     * at any time inside any Bullet-driven functions and callbacks.
     */
    objmesh->btrigidbody->setUserPointer(objmesh);

    /* Only mark the object named "Cube" to receive a contact-added callback. */
    if (!strcmp(objmesh->name, "Cube")) {
        /* Adjust the collision flags for this body by adding
         * CF_CUSTOM_MATERIAL_CALLBACK to the current flags.
         */
        objmesh->btrigidbody->setCollisionFlags(objmesh->btrigidbody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
    }

    /* Add the new rigid body to your physical world. */
    dynamicsworld->addRigidBody(objmesh->btrigidbody);
}
开发者ID:crlarsen,项目名称:gamelibrary,代码行数:89,代码来源:templateApp.cpp


注:本文中的TStack::loadTranslation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。