This site requires JavaScript, please enable it in your browser!
Greenfoot back
GRIFFIN
GRIFFIN wrote ...

2015/9/30

Vectors

GRIFFIN GRIFFIN

2015/9/30

#
Hey! I need some help understanding the basic functionality of Vectors in Greenfoot. I've programmed a lot in Greenfoot, but have never used this, and I couldn't really find any information about it. I just want to know the basic uses of it, and maybe some implementation besides the Asteroids game. ;) If there are any articles out there explaining this, please post links! Thanks for any help!
danpost danpost

2015/9/30

#
Generally speaking, vectors are used to represent distance and direction. These can be represented using Cartesian or Polar coordinate systems. Since they are just different ways of representation, using vectors is not necessary when programming. The main reason for using vectors is usually to provide an easy way to work with changes in movement when forces are involved. This is all fine and good except for the problem that any and all changes in a vector using the Polar coordinate system (adding or subtracting vectors together) requires the vectors to be converted to Cartesian system coordinates and, after the operation, converted back. As well, these operations require floating point operations. These actions are both a waste on CPU time (conversions) as well as an over-use of CPU time (using floats). That is one reason I created my QActor class for smooth moving and turning. It can be downloaded in my Zombie Shooter Demo or in my Asteroids w/improved QActor SuperClass scenarios. The class provides a way to track distance (pixels) and angle (degrees) in units of 100th their size (using int values).
GRIFFIN GRIFFIN

2015/10/1

#
So basically, Vectors allow for more accurate movement and rotation? I just don't understand how you use it, because in your Zombie scenario, I didn't even see the Vector class thing. I also don't understand why the 'force' behind the motion matters. I'm currently in physics right now in school, so I'm only just learning about this stuff.
danpost danpost

2015/10/1

#
GRIFFIN wrote...
So basically, Vectors allow for more accurate movement and rotation? I just don't understand how you use it, because in your Zombie scenario, I didn't even see the Vector class thing. I also don't understand why the 'force' behind the motion matters.
It is not vectors that allow for more accurate movement, it is the use of double (or floating point) values that give more accuracy in the Vector class. My QActor class does have an 'addForce(int, int)' method and a 'move(int, int)' method that both require a length and a direction, which is what a vector consists of. In fact, you could substitute the 'length' of a Vector object and the 'direction' of the same Vector object to represent those parameters. What I meant with 'force' is that an object (in reality) moves at a constant speed and direction unless acted on by an outside force (gravity and air resistance, for example, alter the flight of an object moving within the atmosphere of the earth -- gravity adds a force in a downward direction, causing the object to slow down when rising and fall after reaching its apex; air resistance add a force opposite the direction the object is moving, slowing it down, however slightly).
You need to login to post a reply.