virtual void initEvent()
  {
    vl::Log::print(appletInfo());

    srand((int)time(NULL));

    // populate our scene with some random objects

    vl::ref<vl::Effect> fx = new vl::Effect;
    fx->shader()->enable(vl::EN_DEPTH_TEST);
    fx->shader()->enable(vl::EN_LIGHTING);
    fx->shader()->gocLight(0)->setLinearAttenuation(0.025f);
    fx->shader()->gocMaterial()->setColorMaterialEnabled(true);

    int   count    = 1;
    float displace = 2.0f;
    for(int z=-count; z<=count; ++z)
    for(int y=-count; y<=count; ++y)
    for(int x=-count; x<=count; ++x)
    {
      vl::ref<vl::Geometry> geom = randomObject();
      vl::Actor* act = sceneManager()->tree()->addActor( geom.get(), fx.get(), new vl::Transform );
      act->setObjectName(geom->objectName());
      act->transform()->translate(x*displace, y*displace, z*displace);
      act->transform()->computeWorldMatrix();
    }

    // create a uv-sphere used to highlight the intersection point

    vl::ref<vl::Geometry> intersection_point_geom = vl::makeUVSphere(vl::vec3(0,0,0), 0.1f);
    intersection_point_geom->computeNormals();
    intersection_point_geom->setColor(vl::green);
    vl::Actor* intersection_point_act = sceneManager()->tree()->addActor( intersection_point_geom.get(), fx.get(), new vl::Transform );
    mIntersectionPoint = intersection_point_act->transform();
  }
  void multitexturing()
  {
    if (!GLEW_ARB_multitexture)
    {
      vl::Log::error("Multitexturing not supported.\n");
      return;
    }

    vl::ref<vl::Geometry> box = vl::makeBox( vl::vec3(0,0,0), 5,5,5, true );
    box->computeNormals();
    box->setTexCoordArray(1, box->texCoordArray(0));

    mCubeRightTransform = new vl::Transform;
    mCubeLeftTransform = new vl::Transform;
    rendering()->as<vl::Rendering>()->transform()->addChild(mCubeRightTransform.get());
    rendering()->as<vl::Rendering>()->transform()->addChild(mCubeLeftTransform.get());

    vl::ref<vl::Image> img_holebox = vl::loadImage("/images/holebox.tif");
    vl::ref<vl::Image> img_detail  = vl::loadImage("/images/detail.tif");

    vl::ref<vl::Texture> tex_holebox = new vl::Texture(img_holebox.get(), vl::TF_RGBA, mMipmappingOn, false);
    vl::ref<vl::Texture> tex_detail  = new vl::Texture(img_detail.get(),  vl::TF_RGBA, mMipmappingOn, false);

    tex_holebox->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
    tex_holebox->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);
    tex_detail->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
    tex_detail->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);

    vl::ref<vl::Light> light = new vl::Light(0);

    vl::ref<vl::Effect> cube_right_fx = new vl::Effect;
    // to ensure the cubes are drawn after the textured quads
    cube_right_fx->setRenderRank(1);
    cube_right_fx->shader()->setRenderState( light.get() );
    cube_right_fx->shader()->enable(vl::EN_LIGHTING);
    cube_right_fx->shader()->enable(vl::EN_DEPTH_TEST);
    cube_right_fx->shader()->enable(vl::EN_BLEND);
    cube_right_fx->shader()->enable(vl::EN_ALPHA_TEST);
    cube_right_fx->shader()->gocAlphaFunc()->set(vl::FU_GEQUAL, 1.0f - 0.02f);
    cube_right_fx->shader()->gocLightModel()->setTwoSide(true);
    cube_right_fx->shader()->gocTextureUnit(0)->setTexture( tex_holebox.get() );

    vl::ref<vl::Effect> cube_left_fx = new vl::Effect;
    // to ensure the cubes are drawn after the textured quads
    cube_left_fx->setRenderRank(1);
    cube_left_fx->shader()->setRenderState( light.get() );
    cube_left_fx->shader()->enable(vl::EN_LIGHTING);
    cube_left_fx->shader()->enable(vl::EN_DEPTH_TEST);
    cube_left_fx->shader()->enable(vl::EN_BLEND);
    cube_left_fx->shader()->enable(vl::EN_ALPHA_TEST);
    cube_left_fx->shader()->gocAlphaFunc()->set(vl::FU_GEQUAL, 1.0f - 0.02f);
    cube_left_fx->shader()->gocLightModel()->setTwoSide(true);
    cube_left_fx->shader()->gocTextureUnit(0)->setTexture( tex_holebox.get() );
    cube_left_fx->shader()->gocTextureUnit(1)->setTexture( tex_detail.get() );
    cube_left_fx->shader()->gocTexEnv(1)->setMode( vl::TEM_MODULATE );

    sceneManager()->tree()->addActor( box.get(), cube_right_fx.get(), mCubeRightTransform.get() );
    sceneManager()->tree()->addActor( box.get(), cube_left_fx.get(),  mCubeLeftTransform.get() );
  }
  void initEvent()
  {
    vl::Log::notify(appletInfo());

    // load model
    vl::ref<vl::Geometry> model = vl::loadResource("/models/3ds/monkey.3ds")->get<vl::Geometry>(0);
    model->computeNormals();

    // install transform
    mClipTr = new vl::Transform;
    rendering()->as<vl::Rendering>()->transform()->addChild(mClipTr.get());

    // to be used later
    vl::ref<vl::Light> light = new vl::Light;

    // demonstrates multipassing clipping

    vl::ref<vl::Effect> clip_fx  = new vl::Effect;
    vl::ref<vl::Shader> clip1_sh = new vl::Shader; 
    vl::ref<vl::Shader> clip2_sh = new vl::Shader;
    // setup clipping pass 1
    clip1_sh->setRenderState( light.get(), 0 );
    clip1_sh->enable(vl::EN_LIGHTING);
    clip1_sh->enable(vl::EN_DEPTH_TEST);
    clip1_sh->gocMaterial()->setBackDiffuse(vl::yellow);
    clip1_sh->gocLightModel()->setTwoSide(true);
    // clipping plane 1 setup
    clip1_sh->gocClipPlane(0)->setPlane( vl::Plane(0.2f, vl::vec3(0,+1,0)) );
    clip1_sh->gocClipPlane(0)->bindTransform( mClipTr.get() );
    // setup clipping pass 2
    clip2_sh->setRenderState( light.get(), 0 );
    clip2_sh->enable(vl::EN_LIGHTING);
    clip2_sh->enable(vl::EN_DEPTH_TEST);
    clip2_sh->gocMaterial()->setBackDiffuse(vl::green);
    clip2_sh->gocLightModel()->setTwoSide(true);
    // clipping plane 2 setup
    clip2_sh->gocClipPlane(0)->setPlane( vl::Plane(0.2f, vl::vec3(0,-1,0)) );
    clip2_sh->gocClipPlane(0)->bindTransform( mClipTr.get() );
    // install the two passes for LOD 0
    clip_fx->setLOD(0, clip1_sh.get(), clip2_sh.get());
    // add model to the scene
    sceneManager()->tree()->addActor( model.get(), clip_fx.get(), NULL );

    // renders a plane for visual feedback

    // setup effect
    vl::ref<vl::Effect> plane_fx = new vl::Effect;
    plane_fx->setRenderRank(1); // draw after the clipped model
    plane_fx->shader()->enable(vl::EN_DEPTH_TEST);
    plane_fx->shader()->enable(vl::EN_BLEND);
    plane_fx->shader()->gocLightModel()->setTwoSide(true);
    plane_fx->shader()->gocColor()->setValue(vl::fvec4(1,0,0,0.3f)); // transparent red
    // add plane actor
    vl::ref<vl::Geometry> plane = vl::makeGrid( vl::vec3(0,0,0), 4,4, 2,2 );
    sceneManager()->tree()->addActor( plane.get(), plane_fx.get(), mClipTr.get() );
  }
    void updateKdTreeView()
    {
        /* regenerate scene manager containing the text and the boxes representing the ActorKdTree nodes */
        sceneManager()->tree()->actors()->clear();

        sceneManager()->tree()->addActor( mTextActor.get() );
        mText->setText( vl::Say("Test #%n, Level #%n") << mTestNumber << mViewDepth );

        viewTreeNodes(mSceneKdTree->tree(),0);
    }
Exemplo n.º 5
0
function main()
{
video_set( 1024, 768, 32, 2 ) ; 

level_state = 0 ; 

game_init() ; 
 	
sceneManager() ; 

 // MAIN GAME LOOP //
 
	while(1)
	{
		if( level_state == 0 )
		{
			// pause the game
			freeze_mode = 1 ; 
		}
		else
		{
			freeze_mode = 0;
		}
	
	wait(1);
	}
}
Exemplo n.º 6
0
		void
		OgreModel::attachTo(Ogre::SceneNode* node) const
		{
			std::string name(original->getName());
			OgreRenderer* renderer(OgreRenderer::getInstance());
			Ogre::SceneManager* sceneManager(renderer->getOgreSceneManager());
			Ogre::Entity* ogreEntity;
			if (0 == name.compare("cube"))
			{
				ogreEntity = sceneManager->createEntity(renderer->createUniqueString("cube-Entity"), "cube");
			}
			else
			{
				ogreEntity = sceneManager->createEntity(renderer->createUniqueString(name + "-Entity"), name + ".mesh");
			}
			if (!PURGE::CoordinateSystem::get().isLeftHanded())
			{
				node->attachObject(ogreEntity);
			}
			else
			{
				Ogre::SceneNode* modelNode = node->createChildSceneNode(name + "-Node");
				modelNode->setScale(1, 1, -1);
				modelNode->attachObject(ogreEntity);
			}
		}
  void sphericalMapping()
  {
    vl::ref<vl::Image> img_spheric = vl::loadImage("/images/spheremap_klimt.jpg");

    vl::ref<vl::Geometry> torus = vl::makeTorus(vl::vec3(), 8,3, 40,40);
    // normals already present, needed by GL_SPHERE_MAP to work correctly!

    mFXSpheric = new vl::Effect;
    mFXSpheric->shader()->enable(vl::EN_DEPTH_TEST);
    mFXSpheric->shader()->enable(vl::EN_CULL_FACE);
    mFXSpheric->shader()->enable(vl::EN_LIGHTING);
    mFXSpheric->shader()->setRenderState( new vl::Light(0) );
    // to ensure the torus is drawn after the textured quads
    mFXSpheric->setRenderRank(1);

    vl::ref<vl::Texture> texture_spheric = new vl::Texture;
    texture_spheric->prepareTexture2D( img_spheric.get(), vl::TF_RGBA, mMipmappingOn, false );
    mFXSpheric->shader()->gocTextureUnit(0)->setTexture( texture_spheric.get() );
    texture_spheric->getTexParameter()->setAnisotropy(16.0);
    texture_spheric->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
    texture_spheric->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);
    // enable automatic texture generation for s,t
    mFXSpheric->shader()->gocTexGen(0)->setGenModeS(vl::TGM_SPHERE_MAP);
    mFXSpheric->shader()->gocTexGen(0)->setGenModeT(vl::TGM_SPHERE_MAP);

    mActSpheric = sceneManager()->tree()->addActor( torus.get(), mFXSpheric.get(), new vl::Transform );
    rendering()->as<vl::Rendering>()->transform()->addChild( mActSpheric->transform() );
  }
  void textureRectangle()
  {
    vl::ref<vl::Image> img_holebox = vl::loadImage("/images/holebox.tif");    

    // generate non-normalized uv coordinates, i.e. from <0,0> to <img_holebox->width(),img_holebox->height()>
    vl::ref<vl::Geometry> quad_rect = vl::makeGrid( vl::vec3(0,0,0), 10.0f, 10.0f, 2, 2, true, vl::fvec2(0,0), vl::fvec2((float)img_holebox->width(),(float)img_holebox->height()) );
    quad_rect->setColor(vl::white);
    quad_rect->transform( vl::mat4::getRotation(90, 1,0,0), false );

    vl::ref<vl::Effect> fx_rect = new vl::Effect;

    if(GLEW_ARB_texture_rectangle||GLEW_EXT_texture_rectangle||GLEW_NV_texture_rectangle/*TODO:||GLEW_VERSION_3_1*/)
    {
      vl::ref<vl::Texture> texture_rect = new vl::Texture;
      texture_rect->prepareTextureRectangle( img_holebox.get(), vl::TF_RGBA );
      fx_rect->shader()->gocTextureUnit(0)->setTexture( texture_rect.get() );
      // mipmaps not allowed with texture rectangle!
      texture_rect->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
      texture_rect->getTexParameter()->setMinFilter(vl::TPF_LINEAR);
      // GL_REPEAT (the default) not allowed with texture rectangle!
      texture_rect->getTexParameter()->setWrapS(vl::TPW_CLAMP);
      texture_rect->getTexParameter()->setWrapT(vl::TPW_CLAMP);
      texture_rect->getTexParameter()->setWrapR(vl::TPW_CLAMP);
    }
    else
      vl::Log::error("Texture rectangle not supported.\n");

    vl::Actor* act_rect = sceneManager()->tree()->addActor( quad_rect.get(), fx_rect.get(), new vl::Transform );
    act_rect->transform()->setLocalMatrix( vl::mat4::getTranslation(-6,-6,0) );
    act_rect->transform()->computeWorldMatrix();
  }
  void texture2DArray()
  {
    vl::ref<vl::Image> img_volume = vl::loadImage("/volume/VLTest.dat");
    m2DArraySize = img_volume->depth(); // save this to be used during the animation

    vl::ref<vl::Geometry> quad_2darray = vl::makeGrid( vl::vec3(0,0,0), 10, 10, 2, 2 );
    quad_2darray->setColor(vl::white);
    quad_2darray->transform( vl::mat4::getRotation(90, 1,0,0), false );

    mTexCoords_2DArray = new vl::ArrayFloat3;
    quad_2darray->setTexCoordArray(0, mTexCoords_2DArray.get());
    mTexCoords_2DArray->resize( 2*2 );
    quad_2darray->setVBOEnabled(false);

    vl::ref<vl::Effect> fx_2darray = new vl::Effect;

    if(GLEW_EXT_texture_array||GLEW_VERSION_3_0)
    {
      vl::ref<vl::Texture> texture_2darray = new vl::Texture;
      texture_2darray->prepareTexture2DArray( img_volume.get(), vl::TF_RGBA, mMipmappingOn );
      fx_2darray->shader()->gocTextureUnit(0)->setTexture( texture_2darray.get() );
      texture_2darray->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
      texture_2darray->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);
      
      // we need an OpenGL Shading Language program that uses 'sampler2DArray()' to access the texture!
      vl::GLSLProgram* glsl = fx_2darray->shader()->gocGLSLProgram();
      glsl->attachShader( new vl::GLSLFragmentShader("/glsl/texture_2d_array.fs") );
    }
    else
      vl::Log::error("Texture 2d array not supported.\n");

    vl::Actor* act_2darray = sceneManager()->tree()->addActor( quad_2darray.get(), fx_2darray.get(), new vl::Transform );
    act_2darray->transform()->setLocalMatrix( vl::mat4::getTranslation(+6,+6,0) );
    act_2darray->transform()->computeWorldMatrix();
  }
  void texture3D()
  {
    vl::ref<vl::Image> img_volume = vl::loadImage("/volume/VLTest.dat");

    vl::ref<vl::Geometry> quad_3d = vl::makeGrid( vl::vec3(0,0,0), 10, 10, 2, 2 );
    quad_3d->setColor(vl::white);
    quad_3d->transform( vl::mat4::getRotation(90, 1,0,0), false );

    mTexCoords_3D = new vl::ArrayFloat3;
    quad_3d->setTexCoordArray(0, mTexCoords_3D.get());
    mTexCoords_3D->resize( 2*2 );
    quad_3d->setVBOEnabled(false);

    vl::ref<vl::Effect> fx_3d = new vl::Effect;

    if(GLEW_VERSION_1_2||GLEW_EXT_texture3D)
    {
      vl::ref<vl::Texture> texture_3d = new vl::Texture;
      texture_3d->prepareTexture3D( img_volume.get(), vl::TF_RGBA, mMipmappingOn, false );
      fx_3d->shader()->gocTextureUnit(0)->setTexture( texture_3d.get() );
      texture_3d->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
      texture_3d->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);
    }
    else
      vl::Log::error("Texture 3D not supported.\n");

    vl::Actor* act_3d = sceneManager()->tree()->addActor( quad_3d.get(), fx_3d.get(), new vl::Transform );
    act_3d->transform()->setLocalMatrix( vl::mat4::getTranslation(-6,+6,0) );
    act_3d->transform()->computeWorldMatrix();
  }
  void generateStars(float side, int star_count)
  {
    // simple effect to render a star billboard
    vl::ref<vl::Effect> effect = new vl::Effect;
    // speedup tip: this allows VL to batch all the stars together greatly speeding up the rendering and avoiding switching textures back and forth with the trees.
    effect->setRenderRank(1);
    effect->shader()->enable(vl::EN_BLEND);
    effect->shader()->enable(vl::EN_DEPTH_TEST);
    effect->shader()->gocTextureSampler(0)->setTexture( new vl::Texture("images/sun.png", vl::TF_RGBA, true) );

    vl::ref<vl::Geometry> star = generateQuad();

    for(int i=0; i<star_count; i++)
    {
      // new billboard
      vl::ref<vl::Billboard> billboard = new vl::Billboard;
      // set spherical billboard type: orient the object always towards the camera.
      billboard->setType(vl::BT_SphericalBillboard);
      // add billboard to the transform tree
      rendering()->as<vl::Rendering>()->transform()->addChild(billboard.get());
      // compute a random point on the skydome
      vl::real x = vl::random(-1.0f,+1.0f);
      vl::real y = vl::random(0,2.0f);
      vl::real z = vl::random(-1.0f,+1.0f);
      vl::vec3 n(x,y,z);
      n.normalize();
      n = n * sqrt(side*side/2.0f);
      n.y() *= 0.2f;
      // set the billboard position and rotation center.
      billboard->setPosition( n );
      // add the star actor
      sceneManager()->tree()->addActor(star.get(), effect.get(), billboard.get());
    }
  }
    virtual void initEvent()
    {
        vl::Log::notify(appletInfo());

        trackball()->setTransform(NULL);

        // setup texture
        vl::ref<vl::Image> img = vl::loadImage("/volume/VLTest.dat")->convertFormat(vl::IF_LUMINANCE);

        vl::ref<vl::Actor> splat_actor = new vl::Actor;
        splat_actor->actorEventCallbacks()->push_back( new vl::DepthSortCallback );
        init_LUMINANCE_UBYTE( splat_actor.get(), img.get(), vl::fvec3(10,10,10), 80, 255, TransferRGBA_255() );

        vl::ref<vl::Effect> fx = new vl::Effect;

        fx->shader()->enable(vl::EN_LIGHTING);
        fx->shader()->setRenderState( new vl::Light, 0 );
        fx->shader()->gocLightModel()->setTwoSide(true);
        // enable color material if you want to see per-point colors
        fx->shader()->gocMaterial()->setColorMaterialEnabled(true);
        fx->shader()->enable( vl::EN_BLEND );
        fx->shader()->enable(vl::EN_POINT_SMOOTH);
        fx->shader()->gocPointSize()->set(1.5f);
        splat_actor->setEffect(fx.get());

        sceneManager()->tree()->addActor( splat_actor.get() );

    }
  void initEvent()
  {
    // Basic initialization
    vl::Log::print(appletInfo());

    // Filled effect
    vl::ref<vl::Effect> filled_fx = new vl::Effect;

    // Wireframe effect
    vl::ref<vl::Effect> wireframe_fx = new vl::Effect;
    wireframe_fx->shader()->gocPolygonMode()->set(vl::PM_LINE,vl::PM_LINE);

    // Add empty Actors
    mStar1 = sceneManager()->tree()->addActor( new vl::Actor(NULL, filled_fx.get(), new vl::Transform) );
    mStar2 = sceneManager()->tree()->addActor( new vl::Actor(NULL, wireframe_fx.get(), new vl::Transform) );
    rendering()->as<vl::Rendering>()->transform()->addChild(mStar1->transform());
    rendering()->as<vl::Rendering>()->transform()->addChild(mStar2->transform());
  }
