Exemple #1
0
void camera_t::SetupOculusRift()
{
	/**
	  * Set the aspect ration.  Note that this has to be statically converted, as the normal
	  * data type is an unsigned integer for the screen resolution values.
	  */
	this->AspectRatio = static_cast<float>(this->riftHMD.HResolution * 0.5f)
		/ static_cast<float>(this->riftHMD.VResolution);
	/**
	  * The aspect ratio is determined based on the distance between the eyes and
	  * the size of the screen.  This is then converted to degrees for OpenGL.
	  */
	this->FieldOfView = RadToDegree(2.0f * 
		atan((this->riftHMD.VScreenSize / 2.0f) / this->riftHMD.EyeToScreenDistance));

	// Set how close an object can be before it clips.
	this->CloseDepth = 0.001f;
	// Set how far an object can be before it vanishes.
	this->FarDepth = 100000.0f;

	this->ViewCenter = this->riftHMD.HScreenSize * 0.25f;
	this->ProjectionCenterOffset = 4.0f * (this->ViewCenter - (this->riftHMD.LensSeparationDistance * 0.5f))
		/ this->riftHMD.HScreenSize;
	this->HalfIPD = this->riftHMD.InterpupillaryDistance * 0.5f;

	this->StereoConfiguration.SetFullViewport(Viewport(0, 0, 1280, 800));
	this->StereoConfiguration.SetStereoMode(Stereo_LeftRight_Multipass);
	this->StereoConfiguration.SetHMDInfo(this->riftHMD);
	this->StereoConfiguration.SetDistortionFitPointVP(-1.0f, 0.0f);

	this->LeftEye = this->StereoConfiguration.GetEyeRenderParams(StereoEye_Left);
	this->RightEye = this->StereoConfiguration.GetEyeRenderParams(StereoEye_Right);
}
Exemple #2
0
void camera_t::UpdateOculusRiftData()
{
	this->sensorFusion->GetOrientation().GetEulerAngles<Axis_Y, Axis_X, Axis_Z>
		(&this->OculusRiftOrientation.yaw,
		&this->OculusRiftOrientation.pitch,
		&this->OculusRiftOrientation.roll);

	this->OculusRiftOrientation.yaw = RadToDegree(this->OculusRiftOrientation.yaw);
	this->OculusRiftOrientation.pitch = RadToDegree(this->OculusRiftOrientation.pitch);
	this->OculusRiftOrientation.roll = RadToDegree(this->OculusRiftOrientation.roll);

	this->Rotation.x -= (this->OculusRiftOrientation.pitch -
		this->PreviousOculusRiftOrientation.pitch);
	this->Rotation.y -= (this->OculusRiftOrientation.yaw -
		this->PreviousOculusRiftOrientation.yaw);
	this->Rotation.z -= (this->OculusRiftOrientation.roll -
		this->PreviousOculusRiftOrientation.roll);

	this->PreviousOculusRiftOrientation.yaw = this->OculusRiftOrientation.yaw;
	this->PreviousOculusRiftOrientation.pitch = this->OculusRiftOrientation.pitch;
	this->PreviousOculusRiftOrientation.roll = this->OculusRiftOrientation.roll;

	{
		this->sensorFusion->GetOrientation().GetAxisAngle(&this->OculusRiftOrientation_quart.axis,
			&this->OculusRiftOrientation_quart.angle);

		this->OculusRiftOrientation_quart.angle = -RadToDegree(this->OculusRiftOrientation_quart.angle);
		this->RotationQuart.angle += this->OculusRiftOrientation_quart.angle - this->PreviousOculusRiftOrientation_Quart.angle;
		this->RotationQuart.axis = this->OculusRiftOrientation_quart.axis;

		this->PreviousOculusRiftOrientation_Quart.angle = this->OculusRiftOrientation_quart.angle;
		this->PreviousOculusRiftOrientation_Quart.axis.x = this->OculusRiftOrientation_quart.axis.x;
		this->PreviousOculusRiftOrientation_Quart.axis.y = this->OculusRiftOrientation_quart.axis.y;
		this->PreviousOculusRiftOrientation_Quart.axis.z = this->OculusRiftOrientation_quart.axis.z;
	}
}
void OculusWorldDemoApp::RenderTextInfoHud(float textHeight)
{
    // View port & 2D ortho projection must be set before call.
    
    float hmdYaw, hmdPitch, hmdRoll;
    switch(TextScreen)
    {
    case Text_Info:
    {
        char buf[512], gpustat[256];

        // Average FOVs.
        FovPort leftFov  = EyeRenderDesc[0].Fov;
        FovPort rightFov = EyeRenderDesc[1].Fov;
        
        // Rendered size changes based on selected options & dynamic rendering.
        int pixelSizeWidth = EyeTexture[0].Header.RenderViewport.Size.w +
                             ((!ForceZeroIpd) ?
                               EyeTexture[1].Header.RenderViewport.Size.w : 0);
        int pixelSizeHeight = ( EyeTexture[0].Header.RenderViewport.Size.h +
                                EyeTexture[1].Header.RenderViewport.Size.h ) / 2;

        // No DK2, no message.
        char latency2Text[128] = "";
        {
            //float latency2 = ovrHmd_GetMeasuredLatencyTest2(Hmd) * 1000.0f; // show it in ms
            //if (latency2 > 0)
            //    OVR_sprintf(latency2Text, sizeof(latency2Text), "%.2fms", latency2);

            float latencies[3] = { 0.0f, 0.0f, 0.0f };
            if (ovrHmd_GetFloatArray(Hmd, "DK2Latency", latencies, 3) == 3)
            {
                char latencyText0[32], latencyText1[32], latencyText2[32];
                FormatLatencyReading(latencyText0, sizeof(latencyText0), latencies[0]);
                FormatLatencyReading(latencyText1, sizeof(latencyText1), latencies[1]);
                FormatLatencyReading(latencyText2, sizeof(latencyText2), latencies[2]);

                OVR_sprintf(latency2Text, sizeof(latency2Text),
                            " DK2 Latency  Ren: %s  TWrp: %s\n"
                            " PostPresent: %s  ",
                            latencyText0, latencyText1, latencyText2);
            }
        }

        ThePlayer.HeadPose.Rotation.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&hmdYaw, &hmdPitch, &hmdRoll);
        OVR_sprintf(buf, sizeof(buf),
                    " HMD YPR:%4.0f %4.0f %4.0f   Player Yaw: %4.0f\n"
                    " FPS: %.1f  ms/frame: %.1f Frame: %d\n"
                    " Pos: %3.2f, %3.2f, %3.2f  HMD: %s\n"
                    " EyeHeight: %3.2f, IPD: %3.1fmm\n" //", Lens: %s\n"
                    " FOV %3.1fx%3.1f, Resolution: %ix%i\n"
                    "%s",
                    RadToDegree(hmdYaw), RadToDegree(hmdPitch), RadToDegree(hmdRoll),
                    RadToDegree(ThePlayer.BodyYaw.Get()),
                    FPS, SecondsPerFrame * 1000.0f, FrameCounter,
                    ThePlayer.BodyPos.x, ThePlayer.BodyPos.y, ThePlayer.BodyPos.z,
                    //GetDebugNameHmdType ( TheHmdRenderInfo.HmdType ),
                    HmdDesc.ProductName,
                    ThePlayer.UserEyeHeight,
                    ovrHmd_GetFloat(Hmd, OVR_KEY_IPD, 0) * 1000.0f,
                    //( EyeOffsetFromNoseLeft + EyeOffsetFromNoseRight ) * 1000.0f,
                    //GetDebugNameEyeCupType ( TheHmdRenderInfo.EyeCups ),  // Lens/EyeCup not exposed
                    
                    (leftFov.GetHorizontalFovDegrees() + rightFov.GetHorizontalFovDegrees()) * 0.5f,
                    (leftFov.GetVerticalFovDegrees() + rightFov.GetVerticalFovDegrees()) * 0.5f,

                    pixelSizeWidth, pixelSizeHeight,

                    latency2Text
                    );

        size_t texMemInMB = pRender->GetTotalTextureMemoryUsage() / 1058576;
        if (texMemInMB)
        {
            OVR_sprintf(gpustat, sizeof(gpustat), " GPU Tex: %u MB", texMemInMB);
            OVR_strcat(buf, sizeof(buf), gpustat);
        }
        
        DrawTextBox(pRender, 0.0f, 0.0f, textHeight, buf, DrawText_Center);
    }
    break;
    
    case Text_Timing:    
        Profiler.DrawOverlay(pRender);    
    break;
    
    case Text_Help1:
        DrawTextBox(pRender, 0.0f, 0.0f, textHeight, HelpText1, DrawText_Center);
        break;
    case Text_Help2:
        DrawTextBox(pRender, 0.0f, 0.0f, textHeight, HelpText2, DrawText_Center);
        break;
    
    case Text_None:
        break;

    default:
        OVR_ASSERT ( !"Missing text screen" );
        break;    
    }
}