Jump to content

dxDrawImage rotation 90*


Tekken

Recommended Posts

Posted

Hi,  I’m trying to make a "tetris" inventory like DayZ/Tarkov/RE4 where you have say 10x5 squares and you have to carefully place items so you optimize your space, the problem is I want to be able to turn items by 90degree so you can take better advantage of the space, all good other than actually drawing the image, I can’t seem to figure out what the rotation offet x and y should be, also note that Items will have different sizes like 1x2 2x3 4x1 etc..

 

You guys have any idea?

Posted
function rotatePos(x, y, w, h, rot)
    local cx = x + w / 2
    local cy = y + h / 2
    local ox = x - cx
    local oy = y - cy

    local rad = math.rad(rot)
    local cos = math.cos(rad)
    local sin = math.sin(rad)

    local nx = cx + ox * cos - oy * sin
    local ny = cy + ox * sin + oy * cos

    return nx, ny
end

--use
local iW = -- item width
local iH = -- item height
local iX = -- item x position
local iY = -- item y position
local rot = 90 -- rotation

local rX, rY = rotatePos(iX, iY, iW, iH, rot)
dxDrawImage(rX, rY, iW, iH, "item.png", rot)

 

  • Like 1
Posted

Thanks but it ain't working as intended

https://imgur.com/a/PPAESu5

Desired should be centered in the gray rectangle:

My code:

local sW, sH = guiGetScreenSize();
local slotSize = 60;
local id, itm, x, y, iw, ih, rot = unpack(draging); --gather data
local r = 0;
local cx, cy = getCursorPosition();
local cx, cy = (cx*sW), (cy*sH);
local w, h = slotSize*iw, slotSize*ih;
if rot then
  r = 90;
end
local rX, rY = rotatePos(cx, cy, w, h, r);
dxDrawImage(rX, rY, w, h, itm..".png", r);

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...