   Edge Picking
  Hi all,I''m currently writing a map editor and I have some trouble figuring out how to do edge picking. Well, the picking itself isn''t the problem, I can just check the ray that comes from the mouse against all edges, but when an edge is selected I want to draw a cylinder on top of it (as highlight). So how would I go about getting the center, translation and rotation of any given edge (2 vertices)?Hope you guys can help me...thanks! 
  if you go te opengl way, you can simply do glLineWidth(4.0f);glCOlor3f(1.0f, 0.0f, 0.0f);glBegin(GL_LINES);glVertex3f(V0.x, V0.y, V0.z);glVertex3f(V1.x, V1.y, V1.z);glEnd();else, for a cylinder, you can generate a matrix/quaternion converting from one axis to another.Matrix.FromDirection(const Vector& In, const Vector& out);Quaternion.FromDirection(const Vector& In, const Vector& out);to rotate from one vector to another, the axis of rotation would be the cross product of the in and out axis, the angle would be the magnitude of the cross product.say your original cylinder is along the Y axis, and you edge has direction DirAxisOfRotation = Dir.Cross(Vector(0, 1, 0));float sin_angle = AxisOfRotation.Length();AxisOfRotation /= sin_angle;cos_angle = Dir.Dot(Vector(0, 1, 0);float angle = (float) atan2(sin_angle, cos_angle);glRotatef(angle, AxisOfRotation.x, AxisOfRotation.y, AxisOfRotation.z);at least, I''d try that for a start. You also need to scale your cylinder by the edge length, obviously. ;  wow, this is great info for the start...thank you!sadly I don''t use opengl, but dx...stupid thing wont let me draw lines more than 1px width. anyway, maybe you can elaborate a bit more on the matrix stuff. Especially quaternions still give me a hard time. Can you tell me a bit more about whatts goin on there, so I can find the adequate DX functions...also, how could you define the correct rotation with only one rotationaxis and angle, or do i need to do that for both axes?o yea, scaling, well..thats the easy part. ;also, how could you define the correct rotation with only one rotationaxis and angle, or do i need to do that for both axes?nope  only an axis in 3D and an angle are required to generate a rotation. a Rotation around X, Y and Z (euler rotations) can be composed into one rotation around an axis. It''s all maths stuff.Since you are using DirectX, D3DXMATRIX Mtx;D3DXVECTOR3 Axis;float angle;D3DXVec3Cross(&Axis, &In, &Out;float sin_angle = D3DXVec3Length(&Axis);float cos_angle = D3DXVec3Dot(&In, &Out;Axis /= sin_angle;float angle = (float) atan2(sin_angle, cos_angle);D3DXMatrixRotationAxis(&Mtx, &Axis, ∠); ;  and about the functions Matrix.FromDirection(const Vector& In, const Vector& out);Quaternion.FromDirection(const Vector& In, const Vector& out);they find the rotation matrix necessary so vector In faces the same way as vector Out. These functions should be part of a maths library, by apparently, DirectX does not have them.There are plenty of posts around to generate the matrix/quaternion you want. But for the moment, you can try the angle/axis trick above. [edited by - oliii on December 18, 2003 4:40:11 AM];  Hell yes, theres sure a lot of strange math going on, I really need to buy a book and read up on that...The edges have to wait now anyway, as I''m having problems getting my pickray, even though I did it as in the sample...I''m posting that over in the DX section, if you wanna take a look But I saved all of it for later reference, even a bloody newbie like me should be able to get it to work with that great description. Thanks again. ;  oops sorry, accidental post 