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;
 }
Esempio n. 2
0
void FuelCellManager::OnLocationEntry()
{
  if (GetGameMode() == AMJU_MODE_EDIT)
  {
    // Add node to Scene Graph
    m_sceneNode = new Ve1Node(this);
    SceneNode* root = GetVe1SceneGraph()->GetRootNode(SceneGraph::AMJU_OPAQUE);
    Assert(root);
    root->AddChild(m_sceneNode);
    m_sceneNode->SetAABB(m_aabb);
  }
  // else... ????

  // Create fuel cells
  static int id = 20000;
  for (int i = 0; i < 10; i++)
  {
    FuelCell* f = new FuelCell;
    f->SetId(id++);

    float s = ROConfig()->GetFloat("fuel-cell-spread", 200.0f); 
    Vec3f r(Rnd(-s, s), Rnd(0, s), Rnd(-s, s));
    Vec3f p = GetPos() + r; 
    if (TerrainReady())
    {
      GetTerrain()->GetCollisionMesh()->GetY(Vec2f(p.x, p.z), &p.y); // TODO TEMP TEST Set all food to y = 0
    }
    f->SetPos(p);
    f->Load(0);
    TheGame::Instance()->AddGameObject(f);
    f->OnLocationEntry();
  }
}
Esempio n. 3
0
PSceneNode MyTextMaker::Decorate(PSceneNode p)
{
  static const int MAX_COLOUR = 4;
  Colour COLOURS[MAX_COLOUR] = 
  {
    Colour(1.0f, 0.0f, 0.375f, 1.0f),
    Colour(0.8f, 0.0f, 0.3f, 1.0f),
    Colour(1.0f, 0.0f, 0.375f, 1.0f),
    Colour(0.8f, 0.0f, 0.3f, 1.0f)
    //Colour(1.0f, 0.0f, 0.7f, 1.0f),
    //Colour(1.0f, 0.0f, 0.9f, 1.0f)
  };
  // Choose colour
  static int c = 0;
  m_colour = COLOURS[c];
  c++;
  if (c == MAX_COLOUR)
  {
    c = 0;
  }
  SceneNode* decorator = new MyCharacterDecorator(m_colour, m_theta);
  // Get next value for theta
  m_theta += 0.2f; 

  decorator->AddChild(p);
  decorator->UpdateBoundingVol();

  return decorator;
}
Esempio n. 4
0
void Room::OnLocationEntry()
{
  // Big AABB so not culled
  m_aabb.Set(-10000, 10000, -1000, 1000, -10000, 10000);
  // Create room node for each tile
  for (int i = 0; i < 2; i++)
  {
    TileVec& tv = m_tiles[i];
    int numTiles = tv.size();
    for (int j = 0; j < numTiles; j++)
    {
      Tile& t = tv[j];
      RoomNode* rn = new RoomNode(t);

      SceneNode* root = GetVe1SceneGraph()->GetRootNode(SceneGraph::AMJU_OPAQUE);
      root->AddChild(rn);
      rn->Build(); // TODO Use tile data we loaded to make tiled textured quads..?
      rn->SetAABB(m_aabb);
    }
  }

////  m_sceneNode = rn;

  TheSoundManager::Instance()->PlaySong(m_music);
}
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;
   }
Esempio n. 6
0
void Ve1Object::OnLocationEntry()
{
    if (m_sceneNode)
    {
        SceneNode* root = GetVe1SceneGraph()->GetRootNode(SceneGraph::AMJU_OPAQUE);
        if (root)
        {
            root->AddChild(m_sceneNode);
            m_sceneNode->SetVisible(!m_hidden);
        }
    }
}
/**
 * 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;
}
Esempio n. 8
0
/**
 * 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;
}
	void GeometryManager::_createGeometry()
	{
		mA = mHeight.y / noMath::Cos(noMath::PI/2-mBeta);
		mB = mHeight.y / noMath::Cos(noMath::PI/2-mAlpha);
	    mC = mRadius;

		for (int k = 0; k < mNumberOfBlocks; k++)
		{
			mGeometryBlocks.push_back(new GeometryBlock(mVClouds, mHeight.y, mAlpha, mBeta, mRadius, mPhi, mNa, mNb, mNc, mA, mB, mC, k));
			mGeometryBlocks.at(k)->create();
			// Each geometry block must be in a different scene node, See: GeometryBlock::isInFrustum(Camera *c)			
			SceneNode *sn = SceneNode::NewNode();
			mSceneNode->AddChild(sn);
			sn->AddChild(mGeometryBlocks.at(k));
		}
	}
Esempio n. 10
0
/**
 * 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;
}
Esempio n. 11
0
void Player::OnLocationEntry()
{
  Ve1ObjectChar::OnLocationEntry();

  SceneNode* root = GetVe1SceneGraph()->GetRootNode(SceneGraph::AMJU_OPAQUE);
  if (root)
  {
    root->AddChild(m_arrow.GetPtr());
    SetArrowVis(false);
  }

  m_nameTag = new PlayerNameNode(this);
  if (m_sceneNode)
  {
    if (m_nameTag)
    {
      m_sceneNode->AddChild(m_nameTag.GetPtr());
    }

    if (m_effect)
    {
      m_sceneNode->AddChild(m_effect.GetPtr());
    }
  }

  // TODO Portal should have a heading which you should face when you appear at the destination
  m_isMoving = false; 
  SetVel(Vec3f(0, 0, 0)); // TODO walk out of doorway ?

  // TODO Set m_newPos ??

  // Set appearance
  SetLoggedIn(IsLoggedIn());

  // If we are carrying something, change its location too
  if (m_carrying)
  {
    TheObjectUpdater::Instance()->SendChangeLocationReq(m_carrying->GetId(), GetPos(), GetLocation()); 
  }
}
/**
 * Construct the scene
 */
void ConstructScene()
{
   // -------------------- Geometry -------------------- //
   movingSquare = new UnitSquareFlatSurface(200,32.2f*.814f,true,Vector2(-.01f,0),.03f);

   SceneNode* house = ConstructHouse(70,90);

   // Construct a unit cylinder surface
   WasherSurface* cylinder = new WasherSurface(.9f, 1.0f, 18);
   
   //Wheel
   WasherSurface* washer = new WasherSurface(10,20,14);
   std::vector<LightNode*> lights;
   lights.push_back(new LightNode(GL_LIGHT3));
   lights.push_back(new LightNode(GL_LIGHT4));
   wheel = new WheelNode(10,20,washer,ConstructBox(9,19.5f,1),8,4,lights);

   waterfall = new ParticleNode(25);

   //-------------------- Materials ------------------------- //

   // Wood
   PresentationNode* wood = new PresentationNode;
   wood->SetMaterialAmbientAndDiffuse(Color4(0.5f, 0.5f, 0.5f));
   wood->SetMaterialSpecular(Color4(0.3f, 0.3f, 0.3f));
   wood->SetMaterialShininess(32.0f);
   wood->setTexture(LoadTextureBMP("images/wood.bin",true,128));

   // Stone
   PresentationNode* stone = new PresentationNode;
   stone->SetMaterialAmbient(Color4(0.19225f, 0.19225f, 0.19225f));
   stone->SetMaterialDiffuse(Color4(0.50754f, 0.50754f, 0.50754f));
   stone->SetMaterialSpecular(Color4(0.508273f, 0.508273f, 0.508273f));
   stone->SetMaterialShininess(10.2f);
   stone->setTexture(LoadTextureBMP("images/stone.bin",true,128));

   PresentationNode* steel = new PresentationNode;
   steel->SetMaterialAmbient(Color4(0.19225f, 0.19225f, 0.19225f));
   steel->SetMaterialDiffuse(Color4(0.7f, 0.7f, 0.7f));
   steel->SetMaterialSpecular(Color4(0.7f, 0.7f, 0.7f));
   steel->SetMaterialShininess(90.2f);

   // Water
   PresentationNode* water = new PresentationNode;
   water->SetMaterialAmbient(Color4(0.01f, 0.01f, 0.1f));
   water->SetMaterialDiffuse(Color4(0.2f, 0.2f, 0.6f));
   water->SetMaterialSpecular(Color4(0.5f, 0.5f, 0.5f));
   water->SetMaterialShininess(10);
   water->setTexture(LoadTextureBMP("images/water.bin",true,128));

   PresentationNode* blue = new PresentationNode;
   blue->SetMaterialAmbient(Color4(0.01f, 0.01f, 0.1f));
   blue->SetMaterialDiffuse(Color4(0.2f, 0.2f, 0.6f));
   blue->SetMaterialSpecular(Color4(0.5f, 0.5f, 0.5f));
   blue->SetMaterialShininess(10);
   // ------------------ Transformations ------------------- //
   TransformNode* wheelTransform = new TransformNode;
   wheelTransform->Translate(-80.0f, 35.0f, 40.0f);
   wheelTransform->Rotate(90.0f, 1.0f, 0.0f, 0.0f);

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

   TransformNode* house2Transform = new TransformNode;
   house2Transform->Rotate(180,0,0,1);
   house2Transform->Translate(-100,-35,0);

   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);
}
/**
 * Construct a room. Like a box but looking inward with a texture for each side
 */
SceneNode* ConstructRoom() {
	GLuint textures[6];
	textures[0]=LoadTextureBMP("images/skybox0.bin",true,256);
	textures[1]=LoadTextureBMP("images/skybox1.bin",true,256);
	textures[2]=LoadTextureBMP("images/skybox2.bin",true,256);
	textures[3]=LoadTextureBMP("images/skybox3.bin",true,256);
	textures[4]=LoadTextureBMP("images/skybox4.bin",true,256);
	textures[5]=LoadTextureBMP("images/skybox5.bin",true,256);

	SceneNode* skybox = new SceneNode;
	int SKYBOX_SIZE=2000;
	int HEIGHT = 800;
	int HALF_HEIGHT = HEIGHT * .5f;
	int HALF_SKYBOX = SKYBOX_SIZE * .5f;
	UnitSquareFlatSurface* unitSquare = new UnitSquareFlatSurface(SKYBOX_SIZE,
		SKYBOX_SIZE,true,Vector2(),.01);
	TransformNode* transform[6];

	UnitSquareFlatSurface* wall = new UnitSquareFlatSurface(1,1,true,Vector2(),1);

	// Construct transform nodes for the walls. Perform rotations so the 
	// walls face inwards
	transform[0] = new TransformNode;
	//transform[0]->Scale(SKYBOX_SIZE,SKYBOX_SIZE,1);

	// Back wall is rotated +90 degrees about x: (y -> z)
	transform[1] = new TransformNode;
	transform[1]->Translate(0.0f, HALF_SKYBOX, HALF_HEIGHT);
	transform[1]->Scale(SKYBOX_SIZE,1,HEIGHT);
	transform[1]->Rotate(90.0f, 1.0f, 0.0f, 0.0f);   

	// Front wall is rotated -90 degrees about x: (z -> y)
	transform[2] = new TransformNode;
	transform[2]->Translate(0.0f, -HALF_SKYBOX, HALF_HEIGHT);
	transform[2]->Scale(SKYBOX_SIZE,1,HEIGHT);
	transform[2]->Rotate(-90.0f, 1.0f, 0.0f, 0.0f); 

	// Left wall is rotated 90 degrees about y: (z -> x)
	transform[3] = new TransformNode;
	transform[3]->Translate(-HALF_SKYBOX, 0.0f, HALF_HEIGHT);
	transform[3]->Scale(1,SKYBOX_SIZE,HEIGHT);
	transform[3]->Rotate(90.0f, 0.0f, 1.0f, 0.0f);

	// Right wall is rotated -90 about y: (z -> -x)
	transform[4]= new TransformNode;
	transform[4]->Translate(HALF_SKYBOX, 0.0f, HALF_HEIGHT);
	transform[4]->Scale(1,SKYBOX_SIZE,HEIGHT);
	transform[4]->Rotate(-90.0f, 0.0f, 1.0f, 0.0f);

	// Ceiling is rotated 180 about x so it faces inwards
	transform[5]= new TransformNode;
	transform[5]->Translate(0.0f, 0.0f, HEIGHT);
	transform[5]->Scale(SKYBOX_SIZE,SKYBOX_SIZE,1);
	transform[5]->Rotate(180.0f, 1.0f, 0.0f, 0.0f);

	for(int i=0;i<6;i++){
		PresentationNode* tex = new PresentationNode();
		tex->SetMaterialAmbientAndDiffuse(Color4(0.8f, 0.8f, 0.8f));
		tex->SetMaterialSpecular(Color4(0.3f, 0.3f, 0.3f));
		tex->SetMaterialShininess(32.0f);
		tex->setTexture(textures[i]);
		tex->AddChild(transform[i]);
		transform[i]->AddChild(i==0 ? unitSquare : wall);
		skybox->AddChild(tex);
	}
	return skybox;
}
Esempio n. 14
0
/**
 * Construct the scene
 */
void ConstructScene()
{
   // Construct the lighting shader node
   LightingShaderNode* lightingShader = new LightingShaderNode();
   if (!lightingShader->Create("phong.vert", "phong.frag") ||
       !lightingShader->GetLocations())
      exit(-1);

   int positionLoc = lightingShader->GetPositionLoc();
   int normalLoc = lightingShader->GetNormalLoc();

   // -------------------- Geometry -------------------- //

   // Construct a unit square - use less subdivisions to see how
   // phong shading improves the lighting
   UnitSquareSurface* unitSquare = new UnitSquareSurface(2, positionLoc, normalLoc);

   // Construct a unit box
   SceneNode* box = ConstructUnitBox(unitSquare);

   // Construct a unit cylinder surface
   ConicSurface* cylinder = new ConicSurface(1.0f, 1.0f, 18, 4, positionLoc, normalLoc);

   // Construct a torus
   TorusSurface* torus = new TorusSurface(20.0f, 5.0f, 18, 18, positionLoc, normalLoc);

   // Teapot
   MeshTeapot* teapot = new MeshTeapot(3, positionLoc, normalLoc);

   // Sphere
   SphereSection* sphere = new SphereSection(-90.0f, 90.0f, 18, 
               -180.0f, 180.0f, 36, 1.0f, positionLoc, normalLoc);

   //-------------------- Materials ------------------------- //

   // Wood
   PresentationNode* wood = new PresentationNode;
   wood->SetMaterialAmbientAndDiffuse(Color4(0.55f, 0.45f, 0.15f));
   wood->SetMaterialSpecular(Color4(0.3f, 0.3f, 0.3f));
   wood->SetMaterialShininess(64.0f);

   // Silver
   PresentationNode* silver = new PresentationNode;
   silver->SetMaterialAmbient(Color4(0.19225f, 0.19225f, 0.19225f));
   silver->SetMaterialDiffuse(Color4(0.50754f, 0.50754f, 0.50754f));
   silver->SetMaterialSpecular(Color4(0.508273f, 0.508273f, 0.508273f));
   silver->SetMaterialShininess(51.2f);

   // Black, shiny
   PresentationNode* shinyBlack = new PresentationNode;
   shinyBlack->SetMaterialAmbient(Color4(0.0f, 0.0f, 0.0f));
   shinyBlack->SetMaterialDiffuse(Color4(0.01f, 0.01f, 0.01f));
   shinyBlack->SetMaterialSpecular(Color4(0.5f, 0.5f, 0.5f));
   shinyBlack->SetMaterialShininess(32.0f);

   // Shiny blue
   PresentationNode* shinyBlue = new PresentationNode;
   shinyBlue->SetMaterialAmbient(Color4(0.05f, 0.05f, 0.2f));
   shinyBlue->SetMaterialDiffuse(Color4(0.2f, 0.2f, 0.6f));
   shinyBlue->SetMaterialSpecular(Color4(0.75f, 0.75, 0.75f));
   shinyBlue->SetMaterialShininess(76.8f);

   // ------------------ Transformations ------------------- //

   // Position the table in the room
   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);
}
Esempio n. 15
0
static void AddToSceneGraph(RB* rb)
{
  SceneNode* root = GetRBSceneGraph()->GetRootNode(SceneGraph::AMJU_OPAQUE);
  root->AddChild(new RBSceneNode(rb));
}