🔒 Locked
Orienting mesh to vector
Advertisement
Original Post
A similar question was asked a few days back, and it was suggested that using properties of the dot product might be useful.
The dot product between an up vector (0,1,0) and the surface normal should give you the cosine of the angle, which you should be able to feed into a rotation calculation.
Not 100% sure on that one, having never tried it myself [oh] - but it could be worth considering?
hth
Jack
The dot product between an up vector (0,1,0) and the surface normal should give you the cosine of the angle, which you should be able to feed into a rotation calculation.
Not 100% sure on that one, having never tried it myself [oh] - but it could be worth considering?
hth
Jack
jollyjeffer's solution should be what you're looking for if you already have an orientation for your mesh. If you're starting from scratch, there isn't one unique orientation that will align with the ground normal, so you'll need some sort of 'make orthonormal basis' function.
If that still doesn't help, you might describe more specifically what you're trying to do.
If that still doesn't help, you might describe more specifically what you're trying to do.
Well I tried an alternative technique I found after learning some more matrix maths, in which I directly put 'axis' vectors into my transformation matrix:
However it doesn't work properly. Sometimes the mesh seems to be orientated correctly, and sometimes it looks at though the mesh is 'slanted' or otherwise distorted. Can anyone see a problem with my code?
private Matrix BuildTransformationMatrix(Vector3 vPos, Vector3 vForward, Vector3 vUp) { Matrix mat; Vector3 vRight = Vector3.Cross(vUp, vForward); mat.M11 = vRight.X; mat.M12 = vRight.Y; mat.M13 = vRight.Z; mat.M21 = vUp.X; mat.M22 = vUp.Y; mat.M23 = vUp.Z; mat.M31 = vForward.X; mat.M32 = vForward.Y; mat.M33 = vForward.Z; mat.M41 = vPos.X; mat.M42 = vPos.Y; mat.M43 = vPos.Z; mat.M14 = mat.M24 = mat.M34 = 0.0f; mat.M44 = 1.0f; return mat; }However it doesn't work properly. Sometimes the mesh seems to be orientated correctly, and sometimes it looks at though the mesh is 'slanted' or otherwise distorted. Can anyone see a problem with my code?
Quote:Unless up and forward were perpendicular to begin with, the resulting basis won't be orthonormal if you only calculate vRight. Remember that in an orthonormal basis all three vectors are unit-length and perpendicular to one another. So the way you were doing it initially, the final basis was only orthonormal if the up and forward vectors you passed in were perpendicular to begin with.
I can see why I should normalize vRight, but why the need to calculate a new vForward? vRight is calculated from vForward (and vUp) in the first place?
Let me know if that doesn't make sense...
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement