当前位置: 首页>>代码示例>>C++>>正文


C++ TransformNode::AddChild方法代码示例

本文整理汇总了C++中TransformNode::AddChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TransformNode::AddChild方法的具体用法?C++ TransformNode::AddChild怎么用?C++ TransformNode::AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TransformNode的用法示例。


在下文中一共展示了TransformNode::AddChild方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ConstructWall

SceneNode* ConstructWall(PresentationNode* material,PresentationNode* containedMaterial,SceneNode* contained){
	SceneNode* wall = new TransformNode;
	wall->AddChild(material);
	wall->AddChild(containedMaterial);

	SceneNode* box = ConstructBox(200,6,25);

	TransformNode* t = new TransformNode;
	t->AddChild(box);
	t->Translate(0,14.6f,12.5f);
	material->AddChild(t);

	TransformNode* t2 = new TransformNode;
	t2->AddChild(box);
	t2->Translate(0,-14.6f,12.5f);
	material->AddChild(t2);

	TransformNode* inner = new TransformNode;
	inner->AddChild(ConstructBox(200,26.2,15));
	inner->Translate(0,0,7.5f);
	material->AddChild(inner);

	TransformNode* top = new TransformNode;
	top->AddChild(contained);
	top->Translate(0,0,20);
	containedMaterial->AddChild(top);
	return wall;
 }
开发者ID:zmnatz,项目名称:2010-Fall-Computer-Graphics-Class,代码行数:28,代码来源:PhongShading.cpp

示例2: ConstructHouse

SceneNode* ConstructHouse(float x, float z)
   {
		SceneNode* house = new SceneNode;
		SceneNode* topBottom = ConstructBox(x,x,1);
		SceneNode* windowWall = new SceneNode;
	
		SceneNode* partialWall = new SceneNode;
		TransformNode* wallBottom = new TransformNode;
		TransformNode* wallTop = new TransformNode;
	
		float panelSize = .2f*x;

		wallBottom->Translate(0,0,-(z*.25f));
		wallTop->Translate(0,0,.4f*z);

		wallBottom->AddChild(ConstructBox(panelSize,1,z*.5f));
		wallTop->AddChild(ConstructBox(panelSize,1,z*.2f));
		partialWall->AddChild(wallBottom);
		partialWall->AddChild(wallTop);

		SceneNode* fullWall = ConstructBox(panelSize,1,z);

		for(int i=0;i<5;i++){
			TransformNode* wall = new TransformNode;
			wall->AddChild(i%2 ? partialWall : fullWall);
			wall->Translate((float)i*panelSize-.4*x,0,0);
			windowWall->AddChild(wall);
		}
		for(int i=0;i<3;i++){
			TransformNode* wall = new TransformNode;
			wall->AddChild(windowWall);
			wall->Rotate(90*i,0,0,1);
			wall->Translate(0,.5f*x,.5f*z);
			house->AddChild(wall);
		}

		TransformNode* doorWall = new TransformNode;
		doorWall->Rotate(-90,0,0,1);
		doorWall->Translate(0,.5f*x,.5f*z);
		house->AddChild(doorWall);

		for(int i=-1;i<2;i+=2){
			TransformNode* wall = new TransformNode;
			wall->Translate(i*.4f*x,0,0);
			wall->AddChild(fullWall);
			doorWall->AddChild(wall);
		}
		
		TransformNode* floor = new TransformNode;
		floor->AddChild(topBottom);
	
		TransformNode* ceiling = new TransformNode;
		ceiling->Translate(0,0,z);
		ceiling->AddChild(topBottom);

		house->AddChild(floor);
		house->AddChild(ceiling);
		return house;
   }
开发者ID:zmnatz,项目名称:2010-Fall-Computer-Graphics-Class,代码行数:59,代码来源:PhongShading.cpp

示例3: ConstructBox

/**
 * Construct a box with the given dimensions.
 */
SceneNode* ConstructBox(float x, float y, float z)
{
   UnitSquareFlatSurface* xySurf = new UnitSquareFlatSurface(x,y,true,Vector2(),.05f);
   UnitSquareFlatSurface* xzSurf = new UnitSquareFlatSurface(x,z,true,Vector2(),.05f);
   UnitSquareFlatSurface* yzSurf = new UnitSquareFlatSurface(z,y,true,Vector2(),.05f);
   x *= .5;
   y *= .5;
   z *= .5;

   // Contruct transform nodes for the sides of the box.
   // Perform rotations so the sides face outwards
   // Bottom is rotated 180 degrees so it faces outwards
   TransformNode* bottomTransform = new TransformNode;
   bottomTransform->Translate(0.0f, 0.0f, -z);
   bottomTransform->Rotate(180.0f, 1.0f, 0.0f, 0.0f);   

   // Back is rotated -90 degrees about x: (z -> y)
   TransformNode* backTransform = new TransformNode;
   backTransform->Translate(0.0f, y, 0.0f);
   backTransform->Rotate(-90.0f, 1.0f, 0.0f, 0.0f);   

   // Front wall is rotated 90 degrees about x: (y -> z)
   TransformNode* frontTransform = new TransformNode;
   frontTransform->Translate(0.0f, -y, 0.0f);
   frontTransform->Rotate(90.0f, 1.0f, 0.0f, 0.0f);   

   // Left wall is rotated -90 about y: (z -> -x)
   TransformNode* leftTransform = new TransformNode;
   leftTransform->Translate(-x, 0.0f, 00.0f);
   leftTransform->Rotate(-90.0f, 0.0f, 1.0f, 0.0f);

   // Right wall is rotated 90 degrees about y: (z -> x)
   TransformNode* rightTransform = new TransformNode;
   rightTransform->Translate(x, 0.0f, 0.0f);
   rightTransform->Rotate(90.0f, 0.0f, 1.0f, 0.0f);

   // Top 
   TransformNode* topTransform = new TransformNode;
   topTransform->Translate(0.0f, 0.0f, z);

   // Create a SceneNode and add the 6 sides of the box.
   SceneNode* box = new SceneNode;
   box->AddChild(backTransform);
   backTransform->AddChild(xzSurf);
   box->AddChild(leftTransform);
   leftTransform->AddChild(yzSurf);
   box->AddChild(rightTransform);
   rightTransform->AddChild(yzSurf);
   box->AddChild(frontTransform);
   frontTransform->AddChild(xzSurf);
   box->AddChild(bottomTransform);
   bottomTransform->AddChild(xySurf);
   box->AddChild(topTransform);
   topTransform->AddChild(xySurf);
   return box;
}
开发者ID:zmnatz,项目名称:2010-Fall-Computer-Graphics-Class,代码行数:59,代码来源:PhongShading.cpp

示例4: ConstructTable

/**
 * Construct table
 * @param  unitSquare  Geometry node to use for table top
 * @param  legs        Geometry node to use for legs
 * @return  Returns a scene node representing the table
 */
SceneNode* ConstructTable(SceneNode* box, ConicSurface* leg)
{
   // Table legs (relative to center of table)
   TransformNode* lfLegTransform = new TransformNode;
   lfLegTransform->Translate(-20.0f, -10.0f, 10.0f);
   lfLegTransform->Scale(3.0f, 3.0f, 20.0f);
   TransformNode* lrLegTransform = new TransformNode;
   lrLegTransform->Translate(-20.0f, 10.0f, 10.0f);
   lrLegTransform->Scale(3.0f, 3.0f, 20.0f);
   TransformNode* rfLegTransform = new TransformNode;
   rfLegTransform->Translate(20.0f, -10.0f, 10.0f);
   rfLegTransform->Scale(3.0f, 3.0f, 20.0f);
   TransformNode* rrLegTransform = new TransformNode;
   rrLegTransform->Translate(20.0f, 10.0f, 10.0f);
   rrLegTransform->Scale(3.0f, 3.0f, 20.0f);
   
   // Construct dimensions for the table top
   TransformNode* topTransform = new TransformNode;
   topTransform->Translate(0.0f, 0.0f, 23.0f);
   topTransform->Scale(60.0f, 30.0f, 6.0f);

   // Create the tree
   SceneNode* table = new SceneNode;
   table->AddChild(topTransform);
   topTransform->AddChild(box);
   table->AddChild(lfLegTransform);
   lfLegTransform->AddChild(leg);
   table->AddChild(rfLegTransform);
   rfLegTransform->AddChild(leg);
   table->AddChild(lrLegTransform);
   lrLegTransform->AddChild(leg);
   table->AddChild(rrLegTransform);
   rrLegTransform->AddChild(leg);

   return table;
}
开发者ID:m-hogue,项目名称:JHU-Graphics,代码行数:42,代码来源:PhongShading.cpp

