Tic-80: How make fully rotated textri sprite

Created on 27 Feb 2018  路  1Comment  路  Source: nesbox/TIC-80

I don't understand, what function i should use.

Most helpful comment

here is rspr function from the demo https://tic.computer/play?cart=234

-- rotating thingy 
function rspr(sx,sy,scale,angle,mx,my,mw,mh,key,useMap)

  --  this is fixed , to make a textured quad
  --  X , Y , U , V
  local sv ={{-1,-1, 0,0},
             { 1,-1, 0.999,0},
             {-1,1,  0,0.999},
             { 1,1,  0.999,0.999}}

    local rp = {} --  rotated points storage

  --  the scale is mw ( map width ) * 4 * scale 
  --  mapwidth is * 4 because we actually want HALF width to center the image
  local scalex = (mw<<2) * scale
  local scaley = (mh<<2) * scale
  --  rotate the quad points
  for p=1,#sv do 
    -- apply scale
    local _sx = sv[p][1] * scalex 
        local _sy = sv[p][2] * scaley
    -- apply rotation
        local a = -angle
        local rx = _sx * math.cos(a) - _sy * math.sin(a)
        local ry = _sx * math.sin(a) + _sy * math.cos(a)
    -- apply transform
    sv[p][1] = rx + sx
    sv[p][2] = ry + sy
    -- scale UV's 
    sv[p][3] = (mx<<3) + (sv[p][3] * (mw<<3))
    sv[p][4] = (my<<3) + (sv[p][4] * (mh<<3))
  end
  -- draw two triangles for the quad
  textri( sv[1][1],sv[1][2],
          sv[2][1],sv[2][2],
          sv[3][1],sv[3][2],
          sv[1][3],sv[1][4],
          sv[2][3],sv[2][4],
          sv[3][3],sv[3][4],
          useMap,key)

  textri( sv[2][1],sv[2][2],
          sv[3][1],sv[3][2],
          sv[4][1],sv[4][2],
          sv[2][3],sv[2][4],
          sv[3][3],sv[3][4],
          sv[4][3],sv[4][4],
          useMap,key)
end

hope it'll help you

>All comments

here is rspr function from the demo https://tic.computer/play?cart=234

-- rotating thingy 
function rspr(sx,sy,scale,angle,mx,my,mw,mh,key,useMap)

  --  this is fixed , to make a textured quad
  --  X , Y , U , V
  local sv ={{-1,-1, 0,0},
             { 1,-1, 0.999,0},
             {-1,1,  0,0.999},
             { 1,1,  0.999,0.999}}

    local rp = {} --  rotated points storage

  --  the scale is mw ( map width ) * 4 * scale 
  --  mapwidth is * 4 because we actually want HALF width to center the image
  local scalex = (mw<<2) * scale
  local scaley = (mh<<2) * scale
  --  rotate the quad points
  for p=1,#sv do 
    -- apply scale
    local _sx = sv[p][1] * scalex 
        local _sy = sv[p][2] * scaley
    -- apply rotation
        local a = -angle
        local rx = _sx * math.cos(a) - _sy * math.sin(a)
        local ry = _sx * math.sin(a) + _sy * math.cos(a)
    -- apply transform
    sv[p][1] = rx + sx
    sv[p][2] = ry + sy
    -- scale UV's 
    sv[p][3] = (mx<<3) + (sv[p][3] * (mw<<3))
    sv[p][4] = (my<<3) + (sv[p][4] * (mh<<3))
  end
  -- draw two triangles for the quad
  textri( sv[1][1],sv[1][2],
          sv[2][1],sv[2][2],
          sv[3][1],sv[3][2],
          sv[1][3],sv[1][4],
          sv[2][3],sv[2][4],
          sv[3][3],sv[3][4],
          useMap,key)

  textri( sv[2][1],sv[2][2],
          sv[3][1],sv[3][2],
          sv[4][1],sv[4][2],
          sv[2][3],sv[2][4],
          sv[3][3],sv[3][4],
          sv[4][3],sv[4][4],
          useMap,key)
end

hope it'll help you

Was this page helpful?
0 / 5 - 0 ratings