private void GetFireParameters(out Vec3 pos, out Quat rot, out float speed)
        {
            Camera camera = RendererWorld.Instance.DefaultCamera;

            pos = catapult.Position + new Vec3(0, 0, .7f);

            Radian verticalAngle = new Degree(30).InRadians();

            rot   = Quat.Identity;
            speed = 0;

            if (catapultFiring)
            {
                Ray startRay = camera.GetCameraToViewportRay(catapultFiringMouseStartPosition);
                Ray ray      = camera.GetCameraToViewportRay(MousePosition);

                Plane plane = Plane.FromPointAndNormal(pos, Vec3.ZAxis);

                Vec3 startRayPos;
                if (!plane.RayIntersection(startRay, out startRayPos))
                {
                    //must never happen
                }

                Vec3 rayPos;
                if (!plane.RayIntersection(ray, out rayPos))
                {
                    //must never happen
                }

                Vec2 diff = rayPos.ToVec2() - startRayPos.ToVec2();

                Radian horizonalAngle = MathFunctions.ATan(diff.Y, diff.X) + MathFunctions.PI;

                SphereDir dir = new SphereDir(horizonalAngle, verticalAngle);
                rot = Quat.FromDirectionZAxisUp(dir.GetVector());

                float distance = diff.Length();

                //3 meters clamp
                MathFunctions.Clamp(ref distance, .001f, 3);

                speed = distance * 10;
            }
        }
        private bool GetGameAreaCursorPosition(out Vec2 position)
        {
            position = Vec2.Zero;

            Plane plane = new Plane(0, 0, 1, 0);

            Ray ray = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(
                EngineApp.Instance.MousePosition);

            if (float.IsNaN(ray.Direction.X))
            {
                return(false);
            }

            float scale;

            if (!plane.RayIntersection(ray, out scale))
            {
                return(false);
            }

            position = ray.GetPointOnRay(scale).ToVec2();
            return(true);
        }
Esempio n. 3
0
        //Draw minimap
        void Minimap_RenderUI( EControl sender, GuiRenderer renderer )
        {
            Rect screenMapRect = sender.GetScreenRectangle();

            Bounds initialBounds = Map.Instance.InitialCollisionBounds;
            Rect mapRect = new Rect( initialBounds.Minimum.ToVec2(), initialBounds.Maximum.ToVec2() );

            Vec2 mapSizeInv = new Vec2( 1, 1 ) / mapRect.Size;

            //draw units
            Vec2 screenPixel = new Vec2( 1, 1 ) / new Vec2( EngineApp.Instance.VideoMode.Size.ToVec2() );

            foreach( Entity entity in Map.Instance.Children )
            {
                RTSUnit unit = entity as RTSUnit;
                if( unit == null )
                    continue;

                Rect rect = new Rect( unit.MapBounds.Minimum.ToVec2(), unit.MapBounds.Maximum.ToVec2() );

                rect -= mapRect.Minimum;
                rect.Minimum *= mapSizeInv;
                rect.Maximum *= mapSizeInv;
                rect.Minimum = new Vec2( rect.Minimum.X, 1.0f - rect.Minimum.Y );
                rect.Maximum = new Vec2( rect.Maximum.X, 1.0f - rect.Maximum.Y );
                rect.Minimum *= screenMapRect.Size;
                rect.Maximum *= screenMapRect.Size;
                rect += screenMapRect.Minimum;

                //increase 1 pixel
                rect.Maximum += new Vec2( screenPixel.X, -screenPixel.Y );

                ColorValue color;

                if( playerFaction == null || unit.Intellect == null || unit.Intellect.Faction == null )
                    color = new ColorValue( 1, 1, 0 );
                else if( playerFaction == unit.Intellect.Faction )
                    color = new ColorValue( 0, 1, 0 );
                else
                    color = new ColorValue( 1, 0, 0 );

                renderer.AddQuad( rect, color );
            }

            //Draw camera borders
            {
                Camera camera = RendererWorld.Instance.DefaultCamera;

                if( camera.Position.Z > 0 )
                {

                    Plane groundPlane = new Plane( 0, 0, 1, 0 );

                    Vec2[] points = new Vec2[ 4 ];

                    for( int n = 0; n < 4; n++ )
                    {
                        Vec2 p = Vec2.Zero;

                        switch( n )
                        {
                        case 0: p = new Vec2( 0, 0 ); break;
                        case 1: p = new Vec2( 1, 0 ); break;
                        case 2: p = new Vec2( 1, 1 ); break;
                        case 3: p = new Vec2( 0, 1 ); break;
                        }

                        Ray ray = camera.GetCameraToViewportRay( p );

                        float scale;
                        groundPlane.RayIntersection( ray, out scale );

                        Vec3 pos = ray.GetPointOnRay( scale );
                        if( ray.Direction.Z > 0 )
                            pos = ray.Origin + ray.Direction.GetNormalize() * 10000;

                        Vec2 point = pos.ToVec2();

                        point -= mapRect.Minimum;
                        point *= mapSizeInv;
                        point = new Vec2( point.X, 1.0f - point.Y );
                        point *= screenMapRect.Size;
                        point += screenMapRect.Minimum;

                        points[ n ] = point;
                    }

                    for( int n = 0; n < 4; n++ )
                        renderer.AddLine( points[ n ], points[ ( n + 1 ) % 4 ], new ColorValue( 1, 1, 1 ),
                            screenMapRect );
                }
            }
        }
Esempio n. 4
0
        bool GetGameAreaCursorPosition( out Vec2 position )
        {
            position = Vec2.Zero;

            Plane plane = new Plane( 0, 0, 1, 0 );

            Ray ray = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(
                EngineApp.Instance.MousePosition );
            if( float.IsNaN( ray.Direction.X ) )
                return false;

            float scale;
            if( !plane.RayIntersection( ray, out scale ) )
                return false;

            position = ray.GetPointOnRay( scale ).ToVec2();
            return true;
        }