Exemplo n.º 1
0
void LayerNode::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();
	ISceneNode* cameraNode = SceneManager->getActiveCamera();
	
	core::matrix4 mxTrans = cameraNode->getAbsoluteTransformation();
	core::vector3df vCamPos = cameraNode->getPosition();
	core::vector3df vCamScale = cameraNode->getScale();
	core::vector3df vCamRot = cameraNode->getRotation();

	//Zoom factor: for Factor=0, zoom = 1; for Factor=1, zoom = vCamScale;
	vCamScale.X = 1 - ( (1 - vCamScale.X) * m_paraxZoomFactor );
	vCamScale.Y = 1 - ( (1 - vCamScale.Y) * m_paraxZoomFactor );

	core::vector3df vCamPos2 = cameraNode->getPosition();
	
	// Apply Offset
	core::vector3df vOffset(m_offsetX, m_offsetY, 0);

	// Apply parallax factor
	vCamPos2.X *= m_paraxFactorX;
	vCamPos2.Y *= m_paraxFactorY;

	mxTrans = 
		core::matrix4().setTranslation(vCamPos)*
		core::matrix4().setScale(vCamScale)*
		core::matrix4().setTranslation(-vCamPos)*
		core::matrix4().setRotationDegrees(vCamRot)*
		core::matrix4().setTranslation(-vCamPos)*		// remove camera offset because is applied automatically later by Irrlicht
		core::matrix4().setTranslation(vOffset)*		// apply offset without parallax factor to make easy to adjust layer
		core::matrix4().setTranslation(vCamPos2)		// then apply modified by parallax factor camera position
		;
	driver->setMaterial(Material);


	driver->setTransform(video::ETS_WORLD, mxTrans*AbsoluteTransformation);

	Drawing::draw2DImage( driver, m_texture, core::recti( 0, 0, m_width, m_height), core::IdentityMatrix, true, video::SColor(255, 255, 255, 255));

}
Exemplo n.º 2
0
// ----------------------------------------------------------------------------
void Track::exportElements(std::ofstream& stream, bool obj)
{
    ISceneManager* sm = Editor::getEditor()->getSceneManager();
    ISceneNode* node;
    stringc name;
    int i = 1;
    while ((node = sm->getSceneNodeFromId(MAGIC_NUMBER + i)))
    {
        name = node->getName();
        vector3df pos, rot, sca;
        if (node->isVisible() && name != "banana" && name != "item"
            && name != "small-nitro" && name != "big-nitro"
            && (name.equalsn("obj/", 4) == obj))
        {
            pos = node->getPosition();
            rot = node->getRotation();
            sca = node->getScale();
            if (name.equalsn("obj/", 4))
            {
                stream << "    <static-object model=\"" << Editor::toRelative(name).c_str();
                copyObj(name);

                ITexture* tex;
                for (int j = 0; (tex = node->getMaterial(0).getTexture(j)); j++)
                    copyObj(stringc("obj/") + Editor::toRelative(tex->getName()));
            } // export as static-object
            else
            {
                stream << "  <library name=\"" << Editor::getLib(node->getName()).c_str();
            } // export as library
            stream << "\" xyz=\"";
            stream << pos.X << " " << pos.Y << " " << pos.Z << "\" hpr=\"";
            stream << rot.X << " " << rot.Y << " " << rot.Z << "\" scale=\"";
            stream << sca.X << " " << sca.Y << " " << sca.Z << "\"/>\n";
        }
        i++;
    }
} // exportElements
Exemplo n.º 3
0
// ----------------------------------------------------------------------------
void Track::save()
{
  FILE* pFile = 0;

  path p = Editor::getEditor()->getMapsPath() + "/" + m_file_name.c_str();
  pFile = fopen(p.c_str(), "wb");

  if (!pFile)
  {
      MsgWndw::get()->showMsg(_("Save failed: file could not be created!\n"));
      return;
  }

  // SIGN
  u64 sign = TOP_SECRET_SIGNATURE_NUMBER;
  fwrite(&sign, sizeof(u64), 1, pFile);

  // TRACK NAME
  u8 size = m_track_name.size() + 1;
  fwrite(&size, sizeof(u8), 1, pFile);
  fwrite(m_track_name.c_str(), sizeof(wchar_t), size, pFile);

  // DESIGNER NAME
  size = m_designer.size() + 1;
  fwrite(&size, sizeof(u8), 1, pFile);
  fwrite(m_designer.c_str(), sizeof(wchar_t), size, pFile);

  // FILE NAME
  size = m_file_name.size() + 1;
  fwrite(&size, sizeof(u8), 1, pFile);
  fwrite(m_file_name.c_str(), sizeof(c8), size, pFile);

  // MUSIC
  size = m_music.size() + 1;
  fwrite(&size, sizeof(u8), 1, pFile);
  fwrite(m_music.c_str(), sizeof(c8), size, pFile);

  // TERRAIN
  m_terrain->save(pFile);

  // SKY
  Viewport::get()->getSky()->save(pFile);

  // GRAVITY ROAD FLAG
  fwrite(&m_gravity_road, sizeof(bool), 1, pFile);

  // ROADS
  size = m_roads.size();
  fwrite(&size, sizeof(u8), 1, pFile);
  IRoad* r;
  for (u8 i = 0; i < size; i++)
  {
      r = m_roads[i];
      r->save(pFile);
  }

  //CHECKLINES

  Viewport::get()->saveCheckLines(pFile);

  // OBJECTS
  ISceneManager* sm = Editor::getEditor()->getSceneManager();
  ISceneNode* node;
  u32 num = Viewport::getLastEntityID() - MAGIC_NUMBER;
  u32 vnum = 0;
  for (u32 i = 0; i < num; i++)
  {
      node = sm->getSceneNodeFromId(MAGIC_NUMBER + i + 1);
      if (node && node->isVisible()) vnum++;
  }

  fwrite(&vnum, sizeof(u32), 1, pFile);

  for (u32 i = 0; i < num; i++)
  {
      node = sm->getSceneNodeFromId(MAGIC_NUMBER + i + 1);
      assert(node);
      if (node->isVisible())
      {
          fwrite(&node->getPosition(), sizeof(vector3df), 1, pFile);
          fwrite(&node->getRotation(), sizeof(vector3df), 1, pFile);
          fwrite(&node->getScale(),    sizeof(vector3df), 1, pFile);
          u8 size = strlen(node->getName()) + 1;
          fwrite(&size, sizeof(u8), 1, pFile);
          fwrite(node->getName(), sizeof(c8), size, pFile);
      }
  }
  fclose(pFile);
  Editor::getEditor()->addToRecentlyOpenedList(m_file_name);

  MsgWndw::get()->showMsg(_("Track saved!\n"));

} // save