// creates a green or yellow spehere
    void Update()
    {
        if (WestdriveSettings.isPlaying)
        {
            if (currentFrame <= lastFrame)
            {
                transform.position = recordedData.Data[currentFrame][0].cameraPosition;
                transform.rotation = recordedData.Data[currentFrame][0].cameraRotation;
                foreach (HitPositionType hitPoint in recordedData.Data[currentFrame])
                {
                    if (hitPoint.centerHitPostion != Vector3.zero)
                    {
                        GameObject centerHit = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                        centerHit.transform.position = hitPoint.centerHitPostion;
                        centerHit.transform.lossyScale.Set(0.5f, 0.5f, 0.5f);
                        centerHit.transform.parent = visualisationDotsParent;
                        Renderer renderer = centerHit.GetComponent <Renderer>();
                        renderer.material = new Material(baseMaterial);
                        renderer.material.SetColor("_Color", Color.green);
                    }

                    if (hitPoint.boxHitPostion != Vector3.zero)
                    {
                        GameObject boxHit = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                        boxHit.transform.position = hitPoint.boxHitPostion;
                        boxHit.transform.lossyScale.Set(0.5f, 0.5f, 0.5f);
                        boxHit.transform.parent = visualisationDotsParent;
                        Renderer renderer = boxHit.GetComponent <Renderer>();
                        renderer.material = new Material(baseMaterial);
                        renderer.material.SetColor("_Color", Color.yellow);
                    }
                }

                TimeGaurd.setCurrentFrame(currentFrame);
                currentFrame++;
            }
        }
    }
    //tracks the headposition, rotation and movement

    private void Update()
    {
        if (isTracking)
        {
            PositionRotationType dataPoint = new PositionRotationType();
            dataPoint.position = gameObject.transform.position;
            dataPoint.rotaion  = gameObject.transform.rotation;
            if (!recordedData.Data.ContainsKey(Time.frameCount - WestdriveSettings.frameCorrection))
            {
                recordedData.Data.Add(Time.frameCount - WestdriveSettings.frameCorrection, dataPoint);
            }
            else
            {
                recordedData.Data[Time.frameCount - WestdriveSettings.frameCorrection] = dataPoint;
            }
        }

        else if (isRayCasting && WestdriveSettings.isPlaying)
        {
            if (currentFrame <= lastFrame)
            {
                AnalyzableData  frameData    = new AnalyzableData();
                HitPositionType hitPositions = new HitPositionType();
                frameData.frameNumber       = currentFrame;
                transform.position          = recordedData.Data[currentFrame].position;
                transform.rotation          = recordedData.Data[currentFrame].rotaion;
                frameData.trackerPosition   = transform.position;
                frameData.trackerRotation   = transform.rotation;
                hitPositions.cameraPosition = transform.position;
                hitPositions.cameraRotation = transform.rotation;
                Ray imaginaryMiddleEye =
                    GetComponent <Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
                RaycastHit centerHit;
                Debug.DrawRay(imaginaryMiddleEye.origin, imaginaryMiddleEye.direction * 1000, Color.red);

                if (Physics.Raycast(imaginaryMiddleEye, out centerHit, Mathf.Infinity, 1 << WestdriveSettings.trackableLayerMask))
                {
                    frameData.centerHit           = centerHit.transform.name;
                    hitPositions.centerHitPostion = centerHit.point;
                    frameData.centerHitPosition   = centerHit.point;
                    frameData.centerHitGroup      = centerHit.transform.root.name;
                }
                else
                {
                    frameData.centerHit           = "null";
                    hitPositions.centerHitPostion = Vector3.zero;
                    frameData.centerHitPosition   = Vector3.zero;
                    frameData.centerHitGroup      = "null";
                }
                RaycastHit boxHit;
                if (Physics.BoxCast(transform.position, new Vector3(5, 5, 5), transform.forward, out boxHit,
                                    transform.rotation, Mathf.Infinity, 1 << WestdriveSettings.trackableLayerMask))
                {
                    frameData.boxHit           = boxHit.transform.name;
                    hitPositions.boxHitPostion = boxHit.point;
                    frameData.boxHitPosition   = boxHit.point;
                    frameData.boxHitGroup      = boxHit.transform.root.name;
                }
                else
                {
                    frameData.boxHit           = "null";
                    hitPositions.boxHitPostion = Vector3.zero;
                    frameData.boxHitPosition   = Vector3.zero;
                    frameData.boxHitGroup      = "null";
                }
                Collider[] environment = Physics.OverlapBox(transform.position, new Vector3(5, 5, Mathf.Infinity),
                                                            transform.rotation, 1 << WestdriveSettings.trackableLayerMask);
                frameData.presentObjectName  = "";
                frameData.presentObjectGroup = "";
                if (environment.Length == 0)
                {
                    frameData.presentObjectName  += "null";
                    frameData.presentObjectGroup += "null";
                }
                else
                {
                    foreach (Collider presentObject in environment)
                    {
                        frameData.presentObjectName  += (presentObject.transform.name + "*");
                        frameData.presentObjectGroup += (presentObject.transform.root.name + "*");
                    }
                }
                WestdriveSettings.processedData.Add(frameData);
                WestdriveSettings.hitData.Data.Add(currentFrame, hitPositions);
                TimeGaurd.setCurrentFrame(currentFrame);
                currentFrame++;
            }
        }
    }
Example #3
0
 public void setCurretFrame(int frameNumber)
 {
     this.currentFrame = frameNumber;
     TimeGaurd.setCurrentFrame(currentFrame);
 }