Example #1
0
        /// <summary>Set up the cube map by rendering the scene into it</summary>
        private void RenderSceneIntoCubeMap(Device device, double totalTime, float elapsedTime, Vector3 position)
        {
            if (invalidated)
            {
                rendering = true;
                CameraBase cam = Framework.Instance.CurrentCamera;
                cubeCamera.LookFrom = position;
                Framework.Instance.CurrentCamera = cubeCamera;
                for (int f = 0; f < 6; ++f)
                {
                    CubeTexture cubeTex = cubeTexture.Texture as CubeTexture;
                    using (Surface s = cubeTex.GetCubeMapSurface((CubeMapFace)f, 0))
                    {
                        SetCubeMapCamera((CubeMapFace)f);

                        renderHelper.BeginScene(s);
                        cubeCamera.OnFrameMove(device, totalTime, elapsedTime);
                        cubeCamera.OnFrameRender(device, totalTime, elapsedTime);
                        if (OnFrameRenderMethod != null)
                        {
                            OnFrameRenderMethod(device, totalTime, elapsedTime);
                        }
                        device.Transform.World = Matrix.Identity;
                        renderHelper.EndScene(Filter.None);
                    }
                }
                Framework.Instance.CurrentCamera = cam;
                Framework.Instance.CurrentCamera.OnFrameRender(device, totalTime, elapsedTime);
                rendering   = false;
                invalidated = false;
            }
        }
Example #2
0
        /// <summary>
        /// adds a camera and viewport.
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="viewportRectangle"></param>
        public void Add(CameraBase camera, Rectangle?viewportRectangle)
        {
            this.camera.Add(camera);

            Viewport newViewport = FrameworkCore.Game.GraphicsDevice.Viewport;

            if (viewportRectangle == null)
            {
                newViewport.X      = 0;
                newViewport.Y      = 0;
                newViewport.Width  = FrameworkCore.Game.GraphicsDevice.Viewport.Width;
                newViewport.Height = FrameworkCore.Game.GraphicsDevice.Viewport.Height;
            }
            else
            {
                newViewport.X      = viewportRectangle.Value.X;
                newViewport.Y      = viewportRectangle.Value.Y;
                newViewport.Width  = viewportRectangle.Value.Width;
                newViewport.Height = viewportRectangle.Value.Height;
            }

            this.viewport.Add(newViewport);

            count++;
        }
Example #3
0
        public Reflection()
        {
            instance = this;

            cubeCamera             = new CameraBase("cubecamera");
            cubeCamera.AspectRatio = 1;
            cubeCamera.FieldOfView = (float)Math.PI / 2;
            cubeCamera.Up          = new Vector3(0, 1f, 0);
            cubeCamera.Near        = 0.1f;

            int detailInt = Convert.ToInt32(Settings.GetValue("ReflectionDetail", "2"));

            switch (detailInt)
            {
            case 0:
                reflectionDetail = ReflectionDetailEnum.Off;
                break;

            case 1:
                reflectionDetail = ReflectionDetailEnum.Low;
                break;

            case 2:
                reflectionDetail = ReflectionDetailEnum.High;
                break;
            }
            Initialize();

            Framework.Instance.DeviceReset   += new Bonsai.Core.EventArgs.DeviceEventHandler(Instance_DeviceReset);
            Framework.Instance.DeviceCreated += new Bonsai.Core.EventArgs.DeviceEventHandler(Instance_DeviceCreated);
            Framework.Instance.DeviceLost    += new EventHandler(Instance_DeviceLost);

            this.OnFrameRenderMethod = Program.Instance.OnFrameRenderReflection;
        }
Example #4
0
        private static void Render( CameraBase CameraState, SceneBase Scene, RenderMethod Method, byte MaxDepth, float Epsilon,
                                    byte RouletteDepth, float MaximumTerminationProbability, Framebuffer Fb, bool UseMultithreading )
        {
            if ( UseMultithreading )
            {
                Parallel.For<ThreadLocalState>( 0, Fb.Rows,
                                               () => new ThreadLocalState( Scene, Method, MaxDepth, Epsilon, RouletteDepth, MaximumTerminationProbability ),
                                               ( Y, Loop, State ) =>
                                               {
                                                   for ( int X = 0; X < Fb.Columns; X++ )
                                                   {
                                                       Fb[Y, X] = CameraState.RenderPixel( Fb.Columns, Fb.Rows, X, Y, State );
                                                   }

                                                   return State;
                                               }, ( State ) => { } );
            }
            else
            {
                ThreadLocalState State = new ThreadLocalState( Scene, Method, MaxDepth, Epsilon, RouletteDepth, MaximumTerminationProbability );

                for ( int Y = 0; Y < Fb.Rows; Y++ )
                {
                    for ( int X = 0; X < Fb.Columns; X++ )
                    {
                        Fb[Y, X] = CameraState.RenderPixel( Fb.Columns, Fb.Rows, X, Y, State );
                    }
                }
            }
        }
