简体   繁体   English

在对象wpf的中心周围旋转cammera

[英]rotate cammera around center of object wpf

Expression blend enables you to import 3d models. 表达式混合使您可以导入3d模型。 I want to animate a 3d object with code. 我想用代码为3d对象设置动画。 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: 让我告诉你我的意思:

在此输入图像描述

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: 如果我使用它,我最终会得到类似的东西:

在此输入图像描述

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. 我需要使用滑块沿x轴旋转对象。 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 例如,当我使用相机轨道工具沿x轴旋转物体时,我可以看到所有这些 在此输入图像描述 properties are changing. 属性正在发生变化 I need to figure out what is the algorithm being used to rotate the object. 我需要弄清楚用于旋转对象的算法是什么。

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: 移动相机位置以使您看起来围绕X轴旋转的数学运算只是圆的参数方程:

圆的参数方程

where t is the angle from zero to 2 pi . 其中t是从0到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. 一旦知道摄像机位置,方向就是原点和摄像机位置之间的差异。

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: 这是一篇MSDN文章,其中包含该方法的示例,包括动画:

That article is meant for WPF and Visual Studio but you can easily adapt the same ideas to Expression Blend. 该文章适用于WPF和Visual Studio,但您可以轻松地将相同的想法应用于Expression Blend。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM