GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


Heightmap thingie by Daveyand
//--------------------------------------------------------
// ^-- sets up the projection matrix and viewPort
// v-- display is the main meat of this header file
//--------------------------------------------------------

void sTree_display(void){
    
    
    glClearColor(bgColor.r, bgColor.g, bgColor.b, 0.0);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //reset the position to 0,0,0
    glLoadIdentity();


    gluLookAt(cam_pos.x,cam_pos.y,cam_pos.z,cam_view.x,cam_view.y,cam_view.z,0,1,0);
    
    
    glPushMatrix();
      glRotatef(sun_rot,0,0,1);
      sun_drawSun();
    glPopMatrix();
    
    glPushMatrix();
      glRotatef(moon_rot,0,0,-1);
      sun_drawMoon();
    glPopMatrix();
    
    glPushMatrix();
    
      glTranslatef(-500,-200,0);
      if(G)map_drawMap(heightMapArray);
    glPopMatrix();
        
    //loop through the trees
    for(tree_loop=0;tree_loop<treeCount;tree_loop++){
        
        if(tree_loop!=treeCount+1){

            //if the trunk has reached max size then make all branches there max
            if(tree[tree_loop]->branches[0].maxLengthBool == 1) tree[tree_loop]->endBool =1;

            glColor3f(tree[tree_loop]->treeColour.r,tree[tree_loop]->treeColour.g,tree[tree_loop]->treeColour.b);
                
            //loop through the branches
            for(n=0;n<tree[tree_loop]->branchCount+1;n++){
            
                if(n != tree[tree_loop]->branchCount+1){
    
                    //check to see if enough time has passed, if so do algorithm, else do the drawTree
                    if(timeFlag){
                
                        affectingFunctions(tree[tree_loop],n);

                    }else{

                        nonAffectingFunctions(tree[tree_loop],n);

                    }//if timeflag
                    
                }//if(branchCOunt +1)

            }//for(n)
            
        }//if(treeCount+1)
                    
    }//for(treearray)
    
    //reset the timeflag
    timeFlag =0;
    
    //swap the buffers to display what just got drawn.
    glutSwapBuffers();

}//sTree_display(VOID)

//--------------------------------------------------------
// ^-- display is the main meat of this header file
// v-- These functions affect the tree algorithm, only called if right amount of time has passed
//--------------------------------------------------------

void affectingFunctions(TREE *tree, int br){
    int error;

    
    glPushMatrix();
     glTranslatef(-500,-200,0);
      //draw the tree and do all other algorithm stuff
      glRotatef(treeRot,0,1,0);
      sTree_treeAlgorithm(tree, br);
    glPopMatrix();

    
    if(tree->endBool){

        //the trunk has grown to max size, so simulation should end
        error = sTree_makeBranchesMax(tree, br);
    
    }else{                
                                                    
        //this checks if there are any branches and then increments the branch origY
        error = sTree_moveBranchesUpTrunk(tree, br);
        //ammend the dirBias of the given tree
        sun_ammendBias(tree, br);
    
        //modify intensity calculates and refreshes how much sun the tree gets
        //scale is 1
        sun_modifyIntensity(tree, br, 1);
        //change the spawnrate of the tree
        sun_modifySpawnRate(tree);

        //changes the maxLength of all the branches depending on the lightintensity
        //first check to see if the branch is at actual max length
        if(tree->branches[0].maxLength != BRANCH_MAX_LENGTH ) sun_changeMaxLength(tree);
                                
    }//endBool

    
    
}//affectingFunctions(TREE, int)

//--------------------------------------------------------
// ^-- These functions affect the tree algorithm, only called if right amount of time has passed
// v-- These functions dont affect the tree algorithm, called if timeFlag not set
//--------------------------------------------------------

void nonAffectingFunctions(TREE *tree, int br){
    
    
    glPushMatrix();
      glTranslatef(-500,-200,0);
      glRotatef(treeRot,0,1,0);                  
      sTree_drawTree(tree, br);
    glPopMatrix();
                        
    //increase the intensity of the tree but only by a factor of 1/3
    //scale is 3
    sun_modifyIntensity(tree, br, 3);
    
    
}//affectingFunctions(TREE, int)