bool ForestWindEmitter::onAdd()
{
   if ( !Parent::onAdd() )
      return false;
  
   // Only the client side actually does wind.
   if ( isClientObject() )
   {
      // TODO: wasn't this a big hack we already fixed better?
      //Projectile::getGhostReceivedSignal().notify( this, &ForestWindEmitter::_onMountObjectGhostReceived );
   
      _initWind();
      WINDMGR->addEmitter( this );
   }

   Point3F boxRad( 0, 0, 0 );

   if ( !isRadialEmitter() )
      boxRad.set( 10000.0f, 10000.0f, 10000.0f );
   else
      boxRad.set( mWindRadius, mWindRadius, mWindRadius ); 
      
   mObjBox.set( -boxRad, boxRad );
   resetWorldBox();

   enableCollision();

   // If we are we editing the mission then
   // be sure to add us to the scene.
   if ( gEditingMission || mHasMount )
   {
      addToScene();
      mAddedToScene = true;
   }

   return true;
} 
예제 #2
0
bool NavPath::onAdd()
{
   if(!Parent::onAdd())
      return false;

   if(gEditingMission)
      mNetFlags.set(Ghostable);

   resize();

   addToScene();

   if(isServerObject())
   {
      mQuery = dtAllocNavMeshQuery();
      if(!mQuery)
         return false;
      checkAutoUpdate();
      if(!plan())
         setProcessTick(true);
   }

   return true;
}
예제 #3
0
파일: sun.cpp 프로젝트: AlkexGas/Torque3D
bool Sun::onAdd()
{
   if ( !Parent::onAdd() )
      return false;

   // Register as listener to TimeOfDay update events
   TimeOfDay::getTimeOfDayUpdateSignal().notify( this, &Sun::_updateTimeOfDay );

	// Make this thing have a global bounds so that its 
   // always returned from spatial light queries.
	setGlobalBounds();
	resetWorldBox();
	setRenderTransform( mObjToWorld );
	addToScene();

   _initCorona();

   // Update the light parameters.
   _conformLights();

   setProcessTick( true );

   return true;
}
예제 #4
0
void Entity::unsetParent(Time ti, const Location &newLocation) {
    addToScene(NULL);
}
예제 #5
0
bool ConvexShape::onAdd()
{
   if ( !Parent::onAdd() )
      return false;
   
   //mObjBox.set( -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f );
   //resetWorldBox();   

   // Face Order:
   // Top, Bottom, Front, Back, Left, Right

   // X Axis
   static const Point3F cubeTangents[6] =
   {
      Point3F( 1,  0,  0 ),
      Point3F(-1,  0,  0 ),
      Point3F( 1,  0,  0 ),
      Point3F(-1,  0,  0 ),
      Point3F( 0,  1,  0 ),
      Point3F( 0, -1,  0 )      
   };

   // Y Axis
   static const Point3F cubeBinormals[6] =
   {
      Point3F( 0,  1,  0 ),
      Point3F( 0,  1,  0 ),
      Point3F( 0,  0, -1 ),
      Point3F( 0,  0, -1 ),
      Point3F( 0,  0, -1 ),
      Point3F( 0,  0, -1 )
   };

   // Z Axis
   static const Point3F cubeNormals[6] = 
   {
      Point3F( 0,  0,  1),
      Point3F( 0,  0, -1),
      Point3F( 0,  1,  0),
      Point3F( 0, -1,  0),
      Point3F(-1,  0,  0),
      Point3F( 1,  0,  0),      
   };

   if ( mSurfaces.empty() )
   {      
      for ( S32 i = 0; i < 6; i++ )
      {
         mSurfaces.increment();
         MatrixF &surf = mSurfaces.last();

         surf.identity();
         
         surf.setColumn( 0, cubeTangents[i] );
         surf.setColumn( 1, cubeBinormals[i] );
         surf.setColumn( 2, cubeNormals[i] );
         surf.setPosition( cubeNormals[i] * 0.5f );         
      }
   }

   if ( isClientObject() )   
      _updateMaterial();      
   
   _updateGeometry( true );

   addToScene();

   return true;
}
예제 #6
0
bool Projectile::onAdd()
{
   if(!Parent::onAdd())
      return false;

   if( !mDataBlock )
   {
      Con::errorf("Projectile::onAdd - Fail - Not datablock");
      return false;
   }

   if (isServerObject())
   {
      ShapeBase* ptr;
      if (Sim::findObject(mSourceObjectId, ptr))
      {
         mSourceObject = ptr;

         // Since we later do processAfter( mSourceObject ) we must clearProcessAfter
         // if it is deleted. SceneObject already handles this in onDeleteNotify so
         // all we need to do is register for the notification.
         deleteNotify( ptr );
      }
      else
      {
         if (mSourceObjectId != -1)
            Con::errorf(ConsoleLogEntry::General, "Projectile::onAdd: mSourceObjectId is invalid");
         mSourceObject = NULL;
      }

      // If we're on the server, we need to inherit some of our parent's velocity
      //
      mCurrTick = 0;
   }
   else
   {
      if (bool(mDataBlock->projectileShape))
      {
         mProjectileShape = new TSShapeInstance(mDataBlock->projectileShape, isClientObject());

         if (mDataBlock->activateSeq != -1)
         {
            mActivateThread = mProjectileShape->addThread();
            mProjectileShape->setTimeScale(mActivateThread, 1);
            mProjectileShape->setSequence(mActivateThread, mDataBlock->activateSeq, 0);
         }
      }
      if (mDataBlock->particleEmitter != NULL)
      {
         ParticleEmitter* pEmitter = new ParticleEmitter;
         pEmitter->onNewDataBlock(mDataBlock->particleEmitter,false);
         if (pEmitter->registerObject() == false)
         {
            Con::warnf(ConsoleLogEntry::General, "Could not register particle emitter for particle of class: %s", mDataBlock->getName());
            delete pEmitter;
            pEmitter = NULL;
         }
         mParticleEmitter = pEmitter;
      }

      if (mDataBlock->particleWaterEmitter != NULL)
      {
         ParticleEmitter* pEmitter = new ParticleEmitter;
         pEmitter->onNewDataBlock(mDataBlock->particleWaterEmitter,false);
         if (pEmitter->registerObject() == false)
         {
            Con::warnf(ConsoleLogEntry::General, "Could not register particle emitter for particle of class: %s", mDataBlock->getName());
            delete pEmitter;
            pEmitter = NULL;
         }
         mParticleWaterEmitter = pEmitter;
      }
   }
   if (mSourceObject.isValid())
      processAfter(mSourceObject);

   // Setup our bounding box
   if (bool(mDataBlock->projectileShape) == true)
      mObjBox = mDataBlock->projectileShape->bounds;
   else
      mObjBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));

   MatrixF initialTransform( true );
   initialTransform.setPosition( mCurrPosition );
   setTransform( initialTransform );   // calls resetWorldBox

   addToScene();

   if ( PHYSICSMGR )
      mPhysicsWorld = PHYSICSMGR->getWorld( isServerObject() ? "server" : "client" );

   return true;
}
예제 #7
0
파일: main.cpp 프로젝트: Shervanator/Engine
void CoolGame::init(GLManager *glManager)
{
  auto input = getEngine()->getWindow()->getInput();
  input->registerKeyToAction(SDLK_SPACE, "fire");
  input->registerKeyToAction(SDLK_c, "swapCamera");

  input->bindAction("fire", IE_PRESSED, [this]() {
    MeshLoader cube("cube.obj");
    cube.getEntity()->getTransform().setPosition(primary_camera->getParent()->getPosition());
    cube.getEntity()->addComponent<BoxCollider>(glm::vec3(0.5, 0.5, 0.5), 50);
    addToScene(cube.getEntity());
    auto dir = primary_camera->getParent()->getDirection();
    cube.getEntity()->getComponent<BoxCollider>()->applyCentralImpulse(glm::vec3(dir.x * 500.0f, dir.y * 500.0f, dir.z * 500.0f));
  });

  input->bindAction("swapCamera", IE_PRESSED, [this]() {
    getEngine()->getGLManager()->setActiveCamera(primary_camera2);
  });

  input->bindAction("swapCamera", IE_RELEASED, [this]() {
    getEngine()->getGLManager()->setActiveCamera(primary_camera);
  });

  auto brickMat = std::make_shared<Material>(std::make_shared<Texture>(Asset("bricks2.jpg")), std::make_shared<Texture>(Asset("bricks2_normal.jpg")), std::make_shared<Texture>(Asset("bricks2_specular.png")));
  auto planeMesh = Plane::getMesh();
  // ground
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform().setPosition(glm::vec3(-5, -2, 0)).setScale(glm::vec3(10, 1, 10));
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform().setPosition(glm::vec3(5, -2, 0)).setScale(glm::vec3(10, 1, 10));
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform().setPosition(glm::vec3(-5, -2, 10)).setScale(glm::vec3(10, 1, 10));
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform().setPosition(glm::vec3(5, -2, 10)).setScale(glm::vec3(10, 1, 10));
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }

  // front wall
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform()
        .setPosition(glm::vec3(-5, 3, -5))
        .setScale(glm::vec3(10, 1, 10))
        .rotate(glm::vec3(1, 0, 0), glm::pi<float>() / 2.f);
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform()
        .setPosition(glm::vec3(5, 3, -5))
        .setScale(glm::vec3(10, 1, 10))
        .rotate(glm::vec3(1, 0, 0), glm::pi<float>() / 2.f);
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }

  // back wall
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform()
        .setPosition(glm::vec3(-5, 3, 15))
        .setScale(glm::vec3(10, 1, 10))
        .rotate(glm::vec3(1, 0, 0), -glm::pi<float>() / 2.f);
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform()
        .setPosition(glm::vec3(5, 3, 15))
        .setScale(glm::vec3(10, 1, 10))
        .rotate(glm::vec3(1, 0, 0), -glm::pi<float>() / 2.f);
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }

  // left wall
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform()
        .setPosition(glm::vec3(-10, 3, 0))
        .setScale(glm::vec3(10, 1, 10))
        .rotate(glm::vec3(0, 0, 1), -glm::pi<float>() / 2.f);
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform()
        .setPosition(glm::vec3(-10, 3, 10))
        .setScale(glm::vec3(10, 1, 10))
        .rotate(glm::vec3(0, 0, 1), -glm::pi<float>() / 2.f);
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }

  // right wall
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform()
        .setPosition(glm::vec3(10, 3, 0))
        .setScale(glm::vec3(10, 1, 10))
        .rotate(glm::vec3(0, 0, 1), glm::pi<float>() / 2.f);
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }
  {
    auto plane = std::make_shared<Entity>();
    plane->addComponent<MeshRenderer>(planeMesh, brickMat);
    plane->getTransform()
        .setPosition(glm::vec3(10, 3, 10))
        .setScale(glm::vec3(10, 1, 10))
        .rotate(glm::vec3(0, 0, 1), glm::pi<float>() / 2.f);
    plane->addComponent<BoxCollider>(glm::vec3(5, 0, 5), 0);

    addToScene(plane);
  }

  /*{
    MeshLoader ml("Pregnant.obj");
    ml.getEntity()->getTransform().setPosition(glm::vec3(0 + (i * 3), -2, -2.5));
    ml.getEntity()->addComponent<Sphere>(1);
    addToScene(ml.getEntity());
  }*/

  for (int i = 0; i < 10; i++)
  {
    MeshLoader ml("AncientUgandan.obj");
    ml.getEntity()->getTransform().setPosition(glm::vec3(0, i * 3, -2.5));
    ml.getEntity()->addComponent<SphereCollider>(1, 1);
    addToScene(ml.getEntity());
  }

  MeshLoader money("monkey3.obj");
  money.getEntity()->getTransform().setPosition(glm::vec3(0, 0, 8));
  money.getEntity()->addComponent<PerspectiveCamera>(glm::pi<float>() / 2.0f, getEngine()->getWindow()->getWidth() / (float)getEngine()->getWindow()->getHeight(), 0.05f, 100.0f);
  //money.getEntity()->addComponent<SpotLight>(glm::vec3(0.1f, 1.0f, 1.0f), 5.8f, 0.7f, std::make_shared<Attenuation>(0, 0, 0.2));
  money.getEntity()->addComponent<SphereCollider>(1, 1);
  addToScene(money.getEntity());

  MeshLoader money2("monkey3.obj");
  money2.getEntity()->addComponent<PerspectiveCamera>(glm::pi<float>() / 2.0f, getEngine()->getWindow()->getWidth() / (float)getEngine()->getWindow()->getHeight(), 0.8f, 100.0f);
  money2.getEntity()->addComponent<FreeMove>();
