• The function surface.DrawLine does not draw the lines the way I want to
    6 replies, posted
So, the thing is that I'm drawing four lines instead of one. Here is the red circle, where the drawing ends in the current iteration. [url]https://drive.google.com/open?id=0B6vgydhudtoAUTFrVkZzSXRYN3M[/url] Remember when the point is not located in the screen, it's not drawn. ( I am using Position:ToScreen() to the star and the end points ) Well, I was hoping if I make smaller segments, when I cover one segment, the others can be drawn, that do not have covered points. I am using the same method for drawing circles and when you cover the part of the circle like so, It is drawn: [url]https://drive.google.com/open?id=0B6vgydhudtoAZUlCNTh6MEVpODQ[/url] I think its maybe surface.DrawLine's fault, as the tangent of delta X and Y produce the same starting angle or something. That will explain why am I able to draw a circle using line segments ( Well 250 of them to be exact ), but when cover some of them the others are drawn as the angle tangent is different in every iteration [code] -- Draw a line from start to end using key "b" ( blue ) from the palette with line segments in 4 iterations Monitor:DrawLine(Start,End,"b","LIN",{4}) -- Draw a circle at origin "Op" using key "y" ( yellow ) from the palette with line segments in 250 iterations Monitor:DrawCircle(Op, mR,"y","LIN",{250}) function self:SetColor(keyColor) ----- Sets the drawing color for text and lines if(not keyColor) then return end local keyColor = keyColor or ColorKey; ColorKey = keyColor local rgbColor = (Palette and keyColor) and Palette:Select(keyColor) or White surfaceSetDrawColor(rgbColor.r, rgbColor.g, rgbColor.b, rgbColor.a) surfaceSetTextColor(rgbColor.r, rgbColor.g, rgbColor.b, rgbColor.a) end function self:Enclose(xyPnt) ------------ Checks that the point is in the screen if(xyPnt.x < sW) then return -1 end if(xyPnt.x > eW) then return -1 end if(xyPnt.y < sH) then return -1 end if(xyPnt.y > eH) then return -1 end return 1 end function self:DrawLine(xyS,xyE,keyColor,sMeth,tArg) --------- Draws a line if(not (xyS and xyE)) then return end if(not (xyS.x and xyS.y and xyE.x and xyE.y)) then return end if(self:Enclose(xyS) == -1 or self:Enclose(xyE) == -1) then return end local sdrwMeth = tostring(sMeth or "API") if(sdrwMeth == "API") then self:SetColor(keyColor) surfaceDrawLine(xyS.x,xyS.y,xyE.x,xyE.y) ------- Look here calling the method type above for circle and line elseif(sdrwMeth == "LIN") then local nIter = tonumber(tArg[1]) or 0 if(nIter <= 0) then return end local nLx, nLy = (xyE.x - xyS.x), (xyE.y - xyS.y) local xyD = {x = (nLx / nIter), y = (nLy / nIter)} local xyOld, xyNew = {x = xyS.x, y = xyS.y}, {x = 0,y = 0} while(nIter > 0) do xyNew.x = xyOld.x + xyD.x xyNew.y = xyOld.y + xyD.y self:DrawLine(xyOld,xyNew,keyColor) surfaceDrawCircle(xyNew.x, xyNew.y, 10, Color(255,0,0)) xyOld.x, xyOld.y = xyNew.x, xyNew.y nIter = nIter - 1; end end end function self:DrawCircle(xyPos,nRad,keyColor,sMeth,tArg) ------ Draws a circle local sdrwMeth = tostring(sMeth or "API") local keyColor = keyColor or ColorKey; ColorKey = keyColor local rgbColor = (Palette and keyColor) and Palette:Select(keyColor) or White if(sdrwMeth == "API") then surfaceDrawCircle(xyPos.x, xyPos.y, nRad, rgbColor) elseif(sdrwMeth == "LIN") then local nIter = tonumber(tArg[1]) or 0 if(nIter <= 0) then return end local nCurAng = 0 local nMaxRot = (GetOpVar("MAX_ROTATION") * mathPi / 180) local nItStep = nMaxRot / nIter local xyOld, xyNew, xyRad = {x=0,y=0}, {x=0,y=0}, {x=nRad,y=0} xyOld.x = xyPos.x + xyRad.x xyOld.y = xyPos.y + xyRad.y while(nIter > 0) do nCurAng = nCurAng + nItStep local nSin, nCos = mathSin(nCurAng), mathCos(nCurAng) xyNew.x = xyPos.x + (xyRad.x * nCos - xyRad.y * nSin) xyNew.y = xyPos.y + (xyRad.x * nSin + xyRad.y * nCos) self:DrawLine(xyOld,xyNew,keyColor) ----- Draw the segment xyOld.x, xyOld.y = xyNew.x, xyNew.y nIter = nIter - 1; end end end [/code] Do you have any Idea why this happens ? Best regards !
:snip:
Is anyone there ?
[QUOTE=dvd_video;50099545]Is anyone there ?[/QUOTE] Maybe talking to myself right now, but nobody seems to interest anyway ...
I haven't looked into your code, by why not use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/DrawLine]render.DrawLine[/url] instead of surface? Since you're doing it for 3D space anyway.
[QUOTE=NeatNit;50464362]I haven't looked into your code, by why not use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/DrawLine]render.DrawLine[/url] instead of surface? Since you're doing it for 3D space anyway.[/QUOTE] Is it going to be more demanding ? Surface seems rather simple ...
it's going to look exactly the same except it would actually work. And no, i don't think it's more demanding, even if it was it would still be negligible compared to rendering as a whole.
Sorry, you need to Log In to post a reply to this thread.