void* DefaultAllocator::AllocDebug(size_t size, const char* file, unsigned line)
{
    OVR_UNUSED2(file, line); // should be here for debugopt config
#if defined(OVR_CC_MSVC) && defined(_CRTDBG_MAP_ALLOC)
    return _malloc_dbg(size, _NORMAL_BLOCK, file, line);
#else
    return malloc(size);
#endif
}
void* DefaultAllocator::AllocDebug(UPInt size, const char* file, unsigned line)
{
#if defined(OVR_CC_MSVC) && defined(_CRTDBG_MAP_ALLOC)
    return _malloc_dbg(size, _NORMAL_BLOCK, file, line);
#else
    OVR_UNUSED2(file, line);
    return malloc(size);
#endif
}
Beispiel #3
0
void Log::DefaultLogOutput(const char* formattedText, LogMessageType messageType, int bufferSize)
{
    bool debug = IsDebugMessage(messageType);
    OVR_UNUSED(bufferSize);

#if defined(OVR_OS_WIN32)
    // Under Win32, output regular messages to console if it exists; debug window otherwise.
    static DWORD dummyMode;
    static bool  hasConsole = (GetStdHandle(STD_OUTPUT_HANDLE) != INVALID_HANDLE_VALUE) &&
                              (GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &dummyMode));

    if (!hasConsole || debug)
    {
        ::OutputDebugStringA(formattedText);
    }

    fputs(formattedText, stdout);

#elif defined(OVR_OS_MS) // Any other Microsoft OSs

    ::OutputDebugStringA(formattedText);

#elif defined(OVR_OS_ANDROID)
    // To do: use bufferSize to deal with the case that Android has a limited output length.
    __android_log_write(ANDROID_LOG_INFO, "OVR", formattedText);

#else
    fputs(formattedText, stdout);

#endif

    if (messageType == Log_Error)
    {
#if defined(OVR_OS_WIN32)
        if (!ReportEventA(hEventSource, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 1, 0, &formattedText, NULL))
        {
            OVR_ASSERT(false);
        }
#elif defined(OVR_OS_MS) // Any other Microsoft OSs
        // TBD
#elif defined(OVR_OS_ANDROID)
        // TBD
#elif defined(OVR_OS_MAC) || defined(OVR_OS_LINUX)
        syslog(LOG_ERR, "%s", formattedText);
#else
        // TBD
#endif
    }

    // Just in case.
    OVR_UNUSED2(formattedText, debug);
}
void* DefaultAllocator::AllocDebug(size_t size, const char* file, unsigned line)
{
    void* p;

#ifdef OVR_USE_JEMALLOC
    OVR_UNUSED2(file, line);

    p = Alloc(size);
#else // OVR_USE_JEMALLOC

#if defined(OVR_CC_MSVC) && defined(_CRTDBG_MAP_ALLOC)
    p = _malloc_dbg(size, _NORMAL_BLOCK, file, line);
#else
    OVR_UNUSED2(file, line); // should be here for debugopt config
    p = malloc(size);
#endif

#endif // OVR_USE_JEMALLOC

    trackAlloc(p, size);
    return p;
}
UInt16 SelectSensorRampValue(const UInt16* ramp, unsigned count,
                                    float val, float factor, const char* label)
{    
    UInt16 threshold = (UInt16)(val * factor);

    for (unsigned i = 0; i<count; i++)
    {
        if (ramp[i] >= threshold)
            return ramp[i];
    }
    OVR_DEBUG_LOG(("SensorDevice::SetRange - %s clamped to %0.4f",
                   label, float(ramp[count-1]) / factor));
    OVR_UNUSED2(factor, label);
    return ramp[count-1];
}
Beispiel #6
0
void Log::DefaultLogOutput(LogMessageType messageType, const char* formattedText)
{

#if defined(OVR_OS_WIN32)
    // Under Win32, output regular messages to console if it exists; debug window otherwise.
    static DWORD dummyMode;
    static bool  hasConsole = (GetStdHandle(STD_OUTPUT_HANDLE) != INVALID_HANDLE_VALUE) &&
                              (GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &dummyMode));

    if (!hasConsole || IsDebugMessage(messageType))
    {
        ::OutputDebugStringA(formattedText);
    }
    else
    {
         fputs(formattedText, stdout);
    }    

#elif defined(OVR_OS_ANDROID)

    int logPriority = ANDROID_LOG_INFO;
    switch(messageType)
    {
    case Log_DebugText:    
    case Log_Debug:     logPriority = ANDROID_LOG_DEBUG; break;
    case Log_Assert:
    case Log_Error:     logPriority = ANDROID_LOG_ERROR; break;
    default:
        logPriority = ANDROID_LOG_INFO;       
    }

	__android_log_write(logPriority, "OVR", formattedText);

#else
    fputs(formattedText, stdout);

