开发者

Getting a 3D object's orientation and aligning it parallel to a Vector3D in WPF

开发者 https://www.devze.com 2023-04-10 08:53 出处:网络
I have a WPF project in which I have imported code that represents a 3D scene created in 3D Max Studio and then converted using a tool to XAML code that I can use in WPF.

I have a WPF project in which I have imported code that represents a 3D scene created in 3D Max Studio and then converted using a tool to XAML code that I can use in WPF.

So, I have a Viewport3D and inside it a GeometryModel3D object that represents a rectangular prism. I have two 3D points (X, Y, Z) that represent the beginning and the end of my vector.

What I would like to do is just align the prism parallel to my Vector3D along the prism's longest side. I know a few things about transformations and translations of 3D objects in code and I have some knowledge in math, my biggest problem is getting the orientation of a 3D object.

I would like somehow to be able to determine the up vector of the object because I think that it could help me, and what I would also like is to somehow be able to determine the coordinates of the base and the top of the prism, so I could calcul开发者_如何转开发ate the prism's "direction" vector.

I've been on the web for a few days trying to figure this out but I'm really stuck, please, any help would be very much appreciated.

Thanks!


I do not know the code about the WPF actually. But I think it is a math problem.

You can construct the local matrix for a vector. That is, using the vector you want to align as Z vector, and find another vector(which is usually a vector parallel to your prism's bottom side) as X, after that do a cross product of Z,X, then you get the Y.

Finally the matrix is M=[X,Y,Z]. If you want affine matrix, get the position vector of prism, set it as T, then the matrix will be M=[X,Y,Z,T]

using this matrix, transform your prism's vertices: v=Mv

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号