Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Citizen Erased
Mar 20, 2004

Wash Me Away
I think this has been addressed twice now in this thread but I can't wrap my head around it in the context of my application:

I have a ring of verticies that are at an arbritrary position in local 3D space which I want to rotate to face an arbritrary direction and then translate in that direction by n units. I'm using the x,y and z coordinates of the verticies to do these transformations and am trying to work out how to get this to work. So far, I've got the rotation down with D3DXMatrixRotationYawPitchRoll to rotate a blank matrix and then taken the position from that matrix and transfered it to the verticies using D3DXVec3TransformCoordArray. What I can't work out how to do is translate the verticies in the direction they are now facing. What do I do to the x,y,z position coordinates to make them move in this abritrary direction?

Adbot
ADBOT LOVES YOU

Citizen Erased
Mar 20, 2004

Wash Me Away

tyrelhill posted:

Use the view matrix. I'm a little rusty with DirectX since I've been using OpenGL a lot lately, but I'm pretty sure this is correct.

code:
D3DXMATRIX mat;
D3DXMatrixIdentity(&mat);
D3DXMatrixRotationAxis(&mat, &AxisToRotateAround, TheAngle);
D3DXMatrixTranslation(&mat, TranslationX, TranslationY, TranslationZ);
YourD3DDevicePointer->SetTransform(D3DTS_VIEW, &mat);
Then just draw your object at the origin. Make sure if you're drawing other objects to set the view matrix back to an identity.

This is my opinion but never use Euler Angles for stuff like this, they get really messy after you move them around a lot.

Unfortunatly one of the things I need to do with the geometry after I've transformed it is export it to an .obj file. Because of that, I can't just transform by the view matrix at draw time or such, I physically need to change the x, y, z values of each vertex in the ring. Anyone got any clue on how to do so?

Citizen Erased
Mar 20, 2004

Wash Me Away

Stanlo posted:

You want to rotate verts so that they face an arbitrary direction and then translate in that direction right? You have the rotation done too? Can't you just add the direction to all the verts?

Someone else just suggested to me that if I have a vector for the direction I want to move in before the rotation (say (0,1,0)) and I rotate this with the verticies, I could just add this vector * the amount I want to move to the vertcies and it should move them in the direction I want after the rotation. I wont be able to try this for a while, does this sound like it would work though?

Citizen Erased
Mar 20, 2004

Wash Me Away
Sorry to poo poo things up with my odd needs once again. 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 big):


The unit vector values:
code:
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:
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
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply