Example #1
0
    StereoManager::StereoMode StereoManager::loadConfig(const Ogre::String &filename)
    {
        Ogre::ConfigFile cf;
        cf.load(filename.c_str());

        StereoMode mode = SM_NONE;

        const Ogre::String &modeName = cf.getSetting("Stereo mode","Stereoscopy");
        const StereoModeList::const_iterator end = available_nodes_.end();
        StereoModeList::iterator it;
        for(it = available_nodes_.begin(); it != end; ++it)
        {
            if(it->second.name_ == modeName)
            {
                mode = it->first;
                break;
            }
        }
        if(it == available_nodes_.end())
            mode = SM_NONE;

        fixFocalPlanePos(Ogre::StringConverter::parseBool(cf.getSetting("Fixed screen","Stereoscopy")));

        if(cf.getSetting("Focal length","Stereoscopy") == "inf")
            infinite_focal_length_ = true;
        else
            setFocalLength(Ogre::StringConverter::parseReal(cf.getSetting("Focal length","Stereoscopy")));

        setEyesSpacing(Ogre::StringConverter::parseReal(cf.getSetting("Eyes spacing","Stereoscopy")));
        setScreenWidth(Ogre::StringConverter::parseReal(cf.getSetting("Screen width","Stereoscopy")));
        inverseStereo(Ogre::StringConverter::parseBool(cf.getSetting("Inverse stereo","Stereoscopy")));

        return mode;
    }
