Your question is not clear, but as I’ve handled Unity3d, I saw that’s what you’re talking about, not just C#.
Let’s explain the code, line by line:
var device3d = helixViewport3D.Children[0];
I don’t know exactly what the helixViewport3D
, but the way it’s being used is something that contains one or more objects as a child. The first of these objects is the device3d
, who I suppose is a GameObject
.
var matrix = device3d.Transform.Value;
Each object has an associated matrix. This matrix contains data about the position of the object in the virtual world, as well as its size and orientation. The details of the mathematical functioning of the matrix are difficult to understand, as they require an advanced knowledge in linear algebra.
However, the Unity3d API abstracts the gory mathematical details so that you can work with these matrices without having to go so deep into the details of the mathematics behind it.
matrix.Rotate(new Quaternion(new Vector3D(1, 0, 0), 1));
That one Quaternion
created is a set of values that represents a rotation at 90 degrees. Again, the mathematical foundation behind it is complicated, but it is abstracted. This rotation is applied to the matrix. Since the matrix represents the position of an object, along with its size and rotation, this operation will rotate the object by 90 degrees.
device3d.Transform = new MatrixTransform3D(matrix);
This applies the new matrix to the object, which results in its rotation by 90 degrees.
helixViewport3D.Children.RemoveAt(0);
helixViewport3D.Children.Add(device3d);
These two lines remove the element from the first position of the helixViewport3D
(which is the device3d
) and puts it there again. I believe it’s totally unnecessary and that in the end it doesn’t end up doing anything, but I’m not sure that.
As a result of these operations, the object will be rotated by 90 degrees. When applying this twice, the rotation will be 180 degrees.
Icarus, if I were to vote to close your question it would be as if it were not clear. You had not tagged Unity3d, but this has already been solved for you. Anyway, when you say that the object "rotates", what exactly you mean? Try to illustrate your scenario, perhaps with images (small!) of before and after the object being rotated or with some sketch of the axis and angle of the intended and realized turn. Or, better yet, provide a [mcve] so that someone interested in helping you can at least test your problem.
– Luiz Vieira
@Luizvieira I also felt inclined to vote to close. If I hadn’t tagged unity3d, she would have already gone into space. However, even as it is and having risked posting an answer, I still see it as a question that is on top of the "should be closed vs still can answer" line. Icarus, consider Luiz’s comment up there to improve your question and make it perfectly responsive for everyone. Even to write my answer, I had to guess and risk a few things, which is not a good sign.
– Victor Stafusa
@Victorstafusa I found her response very good (and I even voted for her). I just don’t know if it helps in fact the AP based on the comments you exchanged later. And the fault is that the question is not clear enough (although it is not totally bad). Icarus, improve the question if possible, consider accept the answer of Victor if she helped you, and remember that you can open new questions if you have other related questions. If you haven’t done it yet, do the [tour] and mainly read [Ask].
– Luiz Vieira