# Translation along rotated unit vector problems

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

## Recommended Posts

I'm trying to create a series of vertex connected 'segments' that bend in a certain direction. Currently I'm starting the join of each 'segment' at 0,0,0, rotating it and then translating it in the direction it is now facing (by translating along a unit vector which also gets rotated). Each time a new segment is created, the amount to rotate is increased so that along the length of all the segments there's a smooth bending. However, once the unit vector gets rotated a certain amount, when translating along it the verticies start to become squashed and distorted. As you can see from the picture, the bending is smooth and then suddenly flatens off before curling round in the opposite direction. I dumped the values for the unit vector for each segment and the problem seems to occur when the unit vector goes into negative values. Does anyone have any idea what I'm doing wrong? I assume I'm not using the unit vector correctly but I'm not sure where I'm going wrong. Thanks. The problem(click for larger): The unit vector values:
X0.000, Y0.996, Z0.087,
X0.000, Y0.966, Z0.259,
X0.000, Y0.866, Z0.500,
X0.000, Y0.643, Z0.766,
X0.000, Y0.259, Z0.966,
X0.000, Y-0.259, Z0.966,
X0.000, Y-0.766, Z0.643,
X0.000, Y-1.000, Z0.000,
X0.000, Y-0.707, Z-0.707,
X0.000, Y0.087, Z-0.996,

The Code:
D3DXMATRIX mTransform;
D3DXMATRIX mRotate;
D3DXMATRIX mTranslate;

...

//floats for rotation
float rotx = 5.0f;
float roty = 0.0f;
float rotz = 0.0f;

//Update the rotation values with the current rotation
vRotation.x += rotx;
vRotation.y += roty;
vRotation.z += rotz;

//Unit vectors (the vector4 is for use with D3DXVec3Transform and is then copied into the Vector3 for normalization)
D3DXVECTOR4 transformedOrientation;
transformedOrientation = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 0.0f);

D3DXVECTOR3 transformedOrientation2;
transformedOrientation2 = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

//Rotation (convert from degrees to radians)
D3DXMatrixRotationYawPitchRoll(&mRotate, (vRotation.y * (PI / 180)), (vRotation.x * (PI / 180)), (vRotation.z * (PI / 180)));

//Transform the orientation unit vector by the rotation
D3DXVec3Transform(&transformedOrientation, &vOrientation, &mRotate);

//Translate the rotated verts to the desired location
D3DXMatrixTranslation(&mTranslate, vLocation.x, vLocation.y, vLocation.z);

//Shove the VEC4 orientation vector into a VEC3
transformedOrientation2 = D3DXVECTOR3(transformedOrientation.x, transformedOrientation.y, transformedOrientation.z);

//Normalise the VEC3
D3DXVec3Normalize(&transformedOrientation2, &transformedOrientation2);

//Combine the rotation and translation matrixs into a final transform matrix
mTransform = mRotate * mTranslate;

//Transform verticies by this final transformation matrix
D3DXVec3TransformCoordArray(vOutput, sizeof(D3DXVECTOR3), vInput, sizeof(D3DXVECTOR3), &mTransform, iNumPointsPerSeg);

//Update the branch's location vector for the next segment
vLocation.x += transformedOrientation2.x * 2.0f;
vLocation.y += transformedOrientation2.y * 2.0f;
vLocation.z += transformedOrientation2.z * 2.0f;



1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633430
• Total Posts
3011831
• ### Who's Online (See full list)

There are no registered users currently online

×