Jump to content
  • Advertisement
Sign in to follow this  
sipickles

Stretch a mesh between two points

This topic is 2759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

Not sure if this should be in the maths section but since I'd like to use D3DX operations to achieve this, I've posted here.

Say I have a unit cube - a simple cube mesh 1 x 1 x 1 - and two points in 3d space.

I'd like to link the points with a 3d line made by transforming the cube.

Could anyone take me through the translation, rotation and scaling stages required to do this?

My thoughts:

Position cube midway between two points
Scale cube to height of distance between two points, and width of desired line
Perform a 3d rotation to match ends of stretched cube to two points

Its really the last operation I am having trouble with.

Any advice gratefully received. I am using DX9 btw.

Thanks

Simon

Share this post


Link to post
Share on other sites
Advertisement
If you scale the height to match the distance between the 2 points, then the "up" vector of the cube has to be parallel (or anti-parallel) to the difference vector between the 2 points. Hence compute the difference vector, normalize it, and use that as up vector. Construct the other 2 vectors as usual, and compose all 3 vectors to yield in the rotation matrix. (Its just the same as computing a look-at matrix, for which dozens of threads can be found.)

Use the correct order of transformations: Scale the initial cube, rotate the scaled cube, translate the rotated and scaled cube.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!