Vector2D AS3 Class

Custom class dependencies: Trig

Working with vectors – Part 1, Part 2, Part 3

This is my second post regarding my vector class quest. The first post was about the utility that I decided to create for all those very useful trigonometric functions that are always popping up in almost every complex piece of code and game development.

The second step is to extend the built-in class of flash.geom.Point. This is because I need all the things this class already has, and I don’t want to reinvent the wheel. Second, I import my newly created Trig utility that I will be using extensively in this vector class.

The basic concept is this…
You have a point on the stage, that has an X and a Y coordinate. All I have done is extended that point to also have an angle property. With this property it can be moved with a distance or magnitude by trigonometric functions such as SIN and COS.

This is how these simple “move” methods work. They simply build on each other, but the basis is from those old 8th grade(ish) concepts from math class.

What I have also done in this class is corrected the degree values for the angle property. Unlike rotation, which in Actionscript, is in degrees, though can be negative, and is unclamped. This means it can be all to easy to hit the max numeric absolute value for rotation. What this class does is makes sure no matter what value you set the angle at, it always corrects the value to a normal 0 to 360 number. This can be turned on or off through another Boolean property called “correctDegrees”. Keeping it a flag is good, because sometimes it is very useful and even a necessity for degrees to be negative and unclamped.

In the end, now we have a new Vector Point class that has no visual representation but virtually does everything a vector should do.

Comment if you have any questions, or suggestions.


Posted

in

, ,

by

Comments

5 responses to “Vector2D AS3 Class”

  1. Mark A. Avatar
    Mark A.

    if you provide a class you should also include other dependencies. your com.jidd.utils.Trig class is not part of your download. this class should work on it's own, anyways.

    1. jimisaacs Avatar

      Seriously, it is one thing to tell me how to write code, because we all have different ideas, practices, and we are all entitled to their opinions.

      It is another thing to tell me how to provide code.

      Providing free source code out of my personal library isn't my day job you know? I provided links to the dependencies, to the ONE dependency, that is enough. If tracking down a couple files is too much work for somebody to figure out, I really don't care anymore. You sound like a kid who just received a sandwich, and you're asking me to remove your crust.

  2. Me and my self Avatar
    Me and my self

    I can feel the love … lol

  3. […] Finally, I Gave InVector2D AS3 Class » Trig AS3 ClassPosted by: Jim IsaacsJune27th2008 Custom class dependencies: NoneWorking […]

  4. […] Class » VectorClip AS3 ClassPosted by: Jim IsaacsAugust7th2008 Custom class dependencies: Vector2DWorking with vectors – Part 1, Part 2, Part 3So far everything done in the series […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.