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.
com.jimisaacs.geom.Vector2D
Comment if you have any questions, or suggestions.
Leave a Reply