Hello I’m programming a 3d game in c# monogame and currently I’m working on foliage.

I’m wanting foliage to face upwards as the same direction as the terrain tile its on, I have the normal of the tile represented by the green arrows. But the foliage is not correctly facing upwards as the same direction as the tiles Normal.

Currently I’m creating a world matrix using the Tiles Normal for the EULER rotation.XYZ like below

As you can see within the red circles in the gameplay picture below the terrain normal (the green arrow) is not matching the direction the foliage is facing.

Thankyou for your reply. I tried using Matrix.CreateFromAxisAngle I set the normal as a Axis but I don’t know what angle parameter to enter as I’m using the normal to find the terrains angle.

I tried using Matrix.CreateFromAxisAngle using Up, Forward, Right etc like below

The object’s up direction will match the terrain’s normal with this. The angle is the roll around this axis which should be set to which direction you want the object to face, it isn’t related to any terrain normal/angle calculations.

The second method would look something like:

Matrix rotationMatrix = Matrix.Identity;
rotationMatrix.Up = tileNormal;
rotationMatrix.Forward = tileForward; // or face forward using Vector3.Normalize(Vector3.Cross(tileNormal, Vector3.Right))
rotationMatrix.Right = tileRight; // or calculate using Vector3.Normalize(Vector3.Cross(rotationMatrix.Forward, tileNormal))
Matrix.Transpose(Matrix.CreateScale(size.X, size.Y, size.Z) *
rotationMatrix *
Matrix.CreateTranslation(position));