Reputation: 191
I am working on 3D vertex skinning. Everything is working fine. I am now stuck on how to best represent my bones graphically. I recognize that I can draw the bones as simple lines from one joint to the next.
However, I strongly want to draw something similar to that of blenders graphical representation of blender bones ( with heads and tails).
I sample code I have( below ) works however only for joints that are facing in the direction (0,1,0). If I have a bone facing (1,0,0), then it does not accurately represent that bone.
So ultimately, my question is: is there a math equation to use to orientate these vertices from (0,1,0) to some arbitrary vector direction based on how my bone joints are facing.
glm::vec3 vert[14];
vert[ 0] = glm::vec3( 0.0f, 0.0f, 0.0f);
vert[ 1] = glm::vec3(-0.2f, 0.2f,-0.2f);
vert[ 2] = glm::vec3( 0.2f, 0.2f,-0.2f);
vert[ 3] = glm::vec3( 0.0f, getLength(), 0.0f);
vert[ 4] = glm::vec3(-0.2f, 0.2f,-0.2f);
vert[ 5] = glm::vec3(-0.2f, 0.2f, 0.2f);
vert[ 6] = glm::vec3( 0.0f, 0.0f, 0.0f);
vert[ 7] = glm::vec3( 0.2f, 0.2f,-0.2f);
vert[ 8] = glm::vec3( 0.2f, 0.2f, 0.2f);
vert[ 9] = glm::vec3( 0.0f, 0.0f, 0.0f);
vert[10] = glm::vec3(-0.2f, 0.2f, 0.2f);
vert[11] = glm::vec3( 0.0f, getLength(), 0.0f);
vert[12] = glm::vec3( 0.2f, 0.2f, 0.2f);
vert[13] = glm::vec3(-0.2f, 0.2f, 0.2f);
Upvotes: 1
Views: 827
Reputation: 14730
The following is a more general recipe, but may work for your problem.
You basically need a model lined up against an arbitrary direction, usually the vertical axis is used, but any would do. Then you may use the difference of the bone application points as a the destination vector, and the model axis as the origin vector. From then,:
you compute the rotation quaternion between these vectors, as explained there,
and the scale factor by dividing the destination vector length by the origin vector length.
You may repeat the first operation with the model facing vector, if the rendered one needs to be facing a specific direction.
You now have rotation and scale parameters to transform your model to the desired fit. Just turn these into a matrix, and apply it in your vertex transform stage.
This recent question deals with rendering many instances of the same mesh, it might be helpful in getting an idea of how you may proceed once you have all the data ready.
Upvotes: 1