2D-Vector class library

Showcase your libraries, tools and other projects that help your fellow love users.
blackops7799
Prole
Posts: 13
Joined: Mon Apr 19, 2010 4:30 pm

2D-Vector class library

Post by blackops7799 »

I was making a physics based pong game so I came up with this class library.

It allows you to use vectors like so in the code below.

Code: Select all

	--I used this within a collision callback for my pong game
	local velx, vely = coll:getVelocity()
	local IncidentVec = Vector.new( velx, vely )
	local speed = IncidentVec:Length()
	local colx, coly = coll:getNormal()
	local Normal = Vector.new( colx, coly )
	Normal:Normalize()
	
	local DotProduct = Normal:Dot( IncidentVec * -1 ) --reflect the bounce
	local Dir = ( 2 * Normal * DotProduct ) + IncidentVec
	Dir:Normalize()
	
	someBodyObject:setLinearVelocity( Dir.x * speed, Dir.y * speed )
It just makes things a lot simpler, organized, and easy to read. Sorry if there is already something like this here, but I searched and didn't find anything.

Enjoy!

Demo:
http://www.blackopsservers.com/blackops ... _demo.love
Demo shows a ball continuously bouncing around on your screen.
Press space to reset the ball and randomly punt it again.
Attachments
vector.lua
2D-Vector class library
(4.54 KiB) Downloaded 369 times
Last edited by blackops7799 on Wed Apr 21, 2010 7:28 pm, edited 4 times in total.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: 2D-Vector class library

Post by nevon »

I can tell you're new here. Libraries and other useful snippets of code are required to have a NSFW name.
blackops7799
Prole
Posts: 13
Joined: Mon Apr 19, 2010 4:30 pm

Re: 2D-Vector class library

Post by blackops7799 »

That's pretty stupid. Shows the maturity of this place.
Umbrageous
Prole
Posts: 8
Joined: Sat Apr 10, 2010 5:45 pm

Re: 2D-Vector class library

Post by Umbrageous »

Nah, I see it as kind of fun, not everything has to be serious you know, The best part is the nsfw name lol.
But This is really cool, and pretty useful too
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: 2D-Vector class library

Post by bmelts »

I think nevon may have been being a tad facetious :ehem:
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: 2D-Vector class library

Post by Jasoco »

As hard as I think, I can't come up with a clever NSFW name for this library. Anyone else?

Also, is MiddleClass and MindState the exceptions to this silly rule? ;)
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: 2D-Vector class library

Post by bmelts »

Vectors Are Great
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: 2D-Vector class library

Post by bartbes »

blackops7799 wrote:That's pretty stupid. Shows the maturity of this place.
Maturity is overrated.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: 2D-Vector class library

Post by nevon »

blackops7799 wrote:That's pretty stupid. Shows the maturity of this place.
I know it can be kind of hard to tell what's serious or not on the internet, but geez!

At least Anjo got it. :ehem:
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: 2D-Vector class library

Post by kikito »

Jasoco wrote:As hard as I think, I can't come up with a clever NSFW name for this library. Anyone else?

Also, is MiddleClass and MindState the exceptions to this silly rule? ;)
Well, PÄSSION is also quite SFW, IMHO. OMG BBQ.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests