这里有没有人编写使用Gizmo移动对象的代码? 我的意思是通过鼠标翻译或旋转立方体? 例如,在3ds max或blender编辑器中。 我无法理解如何使用3d鼠标位置。
答案 0 :(得分:1)
我做到了。我的算法:
Vector2 mouseDelta;//set this for your own
Vector3 objectPosition;//and this
Vector3 objectUpDir;//and this
//Here
Vector3 MoveY(){
Vector2 center = worldToScreen(objectPosition);//get center to screen
Vector2 up = worldToScreen(objectPosition+objectUpDir);//get up to screen
float ang = Vector2.CalculateAngle(mouseDelta,up-center);//get angle from up && mouse delta
ang = MathHelper.RadiansToDegrees(ang);//get degreees
ang = ang/90-1;//here :if perpendicular, then ang = 0
return objPosition + objUpDir * (ang/5);//5 - your speed
}