コード例 #1
0
ファイル: camera.cpp プロジェクト: Gordath/mars2030
const Matrix4x4& TargetCamera::get_matrix() const
{

	camera_matrix.reset_identity();
	camera_matrix.set_lookat(get_position(),target->get_position(),get_up_vector());
	return camera_matrix;			
}
コード例 #2
0
ファイル: turret.c プロジェクト: drhastings/balance
void pointer(struct robot *robot)
{
  struct vect point;

  point.x = (cosf(robot->rotational_target + (robot->rotational_velocity * 0)) * 1000) + robot->position2.position.x;
  point.y = (sinf(robot->rotational_target + (robot->rotational_velocity * 0)) * 1000) + robot->position2.position.y;
  point.z = -40;

  //fprintf(stderr, "%f, %f, %f\n\n", robot->turret.target.x, robot->turret.target.y, robot->turret.target.z);

	point_at_world(robot, &robot->turret.target);

  struct vect cam_in_world;

  local_to_world(robot, &cam_in_world, &camera_center);

//  fprintf(stderr, "%f, %f, %f\n", cam_in_world.x, cam_in_world.y, cam_in_world.z);
//  fprintf(stderr, "%f, %f\n", robot->position2.position.x, robot->position2.position.y);

  struct vect d;

  difference(&d, &cam_in_world, &point);

  float xx = d.x * d.x;

  float yy = d.y * d.y;

  float zz = d.z * d.z;

  float predicted_distance = sqrtf(xx + yy + zz) - 40;

  //fprintf(stderr, "%f, %f\n", predicted_distance, robot->range);

  if (predicted_distance < robot->range)
  {
    gpioWrite(14, 0);
  }
   else
  {
    gpioWrite(14, 0);
  }

	struct vect output;

	get_up_vector(robot, &output);

//	printf("%f, %f, %f\n", output.x, output.y, output.z);

	struct vect cam_up, up, look, cam_forward, product;

	up.x = 0;
	up.y = 0;
	up.z = 1.0;

	cam_forward.x = 0;
	cam_forward.y = -1;
	cam_forward.z = 0;

	rotate_vector(&cam_up, &up, &robot->turret.turret_rotation);
	rotate_vector(&look, &cam_forward, &robot->turret.turret_rotation);

	robot->turret.roll = acosf(dot(&cam_up, &output));

	cross(&cam_up, &output, &product);

	robot->turret.roll = -asinf(product.x / look.x);

  if (robot->turret.pitch > robot->turret.pitch_guess)
  {
    robot->turret.pitch_guess += 0.000000174532925;
 
    if (robot->turret.pitch_guess > robot->turret.pitch)
    {
      robot->turret.pitch_guess = robot->turret.pitch;
    }
  }

  if (robot->turret.pitch < robot->turret.pitch_guess)
  {
    robot->turret.pitch_guess -= 0.000000174532925;
 
    if (robot->turret.pitch_guess < robot->turret.pitch)
    {
      robot->turret.pitch_guess = robot->turret.pitch;
    }
  } 

  if (robot->turret.yaw > robot->turret.yaw_guess)
  {
    robot->turret.yaw_guess += 0.000000174532925;
 
    if (robot->turret.yaw_guess > robot->turret.yaw)
    {
      robot->turret.yaw_guess = robot->turret.yaw;
    }
  }

  if (robot->turret.yaw < robot->turret.yaw_guess)
  {
    robot->turret.yaw_guess -= 0.000000174532925;
 
    if (robot->turret.yaw_guess < robot->turret.yaw)
    {
      robot->turret.yaw_guess = robot->turret.yaw;
    }
  } 

	//printf("%f, %f, %f\n", local.x, local.y, local.z);
	//fprintf(stderr, "%f\n", robot->turret.roll);
}