#endif

    // Just in case.
    OVR_UNUSED2(formattedText, messageType);
}
Beispiel #7
0
void Log::DefaultLogOutput(const char* formattedText, LogMessageType messageType, int bufferSize)
{
    OVR_UNUSED2(bufferSize, formattedText);

#if defined(OVR_OS_WIN32)

    ::OutputDebugStringA(formattedText);
    fputs(formattedText, stdout);

#elif defined(OVR_OS_MS) // Any other Microsoft OSs

    ::OutputDebugStringA(formattedText);

#elif defined(OVR_OS_ANDROID)
    // To do: use bufferSize to deal with the case that Android has a limited output length.
    __android_log_write(ANDROID_LOG_INFO, "OVR", formattedText);

#else
    fputs(formattedText, stdout);

#endif

    if (messageType == Log_Error)
    {
#if defined(OVR_OS_WIN32)
        if (!ReportEventA(hEventSource, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 1, 0, &formattedText, NULL))
        {
            OVR_ASSERT(false);
        }
#elif defined(OVR_OS_MS) // Any other Microsoft OSs
        // TBD
#elif defined(OVR_OS_ANDROID)
        // TBD
#elif defined(OVR_OS_MAC) || defined(OVR_OS_LINUX)
        syslog(LOG_ERR, "%s", formattedText);
#else
        // TBD
#endif
    }
}
bool GetFirmwarePath(std::wstring* outPath)
{
#ifdef OVR_OS_MS

    std::wstring basePath = GetModulePath();

    // Remove trailing slash.
    std::wstring::size_type lastSlashOffset = basePath.find_last_of(L"/\\", std::wstring::npos, 2);
    if (lastSlashOffset == std::string::npos)
    {
        // Abort if no trailing slash.
        return false;
    }
    basePath = basePath.substr(0, lastSlashOffset + 1);

    // For each relative path to test,
    for (int i = 0; i < RelativePathsCount; ++i)
    {
        // Concatenate the relative path on the base path (base path contains a trailing slash)
        std::wstring candidatePath = basePath + FWRelativePaths[i];

        // If a file exists at this location,
        if (::PathFileExistsW(candidatePath.c_str()))
        {
            // Return the path if requested.
            if (outPath)
            {
                *outPath = candidatePath;
            }

            return true;
        }
    }
#else
    OVR_UNUSED2(firmwarePath, numSearchDirs);
    //#error "FIXME"
#endif //OVR_OS_MS
    return false;
}
Beispiel #9
0
 virtual int         CopyFromStream(File *pstream, int byteSize)   { return -1; OVR_UNUSED2(pstream, byteSize); }
Beispiel #10
0
 virtual SInt64      LSeek(SInt64 offset, int origin)              { return -1; OVR_UNUSED2(offset, origin); }
Beispiel #11
0
 virtual int         Seek(int offset, int origin)                  { return -1; OVR_UNUSED2(offset, origin); }
Beispiel #12
0
 virtual int         Read(UByte *pbuffer, int numBytes)            { return -1; OVR_UNUSED2(pbuffer, numBytes); }
Beispiel #13
0
 // ** Stream implementation & I/O
 virtual int         Write(const UByte *pbuffer, int numBytes)     { return -1; OVR_UNUSED2(pbuffer, numBytes); }
