Skip to content

Commit

Permalink
update quad
Browse files Browse the repository at this point in the history
  • Loading branch information
thisdp committed Mar 24, 2024
1 parent 64b513c commit 33765cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
6 changes: 5 additions & 1 deletion plugin/BasicShape/quadrilateral.fx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// 定义四边形的四个顶点
float4x2 vertices = {
0,0,
0,0,
Expand All @@ -8,6 +7,7 @@ float4x2 vertices = {
float4 color = float4(1,1,1,1);
float borderSoft = 0.01;
float4 UV = float4(0,0,1,1);
float4 isRelative = 0;
float textureRot = 0;
float rotation = 0;
float2 textureRotCenter = float2(0.5,0.5);
Expand Down Expand Up @@ -71,6 +71,10 @@ float4 checkPointInQuad(float2 tex:TEXCOORD0,float4 _color:COLOR0):COLOR0{
nVertices[3].y *= a;
nBorderSoft *= dd.x;
}
nVertices[0] = isRelative.x==1?nVertices[0]:nVertices[0]*dd;
nVertices[1] = isRelative.y==1?nVertices[1]:nVertices[1]*dd;
nVertices[2] = isRelative.z==1?nVertices[2]:nVertices[2]*dd;
nVertices[3] = isRelative.w==1?nVertices[3]:nVertices[3]*dd;
float2 d1 = nVertices[1] - nVertices[0];
float2 d2 = nVertices[2] - nVertices[1];
float2 d3 = nVertices[3] - nVertices[2];
Expand Down
30 changes: 28 additions & 2 deletions plugin/BasicShape/quadrilateral.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ function requestQuadShader()
return str
end

function dgsCreateQuad(points,color,texture)
function dgsCreateQuad(vertices,color,texture)
if type(vertices) ~= "table" then error(dgsGenAsrt(vertices,"dgsCreateQuad",1,"table")) end
local quad = dxCreateShader(requestQuadShader())
if not quad then return false end
dxSetShaderValue(quad,"vertices",points)
dxSetShaderValue(quad,"sourceTexture",DGSBuiltInTex.white_1x1)
dgsSetData(quad,"asPlugin","dgs-dxquad")
dgsQuadSetVertices(quad,vertices)
dgsQuadSetColorOverwritten(quad,true)
dgsQuadSetTexture(quad,texture)
dgsQuadSetColor(quad,color or tocolor(255,255,255,255))
Expand All @@ -42,6 +43,31 @@ function dgsQuadGetTexture(quad)
return dgsElementData[quad].sourceTexture
end

function dgsQuadSetVertices(quad,vertices)
if not(dgsGetPluginType(quad) == "dgs-dxquad") then error(dgsGenAsrt(quad,"dgsQuadSetVertices",1,"plugin dgs-dxquad")) end
if dgsGetType(vertices) ~= "table" then error(dgsGenAsrt(vertices,"dgsQuadSetVertices",2,"table")) end
local oldVertices = dgsElementData[quad].vertices
local _ve,_re = {},{}
local t = {}
for i=1,4 do
vertices[i] = vertices[i] or oldVertices[i]
vertices[i][1] = tonumber(vertices[i][1]) or 0
vertices[i][2] = tonumber(vertices[i][2]) or 0
vertices[i][3] = vertices[i][3] ~= false
_ve[i*2-1],_ve[i*2] = vertices[i][1],vertices[i][2]
_re[i] = vertices[i][3] and 1 or 0
end
dxSetShaderValue(quad,"vertices",_ve)
dxSetShaderValue(quad,"isRelative",_re)
dgsSetData(quad,"vertices",vertices)
return true
end

function dgsQuadGetVertices(quad)
if not(dgsGetPluginType(quad) == "dgs-dxquad") then error(dgsGenAsrt(quad,"dgsQuadGetVertices",1,"plugin dgs-dxquad")) end
return dgsElementData[quad].vertices
end

function dgsQuadSetTextureRotation(quad,rot,rotCenterX,rotCenterY)
if not(dgsGetPluginType(quad) == "dgs-dxquad") then error(dgsGenAsrt(quad,"dgsQuadSetTextureRotation",1,"plugin dgs-dxquad")) end
if not(type(rot) == "number") then error(dgsGenAsrt(rot,"dgsQuadSetTextureRotation",2,"number")) end
Expand Down

0 comments on commit 33765cd

Please sign in to comment.