示例5: ConstructUnitBox

/**
 * Construct a unit box.
 * @param  unitSquare  Geometry node to use
 */
SceneNode* ConstructUnitBox(UnitSquareSurface* unitSquare)
{
   // Contruct transform nodes for the sides of the box.
   // Perform rotations so the sides face outwards

   // Bottom is rotated 180 degrees so it faces outwards
   TransformNode* bottomTransform = new TransformNode;
   bottomTransform->Translate(0.0f, 0.0f, -0.5f);
   bottomTransform->Rotate(180.0f, 1.0f, 0.0f, 0.0f);   

   // Back is rotated -90 degrees about x: (z -> y)
   TransformNode* backTransform = new TransformNode;
   backTransform->Translate(0.0f, 0.5f, 0.0f);
   backTransform->Rotate(-90.0f, 1.0f, 0.0f, 0.0f);   

   // Front wall is rotated 90 degrees about x: (y -> z)
   TransformNode* frontTransform = new TransformNode;
   frontTransform->Translate(0.0f, -0.5f, 0.0f);
   frontTransform->Rotate(90.0f, 1.0f, 0.0f, 0.0f);   

   // Left wall is rotated -90 about y: (z -> -x)
   TransformNode* leftTransform = new TransformNode;
   leftTransform->Translate(-0.5f, 0.0f, 00.0f);
   leftTransform->Rotate(-90.0f, 0.0f, 1.0f, 0.0f);

   // Right wall is rotated 90 degrees about y: (z -> x)
   TransformNode* rightTransform = new TransformNode;
   rightTransform->Translate(0.5f, 0.0f, 0.0f);
   rightTransform->Rotate(90.0f, 0.0f, 1.0f, 0.0f);

   // Top 
   TransformNode* topTransform = new TransformNode;
   topTransform->Translate(0.0f, 0.0f, 0.50f);

   // Create a SceneNode and add the 6 sides of the box.
   SceneNode* box = new SceneNode;
   box->AddChild(backTransform);
   backTransform->AddChild(unitSquare);
   box->AddChild(leftTransform);
   leftTransform->AddChild(unitSquare);
   box->AddChild(rightTransform);
   rightTransform->AddChild(unitSquare);
   box->AddChild(frontTransform);
   frontTransform->AddChild(unitSquare);
   box->AddChild(bottomTransform);
   bottomTransform->AddChild(unitSquare);
   box->AddChild(topTransform);
   topTransform->AddChild(unitSquare);

   return box;
}
开发者ID:m-hogue,项目名称:JHU-Graphics,代码行数:55,代码来源:PhongShading.cpp

示例6: ConstructScene


