C++ 如何将刚体连接到相机(子弹物理)?

C++ 如何将刚体连接到相机(子弹物理)?,c++,opengl,game-physics,bulletphysics,C++,Opengl,Game Physics,Bulletphysics,我一直在使用OpenGL和Bullet physics进行一个项目,但似乎不知道如何将刚体移动到相机上。我尝试过反复设置运动状态,并在按键时进行转换,但这两种方法都不起作用。这是我的相机移动代码。(我已经注释掉了这两种方法。) void CameraUpdateLoop() { xpos=0; ypos=0; deltatime=glfwGetTime()-prevtime; glfwGetCursorPos(窗口、xpos和YPO); //无法转换(-(btVector3(右x,右y,右z)*

我一直在使用OpenGL和Bullet physics进行一个项目,但似乎不知道如何将刚体移动到相机上。我尝试过反复设置运动状态,并在按键时进行转换,但这两种方法都不起作用。这是我的相机移动代码。(我已经注释掉了这两种方法。)

void CameraUpdateLoop()
{
xpos=0;
ypos=0;
deltatime=glfwGetTime()-prevtime;
glfwGetCursorPos(窗口、xpos和YPO);
//无法转换(-(btVector3(右x,右y,右z)*增量时间*速度);
}
变换输出;
//fallMotionState=新的btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(position.x,position.y,position.z));
//刚体->设置运动状态(fallMotionState);
刚体->getMotionState()->getWorldTransform(输出);
库特
       void CameraUpdateLoop()
{
    xpos = 0;
    ypos = 0;

    deltatime = glfwGetTime() - prevtime;
    glfwGetCursorPos(window,&xpos,&ypos);
    //  cout << xpos << " " << ypos << endl;
    glfwSetCursorPos(window,800/2,600/2);
    hangle += mousesens * deltatime *  (400 - xpos);
    vangle += mousesens * deltatime *  (300 - ypos);
    direction = glm::vec3(cos(vangle)* sin(hangle),sin(vangle),cos(vangle)* cos(hangle));
    right = glm::vec3(sin(hangle - 3.14f/2.0f),0,cos(hangle - 3.14f/2.0f));
    up = glm::vec3(glm::cross(right,direction));
    if(glfwGetKey(window,GLFW_KEY_W) == GLFW_PRESS)
    {
        position += direction * deltatime * speed;

       // rigidbody->translate(btVector3(direction.x,direction.y,direction.z) * deltatime * speed);

    }
    if(glfwGetKey(window,GLFW_KEY_S) == GLFW_PRESS)
    {
        position -= direction * deltatime * speed;

       // rigidbody->translate(-(btVector3(direction.x,direction.y,direction.z) * deltatime * speed));
    }
    if(glfwGetKey(window,GLFW_KEY_D) == GLFW_PRESS)
    {
        position += right * deltatime * speed;

        //rigidbody->translate(btVector3(right.x,right.y,right.z) * deltatime * speed);
    }
    if(glfwGetKey(window,GLFW_KEY_A) == GLFW_PRESS)
    {
        position -= right * deltatime * speed;


        //rigidbody->translate(-(btVector3(right.x,right.y,right.z) * deltatime * speed));
    }
    btTransform output;
    //fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(position.x,position.y, position.z)));
    //rigidbody->setMotionState(fallMotionState);
    rigidbody->getMotionState()->getWorldTransform(output);
    cout << output.getOrigin().getZ() << endl;

    if(vangle < -90.0f)
    {
        vangle = -90.0f;
    }
    if(vangle > 90.0f)
    {
        vangle = 90.0f;
    }
    // cout << vangle << endl;
    // cout << hangle << endl;
    ProjectionMatrix = glm::perspective(initfov,4.0f/3.0f,0.1f,100.0f);
    ViewMatrix= (glm::lookAt(position,position+direction,up));
    prevtime = glfwGetTime();
}
static void test (btDynamicsWorld *world, btScalar timeStep)
{
    int numManifolds = world->getDispatcher()->getNumManifolds();
    if(numManifolds >= 1)
    {
        cout << "collision" << endl;
        glClearColor(0.0,0.7,0.8,1.0);
    }
    else if(numManifolds < 1)
    {
       glClearColor(0.0,0.3,0.8,1.0);
    }