Example #5
0
        public void Draw(DeviceContext dc, CameraBase camera)
        {
            var eyePos = camera.Position;
            var t      = Matrix.Translation(eyePos);
            var wvp    = t * camera.ViewProj;

            Effects.SkyFX.SetWorldViewProj(wvp);
            Effects.SkyFX.SetCubeMap(_cubeMapSRV);

            var       stride = Marshal.SizeOf(typeof(Vector3));
            const int Offset = 0;

            dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vb, stride, Offset));
            dc.InputAssembler.SetIndexBuffer(_ib, Format.R32_UInt, 0);
            dc.InputAssembler.InputLayout       = InputLayouts.Pos;
            dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            var tech = Effects.SkyFX.SkyTech;

            for (var p = 0; p < tech.Description.PassCount; p++)
            {
                var pass = tech.GetPassByIndex(p);
                pass.Apply(dc);
                dc.DrawIndexed(_indexCount, 0, 0);
            }
        }
Example #6
0
    private void CacheComponents()
    {
        if (null != Camera.main)
        {
            _cameraComponent = Camera.main.gameObject.GetComponent <CameraBase>();
        }

        if (null != characterName)
        {
            _uiLabelCharacterName = characterName.GetComponent <UILabel>();
        }

        if (null != dialogueBody)
        {
            _uiLabelDialogueBody = dialogueBody.GetComponent <UILabel>();
        }

        if (null != speechTail)
        {
            _uiSpriteSpeechTail = speechTail.GetComponent <UISprite>();
        }

        if (null != thoughtTail)
        {
            _uiSpriteThoughtTail = thoughtTail.GetComponent <UISprite>();
        }

        _uiPanel = GetComponent <UIPanel>();
    }
    /// <summary>
    /// Raises the camera mode changed event.
    /// </summary>
    void OnFollowCamera(GameObject target)
    {
        followCamera.SetTarget(target);
        orbitalCamera.SetTarget(target);

        currentCamera = followCamera;
    }
        public Minimap(Device device, DeviceContext dc, int minimapWidth, int minimapHeight, Terrain terrain, CameraBase viewCam)
        {
            _dc = dc;

            _minimapViewport = new Viewport(0, 0, minimapWidth, minimapHeight);

            CreateMinimapTextureViews(device, minimapWidth, minimapHeight);

            _terrain = terrain;

            SetupOrthoCamera();
            _viewCam = viewCam;

            // frustum vb will contain four corners of view frustum, with first vertex repeated as the last
            var vbd = new BufferDescription(
                VertexPC.Stride * 5,
                ResourceUsage.Dynamic,
                BindFlags.VertexBuffer,
                CpuAccessFlags.Write,
                ResourceOptionFlags.None,
                0
                );

            _frustumVB = new Buffer(device, vbd);

            _edgePlanes = new[] {
                new Plane(1, 0, 0, -_terrain.Width / 2),
                new Plane(-1, 0, 0, _terrain.Width / 2),
                new Plane(0, 1, 0, -_terrain.Depth / 2),
                new Plane(0, -1, 0, _terrain.Depth / 2)
            };

            ScreenPosition = new Vector2(0.25f, 0.75f);
            Size           = new Vector2(0.25f, 0.25f);
        }
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            //XXX: hack unity singleton
            Debug.LogError("Two instances of GameManager. Destroying.");
            Destroy(gameObject);
            return;
        }

        if (activeCamera == null)
        {
            activeCamera = GameObject.Find("CameraBase").GetComponent <CameraBase>();
            if (activeCamera == null)
            {
                Debug.LogError("GameManager did not find CameraBase. ActiveCamera not set");
            }
        }

        InitializeManagers();
    }