//.........这里部分代码省略.........

   TransformNode* wallTransform = new TransformNode;
   wallTransform->Translate(0,35,0);

   TransformNode* waterfallTransform = new TransformNode;
   waterfallTransform->Translate(-128.0f,35,15.0f);

   TransformNode* pipeTransform = new TransformNode;
   pipeTransform->Rotate(-90,0,1,0);
   pipeTransform->Translate(76.5f,35,125);
   pipeTransform->Scale(5,5,20);

   // -------------------- Lighting --------------------------/

   // Light 0 - point light source in back right corner
	LightNode* light0 = new LightNode(GL_LIGHT0);
	light0->SetDiffuse(Color4(0.5f, 0.5f, 0.5f, 1.0f));
	light0->SetSpecular(Color4(0.5f, 0.5f, 0.5f, 1.0f));
	light0->SetPosition(HPoint3(90.0f, 90.0f, 30.f, 1.0f));	
	light0->Enable();

   // Light1 - directional light from the ceiling
	LightNode* light1 = new LightNode(GL_LIGHT1);
	light1->SetDiffuse(Color4(0.7f, 0.7f, 0.7f, 1.0f ));
	light1->SetSpecular(Color4(0.7f, 0.7f, 0.7f, 1.0f));
	light1->SetPosition(HPoint3(0.0f, 0.0f, 1.0f, 0.0f));	
	light1->Enable();

   // Light2 - spotlight - we will place at the camera location
   // shining along -VPN
	LightNode* light2 = new LightNode(GL_LIGHT2);
	light2->SetDiffuse(Color4(0.8f, 0.8f, 0.8f, 1.0f ));
	light2->SetSpecular(Color4(0.8f, 0.8f, 0.8f, 1.0f));
	light2->SetPosition(HPoint3(0.0f, 0.0f, 0.0f, 1.0f));	
	light2->SetSpotlight(Vector3(0.0f, 0.0f, -1.0f), 32.0f, 30.0f);
	light2->Enable();

	lights[0]->SetDiffuse(Color4(0.8f, 0.8f, 0.8f, 1.0f));
	lights[0]->SetSpecular(Color4(0.8f, 0.8f, 0.8f, 1.0f));
	lights[0]->SetPosition(HPoint3(-100.0f,35.0f,90.0f,1.0f));
	lights[0]->SetSpotlightDirection(Vector3(0,0,-1));
	lights[0]->SetSpotlight(Vector3(0,0,-1),1,90);
	lights[0]->Disable();

	lights[1]->SetDiffuse(Color4(0.8f, 0.8f, 0.8f, 1.0f));
	lights[1]->SetSpecular(Color4(0.8f, 0.8f, 0.8f, 1.0f));
	lights[1]->SetPosition(HPoint3(100.0f,35.0f,90.0f,1.0f));
	lights[1]->SetSpotlightDirection(Vector3(0,0,-1));
	lights[1]->SetSpotlight(Vector3(0,0,-1),1,90);
	lights[1]->Disable();
  
   // --------------------------- Camera ----------------------- //
   MyCamera = new CameraNode;
   MyCamera->SetPosition(Point3(100.0f, -100.0f, 50.0f));
   MyCamera->SetLookAtPt(Point3(0.0f, 0.0f, 50.0f));
   MyCamera->SetViewUp(Vector3(0.0, 0.0, 1.0));
   MyCamera->SetPerspective(50.0, 1.0, 1.0, 2400);

   // --------------------- Scene construction ----------------- //

   // Construct the scene root node
   SceneRoot = new SceneNode;

   // Create a scene node to hold all scene objects (other than camera
   // and lights)
   SceneNode* myScene = new SceneNode;

   // Add the spotlight as the first child of the root node. Since this is 
   // accessed before the camera it will position the light relative to the
   // camera
   SceneRoot->AddChild(light2);

   // Set the camera

	SceneRoot->AddChild(MyCamera);
	MyCamera->AddChild(light0);
	MyCamera->AddChild(light1);
	MyCamera->AddChild(lights[0]);
	MyCamera->AddChild(lights[1]);
	MyCamera->AddChild(myScene);

   // Construct the room (walls, floor, ceiling)
	SceneNode* skybox = ConstructRoom();

   wallTransform->AddChild(ConstructWall(stone,water,movingSquare));
   myScene->AddChild(wallTransform);

   // Construct the wheel
   AddSubTree(myScene,wood,wheelTransform,wheel);

    // Place 2 Houses
   wood->AddChild(houseTransform);
   houseTransform->AddChild(house);
   wood->AddChild(house2Transform);
   house2Transform->AddChild(house);
   myScene->AddChild(skybox);

   AddSubTree(myScene,steel,pipeTransform,cylinder);
   AddSubTree(myScene,blue,waterfallTransform,waterfall);
}
开发者ID:zmnatz,项目名称:2010-Fall-Computer-Graphics-Class,代码行数:101,代码来源:PhongShading.cpp

示例7: ConstructScene