Exemplo n.º 14
0
void MainPage::tagLongSelected(const QModelIndex &which,
			       const QPointF &position)
{
	if (which.isValid() &&
	    which.row() < TagStorage::storage()->count()) {
		m_longTapIndex = which;
		const Tag *tag = TagStorage::storage()->tag(which.row());
		if (tag->type() == Tag::UNKNOWN_TAG) {
			m_unknownObjectMenu->setCursorPosition(position);
			m_unknownObjectMenu->setTitle(which.data().toString());
			sceneManager()->appearSceneWindow(m_unknownObjectMenu);
		} else {
			m_objectMenu->setCursorPosition(position);
			m_objectMenu->setTitle(which.data().toString());
			sceneManager()->appearSceneWindow(m_objectMenu);
		}
	}
}
void StatusIndicatorMenuWindow::displayInActive()
{
    if (menuWidget && menuWidget->sceneWindowState() != MSceneWindow::Disappeared) {
        sceneManager()->disappearSceneWindowNow(menuWidget);
    }

    // Hide the window when the it is obscured by another view
    // Note: Dialogs and notifications won't close it anyways,
    // as they are not supposed to be full screen and don't completely
    // obstruct the status menu window fully.
    hideWindow();
}
 // displays the text
 void showText()
 {
   vl::ref<vl::Text> text = new vl::Text;
   text->setText("Press the left/right arrow keys to change test.");
   text->setFont( vl::defFontManager()->acquireFont("/font/bitstream-vera/VeraMono.ttf", 10) );
   text->setAlignment( vl::AlignHCenter | vl::AlignTop );
   text->setViewportAlignment( vl::AlignHCenter | vl::AlignTop );
   text->translate(0,-5,0);
   text->setColor(vl::white);
   vl::ref<vl::Effect> effect = new vl::Effect;
   effect->shader()->enable(vl::EN_BLEND);
   sceneManager()->tree()->addActor(text.get(), effect.get());
 }
  // This function demonstrates how a billboard behaves when it is put under an animated transform hierarchy.
  // Note how the cube always faces the camera even if it follows its parent's rotation.
  void generateLunapark()
  {
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->setRenderState( new vl::Light, 0 );
    effect->shader()->enable(vl::EN_BLEND);
    effect->shader()->enable(vl::EN_DEPTH_TEST);
    effect->shader()->enable(vl::EN_LIGHTING);

    vl::ref<vl::Geometry>  arm_g = vl::makeCylinder(vl::vec3(0,0,0), 0.5f, 4.0f);
    arm_g->computeNormals();
    vl::ref<vl::Transform> arm1_t = new vl::Transform;
    vl::ref<vl::Transform> arm2_t = new vl::Transform;
    rendering()->as<vl::Rendering>()->transform()->addChild(arm1_t.get());
    arm1_t->addChild(arm2_t.get());
    arm2_t->setLocalMatrix(vl::mat4::getTranslation(0.0f,2.0f,0.0f) * vl::mat4::getRotation(90,0,0,1) * vl::mat4::getTranslation(0.0f,2.0f,0.0f));

    sceneManager()->tree()->addActor( arm_g.get(), effect.get(), arm1_t.get());
    sceneManager()->tree()->addActor( arm_g.get(), effect.get(), arm2_t.get());

    vl::ref<vl::Geometry> box = vl::makeBox(vl::vec3(0,-0.75f,0), 1, 1, 1);
    box->computeNormals();

    // the billboard
    vl::ref<vl::Billboard> billboard = new vl::Billboard;
    // use an axis aligned billboard
    billboard->setType(vl::BT_AxisAlignedBillboard);
    // the axis is always in world coordinates
    billboard->setAxis(vl::vec3(0,1,0));
    // remember that "position" is relative to the billboard's parent's coordinates
    billboard->setPosition(0,2,0);
    // add the billboard to its transform parent
    arm2_t->addChild(billboard.get());
    // add the box actor
    sceneManager()->tree()->addActor( box.get(), effect.get(), billboard.get());

    // to be animated below
    mArm1Transform = arm1_t;
  }
  // generates the ground
  void generateGround(float side)
  {
    // orange effect using lighting
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->setRenderState( new vl::Light, 0 );
    effect->shader()->enable(vl::EN_LIGHTING);
    effect->shader()->gocLight(0)->setLinearAttenuation(0.025f);
    effect->shader()->gocMaterial()->setDiffuse(vl::orange);
    effect->shader()->enable(vl::EN_DEPTH_TEST);

    // use a simple plane to render the ground
    vl::ref<vl::Geometry> geom = vl::makeGrid(vl::vec3(0,0,0), side, side, 200, 200);
    geom->computeNormals();
    sceneManager()->tree()->addActor( geom.get(), effect.get(), NULL);
  }
  void cubeMapping()
  {
    // cube mapping, see also http://developer.nvidia.com/object/cube_map_ogl_tutorial.html

    vl::ref<vl::Image> img_cubemap = vl::loadCubemap(
      "/images/cubemap/cubemap00.png", // (x+) right
      "/images/cubemap/cubemap01.png", // (x-) left
      "/images/cubemap/cubemap02.png", // (y+) top
      "/images/cubemap/cubemap03.png", // (y-) bottom
      "/images/cubemap/cubemap04.png", // (z+) back
      "/images/cubemap/cubemap05.png");// (z-) front

    vl::ref<vl::Geometry> torus = vl::makeTorus( vl::vec3(), 8,3, 40,40 );
    // normals already present, needed by GL_SPHERE_MAP to work correctly!

    mFXCubic = new vl::Effect;
    mFXCubic->shader()->enable(vl::EN_DEPTH_TEST);
    mFXCubic->shader()->enable(vl::EN_CULL_FACE);
    mFXCubic->shader()->enable(vl::EN_LIGHTING);
    mFXCubic->shader()->setRenderState( new vl::Light(0) );
    // to ensure the torus is drawn after the textured quads
    mFXCubic->setRenderRank(1);

    if (GLEW_VERSION_1_3||GLEW_ARB_texture_cube_map)
    {
      vl::ref<vl::Texture> texture_cubic = new vl::Texture;
      texture_cubic->prepareTextureCubemap( img_cubemap.get(), vl::TF_RGBA, mMipmappingOn, false );
      mFXCubic->shader()->gocTextureUnit(0)->setTexture( texture_cubic.get() );
      texture_cubic->getTexParameter()->setAnisotropy(16.0);
      texture_cubic->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
      texture_cubic->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);
      texture_cubic->getTexParameter()->setWrapS(vl::TPW_CLAMP_TO_EDGE);
      texture_cubic->getTexParameter()->setWrapT(vl::TPW_CLAMP_TO_EDGE);
      texture_cubic->getTexParameter()->setWrapR(vl::TPW_CLAMP_TO_EDGE);
      // enable automatic texture generation for s,t,r
      mFXCubic->shader()->gocTexGen(0)->setGenModeS(vl::TGM_REFLECTION_MAP);
      mFXCubic->shader()->gocTexGen(0)->setGenModeT(vl::TGM_REFLECTION_MAP);
      mFXCubic->shader()->gocTexGen(0)->setGenModeR(vl::TGM_REFLECTION_MAP);
      // texture matrix
      mFXCubic->shader()->gocTextureMatrix(0)->setUseCameraRotationInverse(true);
    }
    else
      vl::Log::error("Texture cubemap not supported.\n");

    mActCubic = sceneManager()->tree()->addActor( torus.get(), mFXCubic.get(), new vl::Transform );
    rendering()->as<vl::Rendering>()->transform()->addChild( mActCubic->transform() );
  }
  /* initialization */
  void initEvent()
  {
    vl::Log::notify(appletInfo());

    /* initialize the text actor */
    mText->setText("Drop a MOL2 file inside the window.");
    mText->setFont( vl::defFontManager()->acquireFont("/font/bitstream-vera/VeraMono.ttf", 10) );
    mText->setAlignment( vl::AlignHCenter | vl::AlignTop );
    mText->setViewportAlignment( vl::AlignHCenter | vl::AlignTop );
    mText->setTextAlignment(vl::TextAlignCenter);
    mText->translate(0,-5,0);
    mText->setColor(vl::white);
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->enable(vl::EN_BLEND);
    sceneManager()->tree()->addActor(mText.get(), effect.get());

    loadMolecule("/mol/molecule.mol2");
  }
