围绕物体中心旋转相机 wpf [英] rotate cammera around center of object wpf

查看:40
本文介绍了围绕物体中心旋转相机 wpf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表达混合使您能够导入 3d 模型.我想用代码为 3d 对象设置动画.我似乎无法弄清楚为了使对象旋转而必须修改的属性值是什么.让我告诉你我的意思:

Expression blend enables you to import 3d models. I want to animate a 3d object with code. I just can't seem to figure out what are the property values that I have to modify in order to make an object rotate. Let me show you what I mean:

所以如果我想旋转这个对象,我可以使用相机轨道工具 和 If我使用它我可以得到类似的东西:

so if I want to rotate this object I could use the camera orbit tool and If I use it I can end up with something like:

我知道我可以通过修改对象来创建故事板并创建动画.我需要使用滑块沿 x 轴旋转对象.如果我只修改一个值,它会以一种奇怪的方式旋转,如果我愿意,我实际上必须更改几个属性.例如,当我使用相机轨道工具沿 x 轴旋转对象时,我可以看到所有这些 属性正在更改.我需要弄清楚用于旋转对象的算法是什么.

I know I can create a storyboard and create the animation by modifying the object. I need to rotate the object along the x axis with a slider. If I modify just one value it will rotate in a weird way I actually have to change several properties if I wish to do so. For example when I am rotating the object along the x-axis with the camera orbit tool I can see that all these properties are changing. I need to figure out what is the algorithm being used to rotate the object.

推荐答案

移动相机位置以使您看起来绕 X 轴旋转的数学运算只是圆的参数方程:

The math to move the camera position around so that you appear to be rotating around the X axis is just the parametric equation of a circle:

其中 t 是从零到 2 pi 的角度.

where t is the angle from zero to 2 pi.

想象一下,您正站在街上看着一所房子.相机的坐标必须围绕房子绕一圈,纬度和经度不断变化以与房子保持相同的距离.因此,您无法更改任何值以使其旋转.

Imagine you are standing on the street looking at a house. The camera's coordinates have to follow a circle around the house and the latitude and longitude are continuously changing to keep the same distance from the house. So there is no one value you can change to make it rotate.

一旦您知道相机位置,方向就是原点和相机位置之间的差值.

Once you know the camera position, the direction is just the difference between the origin and the camera position.

所有这些都不难计算,但有一种更简单的方法.相反,保持相机固定并旋转对象.这使得动画更容易.这是一篇 MSDN 文章,其中包含该方法的示例,包括动画:

All this is not hard to calculate but there is an easier way. Instead, keep the camera fixed and rotate the object. This makes animations much easier. Here is an MSDN article contains examples of that approach, including animations:

该文章适用于 WPF 和 Visual Studio,但您可以轻松地将相同的想法应用于 Expression Blend.

That article is meant for WPF and Visual Studio but you can easily adapt the same ideas to Expression Blend.

这篇关于围绕物体中心旋转相机 wpf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