예제 #1
0
	/** Callback triggered wheneve the user resizes the example window. */
	void renderWindowResized()
	{
		SPtr<RenderWindow> window = gApplication().getPrimaryWindow();
		const RenderWindowProperties& rwProps = window->getProperties();

		windowResWidth = rwProps.getWidth();
		windowResHeight = rwProps.getHeight();

		sceneCamera->setAspectRatio(rwProps.getWidth() / (float)rwProps.getHeight());
	}
예제 #2
0
	/** Set up the 3D object used by the example, and the camera to view the world through. */
	void setUp3DScene(const Assets& assets)
	{
		/************************************************************************/
		/* 								SCENE OBJECT                      		*/
		/************************************************************************/

		// Now we create a scene object that has a position, orientation, scale and optionally
		// components to govern its logic. In this particular case we are creating a SceneObject
		// with a Renderable component which will render a mesh at the position of the scene object
		// with the provided material.

		// Create new scene object at (0, 0, 0)
		HSceneObject pistolSO = SceneObject::create("Pistol");
		
		// Attach the Renderable component and hook up the mesh we imported earlier,
		// and the material we created in the previous section.
		HRenderable renderable = pistolSO->addComponent<CRenderable>();
		renderable->setMesh(assets.exampleModel);
		renderable->setMaterial(assets.exampleMaterial);

		// Add a rotator component so we can rotate the object during runtime
		pistolSO->addComponent<ObjectRotator>();

        /************************************************************************/
        /* 									SKYBOX                       		*/
        /************************************************************************/

        // Add a skybox texture for sky reflections
        HSceneObject skyboxSO = SceneObject::create("Skybox");

        HSkybox skybox = skyboxSO->addComponent<CSkybox>();
        skybox->setTexture(assets.exampleSkyCubemap);

		/************************************************************************/
		/* 									CAMERA	                     		*/
		/************************************************************************/

		// In order something to render on screen we need at least one camera.

		// Like before, we create a new scene object at (0, 0, 0).
		HSceneObject sceneCameraSO = SceneObject::create("SceneCamera");

		// Get the primary render window we need for creating the camera. Additionally
		// hook up a callback so we are notified when user resizes the window.
		SPtr<RenderWindow> window = gApplication().getPrimaryWindow();
		window->onResized.connect(&renderWindowResized);

		// Add a Camera component that will output whatever it sees into that window 
		// (You could also use a render texture or another window you created).
		sceneCamera = sceneCameraSO->addComponent<CCamera>(window);

		// Set up camera component properties

		// Set closest distance that is visible. Anything below that is clipped.
		sceneCamera->setNearClipDistance(0.005f);

		// Set farthest distance that is visible. Anything above that is clipped.
		sceneCamera->setFarClipDistance(1000);

		// Set aspect ratio depending on the current resolution
		sceneCamera->setAspectRatio(windowResWidth / (float)windowResHeight);

        // Enable multi-sample anti-aliasing for better quality
        sceneCamera->setMSAACount(4);

		// Add a CameraFlyer component that allows us to move the camera. See CameraFlyer for more information.
		sceneCameraSO->addComponent<CameraFlyer>();

		// Position and orient the camera scene object
		sceneCameraSO->setPosition(Vector3(0.2f, 0.1f, 0.2f));
		sceneCameraSO->lookAt(Vector3(-0.1f, 0, 0));
	}