|
我创建了一个XY方向的平面,并继承NodeTrackerManipulator写了个操作器观察他。
需要实现切换从平面的侧上方俯视观察这个平面的正面和背面,也就是当center为(x, y, 0)时设置eye在(x+120, y, z)和(x+120, y, -z)
现在发现无法正确设置up方向。尝试取当前up方向,把up.z()取负
- this->getTransformation(eye,center,up);
- eye = osg::Vec3d(eye.x(),eye.y(),-eye.z());
- up = osg::Vec3d(up.x(),up.y(),-up.z());
- this->setTransformation(eye,center,up);
复制代码
但是切换到观察背面时(eye.z()为负时)是一种仰视视角,如图
尝试手动计算up方向,用center到eye的向量叉乘平行于Y轴向量计算up方向
- this->getTransformation(eye,center,up);
- eye = osg::Vec3d(eye.x(),eye.y(),-eye.z());
- osg::Vec3d l = eye-center;
- l.normalize();
- up = osg::Vec3d(0.0,-1.0,0.0)^l;
- this->setTransformation(eye,center,up);
复制代码
但是切换到背面时仍然是仰视的,请问应如何设置up方向?
添加断点:
正视时eye 520.0 390.0 20.0 center 400.0 390.0 0.0 up -0.16439898730535726 0.00000000000000000 0.98639392383214364
背视时eye 520.0 390.0 -20.0 center 400.0 390.0 0.0 up 0.16439898730535726 0.00000000000000000 0.98639392383214364
很奇怪up只有x为改变了符号,应该z也改变符号才对啊?
|
|