Beispiel #14
0
//----------------------------------------------------------------------
void Tracker::Draw(ovrSession Session, RenderDevice* pRender, Player ThePlayer, ovrTrackingOrigin TrackingOriginType,
	               bool Sitting, float ExtraSittingAltitude, Matrix4f * /*ViewFromWorld*/, int eye, ovrPosef * EyeRenderPose)
{
    OVR_UNUSED2(ExtraSittingAltitude, Sitting);

	// Don't render if not ready
	if (!TrackerHeadModel) return;

	// Initial rendering setup
	pRender->SetDepthMode(true, true);
	pRender->SetCullMode(OVR::Render::D3D11::RenderDevice::Cull_Off);

	// Draw in local frame of reference, so get view matrix
	Quatf eyeRot = EyeRenderPose[eye].Orientation;
	Vector3f up = eyeRot.Rotate(UpVector);
	Vector3f forward = eyeRot.Rotate(ForwardVector);
	Vector3f viewPos = EyeRenderPose[eye].Position;
	Matrix4f localViewMat = Matrix4f::LookAtRH(viewPos, viewPos + forward, up);

	// Get some useful values about the situation
	Vector3f          headWorldPos  = ThePlayer.GetHeadPosition(TrackingOriginType);
	ovrTrackerPose    trackerPose   = ovr_GetTrackerPose(Session, 0);
	Vector3f          centreEyePos  = ((Vector3f)(EyeRenderPose[0].Position) + (Vector3f)(EyeRenderPose[1].Position))*0.5f;
	double            ftiming       = ovr_GetPredictedDisplayTime(Session, 0);
	ovrTrackingState  trackingState = ovr_GetTrackingState(Session, ftiming, ovrTrue);
	bool              tracked       = trackingState.StatusFlags & ovrStatus_PositionTracked ? true : false;

	// Find altitude of stand.
    // If we are at floor level, display the tracker stand on the physical floor.
    // If are using eye level coordinate system, just render the standard height of the stalk.
    float altitudeOfFloorInLocalSpace;
    if (TrackingOriginType == ovrTrackingOrigin_FloorLevel)
        altitudeOfFloorInLocalSpace = 0.01f;
    else
        altitudeOfFloorInLocalSpace = trackerPose.Pose.Position.y - 0.22f;  //0.18f;

	Vector3f localStandPos = Vector3f(trackerPose.Pose.Position.x, altitudeOfFloorInLocalSpace,
                                      trackerPose.Pose.Position.z);

	// Set position of tracker models according to pose.
	TrackerHeadModel->SetPosition(trackerPose.Pose.Position);
	TrackerHeadModel->SetOrientation(trackerPose.Pose.Orientation);
	
    // We scale the stalk so that it has correct physical height.
    Matrix4f stalkScale = Matrix4f::Scaling(1.0f, trackerPose.Pose.Position.y - altitudeOfFloorInLocalSpace - 0.0135f, 1.0f);
    TrackerStalkModel->SetMatrix(Matrix4f::Translation(Vector3f(trackerPose.Pose.Position) - Vector3f(0,0.0135f,0)) * stalkScale *
                                 Matrix4f(TrackerStalkModel->GetOrientation()));
	
    TrackerStandModel->SetPosition(localStandPos);
	TrackerConeModel->SetPosition(trackerPose.Pose.Position);
	TrackerConeModel->SetOrientation(trackerPose.Pose.Orientation);
	TrackerLinesModel->SetPosition(trackerPose.Pose.Position);
	TrackerLinesModel->SetOrientation(trackerPose.Pose.Orientation);


    if (trackerLinesAlwaysVisible)
        pRender->SetDepthMode(false, true);

	// Set rendering tint proportional to proximity, and red if not tracked. 
	float dist = DistToBoundary(centreEyePos, trackerPose.Pose, true);    
	 //OVR_DEBUG_LOG(("Dist = %0.3f\n", dist));
    
    // This defines a color ramp at specified distances from the edge.
    // Display staring at 0.4 - 0.2 meter [alpha 0->1]
    // Turn to yellow after [0.2]
    float       distThreshods[4]   = { 0.0f, 0.1f, 0.2f, 0.35f };
    Vector4f    thresholdColors[4] = {
        Vector4f(1.0f, 0.3f, 0.0f, 1.0f),   // Yellow-red
        Vector4f(1.0f, 1.0f, 0.0f, 0.8f),   // Yellow
        Vector4f(1.0f, 1.0f, 1.0f, 0.6f),   // White
        Vector4f(1.0f, 1.0f, 1.0f, 0.0f)    // White-transparent
    };

    // Assign tint based on the lookup table
    Vector4f globalTint = Vector4f(1, 1, 1, 0);

    int distSearch = 0;
    if (dist <= 0.0f)
        dist = 0.001f;
    for (; distSearch < sizeof(distThreshods) / sizeof(distThreshods[0]) - 1; distSearch++)
    {
        if (dist < distThreshods[distSearch+1])
        {
            float startT = distThreshods[distSearch];
            float endT   = distThreshods[distSearch+1];
            float factor = (dist - startT) / (endT - startT);

            globalTint = thresholdColors[distSearch] * (1.0f - factor) +
                         thresholdColors[distSearch + 1] * factor;
            break;
        }
    }
    
    if (!tracked)
        globalTint = Vector4f(1, 0, 0, 1);
    
    pRender->SetGlobalTint(globalTint);

    if (minimumAlphaOfTracker > globalTint.w)
        globalTint.w = minimumAlphaOfTracker;

    // We try to draw twice here: Once with Z clipping to give a bright image,
    // and once with Z testing off to give a dim outline for those cases.

    // Solid bakground
    if (globalTint.w > 0.01)
    {
        pRender->SetDepthMode(true, true);

        // Draw the tracker representation
        LOCAL_RenderModelWithAlpha(pRender, TrackerStandModel, localViewMat);
        LOCAL_RenderModelWithAlpha(pRender, TrackerStalkModel, localViewMat);
        LOCAL_RenderModelWithAlpha(pRender, TrackerHeadModel, localViewMat);
        LOCAL_RenderModelWithAlpha(pRender, TrackerLinesModel, localViewMat);
        if (drawWalls)
            LOCAL_RenderModelWithAlpha(pRender, TrackerConeModel, localViewMat);
    }

    
    if (globalTint.w > 0.01f)
        globalTint.w = 0.01f;    
    pRender->SetGlobalTint(globalTint);
    pRender->SetDepthMode(false, true);
    LOCAL_RenderModelWithAlpha(pRender, TrackerStandModel, localViewMat);
    LOCAL_RenderModelWithAlpha(pRender, TrackerStalkModel, localViewMat);
    LOCAL_RenderModelWithAlpha(pRender, TrackerHeadModel, localViewMat);
    LOCAL_RenderModelWithAlpha(pRender, TrackerLinesModel, localViewMat);
    if (drawWalls)
        LOCAL_RenderModelWithAlpha(pRender, TrackerConeModel, localViewMat);

	// Revert to rendering defaults
	pRender->SetGlobalTint(Vector4f(1, 1, 1, 1));
	pRender->SetCullMode(RenderDevice::Cull_Back);
	pRender->SetDepthMode(true, true);
}