You are not logged in.
Pages: 1
Hi,
I have another directx question. I have a normal vector (position on landscape). Now I want to align another mesh with the landscape using this normal vector. Does anyone know how I can get the rotation values in degrees (0..360) for all three axis based on the landscapes normal vector?
I used matrices before for this, unfortunatly this time I need another approach because matrices are not supported for this kind of mesh. I tried a lot with asin and acos but nothing worked. The only thing that seemed right was using:
xrot = ASin(LandVector.x);
But I couldn't get this working for the z-axis? I belief the Y -axis should just be 0 or the value I want it to point at, correct?
Any help would be much appreciated!
Offline
Urgh, is this complicated? Basically I just have a normalvector where the x,y,z, values needs to be transformed to degrees (I think).
Offline
what do you mean in angles though, because theres more than one way depending upon the order of rotations, and which axis of rotations you use.
for example, you could define it as 2 angles for rotation around the x axis, then the y axis in that order, or around the z axis and y axis in that order, or around the y axis then z axis. etc etc.
The Beginning Of All Things To End.
The End Of All Things To Come.
Offline
Perhaps this is more complicated then I thought. The directx wrapper has a Mesh SetRotation function for all 3 axis. My Thoughts were, a normal vector points in a certain direction depending on the x,y and z values. So it should be possible to calculate the angles this vector makes with the x,y and z axis. As this is a landscape/mesh positioning issue my thoughts were also that horizontal rotation of the mesh (y-axis) is not related to the normal vector but depends on the direction the mesh should point at. So needed are the x and z rotation angles to align the mesh with the landscape at a specific position. Is this relevant information, or am I completely lost here? I don't know about the order of rotations, perhaps this is something I should experiment with when I have a basic idea of how to solve this issue?
Offline
Firstly, let me say that I have no idea how directx works, but I hope this will be helpful.
Secondly, I assume that by the landscape's "normal vector" you mean a vector that is at right angles to the landscape in question, as opposed to a "normal" in the sense of "not unusual" vector. I'm also assuming that we're working in three-dimensional space since you refer to a z-axis.
Anyways, if you have a vector that is normal to the landscape denoted by
and a vector that is normal to the mesh denoted by , then the angle between them, can be expressed by:Where:
andI hope this helps, let me know if there's anything that needs further explaination.
Bad speling makes me [sic]
Offline
well first of all, just finding the angle isnt enough, because first of all, the mesh doesnt have a normal . but even if it did, youd need a vector rotate around, but he said the mesh cant be rotated just using a matrix (at which you could find the cross product to rotate around)
one way you could do it with the landscape normal, is to extrapolate a set of axis to go with it, but again, that requires a matrix to rotate by, since you can only define xrot, yrot, zrot, i still need to know in which order directX does its rotations for these meshes, does it rotate around the x axis, then the y axis? or what?
The Beginning Of All Things To End.
The End Of All Things To Come.
Offline
Ah, I see - so you have to rotate around the x, y and z-axes in some order? Again, I'm not familiar with directx, I infered from the first post that it was simply the angle that was sought after.
Do you have (or can you get) the unit vector in terms of i, j and k with respect to the mesh you want to put it on? In this case you can use the formula above with
to find the angle between your normal vector and the x-axis of the mesh, and then do similar with j and k to find the appropriate angles there as well.Is this any nearer to what you're after?
Bad speling makes me [sic]
Offline
@ Dross, Yes, That's what I mean with normal vector and yes it is 3D where Y is up, x is right and Z is forward.
@ luca-deltodesco, I did a quick search for the rotation order but no luck so far. I will search further and post here if I find it. Is the solution different for each type of order or is there a basic approach and can I find out the correct order by trial and error?
Offline
@ Dross, Yes, That's what I mean with normal vector and yes it is 3D where Y is up, x is right and Z is forward.
@ luca-deltodesco, I did a quick search for the rotation order but no luck so far. I will search further and post here if I find it. Is the solution different for each type of order or is there a basic approach and can I find out the correct order by trial and error?
the order of rotations does matter, simply because matrix multiplication is not always commutive, i.e. AB doesnt always equal BA
you can figure out the order by just rotating the mesh around changing one value at a time and seeing how it effects its orientation.
The Beginning Of All Things To End.
The End Of All Things To Come.
Offline
I did a test with 2 meshes. mesh1 by default rotated on all 3 axis in one call. Mesh 2 rotated by each axis individually at a time. The order does not influence the end rotation. Mesh 2 always ends up exactly like Mesh 1.
Offline
no, the order DOES influence the end rotation, but it still depends on how directx handles things, sice its not influencing end result, it simply means, that whenever you change a rotational value, it reacalculates the rotation using the same order of rotations from the base. rather than rotating the current rotation matrix.
The Beginning Of All Things To End.
The End Of All Things To Come.
Offline
luca-deltodesco, I belief you for the full 100%. It was just to say that I cannot get the rotation order by doing what you suggested as no matter what order I tried it resulted in the same end position. I hope I can find more about this.
Offline
There is is still no 100% clear answer to this but all of us, including real DirectX experts online, think it is YXZ (Y > up, X > right, Z > forward) because all functions related to this have YawPitchRoll in it which basically stands for YXZ (not sure if this is the same in maths terminology?).
Last edited by safra (2006-09-12 08:12:46)
Offline
Pages: 1