//.........这里部分代码省略.........
   TransformNode* tableTransform = new TransformNode;
   tableTransform->Translate(-50.0f, 50.0f, 0.0f);
   tableTransform->Rotate(30.0f, 0.0f, 0.0f, 1.0f);

   // Teapot transform
   TransformNode* teapotTransform = new TransformNode;
   teapotTransform->Translate(0.0f, 0.0f, 26.0f);
   teapotTransform->Scale(2.5f, 2.5f, 2.5f);

   // Torus
   TransformNode* torusTransform = new TransformNode;
   torusTransform->Translate(0.0f, 90.0f, 20.0f);
   torusTransform->Rotate(60.0f, 1.0f, 0.0f, 0.0f);

   // Sphere
   TransformNode* sphereTransform = new TransformNode;
   sphereTransform->Translate(80.0f, 20.0f, 10.0f);
   sphereTransform->Scale(10.0f, 10.0f, 10.0f);

   // --------------------------- Camera ----------------------- //
   MyCamera = new CameraNode;
   MyCamera->SetPosition(Point3(0.0f, -100.0f, 20.0f));
   MyCamera->SetLookAtPt(Point3(0.0f, 0.0f, 20.0f));
   MyCamera->SetViewUp(Vector3(0.0, 0.0, 1.0));
   MyCamera->SetPerspective(50.0, 1.0, 1.0, 300.0);

   // -------------------- Lighting --------------------------/

   // Set the global light ambient
   Color4 globalAmbient(0.4f, 0.4f, 0.4f, 1.0f);
   lightingShader->SetGlobalAmbient(globalAmbient);

   // Light 0 - point light source in back right corner
	LightNode* light0 = new LightNode(0);
	light0->SetDiffuse(Color4(0.5f, 0.5f, 0.5f, 1.0f));
	light0->SetSpecular(Color4(0.5f, 0.5f, 0.5f, 1.0f));
   light0->SetPosition(HPoint3(90.0f, 90.0f, 30.f, 1.0f));	
	light0->Enable();

   // Light1 - directional light from the ceiling
   LightNode* light1 = new LightNode(1);
	light1->SetDiffuse(Color4(0.7f, 0.7f, 0.7f, 1.0f ));
	light1->SetSpecular(Color4(0.7f, 0.7f, 0.7f, 1.0f));
   light1->SetPosition(HPoint3(0.0f, 0.0f, 1.0f, 0.0f));	
	light1->Enable();

   // Spotlight - reddish spotlight - we will place at the camera location
   // shining along -VPN
   Spotlight = new LightNode(2);
	Spotlight->SetDiffuse(Color4(0.5f, 0.1f, 0.1f, 1.0f ));
	Spotlight->SetSpecular(Color4(0.5f, 0.1f, 0.1f, 1.0f));
   Point3 pos = MyCamera->GetPosition();
   Spotlight->SetPosition(HPoint3(pos.x, pos.y, pos.z, 1.0f));
   Vector3 dir = MyCamera->GetViewPlaneNormal() * -1.0f;
   Spotlight->SetSpotlight(dir, 32.0f, 30.0f);
	Spotlight->Enable();

   // --------------------- Scene construction ----------------- //

   // Construct the scene root node
   SceneRoot = new SceneNode;
   SceneRoot->AddChild(lightingShader);
   lightingShader->AddChild(MyCamera);

   // Add the lights as the children of the camera
	MyCamera->AddChild(light0);
   light0->AddChild(light1);
   light1->AddChild(Spotlight);

   // Create a scene node to hold all scene objects (other than camera
   // and lights)
   SceneNode* myScene = new SceneNode;
   
   // Add the scene under the last light
   Spotlight->AddChild(myScene);

   // Construct the room (walls, floor, ceiling)
   ConstructRoom(myScene, unitSquare);

   // Construct the table
   SceneNode* table = ConstructTable(box, cylinder); 
   myScene->AddChild(wood);
   wood->AddChild(tableTransform);
   tableTransform->AddChild(table);

   // Place a teapot on the table
   tableTransform->AddChild(teapotTransform);
   teapotTransform->AddChild(silver);
   silver->AddChild(teapot);

   // Place a torus
   myScene->AddChild(shinyBlack);
   shinyBlack->AddChild(torusTransform);
   torusTransform->AddChild(torus);

    // Place a sphere
   myScene->AddChild(shinyBlue);
   shinyBlue->AddChild(sphereTransform);
   sphereTransform->AddChild(sphere);
}
开发者ID:m-hogue,项目名称:JHU-Graphics,代码行数:101,代码来源:PhongShading.cpp

示例8: ConstructRoom

/**
 * Construct room as a child of the specified node
 * @param  parent      Parent node
 * @param  unitSquare  Geometry node to use
 */
