2017-03-05 69 views
0

我刚刚实施了libgdxLibgdx轨迹球相机和广告牌

private void rotate(float pitch, float yaw, float roll) { 
     tempQuat.setEulerAngles(pitch, yaw, roll); 
     rotationQuat.mulLeft(tempQuat); 
    } 

的轨迹球凸轮...

float aspect = camera.viewportWidth/camera.viewportHeight; 
    camera.projection.setToProjection(Math.abs(camera.near), Math.abs(camera.far), camera.fieldOfView, aspect); 
    camera.view.setToLookAt(camera.position, tempVector.set(camera.position).add(camera.direction), camera.up); 

     rotate(MyGestureListener.mXAngle, MyGestureListener.mYAngle, 0); 
     camera.view.rotate(rotationQuat); 

    camera.combined.set(camera.projection); 
    Matrix4.mul(camera.combined.val, camera.view.val); 

    camera.invProjectionView.set(camera.combined); 
    Matrix4.inv(camera.invProjectionView.val); 
    camera.frustum.update(camera.invProjectionView); 

一切工作正常,但有一点不好:

我有作为广告牌总是旋转到相机的一些贴花纸:

 p.decalPoint.setPosition(p.pos.x, p.pos.y, p.pos.z); 
     p.decalPoint.setRotation(camera.direction, camera.up); 

现在这个坏了。为什么?我怎样才能解决这个问题?

我需要一个轨迹球相机喜欢这里:

https://youtu.be/YxNjjyv8W0I

上面的代码工作得很好,但广告牌效果不与凸轮工作。

回答

0

我结束了使用两个旋转矩阵和camfocusvector作为轨迹球

四元数是不适合本

1

您正在绕过相机并手动更新矩阵和平截头体成员,但忘记更新其他成员。所以你必须要么更新其他成员(如positiondirectionup)为好,或转而使用相机提供的功能:

  • 不需要

    camera.projection.setToProjection呼叫。
  • 不需要致电camera.view.setToLookAt
  • 致电camera.view.rotate的电话号码是camera.rotate
  • 不需要拨打电话camera.combined.setMatrix4.mul
  • 不需要致电camera.invProjectionView.setMatrix4.inv
  • 不需要致电camera.frustum.update
  • 通话添加到camera.update();

又见http://www.badlogicgames.com/wordpress/?p=1550获取更多信息。

+0

私人四元getRotatedQuaternion(浮动间距,浮子偏航,浮动辊){ tempQuat.setEulerAngles(间距,偏航,滚动); rotateQuat.mulLeft(tempQuat); return rotationQuat; } camera.lookAt(Axis.ORIGO); camera.rotate(getRotatedQuaternion(gestureListener.mXAngle,gestureListener.mYAngle,0)); camera.update();它不能按预期工作:( – lacas

+0

也许然后首先解释你的期望,虽然这段代码看起来非常不同,所以如果你有不同的问题,那么最好问一个新的问题。 – Xoppa

+0

这将是一个弧球相机。如何更新方向和向量? – lacas