Exemplo n.º 21
0
int main(int argc, char** argv)
{
	Viewport window("The People of Earth TestBed ***Demo***", 800, 600/*1920, 1080*/, 0);
	GUIEngine guiEngine("Assets/GUI");
	RenderingEngine renderingEngine(window);
	SceneManager sceneManager(&window);
	PhysicsEngine physicsEngine;
	physicsEngine.getPhysicsWorld()->init(PxVec3(0.0f, 0.0f, 0.0f), 20000.0f);
	AudioEngine audioEngine;

	CoreEngine core(60.0, &window, &renderingEngine, &physicsEngine, &audioEngine, &guiEngine, &sceneManager);

	sceneManager.push(new TestScene, Modality::Exclusive);

	core.start();

	return 0;

}
  // Creates a simple extrusion
  void showSimplePipe()
  {
    // Generates the actual extrusion
    vl::Extrusion extrusion;

    // Define the silhouette to be extruded: 24 sided circle
    const int sides = 24;
    const float radius = 1.0f;
    for(int i=0; i<sides; ++i)
    {
      float t = (float)i/sides*vl::fPi*2.0f;
      extrusion.silhouette().push_back(vl::fvec2(::cos(t)*radius, ::sin(t)*radius));
    }

    // Define the path along which the silhouette is extruded.
    // Note: the first and last control points are not part of the actual extrusion 
    // but are used to define the orientation of the first and start segment.
    extrusion.positionPath().push_back(vl::fvec3(-5, 0, 0) + vl::fvec3(-1,0,0));
    extrusion.positionPath().push_back(vl::fvec3(-5, 0, 0));
    extrusion.positionPath().push_back(vl::fvec3(-5, 5, 0));
    extrusion.positionPath().push_back(vl::fvec3(+5, 5, 0));
    extrusion.positionPath().push_back(vl::fvec3(+5, 0, 0));
    extrusion.positionPath().push_back(vl::fvec3(+5, 0, 0) + vl::fvec3(+1,0,0));

    // Setup the extrusion options.
    extrusion.setSilhouetteMode(vl::SilhouetteClosed);
    extrusion.setSmooth(false);
    extrusion.setFillBottom(true); // start of the extrusion is closed
    extrusion.setFillTop(true);    // end of the extrusion is closed

    // Setup a simple white effect.
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->setRenderState( new vl::Light, 0 );
    effect->shader()->enable(vl::EN_LIGHTING);
    effect->shader()->enable(vl::EN_DEPTH_TEST);

    // Generates the extrusion.
    vl::ref<vl::Geometry> geom = extrusion.extrude();
    sceneManager()->tree()->addActor( geom.get(), effect.get(), NULL );

    // Utility function that visualizes the extrusion path.
    showPath(extrusion.positionPath(),vl::red);
  }
  // Utility function to display a path
  void showPath(const std::vector<vl::fvec3>& ctrl_points, const vl::fvec4& color)
  {
    // generate line geometry with lines and points
    vl::ref<vl::Geometry>   geom       = new vl::Geometry;
    vl::ref<vl::ArrayFloat3> vert_array = new vl::ArrayFloat3;
    geom->setVertexArray( vert_array.get() );
    vert_array->initFrom(ctrl_points);
    geom->drawCalls()->push_back(new vl::DrawArrays(vl::PT_LINE_STRIP, 0, (int)vert_array->size())); // lines
    geom->drawCalls()->push_back(new vl::DrawArrays(vl::PT_POINTS,     0, (int)vert_array->size())); // points

    // setup simple effect
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->gocColor()->setValue(color);
    effect->shader()->enable(vl::EN_LINE_STIPPLE);
    effect->shader()->gocPointSize()->set(3);
    effect->shader()->gocLineStipple()->setPattern(0x3333);
    effect->setRenderRank(1); // always draw over the pipe

    sceneManager()->tree()->addActor( geom.get(), effect.get(), NULL );
  }
  virtual void initEvent()
  {
    vl::Log::notify(appletInfo());

    vl::ref<vl::Effect> fx = new vl::Effect;
    fx->shader()->enable(vl::EN_LIGHTING);
    fx->shader()->setRenderState( new vl::Light, 0 );
    fx->shader()->enable(vl::EN_DEPTH_TEST);

    // vl::ref<vl::Texture> texture = new vl::Texture("/images/world.topo.bathy.200406.3x8192x4096.png");
    vl::ref<vl::Texture> texture = new vl::Texture("/images/world.topo.bathy.200406.3x2048x1024.png");
    // vl::ref<vl::Texture> texture = new vl::Texture("/images/land_lights_16384.tif");
    // vl::ref<vl::Texture> texture = new vl::Texture("/images/land_ocean_ice_cloud_8192.tif");

    fx->shader()->gocTextureSampler(0)->setTexture(texture.get());

    //vl::ref<vl::Shader> wire = new vl::Shader;
    //wire->gocPolygonMode()->set(vl::PM_LINE, vl::PM_LINE);
    //wire->gocPolygonOffset()->set(-1, -1);
    //wire->enable(vl::EN_POLYGON_OFFSET_LINE);
    //wire->enable(vl::EN_DEPTH_TEST);
    //fx->lod(0)->push_back(wire.get());

    float dx = 0.5f / texture->width();
    float dy = 0.5f / texture->height();
    vl::ref<vl::Geometry> earth = vl::makeGrid( vl::vec3(0,0,0), vl::fPi*2.0f, vl::fPi, 40, 40, true, vl::fvec2(dx,dy), vl::fvec2(1-dx,1-dy) );
    vl::ArrayFloat3* coord3 = vl::cast<vl::ArrayFloat3>( earth->vertexArray() );
    vl::ref<vl::ArrayFloat3> norm3 = new vl::ArrayFloat3;
    earth->setNormalArray(norm3.get());
    norm3->resize(coord3->size());
    for(size_t i=0; i<coord3->size(); ++i)
    {
      float longitude = coord3->at(i).x();
      float latitude  = coord3->at(i).z();
      coord3->at(i)   = vl::fmat4::getRotation(longitude*vl::fRAD_TO_DEG, 0,-1,0) * vl::fmat4::getRotation(latitude*vl::fRAD_TO_DEG, 1,0,0) * vl::fvec3(0,0,1);
      norm3->at(i)    = coord3->at(i);
      norm3->at(i).normalize();
    }

    sceneManager()->tree()->addActor(earth.get(), fx.get());
  }
  void visualizeTangentSpace(const vl::Geometry* model, const vl::ArrayFloat3* tangent)
  {
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->enable(vl::EN_DEPTH_TEST);

    vl::ref<vl::ArrayFloat3> ntb_verts = new vl::ArrayFloat3;
    ntb_verts->resize( model->vertexArray()->size() * 6 );

    vl::ref<vl::ArrayFloat4> ntb_cols = new vl::ArrayFloat4;
    ntb_cols->resize( model->vertexArray()->size() * 6 );

    vl::fvec3* verts = (vl::fvec3*)model->vertexArray()->ptr();
    vl::fvec3* norms = (vl::fvec3*)model->normalArray()->ptr();

    float tick_size = 0.5f;

    for( size_t i=0; i<model->vertexArray()->size(); ++i )
    {
      vl::fvec3 bitangent = vl::cross( norms[i], (*tangent)[i] );

      (*ntb_verts)[i*6 + 0] = verts[i];
      (*ntb_verts)[i*6 + 1] = verts[i] + norms[i] * tick_size;
      (*ntb_verts)[i*6 + 2] = verts[i];
      (*ntb_verts)[i*6 + 3] = verts[i] + (*tangent)[i] * tick_size;
      (*ntb_verts)[i*6 + 4] = verts[i];
      (*ntb_verts)[i*6 + 5] = verts[i] + bitangent * tick_size;

      (*ntb_cols)[i*6 + 0] = vl::red;
      (*ntb_cols)[i*6 + 1] = vl::red;
      (*ntb_cols)[i*6 + 2] = vl::green;
      (*ntb_cols)[i*6 + 3] = vl::green;
      (*ntb_cols)[i*6 + 4] = vl::blue;
      (*ntb_cols)[i*6 + 5] = vl::blue;
    }

    vl::ref<vl::Geometry> NTBGeom = new vl::Geometry;
    NTBGeom->setVertexArray( ntb_verts.get() );
    NTBGeom->setColorArray( ntb_cols.get() );
    NTBGeom->drawCalls()->push_back( new vl::DrawArrays(vl::PT_LINES, 0, ntb_verts->size() ) );
    sceneManager()->tree()->addActor( NTBGeom.get(), effect.get(), mTransform.get() );
  }