Example #10
0
        private void SetupDebug()
        {
            Context.ScriptingEngine.Expose("debugCamera",
                                           (Func <string>)(() =>
            {
                _debugCamera = _debugCamera == null
                        ? new CameraBase(new Vector3(Camera.Center.X, Camera.Center.Y, 0), new Vector2(Context.Settings.RenderWidth, Context.Settings.RenderHeight))
                {
                    Zoom = Camera.Zoom / 2f
                }
                        : null;
                _debugCameraDataText.Active = !_debugCameraDataText.Active;

                return("Debug camera " + (_debugCamera == null ? "disabled." : "enabled."));
            }),
                                           "Enables the debug camera. Move it with the arrow keys. Invoke again to cancel.");

            Context.ScriptingEngine.Expose("fps",
                                           (Func <string>)(() =>
            {
                _fpsCounter = !_fpsCounter;
                _debugFpsCounterDataText.Active = !_debugFpsCounterDataText.Active;

                return("Fps counter " + (_fpsCounter ? "enabled." : "disabled."));
            }),
                                           "Enables the fps counter. Invoke again to cancel.");

            Context.ScriptingEngine.Expose("fbf",
                                           (Func <string>)(() =>
            {
                _frameByFrame        = !_frameByFrame;
                _frameByFrameAdvance = false;

                return("Frame by frame mode " + (_frameByFrame ? "enabled." : "disabled."));
            }),
                                           "Enables the frame by frame mode. Press F11 to advance or hold F12 to fast forward. Invoke again to cancel.");

            Context.ScriptingEngine.Expose("debugMouse",
                                           (Func <string>)(() =>
            {
                _drawMouse = !_drawMouse;

                return("Mouse square drawing is " + (_drawMouse ? "enabled." : "disabled."));
            }),
                                           "Enables drawing a square around the mouse cursor. Invoke again to cancel.");

            Font font = Context.AssetLoader.Get <Font>("debugFont.otf");

            _debugCameraDataText = new BasicTextBg(font, 10, "", Color.Yellow, new Color(0, 0, 0, 125), new Vector3(0, 0, 5))
            {
                Padding = new Rectangle(3, 3, 3, 3), Active = false
            };
            _debugFpsCounterDataText = new BasicTextBg(font, 10, "", Color.Yellow, new Color(0, 0, 0, 125), new Vector3(0, 0, 5))
            {
                Padding = new Rectangle(3, 3, 3, 3), Active = false
            };

            Debugger.CornerAnchor.AddChild(_debugCameraDataText, AnchorLocation.BottomLeft);
            Debugger.CornerAnchor.AddChild(_debugFpsCounterDataText, AnchorLocation.TopLeft);
        }
Example #11
0
        protected void RemoveInvisibleTiles(CameraBase camera)
        {
            ArrayList deletionList = new ArrayList();

            lock (m_topmostTiles.SyncRoot)
            {
                foreach (long key in m_topmostTiles.Keys)
                {
                    QuadTile qt = (QuadTile)m_topmostTiles[key];
                    if (!camera.ViewFrustum.Intersects(qt.BoundingBox))
                    {
                        deletionList.Add(key);
                    }
                }

                foreach (long deleteThis in deletionList)
                {
                    QuadTile qt = (QuadTile)m_topmostTiles[deleteThis];
                    if (qt != null)
                    {
                        m_topmostTiles.Remove(deleteThis);
                        qt.Dispose();
                    }
                }
            }
        }
Example #12
0
        public override void AttachedToController(UIController controller)
        {
            base.AttachedToController(controller);

            _previousCamera        = Engine.Renderer.Camera;
            Engine.Renderer.Camera = new FloatScaleCamera2d(Vector3.Zero);
        }
Example #13
0
        /// <summary>
        /// 为当前视图重设缓存
        /// </summary>
        /// <param name="camera"></param>
        public virtual void ResetCacheForCurrentView(CameraBase camera)
        {
            //                      if (!ImageStore.IsDownloadableLayer)
            //                              return;

            ArrayList deletionList = new ArrayList();

            //reset "root" tiles that intersect current view
            lock (m_topmostTiles.SyncRoot)
            {
                foreach (long key in m_topmostTiles.Keys)
                {
                    QuadTile qt = (QuadTile)m_topmostTiles[key];
                    if (camera.ViewFrustum.Intersects(qt.BoundingBox))
                    {
                        qt.ResetCache();
                        deletionList.Add(key);
                    }
                }

                foreach (long deletionKey in deletionList)
                {
                    m_topmostTiles.Remove(deletionKey);
                }
            }
        }
