Virtual Forest
Plant Designs
CMPE 460 Project #2 Specification Document
CMPE 460
Introduction to Computer Graphics
Contents 1. Introduction a. Purpose b. Development tools 2. Describing Plants a. Layers of plant description i. Skeleton layer ii. Primitive layer iii.OpenGL layer b. PD classes i. PD class ii. Skeleton class c. PD file format 3. Describing Scenes a. Layers of scene description i. Scene layer ii. Plant description layer b. SD class c. SD file format 4. Interface Design a. Flowcharts b. Design constraints c. Design tools i. Plant modelling tool 1. Adding and modifying parts 2. Traversing on the plant ii. Scene modelling tool 1. Setting background and ground texture 2. Adding and setting up modelled plants 3. Setting up animations
2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics
Introduction Purpose of this project What is our purpose of creating virtual plants? Firstly, it is because we are responsible to do it. Secondly, we must somehow make practice to learn using OpenGL to create 3D computer graphics. And thirdly, plants remind people peace and relief, and in computer graphics, there has been too much 3D war and violence so far.
Development environment and tools We used following tools in our development: • Hardware o CPU: Pentium 4 o Memory: 256 MB o Video card: GeForce2. • Software o Operating system: Windows 98 o 3D graphics framework: OpenGL and GLUT o Programming language: Microsoft Visual C++
Describing Plants A plant is described as some primitive parts located geometrically on a skeleton. Thus, properties of a plant is parametrized in three layers.
Skeleton layer
Locating primitive parts hierarchically
Primitive layer OpenGL layer
Drawing primitive parts in the 3D world
OpenGL layer At the bottom, is the OpenGL, receiving commands for creating triangles and quads, texturing, viewing and lighting them. This layer is used by its higher layers to visualize certain geometrical objects in 3d world. Example of using OpenGL layer: glBegin(GL_QUADS); glNormal3f( 0.0f, 0.0f, 1.0f); glTexCoord2f(0.448f, 0.721f); glTexCoord2f(0.729f, 0.525f); glTexCoord2f(0.595f, 0.307f); glTexCoord2f(0.438f, 0.713f); glEnd();
glVertex3f( 0.005f, 0.279f, 0.0f); //24 glVertex3f( 0.286f, 0.475f, 0.0f); //19 glVertex3f( 0.152f, 0.693f, 0.0f); //15 glVertex3f(-0.005f, 0.287f, 0.0f); //2
Primitive layer On top of OpenGL is the primitive layer, which contains hard-coded display lists of certain plant parts such as leaf, branch or fruit. This layer is for keeping certain polyhedra shapes characterizing the plant types. All primitives are in the same layer, but every primitive can be only used by its corresponding type of plant. For example, an imaginary plant cannot have a realistic leaf, vica versa. Example of using primitive layer: 2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics
putprimitive(yaprak1lo);
Skeleton layer Then comes the skeleton layer, which contains geometrical information of the plant. Its duty is to put primitives in the right coordinates in the right time. Modelling and animations are made on the skeleton layer. Example of using skeleton layer: branch->add(dal1,0,58,0,30,90,0,0.8); branch->add(dal1,0,58,0,30,-90,0,0.8); branch = branch->subbranches[0]; branch->add(yaprak1lo,0,58,0,70,0,0); branch->add(yaprak1lo,0,58,0,80,120,0); branch->add(yaprak1lo,0,58,0,60,240,0);
PD classes In describing plants, object-oriented programming is used. Every plant description is an instance of PD class. This class contains general information about the plant, as well as the layer descriptions. In OpenGL layer, no classes are needed to be created, because OpenGL uses global variables. In primitive layer, there is also no need for a class, because primitives are hard-coded global shapes. But in the skeleton layer, there must be some kind of class to contain geometrical information.
Skeleton class Skeleton class contains all information regarding geometrical placement of primitives. This information is kept in a hierarchical tree structure. Every branch of this tree (including the root) contains following information: • The primitive to be located on this branch
• • • • • • • •
Scaling relative to its parent branch. Position in 3 dimensions, relative to its parent branch. Orientation in 3 angular dimensions, relative to its parent branch. Velocity in 3 dimensions, relative to its parent branch. Angular velocity in 3 angular dimensions, relative to its parent branch. Acceleration in 3 dimensions, relative to its parent branch. Angular acceleration in 3 angular dimensions, relative to its parent branch. Subbranches of this branch
Skeleton branch Primitive Position-orientation Velocity data Acceleration data Child branches
PD class PD class is the class of a plant. This contains two things: Type of the plant, and its skeleton in a separate class structure. Also, this class is capable of: • Saving into a PD file • Loading from a PD file • Displaying the plant in the 3d world • Running an animation using the plant skeleton 2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Plant Description Skeleton stem Save(file) Load(file) Display() RunFor(time)
Introduction to Computer Graphics
Skeleton branch Primitive Position-orientation Velocity data Acceleration data Child branches
PD file format Plant descriptions can be saved in PD files in text format. A PD file starts with the "plant type". Then it continues as a list of skeleton branches where every line corresponds to a skeleton element. Example PD file: plant type 1 childs 2 3 4 5 primitive dal2 position 0 0 0 orientation 30 0 0 childs 6 7 primitive dal2 position 0 0 0 with relative orientation 30 80 0 childs 8 9 primitive dal2 position 0 0 0 with relative orientation 30 200 0 childs 10 11 primitive dal2 position 0 0 0 with relative orientation 30 280 0 childs 12 13 primitive dal2 position 0 19 0 with relative orientation 12 25 0 child 14 15 16 17 primitive dal2 position 0 19 0 with relative orientation 12 25 0 child 18 19 20 21 primitive dal2 position 0 19 0 with relative orientation 12 25 0 child 22 23 24 25 primitive dal2 position 0 19 0 with relative orientation 12 25 0 child 26 27 28 29 primitive dal2 position 0 19 0 with relative orientation 12 25 0 child 30 31 32 33 primitive dal2 position 0 19 0 with relative orientation 12 25 0 child 34 35 36 37 primitive dal2 position 0 19 0 with relative orientation 12 25 0 child 38 39 40 41 primitive dal2 position 0 19 0 with relative orientation 12 25 0 child 42 43 44 45 primitive dal2 position 0 19 0 with relative orientation 13 0 0 child 46 47 48 49 primitive yaprak2 position 0 0 0 with relative orientation 70 130 0 primitive yaprak2 position 0 0 0 with relative orientation 80 250 0 primitive yaprak2 position 0 0 0 with relative orientation 60 10 0 primitive dal2 position 0 19 0 with relative orientation 13 0 0 child 50 51 52 53 primitive yaprak2 position 0 0 0 with relative orientation 70 130 0 primitive yaprak2 position 0 0 0 with relative orientation 80 250 0 ...
Describing Scenes A scene, is a group of plants put in a scenery. To describe the scene, we must be able to describe every single plant in that scene, and its placement in the picture. In addition, we must know the general scenery of the place. Maybe it is dawn, or morning light comes from the sky. There may be grass or rocks on the ground. A scene has a background image and a ground texture.
Layers of scene description A scene description includes two layers. First is the plant description layer, describing the plants involved in the scene. Second layer is the scene layer, which contains information about placement and orientation of the plants described. Also, it includes information about the background image and the ground texture.
2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics
Scene layer Skeleton layer
Viewing and animating plants in the scene Locating primitive parts hierarchically
Primitive layer OpenGL layer
Drawing primitive parts in the 3D world
Plant description layer The plants that are in the scenery, are described in the plant description layer of scene description. This layer contains PD information and it is connected to other layers, skeleton, primitives and OpenGL.
Scene layer Scene layer is on top of plant description layer. This layer uses the modelled descriptions for viewing and animating them in a scene. Operations involving changes in the scene, and changes regarding plant positions, orientations and animations can be done in this layer.
SD class In the scene description class, background image and ground texture locations are kept as tga files. First, there is a list of plant descriptions. Then there is another list of plant samples containing following information for each plant: • Plant position • Plant orientation • Plant animation • Plant description index
Scene Description Plant descriptions Array of plants • Description index • Position • Orientation
Plant Description Skeleton stem Save(file) Load(file) Display() RunFor(time)
Skeleton branch Primitive Position-orientation Velocity data Acceleration data Child branches
SD file format Example SD file: background bg.tga ground texture grass.tga 3 plant descriptions first.pd second.pd third.pd plant plant plant plant
1 1 2 3
position position position position
0 0 -10 orientation 0 0 0 0 0 -50 orientation 0 30 0 -10 0 -40 orientation 0 70 0 -10 0 -10 orientation 0 20 0
2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics
Interface Design In the program, there are two types of descriptive data, plants and scenes. These are kept in the memory as class instances, and saved on the HDD as PD and SD files. These descriptions can be created by a user interface. User interface involves two things, designing and viewing. These can be combined in the same interface, because you must view what you design, and you must design in order to view something. Interfaces will be implemented by "masking" idea. There will be a foreground interaction window for the user to construct the plant, scene etc. The interaction window is not yet implemented, but the details are thought of. Buttons (in the context as we are used to them) will be put and they will exactly be like normal window system buttons, so the user won't lose his/her interest with extraordinary interaction images. Other "hidden" interaction tools will either be prompted on the screen, or not be so complex and written in the manual. These are like camera control keys or mouse buttons (which are, at the moment, available at the program.).
Flowcharts
Choose plant type
Choose scene type
Generate new plant
Generate new scene
Plant Modelling Tool
Scene Modelling Tool
Add/Remove plant parts
Add/Remove plants
Animate plant
Animate scene
Save plant
Save scene
Design constraints Design constraint issue depends on the plant types that we have specified at the beginning. For example, a 'branch' may consist of; • Leaves and a fruit of its species, • Leaves and a flower of its species, • Leaves and subbranches of its species, • Leaves only, • Subbranches only.
Design tools There must be one tool for each data type: Plant modelling tool and scene modelling tool. These self-explanatory named tools are used to edit plant description files and scene description files respectively. These tools must be considered in both ways, as a designing environment and as 2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics
an animation engine-viewing tool. The interface should allow at least two modes in these tools: design mode and viewing. User can toggle between these nodes when designing plants and scenes.
Plant design mode
User can toggle between two modes
Plant view mode
Plant modelling tool Plants were described as three layers, with the skeleton at the top, primitives in the middle, and the OpenGL at the bottom. Plant modelling tool allows user to design plants on the skeleton layer-the most abstract level. It must even allow the user to design the plant in a more abstract way, because skeleton layer is very low level as it involves with angles and positions of every single polyhedron on the plant. User can see top-front-right-perspective views of the plant.
Traversing on the plant In the interface, a plant is considered as a tree structure where every branch (except the root) has a parent and some child branches. User can traverse through the plant, jumping branch to branch. At every moment, interface is focused on a certain branch ("current" branch) on plant's skeleton. Either the user makes a modification on that branch, or jumps to another branch which is either current branch's parent or its child.
Adding and modifying parts Viewing is oriented and focused on the current branch, but the user can rotate the whole plant around it by using the mouse. Then he/she can add-remove-modify a leaf, add a fruit, or any polyhedra that is allowed by plant design constraints. Modifications are either changing its position or orientation, all by simple mouse drags. The plants are simple, but somehow complex 3D objects. That is, there are so many "leaf" primitives, and therefore many vertices at one tree for instance. And usually, no user wants to deal with every other leaf in a tree. Of course, users will have the option to do that, but there is also options for simplifying the plant construction process, like "put some leaves" or "fill with leaves".
Scene design mode
User can toggle between two modes
Scene animation mode
Scene modelling tool Scenes are modelled in a simpler tool, because it only involves combining prepared plants in a prepared scenery. Scenery can be defined as a background image, and a ground texture. Plants require more complex definitions. Each plant has a position and an orientation in the scenery. There are also animations that can be assigned to plants.
Setting background and ground texture Creating a scene description first involves the user to select a background image, and a ground texture. There are certain images and textures the user can choose from. User can also set the ambient and diffuse light colors from the scene modelling tool.
Adding and setting up modelled plants For scene construction, only the perspective view is shown, and mouse buttons determine the position and the orientation of the plant that is put. The interface makes it easy to select and put plants in the scenery in a few mouse clicks and dragging.
Setting up animations Animations are properties assigned to plants. Plants are capable of making the required motion. For example, "winding" animation is defined as regular harmonic angular movement of every branch 2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics
in the plant's skeleton with some periodic phase difference between parent and child branches. Animation requires calculation of every frame, which involves creation of new skeletons for different time instances. This is a built-in function of PD class.
Example Screens
2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics
Our first type of plant in the morning
2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics Our second type of plant in the morning
Our first type of plant at dawn 2001100940 Başar Uğur
2001102110 Işık Barış Fidaner
CMPE 460
Introduction to Computer Graphics
Our second type of plant at dawn
2001100940 Başar Uğur
2001102110 Işık Barış Fidaner