StatusIndicatorMenuWindow::StatusIndicatorMenuWindow(QWidget *parent) :
    MWindow(parent),
    statusBar(new MStatusBar),
    menuWidget(NULL)
{
    QDBusConnection bus = QDBusConnection::sessionBus();
    bus.registerService(SERVICE_NAME);
    bus.registerObject(OBJECT_NAME, this, QDBusConnection::ExportScriptableSlots);

    // Show status bar
    setSceneManager(new MSceneManager);
    sceneManager()->appearSceneWindowNow(statusBar);
    currentLanguage = MLocale().language();

    statusBar->setStyleName("StatusIndicatorMenuWindowStatusBar");

    // Set the X window type, so that the window does not appear in the switcher and
    // home screen can provide the correct UI flow
    setAttribute(Qt::WA_X11NetWmWindowTypeMenu);
    setTranslucentBackground(true);
    setWindowTitle("Status Indicator Menu");
    setProperty("followsCurrentApplicationWindowOrientation", true);
    connect(this, SIGNAL(displayEntered()), this, SLOT(displayActive()));
    connect(this, SIGNAL(displayExited()), this, SLOT(displayInActive()));

#ifdef HAVE_QMSYSTEM
    /*
     * We need to receive updates when device lock state changes
     * to prevent status indicator menu opening when device lock is on
     */
    connect (&qmLocks, SIGNAL(stateChanged (MeeGo::QmLocks::Lock, MeeGo::QmLocks::State)), this,
                                   SLOT(setWindowStateAccordingToDeviceLockState(MeeGo::QmLocks::Lock, MeeGo::QmLocks::State)));
    if (qmLocks.getState(MeeGo::QmLocks::Device) != MeeGo::QmLocks::Locked) {
        deviceLocked = false;
    } else {
        deviceLocked = true;
    }
#endif

    resetMenuWidget();
}
Exemplo n.º 27
0
    void viewTreeNodes(vl::ActorTreeAbstract* tree, int level)
    {
        if (tree && !tree->aabb().isNull())
        {
            if (level == mViewDepth || mViewDepth == -1)
            {
                vl::ref<vl::Effect> effect = new vl::Effect;
                effect->shader()->gocPolygonMode()->set(vl::PM_LINE, vl::PM_LINE);
                effect->shader()->enable(vl::EN_DEPTH_TEST);
                effect->shader()->gocColor()->setValue(vl::gold);
                vl::ref<vl::Geometry> box = vl::makeBox(tree->aabb());
                sceneManager()->tree()->addActor(box.get(), effect.get());

                if (mViewDepth != -1)
                    return;
            }

            for(int i=0; i<tree->childrenCount(); ++i)
                viewTreeNodes(tree->child(i), level+1);
        }
    }
  void mouseDownEvent(vl::EMouseButton, int x, int y)
  {
    vl::Camera* camera = rendering()->as<vl::Rendering>()->camera();

    // convert Y coordinates to the OpenGL conventions
    y = openglContext()->height() - y;
    // compute the ray passing through the selected pixel
    vl::Ray ray = camera->computeRay(x,y);
    // instance our ray-intersector
    vl::RayIntersector intersector;
    // compute a frustum along the ray to accelerate the intersection test
    intersector.setFrustum( camera->computeRayFrustum( x,y ) );
    // compute the intersections!
    // (1) short way
    intersector.intersect(ray, sceneManager());
    // (2) long way
    /*
    // specify the Actor[s] to be tested
    intersector.actors()->clear();
    sceneManager()->extractActors( *intersector.actors() );
    // set the intersecting ray
    intersector.setRay(ray);
    // run intersection test
    intersector.intersect();
    */

    // inspect our intersections, the intersections returned are sorted according to their distance, the first one is the closest.
    if (intersector.intersections().size())
    {
      // highlight the intersection point by moving the green sphere there
      mIntersectionPoint->setLocalMatrix( vl::mat4() );
      mIntersectionPoint->translate( intersector.intersections()[0]->intersectionPoint() );
      mIntersectionPoint->computeWorldMatrix();

      // print the name of the picked object
      vl::Log::print( vl::Say("Intersections detected = %n (%s).\n") << intersector.intersections().size() << intersector.intersections()[0]->actor()->objectName() );
    }
    else
      vl::Log::print("No intersections detected.\n");
  }
