「がんばれない」けど「がんばりたい」

ITエンジニアの仕事のこと。AI、機械学習、ディープラーニング。地頭力。車のこと。

Vector|Nature of Code.

1. 移動(位置)

1-1. 位置の更新

location = location + velocity.

1-2. 速度のlimit

velocity.limit(10);

2. 加速度

  • Acceleration effects velocity.
velocity += acceleration;
location += velocity;

2-1. Algorithms

  1. constant acceleration.
  2. totally random acceleration.
  3. Acceleration towards mouse.

・if acceleration will be updated in each frame, acceleration seems to be like the following.

void update()
{
  acceleration = random();
]

2-2. ex) Affect acceleration by mouse point to the object.

Let’s move the object towards mouse point.

Summarize

  1. Calculate the vector that point from the object to mouse point. This should be the direction vector.

  2. Normalize the vector which we get part 1).

  3. Scale that Normalized vector to an appropriate value as the Acceleration.

  4. Assign that Vector as Acceleration.

void update()
{
  // location | object point.
  ofVec3f mousePoint(mouseX, mouseY, 0);
  ofVec3f dirVec = mousePoint - location;
  ofVec3f dir, acceleration;

  dir = dirVec.normalize();

  dir *= 0.5; //0.5 does not have any meaning.
  acceleration = dir;

  //update velocity and location
  velocity += acceleration;
  location += velocity;
}