2017-03-05 70 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