예제 #1
0
        public void Render(float4x4 mtxRot)
        {
            if (WonDeadAnimation())
            {
                return;
            }

            LoadAnimation();

            var eyeF    = new float3(0, 0, _camPosition);
            var targetF = new float3(0, 0, 0);
            var upF     = new float3(0, 1, 0);

            if (!UseStereo3D)
            {
                // normal mode
                var lookAt = float4x4.LookAt(eyeF, targetF, upF);
                // colh CamTrans = _camTranslation*mtxRot*lookAt;
                CamTrans = lookAt * mtxRot * _camTranslation;

                RContext.SetShaderParamTexture(VTextureObj, TextureField);

                foreach (var feld in _levelFeld)
                {
                    if (feld != null)
                    {
                        feld.Render(_objOrientation);
                    }
                }

                RContext.SetShaderParamTexture(VTextureObj, TextureCube);

                if (_rCube != null)
                {
                    _rCube.RenderCube();
                }
            }
            else
            {
                // 3d mode
                _stereo3D.Prepare(Stereo3DEye.Left);

                for (var x = 0; x < 2; x++)
                {
                    var lookAt = _stereo3D.LookAt3D(_stereo3D.CurrentEye, eyeF, targetF, upF);
                    // colh CamTrans = _camTranslation*mtxRot*lookAt;
                    CamTrans = lookAt * mtxRot * _camTranslation;

                    var renderOnly = (_stereo3D.CurrentEye == Stereo3DEye.Left);

                    RContext.SetShaderParamTexture(VTextureObj, TextureField);

                    foreach (var feld in _levelFeld)
                    {
                        if (feld != null)
                        {
                            feld.Render(_objOrientation, renderOnly);
                        }
                    }

                    RContext.SetShaderParamTexture(VTextureObj, TextureCube);

                    if (_rCube != null)
                    {
                        _rCube.RenderCube(renderOnly);
                    }

                    _stereo3D.Save();

                    if (x == 0)
                    {
                        _stereo3D.Prepare(Stereo3DEye.Right);
                    }
                }
            }
        }
예제 #2
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Mouse and keyboard movement
            if (Keyboard.LeftRightAxis != 0 || Keyboard.UpDownAxis != 0)
            {
                _keys = true;
            }

            if (Mouse.LeftButton)
            {
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Mouse.XVel * DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * Mouse.YVel * DeltaTime * 0.0005f;
            }
            else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                //Reset view on touch
                ResetView();
            }
            else
            {
                if (_keys)
                {
                    _angleVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * DeltaTime;
                    _angleVelVert = -RotationSpeed * Keyboard.UpDownAxis * DeltaTime;
                }
                else
                {
                    var curDamp = (float)System.Math.Exp(-Damping * DeltaTime);
                    _angleVelHorz *= curDamp;
                    _angleVelVert *= curDamp;
                }
            }

            //Rotate Scene with Mouse
            _angleHorz -= _angleVelHorz / 3;
            _angleVert -= _angleVelVert / 3;


            //Calculate view (DeviceTracking)
            float4x4 headsetRotationX = float4x4.CreateRotationX(-gameRotationVector[2] + _angleVert);
            float4x4 headsetRotationY = float4x4.CreateRotationY(-gameRotationVector[0] + _angleHorz);
            float4x4 headsetRotationZ = float4x4.CreateRotationZ(-gameRotationVector[1] + _angleRoll);

            //StereoRendering
            if (_renderStereo)
            {
                //Render Left Eye
                var camTrans = float4x4.CreateTranslation(_eyeDistance / 2, -200, 0);
                var mtxCam   = float4x4.LookAt(_eyeDistance / 2, 0, 0, 0, 0, 400, 0, 1, 0);
                RC.ModelView = headsetRotationZ * headsetRotationX * headsetRotationY * mtxCam * camTrans;
                _stereo3d.Prepare(Stereo3DEye.Left);
                _sceneRenderer.Render(RC);
                _stereo3d.Save();

                //Render Right Eye
                camTrans     = float4x4.CreateTranslation(-_eyeDistance / 2, -200, 0);
                mtxCam       = float4x4.LookAt(-_eyeDistance / 2, 0, 0, 0, 0, 400, 0, 1, 0);
                RC.ModelView = headsetRotationZ * headsetRotationX * headsetRotationY * mtxCam * camTrans;
                _stereo3d.Prepare(Stereo3DEye.Right);
                _sceneRenderer.Render(RC);
                _stereo3d.Save();

                //We do nothing here in Cardboard-Mode. Used in Oculus and Anaglyph
                _stereo3d.Display();
            }
            //no StereoRendering
            else
            {
                // Render the scene loaded in Init()
                var camTrans = float4x4.CreateTranslation(0, -200, 0);
                RC.ModelView = headsetRotationZ * headsetRotationX * headsetRotationY * camTrans;
                _sceneRenderer.Render(RC);
            }

             #if GUI_SIMPLE
            _guiHandler.RenderGUI();     //GUI is overlayed, but can also be rendered for each eye
             #endif


            // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered farame) on the front buffer.
            Present();
        }