Example #1
0
        public static Vector2D WorldToScreen(Vector3D world)
        {
            Vector2D   vec2;
            Vector2D   vector2D;
            ViewMatrix viewMatrix = ViewMatrix;
            float      m41        = viewMatrix.M41 * world.X + viewMatrix.M42 * world.Y + viewMatrix.M43 * world.Z + viewMatrix.M44;

            if (m41 < 0.01)
            {
                vector2D = new Vector2D()
                {
                    X = 0f,
                    Y = 0f
                };
                vec2 = vector2D;
            }
            else
            {
                float single = 1f / m41;
                float m11    = (viewMatrix.M11 * world.X + viewMatrix.M12 * world.Y + viewMatrix.M13 * world.Z + viewMatrix.M14) * single;
                float m21    = (viewMatrix.M21 * world.X + viewMatrix.M22 * world.Y + viewMatrix.M23 * world.Z + viewMatrix.M24) * single;
                vector2D = new Vector2D()
                {
                    X = (m11 + 1f) * 0.5f * ExternalCounterstrike.Overlay.Width,
                    Y = (m21 - 1f) * -0.5f * ExternalCounterstrike.Overlay.Height
                };
                vec2 = vector2D;
            }
            return(vec2);
        }
Example #2
0
        public Vector3 EyeToWorldCoords(Vector4 eyeCoords)
        {
            Matrix4 inverseView      = ViewMatrix.Inverse();
            Vector4 worldCoords      = Vector4.Transform(eyeCoords, inverseView);
            Vector3 worldCoordsFinal = new Vector3(worldCoords.X, worldCoords.Y, worldCoords.Z);

            worldCoordsFinal = worldCoordsFinal.Normalize();

            return(worldCoordsFinal);
        }
        protected override void OnUpdate(TickEventArgs args)
        {
            base.OnUpdate(args);

            //Grab local player
            LocalPlayer.Reset();
            ViewMatrix.Reset();
            //GameRules.Reset();
            PlayerResources.Reset();
            ClientState.Reset();
            GameDirectory.Reset();

            BaseEntitites.Clear();
            PlayersOld.Clear();
            PlayersOld.CopyFrom(Players);
            Players.Clear();
            Weapons.Clear();

            //Load map
            if (ClientState.Value != null && ClientState.Value.Map.Value != null)
            {
                if (ClientState.Value.Map.Value != lastMap)
                {
                    var path = Path.Combine(GameDirectory.Value, ClientState.Value.Map.Value);
                    //try
                    //{
                    lastMap = ClientState.Value.Map.Value;
                    if (File.Exists(path))
                    {
                        using (var str = new FileStream(path, FileMode.Open, FileAccess.Read))
                        {
                            var bsp = new BSPFile(str);
                            Map = bsp;
                        }
                        //}catch(Exception ex)
                        //{
                        //    Program.Logger.Error("Failed to parse map \"{0}\": {1}", path, ex.Message);
                        //}
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        ///     Renders teh current controller to the renderControl.
        /// </summary>
        /// <param name="renderTarget">The render target.</param>
        /// <param name="swapChain">The swap chain.</param>
        /// <exception cref="System.ObjectDisposedException"></exception>
        private void renderControl_Render([NotNull] RenderTarget renderTarget, [NotNull] SwapChain swapChain)
        {
            IGraphics  graphics   = _directXGraphics;
            Controller controller = _activeController;

            if (graphics == null)
            {
                throw new ObjectDisposedException(nameof(Main));
            }

            renderTarget.BeginDraw();
            renderTarget.Transform = ViewMatrix.ToRawMatrix3x2();
            renderTarget.Clear(Color.White);

            lock (_lock)
                controller?.Draw(graphics);

            renderTarget.EndDraw();
            swapChain.Present(0, PresentFlags.None);
        }
Example #5
0
 public Vector WorldToScreen(Vector v)
 {
     return(ViewMatrix.Transform(v));
 }
Example #6
0
 public Point WorldToScreen(Point p)
 {
     return(ViewMatrix.Transform(p));
 }
 /// <summary>
 /// Transforms a point through the viewMatrix converting it from screen space to world space.
 /// </summary>
 /// <param name="position">The point to transform.</param>
 /// <returns>The provided point in the world.</returns>
 public virtual Vector2 ScreenToWorld(Vector2 position)
 {
     return(Vector2.Transform(position, ViewMatrix.Inverted()));
 }
Example #8
0
        public void Prepare()
        {
            var vp = ViewMatrix.PostMultiply(ProjectionMatrix);

            CullingFrustum.SetViewProjectionMatrix(vp);
        }
Example #9
0
 public Vector3 ToObjectPoint(Vector3 p)
 {
     return(Vector3.Transform(p, ViewMatrix.Inverted()));
 }