Beispiel #1
0
//deltaX and deltaY are in degrees
static void turn(double *eyeVec, double *atVec, double *upVec, double deltaX, double deltaY) {
  //The idea is to have the camera swivel left when you move the mouse left, and swivel up and down when you move the mouse up and down, without gimbol locking.
  //We accomplish this by having at-eye and up be perpendicular to each other, and keep track of the up orientation outside of this function.
	double upDownRotate[16];
	double leftRightRotate[16];
	double toTransform[16];

	double sideAxis[4] = {0,0,0,0};

	//get sideAxis from up and at (all three should be perpendicular)
	mcross(
		upVec[0],upVec[1],upVec[2],
		atVec[0]-eyeVec[0],atVec[1]-eyeVec[1],atVec[2]-eyeVec[2],
		&sideAxis[0],&sideAxis[1],&sideAxis[2]);
  
	rotateAboutAxis(upDownRotate, deltaY, sideAxis);
    
	setMatTranslation(toTransform, eyeVec[0],eyeVec[1],eyeVec[2]);
	multMatMat(toTransform, upDownRotate, toTransform);
	addMatTranslation(toTransform, -eyeVec[0],-eyeVec[1],-eyeVec[2]);
	multMatVec3(toTransform, atVec, atVec, 1);

	multMatVec3(upDownRotate, upVec,upVec, 0);

	////printf("ud: (%.1lf,%.1lf,%.1lf), ca: (%.1lf,%.1lf,%.1lf) cu: (%.1lf,%.1lf,%.1lf)\n", globalUpDownAxis[0], globalUpDownAxis[1], globalUpDownAxis[2], gCameraAt[0], gCameraAt[1], gCameraAt[2], gCameraUp[0], gCameraUp[1], gCameraUp[2]);

	rotateAboutAxis(leftRightRotate, deltaX, upVec);

	setMatTranslation(toTransform, eyeVec[0],eyeVec[1],eyeVec[2]);
	multMatMat(toTransform, leftRightRotate, toTransform);
	addMatTranslation(toTransform, -eyeVec[0],-eyeVec[1],-eyeVec[2]);
	multMatVec3(toTransform, atVec, atVec, 1);
}
Beispiel #2
0
void		rotateImage(t_bunny_pixelarray *s,
			    t_bunny_pixelarray *d, double r)
{
  t_mat3	m;
  t_ivec2	incr;
  t_color	color;
  t_ivec2	v[3];
  t_vec3	tmp;

  v[0] = ivec2(d->clipable.clip_width / 2, d->clipable.clip_height / 2);
  v[2] = subiVec2(v[0], ivec2(s->clipable.clip_width / 2.0,
			      s->clipable.clip_height / 2.0));
  m = mat3();
  translate3(&m, to_vec2(v[0]));
  rotate3D(&m, vec3(0, 0, -r));
  translate3(&m, vec2(-v[0].x, -v[0].y));
  incr.y = -1;
  while (++incr.y < d->clipable.clip_height)
    {
      incr.x = -1;
      while (++incr.x < d->clipable.clip_width)
	{
	  tmp = multMatVec3(&m, vec3(incr.x, incr.y, 1));
	  v[1] = to_ivec2(vec2(tmp.x, tmp.y));
	  color.full = getPixel(s, subiVec2(v[1], v[2]));
	  tekpixel(d, &incr, &color);
	}
    }
}