コード例 #1
0
ファイル: Vehicle.cpp プロジェクト: dimasv28/DogFight
void Vehicle::seek() {
	PVector *target = player->getLocation();
    PVector *desired = PVector::sub(target, location);
    desired->normalize();
    desired->mult(maxspeed);
    PVector *steer = PVector::sub(desired, velocity);
    steer->limit(maxforce);
    applyForce(steer);
  }
コード例 #2
0
ファイル: Mover.cpp プロジェクト: dimasv28/the_nature_of_code
void Mover::update(PVector *mouse)
{
	//Example 1.10: Accelerating towards the mouse
	PVector *dir = PVector::sub(mouse,location);
	dir->normalize();
    dir->mult(0.3);
	acceleration = dir;

	//Example 1.9: Motion 101 (velocity and random acceleration)
	//acceleration->random2D();
	//acceleration->mult(0.3);

	//Example 1.8: Motion 101 (velocity and constant acceleration)
	velocity->add(acceleration);
	velocity->limit(topspeed);
	location->add(velocity);
}