Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vectors are really simple. They are simply arrows marking something like a position, speed or acceleration. In this case, however, they simply mark our position. We write a vector like so: (x, y). Seem familiar? Now, for figure 1, imagine that you are walking on an open field.
- You start at the top left and walk straight right. Your new position is now marked by the vector [A]. We are now standing at the tip of the arrow. The arrow indicates how we moved. Now we turn about 40 degrees to the right and keep walking. This is represented by the vector [B]. However, unlike before, [B] does not mark your location. [A]+[B] does. That is why we write [A]+[B]=[C]. We would write that as
- (5, 0)+(3, 4)=(8, 4).
- The same also works in figure 2. (5, 0)+(-4, 3)=(1, 3). We simply add all the Xs together and all the Ys together.
- Now look at figure 3. This is a representation of using minus on vectors. [B]-[A]=[C]
- (3, 4)-(5, 0)=(-2, 4). You take the vector that point to where you want to end up, subtract the vector pointing to where you stand and you get a vector that represents where you have to go, for how long in what direction.
- To illustrate this property I made figure 4 the exact same as figure 1. [B]-[A]=[C]
- (8, 4)-(5, 0)=(3, 4)
- Look at the bottom left figure. This is the game and for the game, the offset values are the x and y values in the vector that points to the top left corner of your screen(Green vector), while the values you get from Mouse.getX() and getY() is the x and y values in the vector pointing to the mousepointer on your screen(yellow vector). By adding them together we get the mouse location on the game world(Pink vector).
- Look at the last figure on the right. As before, the pink vector points to the mouse position in the game world. The orange one is the vector that points to your character, the player. Now, if you subtract the start vector(orange) from the destination vector(pink) we get the vector representing the direction and distance we have to move our character to reach the point we clicked on.
- You already have the x and y values of where your character is, you have the x and y values of the screen origin and you get the x and y values of your mouse pointer. By adding and subtracting like I explained above you will be able to calculate the data you want.
- Picture> http://i.imgur.com/PiPgwCW.jpg
Advertisement
Add Comment
Please, Sign In to add comment