View Full Version : Simple Trees
03-07-2005, 03:30 AM
Hiya guys i am doing a project that uses an environment to show how weather effects effect it.
Well i want to introduce some sort of trees that allow me to show the way the leaves of the trees move in the wind.
I have looked at a few methods but cant really see any that allow the tree to move. (eg billboarding).
Are there any methods that you guys use that could help me out.
All your advice is greatly appreciated
03-07-2005, 04:42 AM
Simple trees do not have moving leaves :D
For this you will need the hard way, with geometry for a trunk, branches, and leaves, then animate the leaves.
Maybe this can be a starter, there is an OpenGl tree demo :
03-08-2005, 05:21 AM
thanx for the reply i was just wondering something to do with the code in that zip. I realise that it may not be yours, but could you explain to me how
fig_tree = malloc(sizeof(figure) * (size_t)no_of_trees * (size_t)pow(5, MAX_DEPTH+1)); works. I have tried writing a similar thing to the tree.c but in c++ and it will not compile that code. I get
Trees.cpp(78) : error C2440: '=' : cannot convert from 'void *' to 'Tree *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Where i have a Tree and Trees class that contain the methods of tree.c.
If this doesnt make sense please let me know what i can do to help.
Thanx again as once this is done i hope to be able to modify it to introduce wind blowing through the leaves as required.
03-08-2005, 08:14 AM
That's because malloc returns a void pointer.
cast the return value of malloc to your class type.
03-08-2005, 10:32 AM
Actually billboarding can be used to show such motion; I do it frequently using a C++ class I wrote called a FilmStripQuad. Just load several textures (such as leaves in position #1, position #2, ...) then as you render a simple billboarded quad alternate the bound texture name as a function of some time value. So ... at time t=0 texture n=0 is bound, at time t=5 texture n=5 is bound, and so on (see below time graph). The billboarded is simply animated.
Tex n=0 n=1 n=2 n=3 n=4 n=5 n=6 n=7
Time t=0 t=1 t=2 t=3 t=4 t=5 t=6 t=7
03-10-2005, 05:14 AM
Well i have mangaged to get the trees working in my program but drawing even more than a couple of them reduces the fps too much for me to use them.
pleopard: i was wondering if you could explain in a little more detail exactly how you move the billboarded trees.
From what i understand u retain the shape of the object (a quad) but change the image that you use on the quad so that it looks as if it is moving. A problem that i thought would come up using something like this is the change from one image to another would be obvious and not give a decent effect. How do you get around this?
Another, more general question, is where do you find these images that you use to billboard? Do you use just one single image and make it face the eye at all times, or do you use multiple images and quads that intersect with one another at a certain angle.
Please help i am desperate.
03-10-2005, 10:08 AM
What pleopard is suggesting is that you upload sort of a 'flipbook' of the animation of your leaves.
Your concern about the obviousness of transitioning from one image to the next is completely up to you. The more images you have defining the animation the smoother the animation - that is, if you make the leaf movement smaller from one frame to the next they will appear to move more smoothly. Standard animation stuff.
So, you load all of these images and then cycle through them, using glBindTexture.
For example, suppose the animation of your leaves is made up of 10 frames (or images). For simplicity let's suppose the leaves exhibit some simple harmonic motion - like swaying. So, the first 5 images define the leaves moving one way and the last 5 define them moving back into their original position.
GLint LeafFrames. In this array we store the texture names of the 10 uploaded textures.
additionally, we have a counter that cylcles through the frames - call it 'i'.
then each frame you do something like this before you draw the billboard:
You're still using billboarding, so naturally these techniques break down as the billboard become less and less screen aligned because the looker suddenly is seeing the leaves 'edge on'.
This should give you a 'simple tree with animating leaves'.
For better looking trees, you're going to have to use real geometry to render those leaves - but at that point, those trees would be far from 'simple'.
hiya guys its me again.
I have not got newhere since the last time i posted. I have been trying all different methods. I found something called speedTreeRT which would have been ideal but unfortunately i cannot install it on my university computers and so have no way of demoing it later on, it is also only a 30 day trial so will run out before i have to demo.
I have so far gone ahead with the tree demo mentioned http://www.student.nada.kth.se/~d96-ony/development.html . I have put it into c++ and now am trying to manipulate each leaf individually. If ne1 else has any other ideas i would greatly appreciate it as i feel as if i am in a lot of trouble here :( .
03-18-2005, 03:08 AM
I think it's directx nevertheless should be portable to gl. has a relatively simple tree swaying in the wind.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.