void ConstructRoom(SceneNode* parent, UnitSquareSurface* unitSquare)
{
   // Contruct transform nodes for the walls. Perform rotations so the 
   // walls face inwards
   TransformNode* floorTransform = new TransformNode;
   floorTransform->Scale(200.0f, 200.0f, 1.0f);

   // Back wall is rotated +90 degrees about x: (y -> z)
   TransformNode* backWallTransform = new TransformNode;
   backWallTransform->Translate(0.0f, 100.0f, 40.0f);
   backWallTransform->Rotate(90.0f, 1.0f, 0.0f, 0.0f);   
   backWallTransform->Scale(200.0f, 80.0f, 1.0f);

   // Front wall is rotated -90 degrees about x: (z -> y)
   TransformNode* frontWallTransform = new TransformNode;
   frontWallTransform->Translate(0.0f, -100.0f, 40.0f);
   frontWallTransform->Rotate(-90.0f, 1.0f, 0.0f, 0.0f);   
   frontWallTransform->Scale(200.0f, 80.0f, 1.0f);

   // Left wall is rotated 90 degrees about y: (z -> x)
   TransformNode* leftWallTransform = new TransformNode;
   leftWallTransform->Translate(-100.0f, 0.0f, 40.0f);
   leftWallTransform->Rotate(90.0f, 0.0f, 1.0f, 0.0f);
   leftWallTransform->Scale(80.0f, 200.0f, 1.0f);

   // Right wall is rotated -90 about y: (z -> -x)
   TransformNode* rightWallTransform = new TransformNode;
   rightWallTransform->Translate(100.0f, 0.0f, 40.0f);
   rightWallTransform->Rotate(-90.0f, 0.0f, 1.0f, 0.0f);
   rightWallTransform->Scale(80.0f, 200.0f, 1.0f);

   // Ceiling is rotated 180 about x so it faces inwards
   TransformNode* ceilingTransform = new TransformNode;
   ceilingTransform->Translate(0.0f, 0.0f, 80.0f);
   ceilingTransform->Rotate(180.0f, 1.0f, 0.0f, 0.0f);
   ceilingTransform->Scale(200.0f, 200.0f, 1.0f); 

   // Floor should be tan, mostly dull
   PresentationNode* floorMaterial = new PresentationNode;
   floorMaterial->SetMaterialAmbientAndDiffuse(Color4(0.3f, 0.45f, 0.1f));
   floorMaterial->SetMaterialSpecular(Color4(0.1f, 0.1f, 0.1f));
   floorMaterial->SetMaterialShininess(2.0f);

   // Make the walls reddish, slightly shiny
   PresentationNode* wallMaterial = new PresentationNode;
   wallMaterial->SetMaterialAmbientAndDiffuse(Color4(0.7f, 0.55f, 0.55f));
   wallMaterial->SetMaterialSpecular(Color4(0.5f, 0.5f, 0.5f));
   wallMaterial->SetMaterialShininess(16.0f);

   // Ceiling should be white, moderately shiny
   PresentationNode* ceilingMaterial = new PresentationNode;
   ceilingMaterial->SetMaterialAmbientAndDiffuse(Color4(1.0f, 1.0f, 1.0f));
   ceilingMaterial->SetMaterialSpecular(Color4(0.9f, 0.9f, 0.9f));
   ceilingMaterial->SetMaterialShininess(64.0f);

   // Add floor and ceiling to the parent. Use convenience method to add material,
   // then presentation, then geometry.
   AddSubTree(parent, floorMaterial,   floorTransform,   unitSquare);
   AddSubTree(parent, ceilingMaterial, ceilingTransform, unitSquare);

   // Walls. We can group these all under a single presentation node.
   parent->AddChild(wallMaterial);
   wallMaterial->AddChild(backWallTransform);
   backWallTransform->AddChild(unitSquare);
   wallMaterial->AddChild(leftWallTransform);
   leftWallTransform->AddChild(unitSquare);
   wallMaterial->AddChild(rightWallTransform);
   rightWallTransform->AddChild(unitSquare);
   wallMaterial->AddChild(frontWallTransform);
   frontWallTransform->AddChild(unitSquare);
}
开发者ID:m-hogue,项目名称:JHU-Graphics,代码行数:76,代码来源:PhongShading.cpp

示例9: bodyPosition

