I am trying to draw a 3d tube. Using glTranslate I am able to position the rings on the spine’s corners, however I am struggling providing them with the correct angle. As you can see on this image, the rings need to be perpendicular to half of the angle between the legs of the spine.
first pic is the spine, next to it a wannabe 3d pic of the tube and the lower one shows the spine from one side, showing how the rings should be rotated.
I’ve been reading about matrices, vectors, parallel transport, dot product, crossing vectors and I am getting all dizzy. Also I havent been able to find any real code examples, it’s all just theory.
Reading it I guess I am able to calculate vectors (x of next vertice minus x of the current vertice, y of next vertice minus y of current vertice and z onvmzocv Is this right?
Also I read about normalizing which I should be able to do as well.
I am using openGL calls within JAVA.
Now how would I go about doing this? How would I turn a vector like I calculated the way above into a rotation matrix? Should I divide the values by 2 to have it center between the legs?
For each leg of the spine, you need to find a plane that is perpendicular to that leg. You will define a circle (or whatever shape is the cross-section of your tube) on that plane and then project its vertices orthographically onto a plane that is at the junction of that leg and its adjoining leg of the spine to provide a mitered joint.
You can define a plane that is perpendicular to a leg by taking the cross product of that leg and its adjoining leg on the spine. That gives a vector perpendicular to the plane both legs lie in. Next, take the cross product of the leg and the vector perpendicular to the plane both legs lie in. That gives a vector that is perpendicular to both the leg and the vector that’s perpendicular to the plane both legs lie in. So, you’ve got two vectors that are perpendicular to each other and are perpendicular to the leg. Those two vectors define a plane that is perpendicular to the leg.
You can define the plane at the junction of two adjoining legs by taking the cross product of the two legs. That gives you a vector that is perpendicular to the plane the two adjoining legs lie in. Next, find the angle between the two adjoining legs, divide it by two, and use that to define a vector half way between them from the junction of the two legs (this vector lies in the plane that both legs lie in). Those two vectors are perpendicular to each other and define the plane that contains the junction of the two legs and is at the angle half way between the two legs’ angle to each other.
Project the vertices of the tube’s cross section from the plane that’s perpendicular to the leg onto the plane that’s at the junction of the two adjoining legs. Repeat this for each junction of spine legs. Just use a plane that’s perpendicular to the first leg to cap the end of that leg, and likewise for the last leg.
That gives you all the planes you need. I didn’t suggest how to project the tube’s cross section vertices orthographically onto the planes passing through the leg junctions, and then connect the vertices as a bunch of triangles from one plane to the next (assuming you want to render surfaces). It may be very tricky keeping the orientation of the tube cross sections so there is no twist when connecting the vertices of the cross sections to form triangles.
Hopefully, though, what I’ve provided is enough to get you started. Good luck.
Your problem is not trivial.