Author |
Message |
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
DrawLine()
haha just kidding but really: Code: function plot(a,b) local pixel = CreateMOPixel("Line Particle"); pixel.Pos = Vector(a,b); MovableMan:AddParticle(pixel); end function line(x0, x1, y0, y1) if math.abs(y1-y0) > math.abs(x1-x0) then steep = true; end if steep == true then x0,y0,x1,y1 = y0,x0,y1,x1; end if x0 > x1 then x0,x1,y0,y1 = x1,x0,y1,y0; end deltax = x1 - x0; deltay = math.abs(y1 - y0); xerror = deltax / 2 y = y0; if y0 < y1 then ystep = 1; else ystep = -1; end for x=x0,x1 do if steep == true then plot(y,x); else plot(x,y); end xerror = xerror - deltay; if xerror < 0 then y = y + ystep; xerror = xerror + deltax; end end end
|
Tue Sep 22, 2009 12:52 am |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: DrawLine()
I know just how to express my opinion on this;
|
Tue Sep 22, 2009 12:58 am |
|
|
ProjektTHOR
Banned
Joined: Tue Feb 27, 2007 4:05 pm Posts: 2527
|
Re: DrawLine()
Its how to draw a line with Lua.
|
Tue Sep 22, 2009 1:40 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: DrawLine()
More specifically it's Bresenham's line algorithm, in Lua. http://en.wikipedia.org/wiki/Bresenham_line_algorithm
|
Tue Sep 22, 2009 1:43 am |
|
|
zalo
Joined: Sat Feb 03, 2007 7:11 pm Posts: 1496
|
Re: DrawLine()
It works fairly kinda well. As you can see here, a Bersenham-Grappling gun splice shows fairly well (Edited for MOSParticle Main thruster blast ball at Lifetime 10). But here and here you can see that it oddly doesn't connect when I move out of an invisible area. Anyway, do the formula for plotting trajectory, and we have a deal. So you don't have to go through the effort of combining them together yourself to test.
Attachments:
File comment: Kyred and Roon3, Hope you don't mind.
Grapple.rte.rar [31.62 KiB]
Downloaded 187 times
|
Tue Sep 22, 2009 4:09 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: DrawLine()
Yeah, I think one of the line slopes isn't quite right, since it's designed for a four-quadrant system.
Need to fix it.
|
Tue Sep 22, 2009 4:54 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: DrawLine()
Now if only Lua had support for derivatives and integrals, then I'd be happy:P.
|
Tue Sep 22, 2009 7:18 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: DrawLine()
they are. you just have to write a function to do them yourself i do love my calculus though. this could be made more efficient by using the velocity of a mopixel to make it have a longer trail.
|
Wed Sep 23, 2009 7:06 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: DrawLine()
Geti wrote: they are. you just have to write a function to do them yourself i do love my calculus though. this could be made more efficient by using the velocity of a mopixel to make it have a longer trail. Ugh...I really do not want to write a Riemann Sum script for Lua. Wouldn't be so bad if it were in C/C++, but not Lua. Same goes for Newton's Method for derivitives.
|
Thu Sep 24, 2009 1:43 am |
|
|
Daman
Joined: Fri Jan 26, 2007 3:22 am Posts: 1451
|
Re: DrawLine()
Kyred wrote: Geti wrote: they are. you just have to write a function to do them yourself i do love my calculus though. this could be made more efficient by using the velocity of a mopixel to make it have a longer trail. Ugh...I really do not want to write a Riemann Sum script for Lua. Wouldn't be so bad if it were in C/C++, but not Lua. Same goes for Newton's Method for derivitives. riemann sums have absolutely nothing to do with this look guys i can spew off buzzwords derp derp derivative factors of polynomial ellipsis using sigma additivity
|
Thu Sep 24, 2009 3:35 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: DrawLine()
Daman wrote: Kyred wrote: Geti wrote: they are. you just have to write a function to do them yourself i do love my calculus though. this could be made more efficient by using the velocity of a mopixel to make it have a longer trail. Ugh...I really do not want to write a Riemann Sum script for Lua. Wouldn't be so bad if it were in C/C++, but not Lua. Same goes for Newton's Method for derivitives. riemann sums have absolutely nothing to do with this look guys i can spew off buzzwords derp derp derivative factors of polynomial ellipsis using sigma additivity A Riemann Sum is used to approximate an integral. Newton's method is used to approximate a derivative. Using either of these in Lua, you could adapt the DrawLine() method to efficiently drawing something such as a parabola, something that would be useful for showing the path a projectile will fly before you fire it. So actually, Riemann Sums do have something to do with this.
|
Thu Sep 24, 2009 4:19 am |
|
|
ProjektTHOR
Banned
Joined: Tue Feb 27, 2007 4:05 pm Posts: 2527
|
Re: DrawLine()
I think his point was "Stop being a Wikipedia scholar."
|
Thu Sep 24, 2009 4:46 am |
|
|
Daman
Joined: Fri Jan 26, 2007 3:22 am Posts: 1451
|
Re: DrawLine()
Kyred wrote: A Riemann Sum is used to approximate an integral. Newton's method is used to approximate a derivative. Using either of these in Lua, you could adapt the DrawLine() method to efficiently drawing something such as a parabola, something that would be useful for showing the path a projectile will fly before you fire it.
So actually, Riemann Sums do have something to do with this. uh nope it doesn't because you'd be a fucking idiot to use riemann sums to draw a trajectory you don't find the area under a curve to draw a trajectory sorry you're completely wrong
|
Thu Sep 24, 2009 5:21 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: DrawLine()
Daman wrote: Kyred wrote: A Riemann Sum is used to approximate an integral. Newton's method is used to approximate a derivative. Using either of these in Lua, you could adapt the DrawLine() method to efficiently drawing something such as a parabola, something that would be useful for showing the path a projectile will fly before you fire it.
So actually, Riemann Sums do have something to do with this. uh nope it doesn't because you'd be a fucking idiot to use riemann sums to draw a trajectory you don't find the area under a curve to draw a trajectory sorry you're completely wrong You can integrate velocity with respect to time to get a position function. The physics equation y = y0 + y0*t + 1/2*a*t^2 is created this way (integrate v = v0 + at with respect to 't'), which is an equation for trajectory when 'a' is negative. Plug in a projectile's velocity function into the integrand, and you will get a basic parabola to model the trajectory. Then you can use the line algorithm to draw the trajectory. ProjektTHOR wrote: I think his point was "Stop being a Wikipedia scholar." For the record, I am currently in my 4th (and last ) semester of calculus, and will be taking differential equations after that. I typed out all this from memory, since I am forced to use some of this stuff on almost a daily basis.
|
Thu Sep 24, 2009 6:04 am |
|
|
piipu
Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
|
Re: DrawLine()
For the record, for loops can be used to calculate trajectories by using the s = s0 + v0 * t + 1/2 * a * t² formula thingy:
|
Thu Sep 24, 2009 8:53 am |
|
|
|