Ejemplo n.º 1
0
//--------------------------------------------------------------
void ofApp::drawBranch(int depth, float angle) {
	float newAngle = angle + angleOffset;

	ofPushMatrix();
	ofRotate(newAngle);
	drawLeaf(depth, newAngle);
	ofPopMatrix();
	ofRotate(-newAngle);
	drawLeaf(depth, newAngle);
}
void Tree::drawTree()
{
	int ii=0,countF=0;
	addressF=basicUnitList.begin();
	
	//FF[F[F]F]FFF
	glRotatef(90.0,-1.0,0.0,0.0);

	for(int i=0;i<simpleStringF.length();i++)
	{
		if (simpleStringF[i]=='[')
		{
			glPushMatrix();						
		}
		else if (simpleStringF[i]==']')
		{
			glPopMatrix();
		}
		else //simpleStringF[i]=='F'
		{
			countF++;
			//生成随机颜色
			glColor3ub(color[countF%2][0],color[countF%2][1],color[countF%2][2]);
					
			if (addressF->angleZ!=0)
				glRotatef(addressF->angleZ,0.0,0.0,addressF->angleZ);
			if (addressF->angleY!=0)
				glRotatef(addressF->angleY,0.0,addressF->angleY,0.0);
			if (addressF->angleX!=0)
				glRotatef(addressF->angleX,addressF->angleX,0.0,0.0);

			drawSegment(addressF->redius,addressF->length);
			
			if (addressF->leafAmount)
			{
					drawLeaf(addressF->leafArea[0],addressF->length);
					drawLeaf(addressF->leafArea[0],addressF->length-0.35);
			}

			addressF++;
		}
	}

	//drawLeaf(1,1);
}
Ejemplo n.º 3
0
void drawGreen(void)
{
	mvstack.push(model_view);
	set_colour(.1, .4, .1);
	model_view *= Scale (10, 7, 12);
	model_view *= RotateX(-90);
	drawLeaf();
	model_view = mvstack.pop();
}
Ejemplo n.º 4
0
// Draws 3 leaves around the end of a branch.. once upon a time
void terminatingLeaf(void) {
    if (!drawLeaves) {
        return;
    } // if
    
    if ( (rand() % 100)  < 2) {
        drawFruit();
    } else {
        pushMatrix();
        rotateBy( (rand() % 90), 0, 0, 1);
        rotateBy( -(rand() % 10), 0, 1, 0);
        drawLeaf();
        popMatrix();
    } // if-else
} // terminatingLeaf
Ejemplo n.º 5
0
// Drawing a single tree
void drawTree(double heightScale, double widthScale, double xLoc, double yLoc, double zLoc)
{
   ErrCheck("Before drawTree");
   glPushMatrix();
   //Everything is rotated, so it is weird coordinates
   glTranslated(xLoc, zLoc, yLoc);

   //Make sure everything is the right height
   glScaled(widthScale, heightScale, widthScale);

   //Draw Cylinder;
   double treeWidth = (rand()%40+80)/300.0; //Gets a tree trunk around .4
   double treeHeight = (rand()%30+100)/20.0; //gets a tree height around 4
   glTranslated(0,treeHeight, 0); //Brings the bottom of the tree to zero

	//Rotate the tree so they don't all look the same
	glRotated(rand()%360,0,1,0); 
	
	double treeColor[] = {210.0/255, 105.0/255, 30.0/255}; 
   cylinder::drawCylinder(treeWidth, treeHeight, 60, treeColor, treeTexture, logEndTexture, true);
   double currentAngle = 0;
   glTranslated(0,treeHeight*.05, 0); //Moves just above the cylinder
   while(currentAngle < 720) //Draws three things of leaves
   {
      glPushMatrix();
      if(currentAngle > 360) 
      {
        glTranslated(0, -.05, 0); 
      }
      double thisLeafAngle = rand()%20+40;//Gets an angle between 20 and 40
      double leafScaleX = (rand()%10+90)/25; //Changes size a little bit
      double leafScaleY = (rand()%10+90)/25; //Changes size a little bit
      double leafScaleZ = (rand()%10+90)/25; //Changes size a little bit

      glScaled(leafScaleX, leafScaleY * thisLeafAngle/30.0, leafScaleZ);
      glRotated(currentAngle, 0, 1, 0);
      glRotated(-(rand()%6+27), 0, 0, 1); //random angle for the pitch
      glRotated(-(rand()%5-2.5), 1, 0, 0); //Rotates the leaf a bit

      drawLeaf();
      glPopMatrix();
      currentAngle += thisLeafAngle;
   }
   glPopMatrix();
   ErrCheck("After drawTree");
}
Ejemplo n.º 6
0
	void TurtleRenderer::parseSystem()
	{
		m_stack = std::stack<glm::mat4>();
		m_stack.push(glm::mat4(1.0f));
		
		std::stack<Node*> branchStack;

		std::string path = m_system->generate();
		//std::cout << "Word: " << path << std::endl;

		float angle = m_system->definition()->angle;

		glm::mat4 m;
		glm::vec3 right, up, forward;
		Node * parent = m_root = new Node();

		for (unsigned i = 0; i < path.length(); i++)
		{
			char chr = path[i];
			switch (chr)
			{
			case 'X':
				// ignored symbol
				break;
			case 'F':
				parent = drawSegment(parent);
				m = glm::translate(m_stack.top(), glm::vec3(0.0f, length, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case 'Q':
			case 'f':
				parent = drawLeaf(parent);
				break;
			case '+':
				m = glm::rotate(m_stack.top(), angle, glm::vec3(1.0f, 0.0f, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '-':
				m = glm::rotate(m_stack.top(), -angle, glm::vec3(1.0f, 0.0f, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '!':
				m = glm::rotate(m_stack.top(), angle, glm::vec3(0.0f, 1.0f, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '?':
				m = glm::rotate(m_stack.top(), -angle, glm::vec3(0.0f, 1.0f, 0.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '&':
				m = glm::rotate(m_stack.top(), angle, glm::vec3(0.0f, 0.0f, 1.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '/':
				m = glm::rotate(m_stack.top(), -angle, glm::vec3(0.0f, 0.0f, 1.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '|':
				m = glm::rotate(m_stack.top(), 180.0f, glm::vec3(0.0f, 0.0f, 1.0f));
				m_stack.pop();
				m_stack.push(m);
				break;
			case '[':
				m_stack.push(m_stack.top());
				thickness /= thinning;
				branchStack.push(parent);
				break;
			case ']':
				m_stack.pop();
				thickness *= thinning;
				parent = branchStack.top();
				branchStack.pop();
				break;
			default:
				{
				//Trace::info("Encountered unkown turtle command: %c\n", chr);
				}
			}
		}
	}
Ejemplo n.º 7
0
void display(void)
{
    // Clear the screen with the background colour (set in myinit)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    model_view = mat4(1.0f);
    model_view *= Translate(0.0f, 0.0f, -15.0f);
    HMatrix r;
    Ball_Value(Arcball,r);

    mat4 mat_arcball_rot(
        r[0][0], r[0][1], r[0][2], r[0][3],
        r[1][0], r[1][1], r[1][2], r[1][3],
        r[2][0], r[2][1], r[2][2], r[2][3],
        r[3][0], r[3][1], r[3][2], r[3][3]);
    model_view *= mat_arcball_rot;

    mat4 view = model_view;
    glUniformMatrix4fv( uView, 1, GL_TRUE, view );

    // Previously glScalef(Zoom, Zoom, Zoom);
    model_view *= Scale(Zoom);
	model_view *= Translate(0.0f, 0.0f, -10.0f);
	model_view *= RotateX(10);


	//if(prologue < 20) {
	//	model_view *= Translate(0.0f, -20.0f+prologue, 0.0f);
	//	cam_eye = vec4(rotateX, 0.0, rotateZ, 1.0);
	//	model_view *= LookAt(cam_eye, cam_ref, cam_up);
	//}
	
	//if(timeline > 57)
	//	model_view *= Translate(0.0f, -temp3, -0.0f);

	// Draw Scene
	drawScene();

	// Draw Leaf
	if(timeline < 8.0f) {
		mvstack.push(model_view);
			model_view *= Translate(0.0f, 25.0f-prologue, 0.0f);
			model_view *= RotateZ(leafSway);
			model_view *= Translate(4.0f, -1.0f-prologue, 3.0f);
			drawLeaf();
		model_view = mvstack.pop();
	}

	/*/ // Draw Bee
	if(timeline > 35.0f && timeline < 38.0f) {
		mvstack.push(model_view);
			model_view *= Translate(15.0f-(temp2-230), pathBeeVert, 4.5f);
			model_view *= Scale(0.5f, 0.5f, 0.5f);
			drawBee();
		model_view = mvstack.pop();
	}
	/*/ 
    //draw GFS
	mvstack.push(model_view);

	if(timeline>28&&timeline<36)
		{
			model_view *= Translate(47.5f-temp5/2, 0.0f, 3.0f);
		    model_view*=RotateY(-90);
			record=40.0f-temp5/2;
	    }

	else if(timeline>=36&&timeline<=40)
	{

		model_view *= Translate(7.5f, 0.0f, 4.0);
		model_view*=RotateY(-135);
	}
	else if(timeline>40&&timeline<59)
	{
		model_view *= Translate(7.5f+temp6/4, 0.0f, 2.0f);
		model_view *= RotateY(90);
	}
	if(timeline>=28)
		drawGFS(1,1,1);

	model_view = mvstack.pop();

	// Draw Male
	mvstack.push(model_view);
		if(timeline > 20.0f && timeline < 24.0f) {
			model_view *= Translate(-5.0f+temp, 0.0f, 2.25f);
			prevX = -5.0+temp;
		}
		else if(timeline >= 24.0f && timeline < 27.0f)
			model_view *= Translate(prevX-temp, 0.0f, 2.25f);
		else if(timeline > 30.5 && timeline < 36.0) {
			model_view *= Translate(-25.0+temp2/10, -.75f, 4.5f);
			prevX = -25.0+temp2/10;
			model_view *= RotateY(90);
		}
		else if(timeline >= 35.0f && timeline < 55.0) {
			model_view *= Translate(prevX, -.75f, 4.5f);
			model_view *= RotateY(135);
		}
		drawDiaoSi(0.3f, 0.6f, .6f);
	model_view = mvstack.pop();

	// Draw Female
	if(timeline > 8.0f) {
		mvstack.push(model_view);
			if(timeline < 12.0f) {
				model_view *= Translate(29.0f-2*timeline, -1.25f, 4.5f);
				model_view *= RotateY(-90);
			}

			if(timeline > 12.0f && timeline < 13.5) {
				model_view *= Translate(5.0f, -1.25f, 4.5f);
				model_view *= RotateY(-90+temp*1.25);
			}

			if(timeline > 13.5f && timeline < 40.0f || timeline > 53.75)
				model_view *= Translate(5.0f, 0.0f, 2.25f);

			if(timeline >= 40.0f && timeline < 59.0f) {
				model_view *= Translate(5.5f+temp6/4, -1.25f, 4.5f);
				model_view *= RotateY(90);
			}

		/*/	if(timeline > 50.0f && timeline < 53.75) {
				if(15.0f-(temp2-560)/10 > 5.0) {
					model_view *= Translate(15.0-(temp2-560)/10, -1.25f, 4.5f);
					prevY = 15.0-(temp2-560)/10;
				}
				else
					model_view *= Translate(prevY, -1.25f, 4.5f);

				if(timeline < 52.6f)
					model_view *= RotateY(-90);
				else
					model_view *= RotateY(-90+temp*2);
			}
		 /*/
			if(timeline < 59.0)
				drawFemale(1.0f, 0.0, 1.0f);
			//else
			//	drawFemale(1.0f, 1.0f, 1.0f);

		model_view = mvstack.pop();
	}

	if(timeline > 59.0)
		exit(0);

	getFPS();

    glutSwapBuffers();
    if(Recording == 1)
        FrSaver.DumpPPM(Width, Height) ;
}