0
\$\begingroup\$

I am currently drawing objects and it works perfectly, when i make x bigger the objects go right and when i make x lower they go left perfect, but when i make y bigger the object goes down and when i make y lower it goes up, i am having problems discovering the part of the code that is making y inverted.

This is the code that i use to initialize:

    static public BitmapManager bitmapManager;
    static public Maze CurrentScene;
    static public Sound.Sound Sound;
    static public InputManager Input;
    static public Renderer renderer;
    static public Point WindowPosition;
    static public Size WindowSize;
    static public GameTime gameTime;
    static public float DeltaTime;
    static public Hierarchy hierarchy;

    static internal RenderForm form;

    static private Device device;
    static private SwapChain swapChain;
    static private Stopwatch stopwatch;
    static private Thread UpdateThread;

    static public void Initialize(Size size)
    {
        GC.Collect();

        form = new RenderForm();
        form.StartPosition = FormStartPosition.CenterScreen;
        form.ClientSize = new System.Drawing.Size((int)size.Width, (int)size.Height);
        form.MaximizeBox = false;
        form.FormBorderStyle = FormBorderStyle.FixedSingle;
        form.FormClosed += form_FormClosed;

        SwapChainDescription SCDescription = new SwapChainDescription()
        {
            BufferCount = 1,
            ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
            IsWindowed = true,
            OutputHandle = form.Handle,
            SampleDescription = new SampleDescription(1, 0),
            SwapEffect = SwapEffect.Discard,
            Usage = Usage.RenderTargetOutput
        };

        Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, SCDescription, out device, out swapChain);

        Factory2D d2dFactory = new Factory2D();

        Factory factory = swapChain.GetParent<Factory>();
        factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);

        Texture2D backBuffer = Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0);
        RenderTargetView RenderView = new RenderTargetView(device, backBuffer);

        Surface surface = backBuffer.QueryInterface<Surface>();

        RenderTarget RenderTarget2D = new RenderTarget(d2dFactory, surface, 
                                                       new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));

        form.SizeChanged += Form_SizeChanged;
        form.GotFocus += Form_GetFocus;
        form.LostFocus += Form_LostFocus;
        form.Move += Form_Move;

        WindowPosition = new Point(form.Location.X + SystemInformation.FixedFrameBorderSize.Width + SystemInformation.DragSize.Width,
                                   form.Location.Y + SystemInformation.FixedFrameBorderSize.Height + SystemInformation.CaptionHeight + SystemInformation.DragSize.Height);

        WindowSize = size;
        renderer = new Renderer(RenderTarget2D);
        Input = new InputManager();
        Sound = new Sound.Sound();
        bitmapManager = new BitmapManager(RenderTarget2D);

        hierarchy = new Hierarchy();

        gameTime = new GameTime();
        stopwatch = new Stopwatch();
        stopwatch.Start();
    }

and this is the code i use to render:

RawMatrix3x2 CurrentTransform = renderTarget.Transform;
Sprite NewSprite = Component as Sprite;
Bitmap Texture = Game.bitmapManager.GetTexture(NewSprite.texture.TexturePath);
RawRectangleF PositionRectangle = new Rectangle(new Point(0, 0), new Size(NewSprite.texture.TextureSize * Zoom)).ToRawRectangleF();
float Transparency = NewSprite.Transparency;
RawRectangleF ImageRectangle = new Rectangle(new Point(0, 0), new Size(NewSprite.texture.TextureSize * Zoom)).ToRawRectangleF();
Vector2 NewScale = (Vector2)Gameobject.transform.Scale;
Matrix3x2 Translation = Matrix3x2.Translation((Vector2)Gameobject.transform.Position);
Matrix3x2 Rotation = Matrix3x2.Rotation(Gameobject.transform.Rotation.X);
Matrix3x2 Scale = Matrix3x2.Scaling((Vector2)Gameobject.transform.Scale);
renderTarget.Transform = (Translation * Rotation * Scale).ToRawMatrix3x2();
renderTarget.DrawBitmap(Texture, PositionRectangle, Transparency, BitmapInterpolationMode.NearestNeighbor, ImageRectangle);
renderTarget.Transform = CurrentTransform;

If you need anything else please warn me

\$\endgroup\$
0
\$\begingroup\$

You haven't done anything wrong, the direct2d coordinate space origin is in the upper left and the y axis increases downward. From the direct2d documentation:

Direct2D uses a left-handed coordinate space; that is, positive x-axis values increase to the right and positive y-axis values increase downward. Everything on the screen is positioned relative to the origin, which is the point where the x-axis and y-axis intersect (0, 0), as shown in the following illustration. Direct2D render targets use this coordinate space.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thank you for the answer, i will accept, but if you know how i can make when y-axis increased go upward i would appreciate. \$\endgroup\$ – Maze Mar 2 '18 at 22:39
  • \$\begingroup\$ @Maze Sorry but I'm not aware of a way to do this; all I came across was this forum discussion where a negative scaling matrix is suggested but it seems to be implied in the last post that this isn't allowed. \$\endgroup\$ – Foggzie Mar 2 '18 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.