Example #2
0
void verifyTerminalSize(void)
{
        setScreenHeight(MIN_LINESIZE);
        setScreenWidth(MIN_COLUMNSIZE);
        
        if (FileOutput)
        {
                struct winsize ws;
                int FileOutputFD = fileno(FileOutput);
                
                if (ioctl(FileOutputFD, TIOCGWINSZ, &ws) < 0)
                {
                        fprintf(FileOutput, "La taille de votre terminal "
                                "doit faire au moins [%dx%d] et n'a pas pu etre determinee\n"
                                "Agrandissez maintenant la fenetre et appuyez sur ENTREE\n",
                                MIN_COLUMNSIZE, MIN_LINESIZE);
                        fflush(stdin);
                        getchar();     
                        fflush(stdin);
                        
                        setScreenHeight(MIN_LINESIZE);
                        setScreenWidth(MIN_COLUMNSIZE);
                }
                else
                {
                        fprintf(FileOutput, "La taille de votre terminal "
                                "doit faire au moins [%dx%d] et fait actuellement [%dx%d]\n"
                                "Agrandissez maintenant la fenetre et appuyez sur ENTREE\n",
                                MIN_COLUMNSIZE, MIN_LINESIZE,
                                ws.ws_col, ws.ws_row);
                        fflush(stdin);
                        getchar();     
                        fflush(stdin);
                        
                        
                        ioctl(FileOutputFD, TIOCGWINSZ, &ws);
                        
                        setScreenHeight(ws.ws_row);
                        setScreenWidth(ws.ws_col);
                        
                        fprintf(FileOutput, "La taille de votre terminal "
                                "enregistrée est : [%dx%d].\nLancement dans 1 seconde...\n",
                                getScreenWidth(), getScreenHeight());
                        sleep(1);       
                }
        }
}
TEST(OsgViewElementRenderTest, StereoView)
{
	std::shared_ptr<Runtime> runtime = std::make_shared<Runtime>();
	std::shared_ptr<OsgManager> manager = std::make_shared<OsgManager>();

	runtime->addManager(manager);
	runtime->addManager(std::make_shared<SurgSim::Framework::BehaviorManager>());

	std::shared_ptr<Scene> scene = runtime->getScene();

	/// Add a graphics component to the scene
	std::shared_ptr<OsgViewElement> viewElement = std::make_shared<OsgViewElement>("view");

	auto boxElement = std::make_shared<SurgSim::Framework::BasicSceneElement>("box");

	RigidTransform3d pose =
		makeRigidTransform(Vector3d(1.0, 1.0, 1.0), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 1.0, 0.0));
	viewElement->setPose(pose);
	scene->addSceneElement(viewElement);

	auto box = std::make_shared<OsgBoxRepresentation>("box");
	box->setSizeXYZ(0.1, 0.1, 0.2);
	boxElement->addComponent(box);

	RigidTransform3d from =
		makeRigidTransform(Vector3d(0.2, 0.0, 0.0), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 1.0, 0.0));
	RigidTransform3d to =
		makeRigidTransform(Vector3d(-0.2, 0.0, 0.0), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 1.0, 0.0));
	auto interpolator = std::make_shared<SurgSim::Blocks::PoseInterpolator>("interpolator");

	interpolator->setDuration(2.0);
	interpolator->setStartingPose(from);
	interpolator->setEndingPose(to);
	interpolator->setPingPong(true);
	interpolator->setTarget(boxElement);

	boxElement->addComponent(interpolator);

	scene->addSceneElement(boxElement);

	auto osgView = std::static_pointer_cast<OsgView>(viewElement->getView());
	osgView->setStereoMode(View::STEREO_MODE_HORIZONTAL_SPLIT);
	osgView->setDisplayType(View::DISPLAY_TYPE_MONITOR);
	osgView->setEyeSeparation(0.06);
	osgView->setScreenWidth(0.486918);
	osgView->setScreenHeight(0.273812);
	osgView->setScreenDistance(1.0);


	runtime->start();
	boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
	runtime->stop();
}
Example #4
0
OculusView::OculusView(const std::string& name) : OsgView(name)
{
	SURGSIM_ADD_SERIALIZABLE_PROPERTY(OculusView, std::shared_ptr<SurgSim::Framework::Component>, InputComponent,
									  getInputComponent, setInputComponent);

	// Default Settings of Oculus DK2
	setFullScreen(true);
	setDisplayType(View::DISPLAY_TYPE_HMD);
	setStereoMode(View::STEREO_MODE_HORIZONTAL_SPLIT);
	setScreenWidth(0.0631);
	setScreenHeight(0.071);
	setEyeSeparation(0.06);
	setScreenDistance(0.10);
	setTargetScreen(1); // Assume Oculus HMD has ID '1'.

	std::array<int, 2> dimensions = {1920, 1080};
	setDimensions(dimensions);
}
Example #5
0
void frts::Drawer::init(const SharedManagerPtr& shared)
{
    assert(shared != nullptr);

    // Set data from config.
    auto gd = getDataValue<GraphicData>(shared, Sdl2Ids::graphicData());
    auto md = getDataValue<ModelData>(shared, ModelIds::modelData());

    sidebarWidth = pixelToTilesX(gd->getSidebarWidth(), shared);
    gd->setSidebarWidth(tilesToPixelX(sidebarWidth, shared));

    Point::value screenHeight = pixelToTilesY(gd->getScreenHeight(), shared);
    screenHeight = std::min(screenHeight, md->getMapSizeY());
    gd->setScreenHeight(tilesToPixelY(screenHeight, shared));

    Point::value screenWidth = pixelToTilesX(gd->getScreenWidth(), shared);
    screenWidth = std::min(screenWidth, md->getMapSizeX() + sidebarWidth);
    gd->setScreenWidth(tilesToPixelX(screenWidth, shared));

    Point::value mapWidth = screenWidth - sidebarWidth;

    // Set screen areas.
    GraphicData::ScreenArea mapArea(0, 0, tilesToPixelX(mapWidth, shared), gd->getScreenHeight());
    gd->setMapArea(mapArea);

    GraphicData::ScreenArea sidebarArea(tilesToPixelX(mapWidth, shared), 0, gd->getSidebarWidth(), gd->getScreenHeight());
    gd->setSidebarArea(sidebarArea);

    // Initialize SDL2.
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
    {
        auto msg = boost::format(R"(SDL_Init Error: %1%)") % SDL_GetError();
        shared->getLog()->error(getName(), msg.str());
        return;
    }

    // Image support.
    int imageFlags = IMG_INIT_PNG;
    if (IMG_Init(imageFlags) != imageFlags)
    {
        auto msg = boost::format(R"(IMG_Init Error: %1%)") % IMG_GetError();
        shared->getLog()->error(getName(), msg.str());
        return;
    }

    // TTF support.
    if(TTF_Init() == -1)
    {
        auto msg = boost::format(R"(TTF_Init Error: %1%)") % TTF_GetError();
        shared->getLog()->error(getName(), msg.str());
        return;
    }

    // Create window.
    window = std::unique_ptr<SDL_Window, Sdl2Deleter>(
       SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                        static_cast<int>(gd->getScreenWidth()),
                        static_cast<int>(gd->getScreenHeight()),
                        SDL_WINDOW_SHOWN),
        Sdl2Deleter()
    );
    if (window == nullptr)
    {
        auto msg = boost::format(R"(SDL_CreateWindow Error: %1%)") % SDL_GetError();
        shared->getLog()->error(getName(), msg.str());
        return;
    }

    // Create renderer.
    renderer = std::shared_ptr<SDL_Renderer>(
        SDL_CreateRenderer(window.get(), -1, SDL_RENDERER_ACCELERATED),
        Sdl2Deleter()
    );
    if (renderer == nullptr)
    {
        auto msg = boost::format(R"(SDL_CreateRenderer Error: %1%)") % SDL_GetError();
        shared->getLog()->error(getName(), msg.str());
        return;
    }

    // Read images.
    for (auto& image : images)
    {
        SDL_Surface *surface = IMG_Load(image.second.c_str());
        if (surface == nullptr)
        {
            auto msg = boost::format(R"(IMG_Load Error: %1%)") % IMG_GetError();
            shared->getLog()->error(getName(), msg.str());
            continue;
        }

        TexturePtr texture = std::shared_ptr<SDL_Texture>(
            SDL_CreateTextureFromSurface(renderer.get(), surface),
            Sdl2Deleter()
        );
        SDL_FreeSurface(surface);
        if (texture == nullptr)
        {
            auto msg = boost::format(R"(SDL_CreateTextureFromSurface Error: %1%)") % SDL_GetError();
            shared->getLog()->error(getName(), msg.str());
            continue;
        }

        textures.insert(std::make_pair(image.first, texture));
    }
    images.clear();

    initialized = true;
}