void StatusIndicatorMenuWindow::makeVisible()
{
#ifdef HAVE_QMSYSTEM
    if (deviceLocked) {
        return;
    }
#endif

    // Show the window if it's not visible (from Qt's point of view). Note that isOnDisplay() should NOT be used here: show() means setVisible(true) and the accessor is isVisible().
    if (!isVisible()) {
        show();
    }

    // Always raise the window. Even if it's visible (from Qt's point of view) it may not be the topmost window.
    raise();

    // If the menu is closed and opened quickly enough, we might never get the displayEnter signal because the display state
    // exits with a delay, so displayActive is not called and we need to make the menu widget appear here
    if(menuWidget->sceneWindowState() == MSceneWindow::Disappeared && isOnDisplay()) {
        sceneManager()->appearSceneWindow(menuWidget);
    }
}
Exemplo n.º 30
0
    virtual void initEvent()
    {
        vl::Log::notify(appletInfo());

        mSceneKdTree = new vl::SceneManagerActorKdTree;
        rendering()->as<vl::Rendering>()->sceneManagers()->push_back(mSceneKdTree.get());

        mText = new vl::Text;
        mText->setFont( vl::defFontManager()->acquireFont("/font/bitstream-vera/VeraMono.ttf", 10, false) );
        mText->setAlignment(vl::AlignHCenter | vl::AlignTop);
        mText->setViewportAlignment(vl::AlignHCenter | vl::AlignTop);
        mText->setColor(vl::white);
        mText->translate(0,-10,0);
        mTextActor = sceneManager()->tree()->addActor(mText.get(), new vl::Effect);
        mTextActor->effect()->shader()->enable(vl::EN_BLEND);

        mTestNumber = 0;
        mViewDepth  = -1;

        createScene();
        mText->setText( mText->text() + "\nPress left/right to change the test number\nPress up/down to change the visible tree level");
    }