View Single Post
  #1  
Old 05-11-2009, 09:39 AM
Penguin Penguin is offline
Member
 
Join Date: Mar 2009
Posts: 14
rotating an object

Hi, I want to rotate an object (sphere) similar to the globe in google earth.

The sphere is mapped in front of the main view. With the use of the viz.pick() command I get the intersection position of the mouse pointer on the sphere (intersectionItem.point).

The following code is running in a mouse button down callback function. While dragging the mouse over the sphere the new intersection position is callculated (curIntersectionItem.point)

With this two points and the center of the sphere I get two direction vectors and the angle inbetween.

The rotation of the sphere seems to work until it rolls. Then the mouse movement does not match to the rotation of the sphere any more!

Is there a better way to achieve a stable rotation? While dragging in google earth the same part of the globe always stays under the mouse pointer.

Code:
curIntersectionItem = calcUiIntersection()
rotationMat = vizmat.Transform()
rotationMat.makeVecRotVec(vizmat.VectorToPoint(sphere.getPosition(viz.ABS_GLOBAL),intersectionItem.point),vizmat.VectorToPoint(sphere.getPosition(viz.ABS_GLOBAL),curIntersectionItem.point))

spherePos = sphere.getPosition(viz.ABS_GLOBAL)
sphereMat = sphere.getMatrix(viz.ABS_GLOBAL)
sphereMat.setTrans(0,0,0)

transformMat = vizmat.Transform()
transformMat = rotationMat * sphereMat

transformMat.setTrans(spherePos)
sphere.setMatrix(transformMat,viz.ABS_GLOBAL)

intersectionItem = curIntersectionItem
Reply With Quote