Scene::Scene(int viewSizeX, int viewSizeY) :
m_root(new Node(0)),
m_camera(vEyePos, vFocus, vUp, Point(viewSizeX, viewSizeY), fov, zNear, zFar),
m_light(lightDirection),
m_renderer(&m_camera, &m_light),
m_viewSize(viewSizeX, viewSizeY),
m_cameraFolows(true),
m_fpsStart(0),
m_numFrames(0),
m_frameTime(0.0f),
fpsString()
{
	// Here we build our scene, adding nodes to the scene graph:
	//
	//			---> terrainMeshNode
	//			|
	//	root ---|										  ---> rwingTransformNode -> rwingAnimationNode -> rwingMeshNode
	//			|										 |
	//			---> bodyTransformNode -> bodyMeshNode --|
	//													 |
	//													  ---> lwingTransformNode -> lwingAnimationNode -> lwingMeshNode

	// std::vectors for raw geometry data (they will be reused)
	std::vector<Vertex> vertices;
	std::vector<unsigned int> indices;

	// Terrain : only mesh node
	CreateGrid(terrainSize, terrainResolution, vertices, indices);
	Mesh* terrainMesh = m_renderer.CreateMesh(vertices, indices, false);

	MeshNode* terrainMeshNode = new MeshNode(terrainMesh, &m_renderer);
	m_root->AddChild(terrainMeshNode);


	// Body : transform node -> mesh node
	TransformNode* bodyTransformNode = new TransformNode(&m_renderer);
	Vector3 bodyPosition(0.0f, 10.0f, 0.0f);
	bodyTransformNode->MoveTo(bodyPosition);
	bodyTransformNode->SetDirection(Vector3(1.0f, 0.0f, 0.0f));
	bodyTransformNode->RotateBy(-math::PiDiv6, Vector3(0.0f, 1.0f, 0.0f));
	m_root->AddChild(bodyTransformNode);

	vertices.clear();
	indices.clear();
	LoadMesh("../../meshes/teapot.obj", vertices, indices, Color(1.0f, 0.0f, 0.0f, 1.0f));
	Mesh* bodyMesh = m_renderer.CreateMesh(vertices, indices);

	MeshNode* bodyMeshNode = new MeshNode(bodyMesh, &m_renderer);
	bodyTransformNode->AddChild(bodyMeshNode);

	m_bird = new PlayerCharacter(bodyTransformNode, &m_keyboard);

	// Right wing : transform node -> animation node -> mesh node
	TransformNode* rwingTransformNode = new TransformNode(&m_renderer);
	Vector3 rwingPosition(0.0f, 0.0f, 0.0f);
	rwingTransformNode->MoveTo(rwingPosition);
	bodyMeshNode->AddChild(rwingTransformNode);

	AnimationNode* rwingAnimationNode = new WingAnimationNode(&m_renderer);
	rwingTransformNode->AddChild(rwingAnimationNode);

	vertices.clear();
	indices.clear();
	LoadMesh("../../meshes/wing.obj", vertices, indices, Color(1.0f, 1.0f, 0.0f, 1.0f));
	Mesh* rwingMesh = m_renderer.CreateMesh(vertices, indices);

	MeshNode* rwingMeshNode = new MeshNode(rwingMesh, &m_renderer);
	rwingAnimationNode->AddChild(rwingMeshNode);


	// Left wing : transform node -> animation node -> mesh node
	TransformNode* lwingTransformNode = new TransformNode(&m_renderer);
	Vector3 lwingPosition(0.0f, 0.0f, 0.0f);
	lwingTransformNode->MoveTo(lwingPosition);
	lwingTransformNode->RotateBy(math::Pi, Vector3(0.0f, 1.0f, 0.0f));
	bodyMeshNode->AddChild(lwingTransformNode);

	AnimationNode* lwingAnimationNode = new WingAnimationNode(&m_renderer, true);
	lwingTransformNode->AddChild(lwingAnimationNode);

	vertices.clear();
	indices.clear();
	LoadMesh("../../meshes/wing.obj", vertices, indices, Color(1.0f, 1.0f, 0.0f, 1.0f));
	Mesh* lwingMesh = m_renderer.CreateMesh(vertices, indices);

	MeshNode* lwingMeshNode = new MeshNode(lwingMesh, &m_renderer);
	lwingAnimationNode->AddChild(lwingMeshNode);

	m_fpsStart = glutGet(GLUT_ELAPSED_TIME);
	fpsString.resize(256);
}
开发者ID:Luckymee,项目名称:INB381,代码行数:91,代码来源:scene.cpp


注:本文中的TransformNode::AddChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。