I thought I had resolved my problem but I’m not, I have tried everything I can think of, But I haven’t found a solution, Obviously I don’t know enough.

Can some one please suggest a way to do this ?

Please look at the following image

There were 3 things I wanted to do. Align them first to the surface (done), then to the grow vector (done) and the last which i haven’t been able to do is to rotate them like the ones in the red circle which I rotate them manually inside max.

This is what I’m doing now.

```
// Align to the adhesion vector
Quat alignAvec;
Matrix3 alignRotAdheVec;
alignRotAdheVec.IdentityMatrix();
alignRotAdheVec.SetRow(2, Normalize(node->adhesionVector));
alignRotAdheVec.SetRow(0, Point3(0, 1, 0) ^ alignRotAdheVec.GetRow(2));
alignRotAdheVec.SetRow(1, alignRotAdheVec.GetRow(2) ^ alignRotAdheVec.GetRow(0));
alignAvec = Quat(alignRotAdheVec*tm);
alignAvec.MakeMatrix(alignRotAdheVec);
tmpTM *= alignRotAdheVec;
/////////////////////////////////////
// Align to the grow direction
// Function came from Math.cpp in the CAT samples
RotateMatrixToAlignWithVector(tmpTM, Normalize(node->primaryDir), Y);
///////////////////////////////////
// Here is were I'm stuck at the moment, I'm trying to rotate the squares by some predefined amounts
// along the grow direction
// I Guess I need to modify the Matrix so the rotations happens at the bottom of the square but I dont know how.
std::vector<float> theAngles = { -80.0f, -70.0f, -60.0f, -50.0f, 50.0f, 60.0f, 70.0f, 80.0f };
float vAngle = theAngles.at(rangeRandomInt(0, 7));
RotateMatrix(tmpTM, AngAxis(Normalize(node->adhesionVector), DegToRad(vAngle)));
// and last set the location of the quad
// I tried to set the offset here but it does not happens in local space so the quads end up off the correct center.
tmpTM.SetTrans(center);
```

Any help really apreciated.

Guillermo