#if defined(ANDROID)
  money2.getEntity()->addComponent<FreeLook>(0.1f);
#else
  money2.getEntity()->addComponent<FreeLook>();
#endif
  money2.getEntity()->getTransform().setPosition(glm::vec3(0, 0, 5)).setScale(glm::vec3(0.8, 0.8, 0.8));
  money2.getEntity()->addComponent<SpotLight>(glm::vec3(1.0f, 1.0f, 1.0f), 2.8f, 0.7f, std::make_shared<Attenuation>(0, 0, 0.2));

  addToScene(money2.getEntity());

  primary_camera = money2.getEntity()->getComponent<PerspectiveCamera>();
  primary_camera2 = money.getEntity()->getComponent<PerspectiveCamera>();

  getEngine()->getGLManager()->setActiveCamera(primary_camera);
}
예제 #8
0
void Scene02::init(const Window& window)
{
    Camera camera(50.0f, window.getAspectRatio(), 0.1f, 100.0f);
    CameraComponent* cameraComponent = new CameraComponent(camera);

    PhysicsEngine physicsEngine;
    PhysicsObject physicsObject1(new BoundingSphere(glm::vec3(-1.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    PhysicsObject physicsObject2(new BoundingSphere(glm::vec3(-2.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    PhysicsObject physicsObject3(new BoundingSphere(glm::vec3(-3.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    PhysicsObject physicsObject4(new BoundingSphere(glm::vec3(-4.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    PhysicsObject physicsObject5(new BoundingSphere(glm::vec3(-5.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    //PhysicsObject physicsObject6(new BoundingSphere(glm::vec3(-6.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);

    //PhysicsObject physicsObject6(new BoundingSphere(glm::vec3(3.0, 0.0, -5.0), 0.1f), glm::vec3(0.0f, 0.0f, 0.0f), false);

    physicsEngine.addObject(physicsObject1);
    physicsEngine.addObject(physicsObject2);
    physicsEngine.addObject(physicsObject3);
    physicsEngine.addObject(physicsObject4);
    physicsEngine.addObject(physicsObject5);
    //physicsEngine.addObject(physicsObject6);

    PhysicsEngineComponent* physicsEngineComponent = new PhysicsEngineComponent(physicsEngine);
    Node* physicsEngineNode = new Node;
    physicsEngineNode->addComponent(physicsEngineComponent);
    addToScene(physicsEngineNode);

    IndexedMesh floorIndexedMesh("models/plane.obj");
    floorIndexedMesh.m_texCoords.push_back( glm::vec2(1.0, 1.0) );
    floorIndexedMesh.m_texCoords.push_back( glm::vec2(1.0, 0.0) );
    floorIndexedMesh.m_texCoords.push_back( glm::vec2(0.0, 0.0) );
    floorIndexedMesh.m_texCoords.push_back( glm::vec2(0.0, 1.0) );
    Mesh floorMesh;
    floorMesh.init(floorIndexedMesh);
    Material* floor = new Material( new Texture("textures/snow.jpg") , glm::vec3(1.0, 1.0, 1.0));

    // adding interior
    Material* back = new Material( new Texture("textures/Fireplace.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* backNode = new Node(glm::vec3(-10.0, 8.0, -10.0), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(20.0f, 1.0f, 10.0f));
    backNode->addComponent(new MeshRenderer(floorMesh, *back));
    addToScene(backNode);

    Material* win = new Material( new Texture("textures/s.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* winNode = new Node(glm::vec3(9.99, 10.0, -10.0), glm::vec3(0.0f, -90.0f, -90.0f), glm::vec3(5.0f, 1.0f, 5.0f));
    winNode->addComponent(new MeshRenderer(floorMesh, *win));
    addToScene(winNode);

    Node* winNode2 = new Node(glm::vec3(10.01, 10.0, -10.0), glm::vec3(0.0f, -90.0f, -90.0f), glm::vec3(5.0f, 1.0f, 5.0f));
    winNode2->addComponent(new MeshRenderer(floorMesh, *win));
    addToScene(winNode2);

    Material* walls = new Material( new Texture("textures/carpet5.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* roofNode = new Node(glm::vec3(-10.0, 18.0, -10.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(20.0f, 1.0f, 20.0f));
    roofNode->addComponent(new MeshRenderer(floorMesh, *walls));
    addToScene(roofNode);

    Node* rwallNode = new Node(glm::vec3(10.0, 8.0, -10.0), glm::vec3(0.0f, 0.0f, -90.0f), glm::vec3(13.0f, 1.0f, 20.0f));
    rwallNode->addComponent(new MeshRenderer(floorMesh, *walls));
    addToScene(rwallNode);

    Material* fwall = new Material( new Texture("textures/Door.jpg") , glm::vec3(1.0, 1.0, 1.0));
     Node* fwallNode = new Node(glm::vec3(-30.0, 8.0, -10.0), glm::vec3(0.0f, 90.0f, -90.0f), glm::vec3(13.0f, 1.0f, 20.0f));
    fwallNode->addComponent(new MeshRenderer(floorMesh, *fwall));
    addToScene(fwallNode);

    Material* flor = new Material( new Texture("textures/carpet4.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* florNode = new Node(glm::vec3(-10.0, -0.99, -10.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(20.0f, 1.0f, 20.0f));
    florNode->addComponent(new MeshRenderer(floorMesh, *flor));
    addToScene(florNode);

    Material* bg1 = new Material( new Texture("textures/n.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* bgNode = new Node(glm::vec3(0.0, 8.0, -10.0), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(30.0f, 1.0f, 10.0f));
    bgNode->addComponent(new MeshRenderer(floorMesh, *bg1));
    addToScene(bgNode);

    Node* bgNode2 = new Node(glm::vec3(30.0, 8.0, -10.0), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(30.0f, 1.0f, 10.0f));
    bgNode2->addComponent(new MeshRenderer(floorMesh, *bg1));
    addToScene(bgNode2);

       Node* bgNode3 = new Node(glm::vec3(90.0, 8.0, -10.0), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(30.0f, 1.0f, 10.0f));
    bgNode3->addComponent(new MeshRenderer(floorMesh, *bg1));
    addToScene(bgNode3);

    // finishing interior

    Node* floorNode = new Node(glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(50.0f, 1.0f, 10.0f));
    floorNode->addComponent(new MeshRenderer(floorMesh, *floor));
    addToScene(floorNode);

    Material* bg = new Material( new Texture("textures/bg2.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* bgNode1 = new Node(glm::vec3(0.0, 2.5, -10.0), glm::vec3(90.0f, 0.0f, 0.0f), glm::vec3(50.0f, 1.0f, 5.0f));
    bgNode1->addComponent(new MeshRenderer(floorMesh, *bg));
    addToScene(bgNode1);

    Mesh* cubeMesh = new Mesh;
    cubeMesh->initCube();
    //Material* building = new Material( new Texture("textures/igloo.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Material* gift = new Material( new Texture("textures/xmas.jpg") , glm::vec3(1.0, 1.0, 1.0));

//    Node* cubeNode1 = new Node(glm::vec3(3.0, 0.0, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
//    cubeNode1->addComponent(new MeshRenderer(*cubeMesh, *building));
//    //cubeNode1->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(5)));
//    addToScene(cubeNode1);
//
//    Node* cubeNode2 = new Node(glm::vec3(13.0, 0.0, -6.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
//    cubeNode2->addComponent(new MeshRenderer(*cubeMesh, *building));
//    addToScene(cubeNode2);

    Material* building = new Material( new Texture("textures/e.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Material* outer = new Material( new Texture("textures/igloo.jpg") , glm::vec3(1.0, 1.0, 1.0));

    Node* cubeNode1 = new Node(glm::vec3(3.0, 0.0, -6.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
    cubeNode1->addComponent(new MeshRenderer(*cubeMesh, *building));
    addToScene(cubeNode1);

    Node* cubeNode2 = new Node(glm::vec3(13.0, 0.0, -6.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
    cubeNode2->addComponent(new MeshRenderer(*cubeMesh, *outer));
    addToScene(cubeNode2);

    Node* cubeNode3 = new Node(glm::vec3(23.0, 0.0, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
    cubeNode3->addComponent(new MeshRenderer(*cubeMesh, *outer));
    addToScene(cubeNode3);

     Node* cubeNode4 = new Node(glm::vec3(-3.0, 0.0, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
    cubeNode4->addComponent(new MeshRenderer(*cubeMesh, *building));
    addToScene(cubeNode4);

//    Node* cubeNode3 = new Node(glm::vec3(23.0, 0.0, -6.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
//    cubeNode3->addComponent(new MeshRenderer(*cubeMesh, *building));
//    addToScene(cubeNode3);

    Node* xmasNode = new Node(glm::vec3(33.0, 0.0, -6.0), glm::vec3(90.0f, 0.0f, 0.0f), glm::vec3(3.0f, 1.0f, 1.0f));
    xmasNode->addComponent(new MeshRenderer(floorMesh, *gift));
    addToScene(xmasNode);

    IndexedMesh paperPlaneIndexedMesh("models/paperbird.obj");
    Mesh paperPlaneMesh;
    paperPlaneMesh.init(paperPlaneIndexedMesh);

    Material* yellowPaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.95, 0.95, 0.25));
    Node* birdNode1 = new Node(glm::vec3(-1.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode1->addComponent(new MeshRenderer(paperPlaneMesh, *yellowPaper));
    birdNode1->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(0)));
    birdNode1->addComponent(cameraComponent);
    addToScene(birdNode1);

    Material* orangePaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.93, 0.67, 0.09));
    Node* birdNode2 = new Node(glm::vec3(-2.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode2->addComponent(new MeshRenderer(paperPlaneMesh, *orangePaper));
    birdNode2->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(1)));
    addToScene(birdNode2);

    Material* redPaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.9, 0.28, 0.28));
    Node* birdNode3 = new Node(glm::vec3(-3.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode3->addComponent(new MeshRenderer(paperPlaneMesh, *redPaper));
    birdNode3->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(2)));
    addToScene(birdNode3);

    Material* greenPaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.43, 0.79, 0.43));
    Node* birdNode4 = new Node(glm::vec3(-4.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode4->addComponent(new MeshRenderer(paperPlaneMesh, *greenPaper));
    birdNode4->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(3)));
    addToScene(birdNode4);

    Material* bluePaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.27, 0.51, 0.78));
    Node* birdNode5 = new Node(glm::vec3(-5.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode5->addComponent(new MeshRenderer(paperPlaneMesh, *bluePaper));
    birdNode5->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(4)));
    addToScene(birdNode5);

//    Material* whitePaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(1.0, 1.0, 1.0));
//    Node* birdNode6 = new Node(glm::vec3(-6.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
//    birdNode6->addComponent(new MeshRenderer(paperPlaneMesh, *whitePaper));
//    birdNode6->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(5)));
//    addToScene(birdNode6);

}
예제 #9
0
bool Projectile::onAdd()
{
   if(!Parent::onAdd())
      return false;

   if (isServerObject())
   {
      ShapeBase* ptr;
      if (Sim::findObject(mSourceObjectId, ptr))
         mSourceObject = ptr;
      else
      {
         if (mSourceObjectId != -1)
            Con::errorf(ConsoleLogEntry::General, "Projectile::onAdd: mSourceObjectId is invalid");
         mSourceObject = NULL;
      }

      // If we're on the server, we need to inherit some of our parent's velocity
      //
      mCurrTick = 0;
   }
   else
   {
      if (bool(mDataBlock->projectileShape))
      {
         mProjectileShape = new TSShapeInstance(mDataBlock->projectileShape, isClientObject());

         if (mDataBlock->activateSeq != -1)
         {
            mActivateThread = mProjectileShape->addThread();
            mProjectileShape->setTimeScale(mActivateThread, 1);
            mProjectileShape->setSequence(mActivateThread, mDataBlock->activateSeq, 0);
         }
      }
      if (mDataBlock->particleEmitter != NULL)
      {
         ParticleEmitter* pEmitter = new ParticleEmitter;
         pEmitter->onNewDataBlock(mDataBlock->particleEmitter);
         if (pEmitter->registerObject() == false)
         {
            Con::warnf(ConsoleLogEntry::General, "Could not register particle emitter for particle of class: %s", mDataBlock->getName());
            delete pEmitter;
            pEmitter = NULL;
         }
         mParticleEmitter = pEmitter;
      }

      if (mDataBlock->particleWaterEmitter != NULL)
      {
         ParticleEmitter* pEmitter = new ParticleEmitter;
         pEmitter->onNewDataBlock(mDataBlock->particleWaterEmitter);
         if (pEmitter->registerObject() == false)
         {
            Con::warnf(ConsoleLogEntry::General, "Could not register particle emitter for particle of class: %s", mDataBlock->getName());
            delete pEmitter;
            pEmitter = NULL;
         }
         mParticleWaterEmitter = pEmitter;
      }
   }
   if (mSourceObject.isValid())
      processAfter(mSourceObject);

   // Setup our bounding box
   if (bool(mDataBlock->projectileShape) == true)
      mObjBox = mDataBlock->projectileShape->bounds;
   else
      mObjBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));
   resetWorldBox();
   addToScene();

   if ( gPhysicsPlugin )
      mPhysicsWorld = gPhysicsPlugin->getWorld( isServerObject() ? "Server" : "Client" );

   return true;
}
예제 #10
0
bool SFXEmitter::onAdd()
{
   if( !Parent::onAdd() )
      return false;

   if( isServerObject() )
   {
      // Validate the data we'll be passing across
      // the network to the client.
      mDescription.validate();
      
      // Read an old 'profile' field for backwards-compatibility.
      
      if( !mTrack )
      {
         static const char* sProfile = StringTable->insert( "profile" );
         const char* profileName = getDataField( sProfile, NULL );
         if( profileName &&  profileName[ 0 ] )
         {
            if( !Sim::findObject( profileName, mTrack ) )
               Con::errorf( "SFXEmitter::onAdd - No SFXTrack '%s' in SFXEmitter '%i' (%s)", profileName, getId(), getName() );
            else
            {
               // Remove the old 'profile' field.
               setDataField( sProfile, NULL, "" );
            }
         }
      }

      // Convert a legacy 'channel' field, if we have one.
      
      static const char* sChannel = StringTable->insert( "channel" );
      const char* channelValue = getDataField( sChannel, NULL );
      if( channelValue && channelValue[ 0 ] )
      {
         const char* group = Con::evaluatef( "return sfxOldChannelToGroup( %s );", channelValue );
         SFXSource* sourceGroup;
         if( !Sim::findObject( group, sourceGroup ) )
            Con::errorf( "SFXEmitter::onAdd - could not resolve channel '%s' to SFXSource", channelValue );
         else
         {
            static const char* sSourceGroup = StringTable->insert( "sourceGroup" );
            setDataField( sSourceGroup, NULL, sourceGroup->getIdString() );
            
            // Remove the old 'channel' field.
            setDataField( sChannel, NULL, "" );
         }
      }
   }
   else
   {
      _update();

      // Do we need to start playback?
      if( mPlayOnAdd && mSource )
         mSource->play();
   }
   
   // Setup the bounds.

   mObjScale.set( mDescription.mMaxDistance, mDescription.mMaxDistance, mDescription.mMaxDistance );
   resetWorldBox();

   addToScene();
   return true;
}