Leaf rotation.

Oct 18, 2009 at 6:47 PM

Hello!

I am really impressed by this project, I just wanted to ask a quick question.

(this is on my 360, as on my laptop the leaves do not render).

If I create a tree, and then look directly at it, and then rotate the camera, keeping the tree in the center of the view, the leaves appear to rotate with me.

I presume that is because of the billboarding, and is unavoidable, but i just wanted to check.

(as I am making a flying game, the camera could often be rotating).

Thanks ever so much, I hope I get some time to look through the code, as the results are very impressive.

J.

 

 

Coordinator
Oct 18, 2009 at 7:57 PM

Yes, this is the expected behavior for this type of billboard. I designed it for high performance and for cameras "walking" near the ground, so I understand if it might not be optimal for flight simulators. All I can suggest is that you hand-tailor the rendering to your application.

On another issue, what video card is on your laptop? I'd like to support most non-antique video cards, but I don't have a lot of cards to test with.

Oct 18, 2009 at 9:01 PM

Thanks for clarifying that Asger, very nice of you to get back to me so quickly.

My graphics card is an ATI Mobility Radeon X300 (which may well count as an antique), If I  work out why it isnt rendering I will post it in this thread.

Thanks again!

J.

 

Jan 27, 2010 at 10:45 PM

Hello. I am also writing a flight sim that uses ltrees and I had the same problem with leaf rotation. The fix is actually very straightforward, using the same code I used to stabilise cloud particle billboards. Search through SimpleTree to find this part;

 

if (skeleton.LeafAxis == null)
            {
                leafEffect.Parameters["BillboardRight"].SetValue(Vector3.Right);
                leafEffect.Parameters["BillboardUp"].SetValue(Vector3.Up);
            }
            else
            {
...
            }

The second part deals with fixed leaves, the first part deals with billboarded ones. By default it locks the leaf alignment to screen. To make it rotate when the camera rolls, use this code;

if (skeleton.LeafAxis == null) {

Vector3 upVector = Vector3.Transform(Vector3.Up, viewMatrix) - Vector3.Transform(Vector3.Zero, viewMatrix);
upVector.Z = 0f; upVector.Normalize();
leafEffect.Parameters["BillboardRight"].SetValue(upVector);
leafEffect.Parameters["BillboardUp"].SetValue(new Vector3(upVector.Y, -upVector.X, 0f));

}
            else
            {
...
            }

 

Obviously you can optimise this to calculate the up and right vectors once per frame instead of once per tree. Maybe too late now for the original person asking, but perhaps this will help anyone else with the same problem.