Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Openscenegraph-如何创建一个不可见的边界,相机不能超出该边界_C++_3d_Openscenegraph_Scenegraph - Fatal编程技术网

C++ Openscenegraph-如何创建一个不可见的边界,相机不能超出该边界

C++ Openscenegraph-如何创建一个不可见的边界,相机不能超出该边界,c++,3d,openscenegraph,scenegraph,C++,3d,Openscenegraph,Scenegraph,我对3d编程还不熟悉,所以现在开始吧。我试着模拟一个房间。我没有加载墙的图像,但我想在代码中模拟边界。请问我该如何做到这一点 下面是处理相机移动的代码 bool calcMovement() { // return if less then two events have been added. if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; //calcIntersect(); doub

我对3d编程还不熟悉,所以现在开始吧。我试着模拟一个房间。我没有加载墙的图像,但我想在代码中模拟边界。请问我该如何做到这一点

下面是处理相机移动的代码

bool calcMovement()
{
    // return if less then two events have been added.
    if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;

    //calcIntersect();

    double dt = _ga_t0->getTime()-_ga_t1->getTime();

    if (dt<0.0f)
    {
        OSG_INFO << "warning dt = "<<dt<< std::endl;
        dt = 0.0;
    }

    double accelerationFactor = _height*10.0;

    switch(_speedMode)
    {
        case(USE_MOUSE_Y_FOR_SPEED):
        {
            double dy = _ga_t0->getYnormalized();
            _velocity = _height*dy;
            break;
        }
        case(USE_MOUSE_BUTTONS_FOR_SPEED):
        {
            unsigned int buttonMask = _ga_t1->getButtonMask();
            //add cases here for finding which key was pressed. 
            if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON || wPressed)
            {
                // pan model.

                _velocity += dt*accelerationFactor;

            }
            else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
                buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON))
            {

                _velocity = 0.0;

            }
            else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON || sPressed)
            {

                _velocity -= dt*accelerationFactor;

            }
            break;
        }
    }

    osg::CoordinateFrame cf=getCoordinateFrame(_eye);

    osg::Matrixd rotation_matrix;
    rotation_matrix.makeRotate(_rotation);

    osg::Vec3d up = osg::Vec3d(0.0,1.0,0.0) * rotation_matrix;
    osg::Vec3d lv = osg::Vec3d(0.0,0.0,-1.0) * rotation_matrix;
    osg::Vec3d sv = osg::Vec3d(1.0,0.0,0.0) * rotation_matrix;

    // rotate the camera.
    double dx = _ga_t0->getXnormalized();

    double yaw = -inDegrees(dx*50.0*dt);


#ifdef KEYBOARD_PITCH
    double pitch_delta = 0.5;
    if (_pitchUpKeyPressed) _pitch += pitch_delta*dt;
    if (_pitchDownKeyPressed) _pitch -= pitch_delta*dt;
#endif

#if defined(ABOSULTE_PITCH)
    // absolute pitch
    double dy = _ga_t0->getYnormalized();
    _pitch = -dy*0.5;
#elif defined(INCREMENTAL_PITCH)
    // incremental pitch
    double dy = _ga_t0->getYnormalized();
    _pitch += dy*dt;
