   Matrix from direction(directx)
  I just can't find this on google yahoo etc.I have point and direction vector. How to create rotation matrix?thx   
  A point and a direction are not sufficient to compute a rotation from. You need an angle and a rotation axis (for what the direction vector you mentioned could be used). But what is the point for or how it is determined?   ;  Creating a matrix using just a point and a direction vector should be pretty straight forward, it's basically the same process as that used to generate a look-at matrix. The only other input you might need is an up vector although it's pretty safe to assume this will be the y axis (i.e. x = 0, y = 1, z = 0).Anyway I think this might be what you're looking for:1) Make sure your direction vector is normalised then copy it to the at vector of the matrix:normalise(direction)matrix._31 = direction.xmatrix._32 = direction.ymatrix._33 = direction.zmatrix._34 = 02) Calculate the right vector of the matrix using the cross product of the up vector and the normalised direction vector:right = cross(vector(0, 1, 0), direction)matrix._11 = right.xmatrix._12 = right.ymatrix._13 = right.zmatrix._14 = 03) Calculate the up vector of the matrix using the cross product of the normalised direction vector and the right vector:up = cross(direction, right)matrix._21 = up.xmatrix._22 = up.ymatrix._23 = up.zmatrix._24 = 03) Copy the position directly to the matrix:matrix._41 = pos.xmatrix._42 = pos.ymatrix._43 = pos.zmatrix._44 = 1Hope this makes sense, it's not specifically directx code but I'm pretty sure directx provides all the functionality you'll need to get it working.   ;  well, basically, with a vector you can define an orientation for your object, but you are leaving one degree of freedom unaffected (the rotation around local z)Also for this, you don't need the point. Just the vector is enough.In directX this should do the job. The matrix m will be the orientation matrix for your object.D3DXMATRIX m;D3DXMatrixIdentity( &m );D3DXVECTOR3 LocalZ, LocalY, LocalX;D3DXVECTOR3 up = D3DXVECTOR3(0.f,1.f,0.f);LocalZ = yourDirectionVector;D3DXVec3Normalize( &LocalZ, &LocalZ );D3DXVec3Cross(&LocalX, &up, &LocalZ );D3DXVec3Cross(&LocalY, &LocalZ, &LocalX );D3DXVec3Normalize( &LocalX, &LocalX );D3DXVec3Normalize( &LocalY, &LocalY );m._11 = LocalX.x; m._12 = LocalX.y; m._13 = LocalX.z;m._21 = LocalY.x; m._22 = LocalY.y; m._23 = LocalY.z;m._31 = LocalZ.x; m._32 = LocalZ.y; m._33 = LocalZ.z;If you also want to position your object at the given point you mentioned (using the same matrix) just set the 4th row of the matrix to ( point.x, point.y, point.z ,1). However, this would turn it into a world matrix, not a rotation one...edit:pauls_1979, you beat me by a split second there :)   ;Quote:pauls_1979, you beat me by a split second there :) Haha, looks like we both had the same idea anyway.   ;Quote:original post by pauls_19792) Calculate the right vector of the matrix using the cross product of the up vector and the normalised direction vector:  right = cross(vector(0, 1, 0), direction)  matrix._11 = right.x matrix._12 = right.y matrix._13 = right.z matrix._14 = 0I think the "right" vector has to be normalized before being copied into the matrix, since||cross(vector(0, 1, 0), direction)||= ||cross(vector(0, 1, 0), vector(dx, dy, dz))||= ||vector(dz, 0, -dx)||= sqrt(dz^2 + dx^2) != sqrt(dx^2 + dy^2 + dz^2) == 1Of course, the entire computation is possible only under the assumption that the object doesn't look in direction of the up vector (as you have stated)...Nevertheless, you pointed out the method ex9 was presumably searching for...   ;Quote:I think the "right" vector has to be normalized before being copied into the matrixI think you're right about the need to normalise the right vector (haven't had chance to test it). If so I guess this should also apply to the final up vector.   ;Quote:Original post by pauls_1979Quote:I think the "right" vector has to be normalized before being copied into the matrixI think you're right about the need to normalise the right vector (haven't had chance to test it). If so I guess this should also apply to the final up vector.For safety it could also be done for the final up vector but in general need not, since (after the correction) the final up vector is the cross product of two perpendicular unit vectors what yields (neglecting finite float resolution) in another unit vector:||a x b|| := ||a|| * ||b|| * sin<a,b> = 1 * 1 * sin(pi/2) = 1;  Thx:)I don't understand the problem with UpVector?For one direction matrix should remains untouched (Identity) is this it?To be more specyfic I have a two points and Iwant one look at another.;Quote:Original post by ex9Thx:)I don't understand the problem with UpVector?For one direction matrix should remains untouched (Identity) is this it?To be more specyfic I have a two points and Iwant one look at another.What the above posters are saying is that there is more than one way to orient an object so that it is looking at another. Imagine a spaceship aiming at another spaceship. It should be clear that the first ship can rotate about its forward vector (roll) and always be aiming at the other ship. Therefore, simply saying 'I want to look at a particular point' is not enough info to completely describe an orientation. This is where the up vector comes in; it supplies an additional piece of information, that is, a frame of reference, that allows you to uniquely define the orientation. The potential problem is when the 'aim' vector is aligned with the up vector. The up vector then supplies no useful information, which is reflected in the degenerate cross product calculated by the algorithm.DirectX has this function for creating the view version of the matrix you're looking for. You could use this function to get the matrix, and then invert it to get the 'object' version. (Or just use the algorithm described by the previous posters, which will be cheaper.)   