Example #14
0
        public void SetupLights(DrawArgs drawArgs)
        {
            Device     device = drawArgs.device;
            CameraBase camera = drawArgs.WorldCamera;

            if (World.Settings.EnableSunShading)
            {
                // Set up material
                Material material = new Material();
                material.Diffuse           = Color.White;
                material.Ambient           = Color.White;
                material.Specular          = Color.White;
                material.SpecularSharpness = 50.0f;                  // thin highlight (smaller = larger)
                device.Material            = material;
                // Use a white, directional light
                device.Lights[0].Diffuse  = Color.White;
                device.Lights[0].Specular = Color.FromArgb(0x80, 0x80, 0x80);                 // soft highlight
                device.Lights[0].Type     = LightType.Directional;
                // Reading current WorldWind Sun position
                Point3d sunPosition = SunCalculator.GetGeocentricPosition(TimeKeeper.CurrentTimeUtc);
                // Setup light direction
                device.Lights[0].Direction = new Vector3((float)sunPosition.X, (float)sunPosition.Y, (float)sunPosition.Z);
                device.Lights[0].Update();
                device.Lights[0].Enabled          = true;
                device.RenderState.SpecularEnable = true;
            }
            else
            {
                // Disale lighting
                device.RenderState.Lighting       = false;
                device.RenderState.Ambient        = World.Settings.StandardAmbientColor;
                device.RenderState.SpecularEnable = false;
            }
        }
Example #15
0
    private void CalculateOffsets(float zoom, CameraBase playerCamera, ref float PosVertical, ref float PosDist, ref float tiltDeg)
    {
        // put into graphing calculator: ( 1-sin((1-x)*1.57) )^1.6
        const float Curve = 0f;
        float       zoomDistanceCurved = Mathf.Lerp(zoom, Mathf.Pow(1.0f - Mathf.Sin((1.0f - zoom) * 1.57f), 1.6f), Curve);

        zoomDistanceCurved = Mathf.Clamp01(zoomDistanceCurved);

        if (!IsGameCamera())
        {
            if (_params != null && _params.useTargetLocalSpace)
            {
                PosVertical = _params.heightOffset;
                PosDist     = _params.distance;
                tiltDeg     = 0f;
            }
            else
            {
                PosVertical = GlobalCameraData.Instance.gameCameraFarVertical;
                PosDist     = GlobalCameraData.Instance.gameCameraFarDist;
                tiltDeg     = 0f;
            }
        }
        else
        {
            PosVertical = Mathf.Lerp(GlobalCameraData.Instance.gameCameraCloseVertical, GlobalCameraData.Instance.gameCameraFarVertical, zoomDistanceCurved);
            PosDist     = Mathf.Lerp(GlobalCameraData.Instance.gameCameraCloseDist, GlobalCameraData.Instance.gameCameraFarDist, zoom);
            tiltDeg     = Mathf.Lerp(GlobalCameraData.Instance.gameCameraClosePitch, GlobalCameraData.Instance.gameCameraFarPitch, zoomDistanceCurved);
        }
    }
Example #16
0
        public override void Initialize(DrawArgs drawArgs)
        {
            Camera = DrawArgs.Camera;

            // Initialize download rectangles
            if (DownloadInProgressTexture == null)
            {
                DownloadInProgressTexture = CreateDownloadRectangle(DrawArgs.StaticDevice, World.Settings.DownloadProgressColor, 0);
            }
            if (DownloadQueuedTexture == null)
            {
                DownloadQueuedTexture = CreateDownloadRectangle(DrawArgs.StaticDevice, World.Settings.DownloadQueuedColor, 0);
            }
            if (DownloadTerrainTexture == null)
            {
                DownloadTerrainTexture = CreateDownloadRectangle(DrawArgs.StaticDevice, World.Settings.DownloadTerrainRectangleColor, 0);
            }

            try {
                lock (m_topmostTiles.SyncRoot) {
                    foreach (QuadTile qt in m_topmostTiles.Values)
                    {
                        qt.Initialize();
                    }
                }
            }
            catch {}
            Inited = true;
        }
        public void Init()
        {
            m_yaskawaRobot = new YaskawaRobot("192.168.255.1", 80);

            m_camera = new HaiKangCamera("camera", CameraConnectType.GigEVision2);
            try
            {
                m_camera.OpenCamera();
                DelegateControls.Instance.DelegateRichTextBoxZd("FormMain_RichTextBoxZd", "successfull to open camera");
            }
            catch (Exception ex)
            {
                DelegateControls.Instance.DelegateRichTextBoxZd("FormMain_RichTextBoxZd", ex.Message, Color.Red);
            }

            try
            {
                m_xinjiePlc = new XinJiePlc("192.168.6.10", 8001, "192.168.6.6", 502);
                m_xinjiePlc.Connect();
                DelegateControls.Instance.DelegateRichTextBoxZd("FormMain_RichTextBoxZd", "successfull to connnect PLC");
            }
            catch (Exception ex)
            {
                DelegateControls.Instance.DelegateRichTextBoxZd("FormMain_RichTextBoxZd", ex.Message, Color.Red);
            }
        }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZoomCamera"/> class.
 /// </summary>
 /// <param name="camera">Camera.</param>
 /// <param name="zoomMin">Zoom minimum.</param>
 /// <param name="zoomMax">Zoom max.</param>
 /// <param name="zoomSpeed">Zoom speed.</param>
 public ZoomCamera(CameraBase camera, int zoomMin, int zoomMax, float zoomSpeed) : base(camera)
 {
     this.transform = camera.getCameraGameObject().transform;
     this.zoomMin   = zoomMin;
     this.zoomMax   = zoomMax;
     this.zoomSpeed = zoomSpeed;
 }
