Sign in to follow this  

Stretch a mesh between two points

This topic is 2544 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
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

This topic is 2544 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this