void frts::Drawer::renderEntities(const EntityVector& entities, const IdPtr& renderableId,
                                  const SDL_Rect& rectToRender, IdUnorderedSet& stacked,
                                  const SharedManagerPtr& shared, double zoom)
{
    assert(initialized);
    assert(renderableId != nullptr);
    assert(shared != nullptr);

    for (auto& entity : entities)
    {
        auto renderable = getComponent<Renderable>(renderableId, entity);

        if (!renderable->doStacking() && stacked.find(renderable->getSprite()) != stacked.end())
        {
            continue;
        }
        stacked.insert(renderable->getSprite());

        auto sprite = spriteManager.getSprite(renderable, entity, shared);
        auto texture = textures.at(sprite.getImage());

        auto width = sprite.getWidth();
        if (width * zoom > rectToRender.w)
        {
            width = static_cast<int>(rectToRender.w / zoom);
        }

        auto height = sprite.getHeight();
        if (height * zoom > rectToRender.h)
        {
            height = static_cast<int>(rectToRender.h / zoom);
        }

        SDL_Rect clip = {
            sprite.getX(),
            sprite.getY(),
            width,
            height
        };
        SDL_RenderCopy(renderer.get(), texture.get(), &clip, &rectToRender);
    }
}

void frts::Drawer::renderNow(const SharedManagerPtr& shared)
{
    assert(shared != nullptr);
    assert(initialized);

    PerformanceLog pl(getName() + "RenderNow", shared, 5);

    SDL_RenderPresent(renderer.get());
}
void ShipBuildingArea::independentUpdate(float deltaTime)
{
	setScreenWidth( IwGxGetScreenWidth() );
	setScreenHeight( IwGxGetScreenHeight() );

	int direction = 0;

	// Make the robot follow the alien
	if(!secondPass_)
	{
		robot()->followAlien(alien()->getX(), alien()->getY());
	}

	// Update pointer system
	input()->update();

	// Check for screen touches
	if (input()->getTouchCount() != 0)
	{
		// Create a touch pointer and let it point to the the current touch command
		Touch* touch = input()->getTouch(0);

		// If a touch was set correctly
		if (touch != NULL)
		{
			escapePodBuildingPuzzle_.touchUpdate(touch->x_, touch->y_);

			if( !escapePodBuildingPuzzle_.movingABuildPiece() && !secondPass_)
			{
				// If player is trying to move right while the alien is at the edge of its moving area
				if( alien()->getX()	>= ( (int)((float)screenWidth() - (((float)screenWidth() / 100.0)*deadZone_))) &&
					touch->x_ > ( (int)((float)screenWidth() - (((float)screenWidth() / 100.0)*deadZone_)) ) )
				{
					if (playerStage_.isScrollingRight())
					{
						alien()->setWalkingState(true);
						robot()->setWalking();
						direction = -1;
					}
				}
				
				// If player is trying to move left while the alien is at the edge of its moving area
				else if( alien()->getX() <= ( (int)(((float)screenWidth() / 100.0)*deadZone_) ) &&
						 touch->x_ < ( (int)(((float)screenWidth() / 100.0)*deadZone_) ) )
				{
					if (playerStage_.isScrollingLeft())
					{
						alien()->setWalkingState(true);
						robot()->setWalking();
						direction = 1;
					}
				}
				else
				{
					// If the touch is to the right of the alien
					if (touch->x_ > alien()->getX() )
					{
						// Move the alien right 
						alien()->moveRight();
						alien()->setWalkingState(true);
					}

					// If the touch is the left of the alien
					if (touch->x_ < alien()->getX())
					{
						// Move the alien left
						alien()->moveLeft();
						alien()->setWalkingState(true);
					}
				}
			}
		}	// end if (touch != NULL)


		// if multi-touch is available then ...
		if (input()->isMultiTouch())
		{
			if (input()->getTouchCount() > 1)
			{
				touch = input()->getTouch(1);
				if (touch != NULL)
				{
					// Add update input effects here
				}
			}
		}
	}
	if (input()->getTouchCount() == 0 )
	{

		escapePodBuildingPuzzle_.noTouchEventsActive();
		// Set the alien walking to false as there are no touch events
		alien()->setWalkingState(false);
	}

	sky_.update(direction*deltaTime*SCROLL_SPEED*0.2);
	distantBackground_.update(direction*deltaTime*SCROLL_SPEED*0.4);
	closeBackground_.update(direction*deltaTime*SCROLL_SPEED*0.6);
	midground_.update(direction*deltaTime*SCROLL_SPEED*0.8);
	playerStage_.update(direction*deltaTime*SCROLL_SPEED);
	foreground_.update(direction*deltaTime*SCROLL_SPEED*1.8);

	escapePodBuildingPuzzle_.movePuzzle(direction*deltaTime*SCROLL_SPEED);

	// If the alien	is beyond a set distance from the escape pod
	if( alien()->getX()	>= ( escapePodBuildingPuzzle_.getCenterX() + offsetFromEscapePod) )
	{
		// Move to the next level
		ambientSound_->stop();
		robot()->stopAllSounds();
		alien()->stopAllSounds();
		Level::playerExitingLevel();
		
	}
	
	if(escapePodBuildingPuzzle_.isComplete() && !endingPlayed_)
	{
		ambientSound_->stop();
		ending_->play();
		endingPlayed_ = true;
	}

	if(secondPass_)
	{
		alien()->setHoldingHose(true);
	}
}