Example #19
0
        private void StartExtTrigger()
        {
            StatusManger status1 = StatusManger.Instance;

            foreach (var item in CameraManger.CameraDic.Values)
            {
                item.SetExtTrigger();
            }
            CameraBase camera = CameraManger.CameraDic.Values.ToList().Find(x => x.IsExtTrigger == false);

            if (camera == null && CameraManger.CameraDic.Count > 0)
            {
                //btnRun.Text = "运行中";
                //btnRun.BackColor = Color.Green;
                //status1.RuningStatus = RuningStatus.系统运行中;
                SetNotifyMessage(string.Format("等待外部触发"));
            }
            else
            {
                if (camera == null)
                {
                    SetNotifyMessage(string.Format("相机未连接,无法开始运行"));
                }
                else
                {
                    SetNotifyMessage(string.Format("相机{0}开始外触发运行异常", camera.CameraIndex));
                }

                btnRun.Text      = "运行";
                btnRun.BackColor = Control.DefaultBackColor;
            }
        }
Example #20
0
        // start the opening sequence
        public void PlayOpeningSequence()
        {
            bool IsInHostileDungeon = false;

            if (IsInHostileDungeon)             // only play the intro in a hostile dungeon
            {
                if (!_cameraComponent)
                {
                    _cameraComponent = mDMono.transform.GetComponent <CameraBase>();
                }

                _cameraComponent.SetZoomDistance(0f);                 // fully pinched in
                _cameraComponent.SetInitialCameraPosition();          // to ensure we cut to fully zoomed in, rather than lerping to it

                PlayerController.LocalPlayerDisableNavigation();

                if (null == player)
                {
                    player = PlayerManager.LocalPlayerGameObject();
                }
                Transform playerTransform = player.transform;
                _spawnerFacingDirection = playerTransform.forward;                 // save off what the player's facing direction from the spawner was, as we'll swivel back to that later

                Vector3 objectToCamera = Vector3.zero;
                if (_cameraComponent.CalculateObjectToCameraXZDir(playerTransform, ref objectToCamera))
                {
                    player.transform.rotation = Quaternion.LookRotation(objectToCamera);                     // make the player look at the camera
                }
                _openingSequenceStage = eOpeningSequenceStage.cutToCloseUp;
            }
        }
Example #21
0
        private void CameraLineOff_Event(object sender, EventArgs e)
        {
            CameraBase camera = sender as CameraBase;

            Util.Notify(Level.Err, $"相机{camera.CameraIndex}断线请检查");
            if (CameraManger.CameraDic.Count == 1)
            {
                CommHandle.Instance.IsLink = false;
            }
            if (CameraManger.CameraDic.ContainsKey(camera.CameraIndex))
            {
                if (cameraSelect == CameraManger.CameraDic[camera.CameraIndex])
                {
                    cameraSelect = null;
                }
                CameraShowUnitDic[camera.CameraIndex].HWndUnit.SetTextBackColor();
                try
                {
                    CameraManger.CameraDic[camera.CameraIndex].Close();  //在这里已经中断退出,后面的不能执行
                }
                catch
                {
                    CameraManger.CameraDic.Remove(camera.CameraIndex);
                }
                CameraManger.CameraDic.Remove(camera.CameraIndex);
            }
        }
Example #22
0
 public void Update(Vector3 direction, CameraBase camera)
 {
     foreach (var split in Splits)
     {
         split.LookAt(direction, camera.Position + camera.Look * split.Size / 2);
     }
 }
 public FormCalibrate(YaskawaRobot Robot, ShapeModle shapeModle, CameraBase cameraBase)
 {
     InitializeComponent();
     this.Robot   = Robot;
     m_ShapeModle = shapeModle;
     m_Camera     = cameraBase;
     Init();
 }
Example #24
0
 public void Add(string key, CameraBase value)
 {
     if (m_cameras.ContainsKey(key))
     {
         throw new Exception($"the keyname {key} is already exist");
     }
     m_cameras.Add(key, value);
 }
