Example #1
0
void GuardianSystemDemo::InitSceneGraph()
{
    for (int32_t i = 0; i < Scene::MAX_MODELS; ++i) {
        TriangleSet mesh;
        mesh.AddSolidColorBox(-0.035f, -0.035f, -0.035f, 0.035f, 0.035f, 0.035f, 0xFFFFFFFF);

        // Objects start 1 meter high
        mObjPosition[i] = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
        // Objects have random velocity
        mObjVelocity[i] = XMVectorSet(randVelocity(), randVelocity() * 0.5f, randVelocity(), 0);
        mObjVelocity[i] = XMVector3Normalize(mObjVelocity[i]) * 0.3f;

        Material* mat = new Material(new Texture(false, 256, 256, Texture::AUTO_FLOOR));
        mDynamicScene.Add(new Model(&mesh, XMFLOAT3(0, 0, 0), XMFLOAT4(0, 0, 0, 1), mat));
    }
}
Example #2
0
    void MainLoop()
    {
	    Layer[0] = new VRLayer(Session);

	    // Create a trivial model to represent the left controller
	    TriangleSet cube;
	    cube.AddSolidColorBox(0.05f, -0.05f, 0.05f, -0.05f, 0.05f, -0.05f, 0xff404040);
	    Model * controller = new Model(&cube, XMFLOAT3(0, 0, 0), XMFLOAT4(0, 0, 0, 1), new Material(new Texture(false, 256, 256, Texture::AUTO_CEILING)));
	
	    // Main loop
	    while (HandleMessages())
	    {
		    // We don't allow yaw change for now, as this sample is too simple to cater for it.
		    ActionFromInput(1.0f,false);
		    ovrTrackingState hmdState = Layer[0]->GetEyePoses();

		    //Write position and orientation into controller model.
		    controller->Pos = XMFLOAT3(XMVectorGetX(MainCam->Pos) + hmdState.HandPoses[ovrHand_Left].ThePose.Position.x,
			                           XMVectorGetY(MainCam->Pos) + hmdState.HandPoses[ovrHand_Left].ThePose.Position.y,
			                           XMVectorGetZ(MainCam->Pos) + hmdState.HandPoses[ovrHand_Left].ThePose.Position.z);
		    controller->Rot = XMFLOAT4(hmdState.HandPoses[ovrHand_Left].ThePose.Orientation.x, 
                                       hmdState.HandPoses[ovrHand_Left].ThePose.Orientation.y,
			                           hmdState.HandPoses[ovrHand_Left].ThePose.Orientation.z, 
                                       hmdState.HandPoses[ovrHand_Left].ThePose.Orientation.w);

		    //Button presses are modifying the colour of the controller model below
		    ovrInputState inputState;
		    ovr_GetInputState(Session, ovrControllerType_Touch, &inputState);

		    for (int eye = 0; eye < 2; ++eye)
		    {
			    XMMATRIX viewProj = Layer[0]->RenderSceneToEyeBuffer(MainCam, RoomScene, eye);

			    // Render the controller model
			    controller->Render(&viewProj, 1, inputState.Buttons & ovrTouch_X ? 1.0f : 0.0f,
				                                 inputState.Buttons & ovrTouch_Y ? 1.0f : 0.0f, 1, true);
		    }

		    Layer[0]->PrepareLayerHeader();
		    DistortAndPresent(1);
	    }

        delete controller;
    }