#endif

    osg::Quat yaw_rotation;
    yaw_rotation.makeRotate(yaw,up);

    _rotation *= yaw_rotation;

    rotation_matrix.makeRotate(_rotation);

    sv = osg::Vec3d(1.0,0.0,0.0) * rotation_matrix;

    wPressed = false;
    sPressed = false;

    // movement is big enough the move the eye point along the look vector.
    if (fabs(_velocity*dt)>1e-8)
    {
        double distanceToMove = _velocity*dt;

        double signedBuffer;
        if (distanceToMove>=0.0) signedBuffer=_buffer;
        else signedBuffer=-_buffer;

        // check to see if any obstruction in front.
        osg::Vec3d ip, np;
        if (intersect(_eye,_eye+lv*(signedBuffer+distanceToMove), ip, np))
        {
            if (distanceToMove>=0.0)
            {
                distanceToMove = (ip-_eye).length()-_buffer;
            }
            else
            {
                distanceToMove = _buffer-(ip-_eye).length();
            }

            _velocity = 0.0;
        }

        // check to see if forward point is correct height above terrain.
        osg::Vec3d fp = _eye + lv*distanceToMove;
        osg::Vec3d lfp = fp - up*(_height*5.0);

        if (intersect(fp, lfp, ip, np))
        {
            if (up*np>0.0) up = np;
            else up = -np;

            _eye = ip+up*_height;

            lv = up^sv;

            computePosition(_eye,_eye+lv,up);

            return true;

        }

        // no hit on the terrain found therefore resort to a fall under
        // under the influence of gravity.
        osg::Vec3d dp = lfp;
        dp -= getUpVector(cf)* (2.0*_modelScale);

        if (intersect(lfp, dp, ip, np))
        {

            if (up*np>0.0) up = np;
            else up = -np;

            _eye = ip+up*_height;

            lv = up^sv;

            computePosition(_eye,_eye+lv,up);

            return true;
        }

        // no collision with terrain has been found therefore track horizontally.

        lv *= (_velocity*dt);

        _eye += lv;
    }

    return true;
}
bool-calcMovement()
{
//如果添加的事件少于两个,则返回。
if(_ga_t0.get()==NULL ||_ga_t1.get()==NULL)返回false;
//煅烧炉组();
双dt=\u ga\u t0->getTime()-\u ga\u t1->getTime();
if(dtgetYnormalized();
_螺距+=dy*dt;
#恩迪夫
osg::四次偏航旋转;
偏航旋转。使旋转(偏航,向上);
_旋转*=偏航旋转;
旋转矩阵。makeRotate(_旋转);
sv=osg::Vec3d(1.0,0.0,0.0)*旋转矩阵;
wPressed=假;
sPressed=false;
//移动足够大,可以沿注视向量移动眼点。
if(晶圆厂(_-velocity*dt)>1e-8)
{
双距离移动=_速度*dt;
双签名缓冲区;
如果(距离移动>=0.0)signedBuffer=\u buffer;
else signedBuffer=-\u buffer;
//检查前方是否有障碍物。
osg::Vec3d-ip,np;
if(相交(_-eye,_-eye+lv*(signedBuffer+distanceToMove),ip,np))
{
如果(距离移动>=0.0)
{
distanceToMove=(ip-\U眼).length()-\U缓冲区;
}
其他的
{
距离移动=_缓冲区-(ip-_眼).length();
}
_速度=0.0;
}
//检查前进点在地形上方的高度是否正确。
osg::Vec3d fp=_eye+lv*距离移动;
osg::Vec3d lfp=fp-up*(_高度*5.0);
if(相交(fp、lfp、ip、np))
{
如果(up*np>0.0)up=np;
else up=-np;
_眼睛=ip+向上*高度;
lv=上升^sv;
计算位置(_眼,_眼+lv,向上);
返回true;
}
//在地形上未发现任何命中,因此,请在
//在重力的影响下。
osg::Vec3d dp=lfp;
dp-=getUpVector(cf)*(2.0*_modelScale);
if(相交(lfp、dp、ip、np))
{
如果(up*np>0.0)up=np;
else up=-np;
_眼睛=ip+向上*高度;
lv=上升^sv;
计算位置(_眼,_眼+lv,向上);
返回true;
}
//未发现与地形发生碰撞,因此水平跟踪。
lv*=(_速度*dt);
_眼+=左心室;
}
返回true;
}

我有一台相机,但我需要阻止它,让它转过来看房间。这就是我被卡住的地方。我已经编辑添加了代码。有问题吗?我有类似的问题,我有一台相机,但我需要阻止它转过来看房间。这就是我被卡住的地方。我已经编辑添加了代码。有问题吗wers?我也有类似的问题