Example #25
0
    // Use this for initialization
    void Awake()
    {
        GameObject editorPre = CoreEntry.gResLoader.Load("Scene/Camera/CameraShakeEditor") as GameObject;// (GameObject)Bundle.AssetBundleLoadManager.Instance.Load("Scene/Camera/CameraShakeEditor", typeof(GameObject));

        m_AnimationCurve  = editorPre.GetComponent <CameraShakeEditor>().m_AnimationCurve;
        m_CameraTransform = gameObject.transform;
        m_CameraFollow    = gameObject.GetComponent <CameraBase>();
    }
    void Start()
    {
        m_MenuLayers = LayerMask.GetMask(m_MenuLayersString);
        m_Camera = gameObject.GetComponent<Camera>();
        m_Camera.cullingMask = ~m_MenuLayers.value;

        m_OtherCameraScript = CameraManager.Instance.CurrentCameraAction;
    }
Example #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FreeCamera"/> class.
 /// </summary>
 /// <param name="camera">Camera.</param>
 /// <param name="minX">Minimum x.</param>
 /// <param name="minZ">Minimum z.</param>
 /// <param name="maxX">Max x.</param>
 /// <param name="maxZ">Max z.</param>
 /// <param name="movementSpeed">Movement speed.</param>
 public FreeCamera(CameraBase camera, int minX, int minZ, int maxX, int maxZ, float movementSpeed) : base(camera)
 {
     this.transform = camera.getCameraGameObject().transform;
     this.minX      = minX;
     this.maxX      = maxX;
     this.minZ      = minZ;
     this.maxZ      = maxZ;
     this.speed     = movementSpeed;
 }
Example #28
0
        public void SetCamera(CameraBase camera)
        {
            if (null == camera)
            {
                throw new ArgumentNullException(nameof(camera));
            }

            _altaxoCamera = camera;
        }
Example #29
0
 /// <summary>
 /// determine whether this chart item is in visuble.
 /// </summary>
 /// <param name="camera"></param>
 /// <returns></returns>
 private bool IsInViewFrustum(CameraBase camera)
 {
     if (base.Position
         == Vector3.Empty)
     {
         base.position = MathEngine.SphericalToCartesian(this.latitude, this.longitude, camera.WorldRadius);
     }
     return(camera.ViewFrustum.ContainsPoint(base.Position));
 }
Example #30
0
 public FormCamera(CameraBase cameraBase, ShapeModle shapeModle)
 {
     InitializeComponent();
     this.FormClosing += FormCamera_FormClosing;
     Camera            = cameraBase;
     ShapeModle        = shapeModle;
     ShapeModle.Dock   = DockStyle.Fill;
     tabPage_Model.Controls.Add(ShapeModle);
 }
Example #31
0
 private bool IsInViewFrustum(CameraBase camera, MyChart c)
 {
     if (c.Position
         == Vector3.Empty)
     {
         c.Position = MathEngine.SphericalToCartesian(c.Latitude, c.Longitude, camera.WorldRadius);
     }
     return(camera.ViewFrustum.ContainsPoint(c.Position));
 }
