somebody621
Member
|
Put me in for collision detection/physics/as3, even though nobody here probably cares about those subjects, cause I come here a lot, just feel too lazy to post. If I see some question that spurs my interest, I'll answer. Not trying to brag, I've done a whole ton of AS3, so I can answer some questions on that too. I might submit some code soon too... Probably will do the rectangle-rectangle SAT collision detection, and maybe circle-line sweep testing. Edit: Heck, some code just for the fact it's a new thread. It's a vector class, used mostly for motion. public class Vector { public var x:Number; public var y:Number; public function Vector(functionX:Number, functionY:Number):void { x = functionX; y = functionY; } //get a copy of the vector public function getCopy():Vector{ return new Vector(x, y); } //get the direction of the vector public function getDir():Number{ return Math.atan2(y, x); } //get the length of the vector public function getMag():Number{ return Math.sqrt(x * x + y * y); } //get the length squared public function getMagSq():Number{ return x*x+y*y; } //add this vector with another public function add (vector:Vector):void{ x += vector.x; y += vector.y; } //return this vector added to another public function addNew (vector:Vector):Vector{ return new Vector(vector.x + x, vector.y + y); } //subtract another vector from this public function subtract (vector:Vector):void{ x -= vector.x; y -= vector.y; } //return another vector subtracted from this public function subtractNew (vector:Vector):Vector{ return new Vector(x - vector.x, y - vector.y); } //scale this vector by a number public function multiply (scalar : Number):void{ x *= scalar; y *= scalar; } //return this vector scaled by a number public function multiplyNew (scalar : Number):Vector{ return new Vector(x*scalar, y*scalar); } //divide this vector by a scalar-effects the scale public function divide (scalar : Number):void{ if(scalar == 0) throw new Error("Cannot divide by zero"); x /= scalar; y /= scalar; } //return this vector divided by a scalar public function divideNew (scalar : Number):Vector{ if(scalar == 0) throw new Error("Cannot divide by zero"); return new Vector(x/scalar, y/scalar); } //return the dotproduct of this vector and another public function dotProduct(vector : Vector):Number{ return x * vector.x + y * vector.y; } //turn this into a unit vector, which is a vector with a length of one public function normalize():void{ var vLen:Number = getMag(); if(vLen==0) throw new Error("Vector cannot be normalized; It is a zero length Vector"); x /= vLen; y /= vLen; } //return the unit vector of this public function unit():Vector{ var vLen:Number = getMag(); if(vLen==0) throw new Error("Vector cannot be normalized; It is a zero length Vector"); return new Vector(x/vLen, y/vLen); } //set the vector public function setTo(xToSet:Number, yToSet:Number):void{ x = xToSet; y = yToSet; } //multiply by a matrix public function matrixMultiply(m:Matrix2D):void{ var tmpX:Number=x; x=m.i1j1*x+m.i2j1*y; y=m.i2j1*tmpX+m.i2j2*y; } //multiply by a matrix and return the vector; public function matrixMultiplyNew(m:Matrix2D):Vector{ return new Vector(m.i1j1*x+m.i1j2*y, m.i2j1*x+m.i2j2*y); } public function getInv():Vector{ return multiplyNew(-1); } public function toString():String{ return ("("+x+", "+y+")"); } }
< Message edited by somebody621 -- 8/9/2007 23:31:59 >
|