Example #32
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// created, which will happen during application initialization and windowed/full screen
        /// toggles. This is the best location to create Pool.Managed resources since these
        /// resources need to be reloaded whenever the device is destroyed. Resources created
        /// here should be released in the Disposing event.
        /// </summary>
        private void OnCreateDevice(object sender, DeviceEventArgs e)
        {
            // Initialize the stats font
            //statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
            //    Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
            //    , "Arial");
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            SoundManager.Initialize(Framework.Instance.Window);
            inputManager = new Bonsai.Input.InputManager(Framework.Instance.Window);

            transparentObjectManager = new TransparentObjectManager();
            weather = new Weather(this);

            //modelControl = new ModelControl("Data/cessna/cessna.par");
            modelControl = new ModelControl();

            rotationAxisMesh = new LineMesh();

            sky = new GameObject();
            DomeMesh skyDome = new DomeMesh(5000, 10, 16);

            skyDome.Texture = new Bonsai.Objects.Textures.TextureBase("data\\sky2.JPG");
            sky.Position    = new Vector3(0, -5f, 0);
            sky.Mesh        = skyDome;

            scenery = new GameObject();
            SquareMesh sceneryMesh = new SquareMesh(5000, 10, 10, 1000f);

            sceneryMesh.Texture  = new Bonsai.Objects.Textures.TextureBase("data\\scenery\\default\\grass1.jpg");
            scenery.Mesh         = sceneryMesh;
            scenery.Position     = new Vector3(0, -5f, 0);
            scenery.RotateXAngle = (float)Math.PI / 2;

            cameraEditor      = new CameraBase("ObserverCamera");
            cameraEditor.Near = 0.05f;

            cameraPilot          = new ObserverCamera("PilotCamera", modelControl.AirplaneModel);
            cameraPilot.LookFrom = new Vector3(5f, -3.3f, 5f);

            //camera.LookAt = modelControl.AirplaneModel.Position;
            //camera.LookFrom = modelControl.AirplaneModel.Position + new Vector3(cameraDistance, 0f, 0f);
            //camera.AutoZoom = true;
            cameraEditor.AspectRatio = (float)(e.BackBufferDescription.Width) / e.BackBufferDescription.Height;
            cameraPilot.AspectRatio  = (float)(e.BackBufferDescription.Width) / e.BackBufferDescription.Height;


            Framework.Instance.CurrentCamera = cameraEditor;

            sun       = new DirectionalLight(new Vector3(-0.5f, -0.707f, 0.5f));
            sun.Color = System.Drawing.Color.FromArgb(148, 148, 148);

            collisionPoints = new CollisionPoints();

            cursor3d  = new Cursor3d();
            cursor3d2 = new Cursor3d();
        }
 internal static HandleRef getCPtr(CameraBase obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Example #34
0
        public void Draw(DeviceContext dc, CameraBase cam, DirectionalLight[] lights)
        {
            if (_useTessellation) {

                dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith4ControlPoints;
                dc.InputAssembler.InputLayout = InputLayouts.TerrainCP;

                var stride = TerrainCP.Stride;
                const int offset = 0;

                dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_quadPatchVB, stride, offset));
                dc.InputAssembler.SetIndexBuffer(_quadPatchIB, Format.R16_UInt, 0);

                var viewProj = cam.ViewProj;
                var planes = cam.FrustumPlanes;
                var toTexSpace = Matrix.Scaling(0.5f, -0.5f, 1.0f) * Matrix.Translation(0.5f, 0.5f, 0);

                Effects.TerrainFX.SetViewProj(viewProj);
                Effects.TerrainFX.SetEyePosW(cam.Position);
                Effects.TerrainFX.SetDirLights(lights);
                Effects.TerrainFX.SetFogColor(Color.Silver);
                Effects.TerrainFX.SetFogStart(15.0f);
                Effects.TerrainFX.SetFogRange(175.0f);
                Effects.TerrainFX.SetMinDist(MinDist);
                Effects.TerrainFX.SetMaxDist(MaxDist);
                Effects.TerrainFX.SetMinTess(MinTess);
                Effects.TerrainFX.SetMaxTess(MaxTess);
                Effects.TerrainFX.SetTexelCellSpaceU(1.0f / Info.HeightMapWidth);
                Effects.TerrainFX.SetTexelCellSpaceV(1.0f / Info.HeightMapHeight);
                Effects.TerrainFX.SetWorldCellSpace(Info.CellSpacing);
                Effects.TerrainFX.SetWorldFrustumPlanes(planes);
                Effects.TerrainFX.SetLayerMapArray(_layerMapArraySRV);
                Effects.TerrainFX.SetBlendMap(_blendMapSRV);
                Effects.TerrainFX.SetHeightMap(_heightMapSRV);
                Effects.TerrainFX.SetMaterial(_material);
                Effects.TerrainFX.SetViewProjTex(viewProj * toTexSpace);

                var tech = Shadows ? Effects.TerrainFX.Light1ShadowTech: Effects.TerrainFX.Light1Tech;
                for (int p = 0; p < tech.Description.PassCount; p++) {
                    var pass = tech.GetPassByIndex(p);
                    pass.Apply(dc);
                    dc.DrawIndexed(_numPatchQuadFaces * 4, 0, 0);
                }
                dc.HullShader.Set(null);
                dc.DomainShader.Set(null);

                if (DebugBvh) {
                    DrawBVHDebug(dc, cam, offset);
                }
            } else {
                dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                dc.InputAssembler.InputLayout = InputLayouts.TerrainCP;

                var viewProj = cam.ViewProj;
                Effects.TerrainFX.SetViewProj(viewProj);
                Effects.TerrainFX.SetEyePosW(cam.Position);
                Effects.TerrainFX.SetDirLights(lights);
                Effects.TerrainFX.SetFogColor(Color.Silver);
                Effects.TerrainFX.SetFogStart(15.0f);
                Effects.TerrainFX.SetFogRange(175.0f);

                Effects.TerrainFX.SetTexelCellSpaceU(1.0f / Info.HeightMapWidth);
                Effects.TerrainFX.SetTexelCellSpaceV(1.0f / Info.HeightMapHeight);
                Effects.TerrainFX.SetWorldCellSpace(Info.CellSpacing);

                Effects.TerrainFX.SetLayerMapArray(_layerMapArraySRV);
                Effects.TerrainFX.SetBlendMap(_blendMapSRV);
                Effects.TerrainFX.SetHeightMap(_heightMapSRV);
                Effects.TerrainFX.SetMaterial(_material);
                var tech = Effects.TerrainFX.Light1TechNT;
                for (var p = 0; p < tech.Description.PassCount; p++) {
                    var pass = tech.GetPassByIndex(p);
                    pass.Apply(dc);
                    for (var i = 0; i < _patches.Count; i++) {
                        var patch = _patches[i];
                        if (cam.Visible(patch.Bounds)) {
                            var ns = new Dictionary<NeighborDir, Patch>();
                            if (i < NumPatchVertCols) {
                                ns[NeighborDir.Top] = null;
                            } else {
                                ns[NeighborDir.Top] = _patches[i - NumPatchVertCols + 1];
                            }
                            if (i%(NumPatchVertCols - 1) == 0) {
                                ns[NeighborDir.Left] = null;
                            } else {
                                ns[NeighborDir.Left] = _patches[i - 1];
                            }
                            if (Util.IsKeyDown(Keys.N)) {
                                patch.Draw(dc, cam.Position);
                            } else {
                                patch.Draw(dc, cam.Position, ns);
                            }
                        }
                    }
                }
            }
        }
Example #35
0
        public void ComputeSsao(DeviceContext dc, CameraBase cam, Ssao ssao, DepthStencilView depthStencilView)
        {
            ssao.SetNormalDepthRenderTarget(depthStencilView);

            dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith4ControlPoints;
            dc.InputAssembler.InputLayout = InputLayouts.TerrainCP;

            var stride = TerrainCP.Stride;
            const int offset = 0;

            dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_quadPatchVB, stride, offset));
            dc.InputAssembler.SetIndexBuffer(_quadPatchIB, Format.R16_UInt, 0);

            var viewProj = cam.ViewProj;
            var planes = cam.FrustumPlanes;

            Effects.TerrainFX.SetViewProj(viewProj);
            Effects.TerrainFX.SetEyePosW(cam.Position);
            Effects.TerrainFX.SetMinDist(MinDist);
            Effects.TerrainFX.SetMaxDist(MaxDist);
            Effects.TerrainFX.SetMinTess(MinTess);
            Effects.TerrainFX.SetMaxTess(MaxTess);
            Effects.TerrainFX.SetTexelCellSpaceU(1.0f / Info.HeightMapWidth);
            Effects.TerrainFX.SetTexelCellSpaceV(1.0f / Info.HeightMapHeight);
            Effects.TerrainFX.SetWorldCellSpace(Info.CellSpacing);
            Effects.TerrainFX.SetWorldFrustumPlanes(planes);
            Effects.TerrainFX.SetHeightMap(_heightMapSRV);
            Effects.TerrainFX.SetView(cam.View);

            var tech = Effects.TerrainFX.NormalDepthTech;
            for (int p = 0; p < tech.Description.PassCount; p++) {
                var pass = tech.GetPassByIndex(p);
                pass.Apply(dc);
                dc.DrawIndexed(_numPatchQuadFaces * 4, 0, 0);
            }
            dc.HullShader.Set(null);
            dc.DomainShader.Set(null);

            ssao.ComputeSsao(cam);
            ssao.BlurAmbientMap(4);
        }
Example #36
0
        private void DrawBVHDebug(DeviceContext dc, CameraBase cam, int offset)
        {
            dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            dc.InputAssembler.InputLayout = InputLayouts.PosColor;
            dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_bvhVB, VertexPC.Stride, offset));
            dc.InputAssembler.SetIndexBuffer(_bvhIB, Format.R32_UInt, 0);

            //dc.OutputMerger.DepthStencilState = RenderStates.NoDepthDSS;
            Effects.ColorFX.SetWorldViewProj(cam.ViewProj);
            for (int p = 0; p < Effects.ColorFX.ColorTech.Description.PassCount; p++) {
                Effects.ColorFX.ColorTech.GetPassByIndex(p).Apply(dc);
                dc.DrawIndexed(_bvhIndices.Count, 0, 0);
            }
            dc.OutputMerger.DepthStencilState = null;
        }