Exemplo n.º 1
0
int             shadow_cyl(t_obj *obj, t_env *e)
{
  t_vec3d  eye_origin;
  double  a;
  double  b;
  double  c;
  double  det;
  t_vec3d sl;

  sl = (t_vec3d){e->sl.x,e->sl.y,e->sl.z};
  eye_origin = eye_or(e->pos, obj->pos);
  rotate_x(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
	   -obj->rot.x);
  rotate_y(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
	   -obj->rot.y);
  rotate_z(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
	   -obj->rot.z);
  rotate_x(&(sl.x), &(sl.y), &(sl.z),
	   -obj->rot.x);
  rotate_y(&(sl.x), &(sl.y), &(sl.z),
	   -obj->rot.y);
  rotate_z(&(sl.x), &(sl.y), &(sl.z),
  -obj->rot.z);
  a = sl.x * sl.x + sl.z * sl.z;
  b = sl.x * eye_origin.x + sl.z * eye_origin.z;
  c = eye_origin.x * eye_origin.x + eye_origin.z * eye_origin.z - obj->size * obj->size;
  det = b * b - a * c;
  if (det > 0.001)
    return(ret_val2(a,b,det,e));
  return (0);
}
Exemplo n.º 2
0
void	rotate::init( float nx, float ny, float nz, float angle )
{
    float	th1, th2;
    float	r;

    th1 = th2 = 0.0f;

    if ( r = sqrtf( nx*nx + ny*ny ) )
    {
        if ( ny > 0.0 )
            th1 = asinf( nx / r );
        else
            th1 = M_PI - asinf( nx / r );
    }

    if ( r = sqrt( nx*nx + ny*ny + nz*nz ) )
    {
        if ( nz > 0.0f )
            th2 = acosf( nz / r );
        else
            th2 = M_PI - acosf( -nz / r );
    }

    matrix	ans(	rotate_z( 180.0f / M_PI * th1 ) *
                    rotate_x( 180.0f / M_PI * th2 ) *
                    rotate_z( angle ) *
                    rotate_x( -180.0f / M_PI * th2 ) *
                    rotate_z( -180.0f / M_PI * th1 ) );

    for ( int i = 1; i < 4; i++ )
        for ( int j = 1; j < 4; j++ )
            set_data(i,j, ans.get_data(i,j));
}
Exemplo n.º 3
0
int             shadow_sphere(t_obj *obj, t_env *e)
{
  t_vec3d  eye_origin;
  double  a;
  double  b;
  double  c;
  double  det;
  t_vec3d sl;

  sl = (t_vec3d){e->sl.x,e->sl.y,e->sl.z};
  eye_origin = eye_or(e->pos, obj->pos);
  rotate_x(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
           -obj->rot.x);
  rotate_y(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
           -obj->rot.y);
  rotate_z(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
           -obj->rot.z);
  rotate_x(&(sl.x), &(sl.y), &(sl.z),
           -obj->rot.x);
  rotate_y(&(sl.x), &(sl.y), &(sl.z),
           -obj->rot.y);
  rotate_z(&(sl.x), &(sl.y), &(sl.z),
	   -obj->rot.z);
  a = mult(&(sl), &(sl));
  b = mult(&eye_origin, &(sl));
  c = mult(&eye_origin, &eye_origin) - obj->size * obj->size;
  det = b * b - a * c;
  if (det > 0.001)
    return(ret_val2(a,b,det,e));
  return (0);
}
Exemplo n.º 4
0
Arquivo: all_inter.c Projeto: NSSX/ray
double		inter_cyl(t_obj *obj, t_env *e)
{
	t_vec3d  eye_origin;
	double  a;
	double  b;
	double  c;
	double  det;
	double angle = 90;
	t_vec3d ray_dir;


	ray_dir = (t_vec3d){e->ray_dir.x,e->ray_dir.y,e->ray_dir.z}; 
	eye_origin = eye_or(e->ray_origin, obj->pos);
	rotate_x(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.x);
	rotate_y(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.y);
	rotate_z(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.z);
	rotate_x(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z),
			-obj->rot.x);
	rotate_y(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z),
			-obj->rot.y);
	rotate_z(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.z);
	a = ray_dir.x * ray_dir.x + ray_dir.z * ray_dir.z;
	b = ray_dir.x * eye_origin.x + ray_dir.z * eye_origin.z;
	c = eye_origin.x * eye_origin.x + eye_origin.z * eye_origin.z - obj->size * obj->size;
	det = b * b - a * c;
	if (det < 0.0001)
		return (-1);
	return (ret_val(a,b,det));
}
Exemplo n.º 5
0
// ICRS to TEME conversion
void icrs_to_teme(double mjd,double a[3][3])
{
  int i,j;
  double dpsi,deps,eps,z,theta,zeta,h;
  double p[3][3],n[3][3],q[3][3],b[3][3];

  // Precession
  precess(51544.5,mjd,&zeta,&z,&theta);
  identity_matrix(p);
  rotate_z(-zeta,p);
  rotate_y(theta,p);
  rotate_z(-z,p);

  // Nutation
  nutation(mjd,&dpsi,&deps,&eps);
  identity_matrix(n);
  rotate_x(eps,n);
  rotate_z(-dpsi,n);
  rotate_x(-eps-deps,n);

  // Equation of equinoxes
  identity_matrix(q);
  rotate_z(dpsi*cos(eps+deps),q);

  // Multiply matrices (left to right)
  matrix_multiply(q,n,b);
  matrix_multiply(b,p,a);

  return;
}
Exemplo n.º 6
0
Arquivo: all_inter.c Projeto: NSSX/ray
double		inter_sphere(t_obj *obj, t_env *e)
{
	t_vec3d		eye_origin;
	double		a;
	double		b;
	double		c;
	double		det;
	t_vec3d		ray_dir;


	ray_dir = (t_vec3d){e->ray_dir.x,e->ray_dir.y,e->ray_dir.z};
	eye_origin = eye_or(e->ray_origin, obj->pos);
	rotate_x(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.x);
	rotate_y(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.y);
	rotate_z(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.z);
	rotate_x(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z),
			-obj->rot.x);
	rotate_y(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z),
			-obj->rot.y);
	rotate_z(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.z);
	a = mult(&(ray_dir), &(ray_dir));
	b = mult(&eye_origin, &(ray_dir));
	c = mult(&eye_origin, &eye_origin) - obj->size * obj->size;
	det = b * b - a * c;
	if (det < 0.0001)
		return (-1);
	return (ret_val(a,b,det));
}
Exemplo n.º 7
0
void model_draw_legs() {
  float modelview[16];

  // draw right foot
  rotate_y(180.0);
  my_gluCylinder(0.25, r_foot_s);

  // draw right lower leg
  rotate_x(-90 + vector[r_ankle_j_0]);
  rotate_z(vector[r_ankle_j_1]);
  my_gluCylinder(0.3, r_l_leg_s);

  // right knee internal rotation
  rotate_internal(vector[r_knee_j_i]);

  // draw right upper leg
  rotate_x(vector[r_knee_j_0]);
  my_gluCylinder(0.4, r_u_leg_s);

  // right hip internal rotation
  rotate_internal(vector[r_hip_j_i]);

  // draw pelvis
  rotate_y(-90 + vector[r_hip_j_0]);
  rotate_z(vector[r_hip_j_1]);
  my_gluCylinder(0.25, pelvis_s);

  // push left hip
  glPushMatrix();

  // draw left upper leg
  rotate_z(-vector[l_hip_j_1]);
  rotate_y(-90 + vector[l_hip_j_0]);
  my_gluCylinder(0.4, l_u_leg_s);

  // left hip internal rotation
  rotate_internal(-vector[l_hip_j_i]);

  // draw left lower leg
  rotate_x(vector[l_knee_j_0]);
  my_gluCylinder(0.3, l_l_leg_s);

  // left knee internal rotation
  rotate_internal(-vector[l_knee_j_i]);

  // draw left foot
  rotate_x(-90 + vector[l_ankle_j_0]);
  rotate_y(vector[l_ankle_j_1]);
  my_gluCylinder(0.25, l_foot_s);

  glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

  correction_angle = -atan2(modelview[13], modelview[12]);

  correction_angle *= 180.0/M_PI;

  // pop back to left hip
  glPopMatrix();
}
Exemplo n.º 8
0
t_vector	rotate_vector(t_vector vec, t_vector rot, int j)
{
  if (j == -1)
    {
      vec = rotate_z(vec, j * rot.z);
      vec = rotate_y(vec, j * rot.y);
      vec = rotate_x(vec, j * rot.x);
    }
  else
    {
      vec = rotate_x(vec, j * rot.x);
      vec = rotate_y(vec, j * rot.y);
      vec = rotate_z(vec, j * rot.z);
    }
  return (vec);
}
Exemplo n.º 9
0
int			key_hook(int keycode, t_mapinfo *map)
{
	t_mapinfo mapcpy;

	mapcpy = *map;
	mapcpy.points = ft_mapcopy(map);
	if (keycode == 53)
		exit(0);
	else if (keycode == 15)
		key_reset(map);
	else if (keycode >= 0 && keycode <= 14)
		key_rot(keycode, map);
	else if (keycode >= 123 && keycode <= 126)
		key_scale(keycode, map);
	mlx_clear_window(0, map->win);
	scale_points(&mapcpy, mapcpy.scale_x, mapcpy.scale_y);
	rotate_x(map->rot_x, &mapcpy);
	rotate_y(map->rot_y, &mapcpy);
	rotate_z(map->rot_z, &mapcpy);
	ft_centremap(&mapcpy);
	ft_draw_map(mapcpy);
	free_map(mapcpy);
	if (keycode == 15 || keycode == 34)
		ft_draw_instruct(*map);
	//ft_putnbr(keycode);
	//ft_putchar('\n');
	return (0);
}
Exemplo n.º 10
0
void		calc_n_for_cube(t_obj *obc, double *p, t_sph *obj_a)
{
  rotate_x(obj_a->xro, obj_a->yro, obj_a->zro, obc->p);
  obc->n[0] = X3(p[0]) - (10 * p[0]);
  obc->n[1] = X3(p[1]) - (10 * p[1]);
  obc->n[2] = X3(p[2]) - (10 * p[2]);
}
Exemplo n.º 11
0
void		calc_n_for_plan(t_obj *obc, double *p, t_sph *obj_a)
{
  p = p;
  obc->n[0] = 0;
  obc->n[1] = 0;
  obc->n[2] = 100;
  rotate_x(obj_a->xro, obj_a->yro, obj_a->zro, obc->n);
}
Exemplo n.º 12
0
void obj_loader::rotate(float dif_x_deg, float dif_y_deg, float dif_z_deg)
{
  //  angle_x += dif_x_deg;
  //  angle_y += dif_y_deg;
  //  angle_z += dif_z_deg;

    rotate_z(dif_z_deg);
    rotate_x(dif_x_deg);
}
Exemplo n.º 13
0
// Draw equipped on character
void Weapon::draw_equipped()
{
  // Point in the correct direction
  int dx = rotate_x(x, 1, rotation);
  int dy = rotate_y(y, 1, rotation);

  // Draw weapon
  mvaddch(dy, dx, display[rotation]);
}
Exemplo n.º 14
0
static void draw_sphere()
{
    const int NUM_FACE_COLOURS = 4;
    vec FACE_COLOURS[NUM_FACE_COLOURS] = {
        vec( 1.0f, 0.0f, 0.0f ),
        vec( 0.0f, 1.0f, 0.0f ),
        vec( 0.0f, 0.0f, 1.0f ),
        vec( 1.0f, 1.0f, 0.0f )
    };

    const float lat_angle = PI / (float)SPHERE_LAT_SLICES;
    const float long_angle = 2.0f * PI / (float)SPHERE_LONG_SLICES;

    const float sin_lat = sin( lat_angle );
    const float cos_lat = cos( lat_angle );
    const float sin_long = sin( long_angle );
    const float cos_long = cos( long_angle );

    glBegin( GL_QUADS );

    vec lat_0( 0.0f, SPHERE_RADIUS, 0.0 );

    for ( int y = 0; y < SPHERE_LAT_SLICES; ++y )
    {
        vec lat_1 = rotate_x( lat_0, sin_lat, cos_lat );

        vec long_0_0 = lat_0;
        vec long_1_0 = lat_1;

        for ( int x = 0; x < SPHERE_LONG_SLICES; ++x )
        {
            vec long_0_1 = rotate_y( long_0_0, sin_long, cos_long );
            vec long_1_1 = rotate_y( long_1_0, sin_long, cos_long );

            vec colour = FACE_COLOURS[(x+y)%NUM_FACE_COLOURS];
            glColor4f( colour.x, colour.y, colour.z, 1.0f );

            glVertex3f( long_0_0.x, long_0_0.y, long_0_0.z );
            glVertex3f( long_1_0.x, long_1_0.y, long_1_0.z );
            glVertex3f( long_1_1.x, long_1_1.y, long_1_1.z );
            glVertex3f( long_0_1.x, long_0_1.y, long_0_1.z );

            long_0_0 = long_0_1;
            long_1_0 = long_1_1;
        }

        lat_0 = lat_1;
    }

    glEnd();

    // Something simpler:
    //glColor3f(1.0f,0.0f,0.0f);
    //glutWireSphere(SPHERE_RADIUS,SPHERE_LONG_SLICES,SPHERE_LAT_SLICES);
}
Exemplo n.º 15
0
t_coordinate		*calculate_vector(t_pov *pov, t_pixel *pixel,
					  t_coordinate *rayvector)
{
  rayvector->x = 500;
  rayvector->y = (WIN_WIDTH / 2) - pixel->x;
  rayvector->z = (WIN_HEIGHT / 2) - pixel->y;
  rotate_x(&(rayvector->y), &(rayvector->z), pov->anglex);
  rotate_y(&(rayvector->x), &(rayvector->z), pov->angley);
  rotate_z(&(rayvector->x), &(rayvector->y), pov->anglez);
  return (rayvector);
}
Exemplo n.º 16
0
//function to rotate along the world coordinate system
void rotate_along(IFS_DATA* ifs_data,int axes)
{
  Matrix k;
  switch(axes)
  {
    case 1:
      k=return_rotate_x(theta);
      break;
    case 2:
      k=return_rotate_y(theta);
      break;
    case 3:
      k=return_rotate_z(theta);
      break;
  }
  
  vector temp;
  temp.A[0]=object_x;
  temp.A[1]=object_y;
  temp.A[2]=object_z;
  temp.A[3]=1.0;
  
  temp=multiply_vector(&k,&temp);
  
  object_x=temp.A[0];
  object_y=temp.A[1];
  object_z=temp.A[2];

int i,j;
  for (i=0; i<ifs_data->numVertices; ++i) 
  {
    vector v;
    v.A[0]=ifs_data->vertices[i].x;
    v.A[1]=ifs_data->vertices[i].y;
    v.A[2]=ifs_data->vertices[i].z;
    v.A[3]=1.0;

    switch(axes)
    {
      case 1:
	v=rotate_x(&v,angle_x);
	break;
      case 2:
	v=rotate_y(&v,angle_y);
	break;
      case 3:
	v=rotate_z(&v,angle_z);
	break;
    }
    ifs_data->vertices[i].x=v.A[0];
    ifs_data->vertices[i].y=v.A[1];
    ifs_data->vertices[i].z=v.A[2];   
  }
}
Exemplo n.º 17
0
static void prep_x(int natom,rvec x[],real rDist,real rAngleZ,real rAngleX)
{
  int  i;
  rvec xcm;
  rvec *xx;
  
  /* Center on Z-axis */
  clear_rvec(xcm);
  for(i=0; (i<natom); i++) {
    xcm[XX] += x[i][XX];
    xcm[YY] += x[i][YY];
    xcm[ZZ] += x[i][ZZ];
  }
  xcm[XX] /= natom;
  xcm[YY] /= natom;
  xcm[ZZ] /= natom;
  for(i=0; (i<natom); i++) {
    x[i][XX] -= xcm[XX];
    x[i][YY] -= xcm[YY];
    x[i][ZZ] -= xcm[ZZ];
  }
  if (rAngleZ != 0) {
    snew(xx,natom);
    rotate_x(natom,x,rAngleZ,xx,TRUE,FALSE,0);
    for(i=0; (i<natom); i++) 
      copy_rvec(xx[i],x[i]);
    sfree(xx);
  }
  if (rAngleX != 0) {
    snew(xx,natom);
    rotate_x(natom,x,rAngleX,xx,FALSE,FALSE,0);
    for(i=0; (i<natom); i++) 
      copy_rvec(xx[i],x[i]);
    sfree(xx);
  }
  if (rDist > 0) {
    for(i=0; (i<natom); i++) 
      x[i][XX] += rDist;
  }
}
Exemplo n.º 18
0
/*
 * Alternate view matrix generator:
 * Takes (X, Y, Z) rotation instead of a point to look at.
 * Generate rotational matrix by rotating a +Z-axis unit vector
 * around Y, then X and generating a view matrix for that target.
 * For now, Z rotation will be ignored.
 * Also generate an 'up' vector from a +Y-axis unit fector rotated by Y, then X.
 */
m4 look_at(v3 pos, v3 t_angles) {
	v4 unit_direction(0.0f, 0.0f, 1.0f, 1.0f);
	v4 up_direction(0.0f, 1.0f, 0.0f, 1.0f);
	m4 ry = rotate_y(t_angles.v[1]);
	unit_direction = ry * unit_direction;
	up_direction = ry * up_direction;
	m4 rx = rotate_x(t_angles.v[0]);
	unit_direction = rx * unit_direction;
	up_direction = rx * up_direction;

	v3 t_vec = pos + unit_direction;
	return look_at(pos, t_vec, up_direction);
}
Exemplo n.º 19
0
// add_rules
//    add a rule and its variants to the table
//
void add_rules(char rules[255][20], int index, char *edges) {
   int i,j,k,l;
   strcpy(rules[index],edges);
   for (i=0; i<4; ++i) {
      for (j=0; j<4; ++j) {
         for (k=0; k<4; ++k) {
            rotate_x(rules,&index);
            }
         rotate_y(rules,&index);
         }
      rotate_z(rules,&index);
      }
   }
Exemplo n.º 20
0
int		calc(int x, int y, t_win *mlxwin)
{
  int		n;
  t_pos		xyz;

  xyz.x = 100;
  xyz.y = 500 - x;
  xyz.z = 500 - y;
  rotate_x(&xyz, mlxwin->r_oeil.x);
  rotate_y(&xyz, mlxwin->r_oeil.y);
  rotate_z(&xyz, mlxwin->r_oeil.z);
  return (get_pixel_color(xyz, mlxwin));
}
Exemplo n.º 21
0
inline double	*rot_tran_inverse(t_sph *obj_a, double *p)
{
  obj_a->xro = obj_a->xro * -1;
  obj_a->yro = obj_a->yro * -1;
  obj_a->zro = obj_a->zro * -1;
  rotate_x(obj_a->xro, obj_a->yro, obj_a->zro, p);
  obj_a->xro = obj_a->xro * -1;
  obj_a->yro = obj_a->yro * -1;
  obj_a->zro = obj_a->zro * -1;
  p[0] = p[0] + (obj_a->x * 1);
  p[1] = p[1] + (obj_a->y * 1);
  p[2] = p[2] + (obj_a->z * 1);
  return (p);
}
Exemplo n.º 22
0
Arquivo: all_inter.c Projeto: NSSX/rkt
double		inter_cone(t_obj *obj, t_env *e)
{
	t_vec3d		eo;
	double		a;
	double		b;
	double		c;
	t_vec3d		ray_dir;

	ray_dir = (t_vec3d){e->ray_dir.x, e->ray_dir.y, e->ray_dir.z};
	eo = eye_or(e->ray_origin, obj->pos);
	rotate_x(&(eo.x), &(eo.y), &(eo.z), -obj->rot.x);
	rotate_y(&(eo.x), &(eo.y), &(eo.z), -obj->rot.y);
	rotate_z(&(eo.x), &(eo.y), &(eo.z), -obj->rot.z);
	rotate_x(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.x);
	rotate_y(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.y);
	rotate_z(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.z);
	a = ray_dir.x * ray_dir.x - ray_dir.y * ray_dir.y + ray_dir.z * ray_dir.z;
	b = ray_dir.x * eo.x - ray_dir.y * eo.y + ray_dir.z * eo.z;
	c = eo.x * eo.x + eo.z * eo.z - eo.y * eo.y;
	e->det = b * b - a * c;
	if (e->det < 0.0001)
		return (-1);
	return (ret_val(a, b, e->det));
}
Exemplo n.º 23
0
int		shadow_sphere(t_obj *obj, t_env *e)
{
	t_vec3d		eo;
	double		a;
	double		b;
	double		c;
	t_vec3d		sl;

	sl = (t_vec3d){e->sl.x, e->sl.y, e->sl.z};
	eo = eye_or(e->pos, obj->pos);
	rotate_x(&(eo.x), &(eo.y), &(eo.z), -obj->rot.x);
	rotate_y(&(eo.x), &(eo.y), &(eo.z), -obj->rot.y);
	rotate_z(&(eo.x), &(eo.y), &(eo.z), -obj->rot.z);
	rotate_x(&(sl.x), &(sl.y), &(sl.z), -obj->rot.x);
	rotate_y(&(sl.x), &(sl.y), &(sl.z), -obj->rot.y);
	rotate_z(&(sl.x), &(sl.y), &(sl.z), -obj->rot.z);
	a = mult(&(sl), &(sl));
	b = mult(&eo, &(sl));
	c = mult(&eo, &eo) - obj->size * obj->size;
	e->det = b * b - a * c;
	if (e->det > 0.001)
		return (ret_val2(a, b, e->det, e));
	return (0);
}
Exemplo n.º 24
0
int		shadow_cone(t_obj *obj, t_env *e)
{
	t_vec3d		eo;
	double		a;
	double		b;
	double		c;
	t_vec3d		sl;

	sl = (t_vec3d){e->sl.x, e->sl.y, e->sl.z};
	eo = eye_or(e->pos, obj->pos);
	rotate_x(&(eo.x), &(eo.y), &(eo.z), -obj->rot.x);
	rotate_y(&(eo.x), &(eo.y), &(eo.z), -obj->rot.y);
	rotate_z(&(eo.x), &(eo.y), &(eo.z), -obj->rot.z);
	rotate_x(&(sl.x), &(sl.y), &(sl.z), -obj->rot.x);
	rotate_y(&(sl.x), &(sl.y), &(sl.z), -obj->rot.y);
	rotate_z(&(sl.x), &(sl.y), &(sl.z), -obj->rot.z);
	a = sl.x * sl.x - sl.y * sl.y + sl.z * sl.z;
	b = sl.x * eo.x - sl.y * eo.y + sl.z * eo.z;
	c = eo.x * eo.x + eo.z * eo.z - eo.y * eo.y;
	e->det = b * b - a * c;
	if (e->det > 0.001)
		return (ret_val2(a, b, e->det, e));
	return (0);
}
Exemplo n.º 25
0
static unsigned char	*calc(t_tmp *tmp, t_obj *obc, t_cod *cor, t_sph *obj_a)
{
  t_sph			*tm;

  tm = obj_a;
  obc->nt = NULL;
  obc->color = 0;
  calcul_X1(cor->x / 4, cor->y, cor->l_x);
  rotate_x(cor->l_o[3], cor->l_o[4], cor->l_o[5], cor->l_x);
  while (obj_a != NULL)
    {
      if (obj_a->type >= 0 && obj_a->type < 20 && obc->inter[obj_a->type]
	  && obc->inter[obj_a->type](cor, tmp, obc, obj_a) == 1
	  && obj_a->negative != -1)
	obc->nt = obj_a;
      else if (obj_a->type >= 0 && obj_a->type < 20 && obc->inter[obj_a->type]
	  && obc->inter[obj_a->type](cor, tmp, obc, obj_a) == 1
	  && obj_a->negative == - 1)
	obc->nt = NULL;
      obj_a = obj_a->nt;
    }
  calc_p_n_color(cor, obc, obc->nt, tmp);
  return (color_func(obc, tm, tmp));
}
Exemplo n.º 26
0
void		rotate_eye(t_eye *eye)
{
  rotate_x(&eye->vectv.x, &eye->vectv.y, &eye->vectv.z, -(eye->rot.z));
  rotate_y(&eye->vectv.x, &eye->vectv.y, &eye->vectv.z, -(eye->rot.y));
  rotate_z(&eye->vectv.x, &eye->vectv.y, &eye->vectv.z, -(eye->rot.x));
}
Exemplo n.º 27
0
void generate( int polygons ) {
	double knob_value;
	vary_node *knobs;
	vary_node vn;
	char frame_name[128];

	if (first_pass()) {
		knobs = second_pass();
	}
	else {
		num_frames = 1;
	}

	// Default values
	char color_type = PNG_RGB, shading = GOROUD;
	int width = 1000, height = 1000, segments = 20;
	screen s = make_screen(width, height);
	vertex_list vlist = new_vlist(100);
	face_list flist = new_flist(100);
	edge_list elist = new_elist(100);
	stack coord_systems = new_stack(5);
	vector center = new_vector(0, 0, 0);
	vector eye = new_vector(0, 0, 200);
	double distance = 200;
	vertex text0, text1;
	text0.x = -100; text0.y = 0; text0.z = 0;
	text1.x =  100; text1.y = 0; text1.z = 0;
	text0.nx = text1.x - text0.x;
	text0.ny = text1.y - text0.y;
	text0.nz = text1.z - text0.z;
	text1.nx = text0.nx * text0.nx + text0.ny * text0.ny + text0.nz * text0.nz;
	text0.color = rgb(255, 255, 255);
	text0.shine = 3;
	text1.color = rgb(255, 0, 255);
	text1.shine = 3;
	uint32_t amb_color = rgb(255, 255, 255), light_color = rgb(0, 255, 255),
	wire_color = rgb(255, 255, 255);
	vector light_source = new_vector(0, 100, 200);
	double amb_ref_constant = 0.1, diff_ref_constant = 1, spec_ref_constant = 1;

	int frame, i, j; double temp;
	for (frame = 0; frame < num_frames; frame++) {
		if (num_frames > 1) {
			for (vn = knobs[frame]; vn != NULL; vn = vn->next) {
				set_value(lookup_symbol(vn->name), vn->value);
			}
		}
		for (i = 0; i < lastop; i++) {
			switch (op[i].opcode) {
				case TEXTURE:
				text0.x = op[lastop].op.texture.d0[0];
				text0.y = op[lastop].op.texture.d0[1];
				text0.z = op[lastop].op.texture.d0[2];
				text1.x = op[lastop].op.texture.d1[0];
				text1.y = op[lastop].op.texture.d1[1];
				text1.z = op[lastop].op.texture.d1[2];
				text0.nx = text1.x - text0.x;
				text0.ny = text1.y - text0.y;
				text0.nz = text1.z - text0.z;
				text1.nx =
				text0.nx * text0.nx + text0.ny * text0.ny + text0.nz * text0.nz;
				text0.color = rgb(
					(uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[0])),
					(uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[1])),
					(uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[2]))
 					);
				text0.shine = op[lastop].op.texture.d2[3];
				text1.color = rgb(
					(uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[0])),
					(uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[1])),
					(uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[2]))
 					);
				text1.shine = op[lastop].op.texture.d3[3];
				break;

				case CAMERA:
				eye.x = op[lastop].op.camera.eye[0];
				eye.y = op[lastop].op.camera.eye[1];
				eye.z = op[lastop].op.camera.eye[2];
				center.x = eye.x + op[lastop].op.camera.aim[0];
				center.y = eye.y + op[lastop].op.camera.aim[1];
				center.z = eye.z + op[lastop].op.camera.aim[2];
				break;

				case FOCAL:
				distance = op[lastop].op.focal.value;
				break;

				case AMBIENT:
				amb_color = rgb(
					(uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[0])),
					(uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[1])),
					(uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[2]))
					);
				break;

				case LIGHT:
				light_color = rgb(
					(uint8_t) max(0, min(0xFF, op[lastop].op.light.c[0])),
					(uint8_t) max(0, min(0xFF, op[lastop].op.light.c[1])),
					(uint8_t) max(0, min(0xFF, op[lastop].op.light.c[2]))
					);
				light_source = new_vector(
					op[lastop].op.light.l[0],
					op[lastop].op.light.l[1],
					op[lastop].op.light.l[2]
					);
				break;

				case SHADING:
				if (strcmp(op[i].op.shading.p->name, "GOROUD") == 0) {
					shading = GOROUD;
				}
				else {
					shading = WIRE;
				}
				break;

				case SPHERE:
				add_sphere(
					vlist, elist, flist,
					op[i].op.sphere.d[0],
					op[i].op.sphere.d[1],
					op[i].op.sphere.d[2],
					op[i].op.sphere.r, segments, text0, text1
					);
				transform(vlist, peek(coord_systems));
				if (shading == GOROUD) {
					draw_faces(
						s, vlist, flist, center, eye, distance,
						amb_color, light_color, light_source,
						amb_ref_constant, diff_ref_constant, spec_ref_constant
						);
				}
				else {
					draw_edges(
						s, vlist, elist, center, eye, distance, wire_color
						);
				}
				clear_vlist(vlist);
				clear_elist(elist);
				clear_flist(flist);
				break;

				case BOX:
				add_box(
					vlist, elist, flist,
					op[i].op.box.d0[0],
					op[i].op.box.d0[1],
					op[i].op.box.d0[2],
					op[i].op.box.d1[0],
					op[i].op.box.d1[1],
					op[i].op.box.d1[2],
					text0, text1
					);
				transform(vlist, peek(coord_systems));
				if (shading == GOROUD) {
					draw_faces(
						s, vlist, flist, center, eye, distance,
						amb_color, light_color, light_source,
						amb_ref_constant, diff_ref_constant, spec_ref_constant
						);
				}
				else {
					draw_edges(
						s, vlist, elist, center, eye, distance, wire_color
						);
				}
				clear_vlist(vlist);
				clear_elist(elist);
				clear_flist(flist);
				break;

				case LINE:
				add_line(
					vlist, elist,
					op[i].op.line.p0[0],
					op[i].op.line.p0[1],
					op[i].op.line.p0[2],
					op[i].op.line.p1[0],
					op[i].op.line.p1[1],
					op[i].op.line.p1[2],
					text0, text1
					);
				transform(vlist, peek(coord_systems));
				draw_edges(s, vlist, elist, center, eye, distance, wire_color);
				clear_vlist(vlist);
				clear_elist(elist);
				break;

				case MOVE:
				if (op[i].op.move.p == NULL){
					knob_value = 1;
				}
				else {
					knob_value = op[i].op.move.p->s.value;
				}
				translate(
					op[i].op.move.d[0] * knob_value,
					op[i].op.move.d[1] * knob_value,
					op[i].op.move.d[2] * knob_value,
					peek(coord_systems)
					);
				break;

				case SCALE:
				if (op[i].op.scale.p == NULL){
					knob_value = 1;
				}
				else {
					knob_value = op[i].op.scale.p->s.value;
				}
				scale(
					op[i].op.scale.d[0] * knob_value,
					op[i].op.scale.d[1] * knob_value,
					op[i].op.scale.d[2] * knob_value,
					peek(coord_systems)
					);
				break;

				case ROTATE:
				if (op[i].op.rotate.p == NULL){
					knob_value = 1;
				}
				else {
					knob_value = op[i].op.rotate.p->s.value;
				}
				temp = op[i].op.rotate.axis;
				if (temp == 0) {
					rotate_x(
						op[i].op.rotate.degrees * knob_value,
						peek(coord_systems)
						);
				}
				else if (temp == 1) {
					rotate_y(
						op[i].op.rotate.degrees * knob_value,
						peek(coord_systems)
						);
				}
				else {
					rotate_z(
						op[i].op.rotate.degrees * knob_value,
						peek(coord_systems)
						);
				}
				break;

				case SET:
				set_value(
					lookup_symbol(op[i].op.set.p->name),
					op[i].op.set.val
					);
				break;

				case SETKNOBS:
				for (j = 0; j < lastsym; j++) {
					set_value(&symtab[j], op[j].op.setknobs.value);
				}
				break;

				case PUSH:
				push(coord_systems);
				break;

				case POP:
				pop(coord_systems);
				break;

				case SAVE:
				make_png(op[i].op.save.p->name, s, color_type);
				break;

				case DISPLAY:
				display_png(s, color_type);
				break;
			}
		}
		if (num_frames > 1){
			sprintf(frame_name, "anim/%s%03d.png", name, frame);
			make_png(frame_name, s, color_type);
			clear_screen(s);
			clear_stack(coord_systems);
		}
	}

	free_screen(s);
	free_vlist(vlist);
	free_flist(flist);
	free_elist(elist);
	free(coord_systems);
}
Exemplo n.º 28
0
int main(int argc, char *argv[])
{
  t_symtab tab;
  static char *desc[] = {
    "[TT]hexamer[tt] takes a single input coordinate file and makes five symmetry",
    "related copies."
  };
#define NPA asize(pa)
  t_filenm fnm[] = {
    { efSTX, "-f", NULL, ffREAD },
    { efPDB, "-o", NULL, ffWRITE }
  };
#define NFILE asize(fnm)
  gmx_bool bCenter    = FALSE;
  gmx_bool bTrimer    = FALSE;
  gmx_bool bAlternate = FALSE;
  real rDist = 0,rAngleZ = 0,rAngleX = 0, alterz = 0;
  t_pargs pa[] = {
    { "-center",   FALSE, etBOOL,  {&bCenter}, 
      "Center molecule on Z-axis first" },
    { "-trimer",   FALSE, etBOOL,  {&bTrimer},
      "Make trimer rather than hexamer" },
    { "-alternate",FALSE, etBOOL,  {&bAlternate},
      "Turn every other molecule upside down" },
    { "-alterz",   FALSE, etREAL,  {&alterz},
      "Add this amount to Z-coordinate in every other molecule" },
    { "-radius",   FALSE, etREAL,  {&rDist},
      "Distance of protein axis from Z-axis (implies [TT]-center[tt])" },
    { "-anglez",   FALSE, etREAL,  {&rAngleZ},
      "Initial angle of rotation around Z-axis of protein" },
    { "-anglex",   FALSE, etREAL,  {&rAngleX},
      "Initial angle of rotation around X-axis of protein" }
  };
#define NPA asize(pa)
  FILE    *fp;
  int     i,iout,now,natom;
  rvec    *xin,*vin,*xout;
  matrix  box;
  t_atoms atoms,aout;
  char    *infile,*outfile,title[256],buf[32];
  
  CopyRight(stderr,argv[0]);
  parse_common_args(&argc,argv,0,NFILE,fnm,NPA,pa,
		    asize(desc),desc,0,NULL);
  bCenter = bCenter || (rDist > 0) || bAlternate;
  
  infile  = ftp2fn(efSTX,NFILE,fnm);
  outfile = ftp2fn(efPDB,NFILE,fnm);
  
  get_stx_coordnum(infile,&natom);
  init_t_atoms(&atoms,natom,TRUE);
  snew(xin,natom);
  snew(xout,natom);
  snew(vin,natom);
  read_stx_conf(infile,title,&atoms,xin,vin,box);
  printf("Read %d atoms\n",atoms.nr); 
  
  if (bCenter) 
    prep_x(atoms.nr,xin,rDist,rAngleZ,rAngleX);
  
  fp = gmx_ffopen(outfile,"w");
  for(i=0; (i<(bTrimer ? 3 : 6)); i++) {
    rotate_x(atoms.nr,xin,i*(bTrimer ? 120.0 : 60.0),xout,TRUE,
	     bAlternate && ((i % 2) != 0),alterz*(((i % 2) == 0) ? 0 : 1));
    sprintf(buf,"Rotated %d degrees",i*(bTrimer ? 120 : 60));
    write_pdbfile(fp,buf,&atoms,xout,box,'A'+i,1+i);
  }
  gmx_ffclose(fp);
  
  gmx_thanx(stderr);
  
  return 0;
}
Exemplo n.º 29
0
int main(int argc, char *argv[])
{
  int i,j,k ;
/*---Arguments-------------------------*/
  int geometry,zspace,ifib,tbin_out=0;
  double rotanglex,rotangley,rotanglez,zmin,zmax,fgot_min ;
/*---Particle-distribution-variables---*/
  int np,ibyte,*idat ;
  float *fdat,znow ;
  float Lbox ;
  float *x,*y,*z,*vx,*vy,*vz ;
/*---Cosmodistfile-variables-----------*/
  int Nzdc ;
  double *zc,*dc ;
/*---Redshift-space--------------------*/
  double r,vr,*cz1 ;
/*---SDSS-mask-------------------------*/
  int *ID,Ngal ;
  double comp1,*comp,*ra,*dec,*cz ;
  double ra1,dec1,vec[3] ;
  char *pixfile ;
/*---Fiber-collisions------------------*/
  int Nfibmax,Nfibgrp,indx,jndx,Ni,indx2,done,ipick ;
  int **IDfib,*fiblist,*idrank,*fibcollisions ;
  long seed=-1 ;
  double *x1,*y1,*z1,length ;
  double costheta,cosfiber,*costhetarank ;
/*---Functions-------------------------*/
  void InitializePolygonMask(char *) ;
  double FindCompleteness(double, double) ;
  void rotate_x(double,double *) ;
  void rotate_y(double,double *) ;
  void rotate_z(double,double *) ;
  int set_cosmo_dist(const double Omegam, const double OmegaL, const double zmax, const int maxsize, 
                     double * zc, double * dc ) ;

/*---Read-Arguments---------------------------------------------------------*/

  if(argc < 11) 
    { 
      fprintf(stderr, "Usage:\n  %s  geometry zspace ifib rotanglex rotangley rotanglez zmin zmax maskfile fgot_min tbin_out < partfile > outfile\n",
              argv[0]) ;
      exit(1) ;
    } 

  sscanf(argv[1],"%d",&geometry) ;
  sscanf(argv[2],"%d",&zspace) ;
  sscanf(argv[3],"%d",&ifib) ;
  sscanf(argv[4],"%lf",&rotanglex) ;
  sscanf(argv[5],"%lf",&rotangley) ;
  sscanf(argv[6],"%lf",&rotanglez) ;
  sscanf(argv[7],"%lf",&zmin) ;
  sscanf(argv[8],"%lf",&zmax) ;
  pixfile = argv[9];
  sscanf(argv[10],"%lf",&fgot_min) ;
  if(argc >= 12) 
    { 
      sscanf(argv[11],"%d",&tbin_out) ;
    } 

/*---Read-particle-file-----------------------------------------------------*/

  idat=(int *)calloc(5,sizeof(int));
  fdat=(float *) calloc(9,sizeof(float));       

  ftread(idat,sizeof(int),5,stdin);
  ftread(fdat,sizeof(float),9,stdin);
  ftread(&znow,sizeof(float),1,stdin) ;
 
  np=idat[1];
  Lbox=fdat[0];

  x=(float *) calloc(np,sizeof(float));       
  y=(float *) calloc(np,sizeof(float));       
  z=(float *) calloc(np,sizeof(float));       
  vx=(float *) calloc(np,sizeof(float));       
  vy=(float *) calloc(np,sizeof(float));       
  vz=(float *) calloc(np,sizeof(float));       
      
  ftread(x,sizeof(float),np,stdin);
  ftread(y,sizeof(float),np,stdin);
  ftread(z,sizeof(float),np,stdin);
  ftread(vx,sizeof(float),np,stdin);
  ftread(vy,sizeof(float),np,stdin);
  ftread(vz,sizeof(float),np,stdin);

//  fprintf(stderr,"makemock> Read galaxy distribution, np=%d\n",np) ;
//  fprintf(stderr,"makemock> Size of box, Lbox=%g\n",Lbox) ;

/*---Use-center-of-box-as-origin--------------------------------------------*/

  for (i=0;i<np;i++) 
    {
      x[i] -= 0.5*Lbox ;
      y[i] -= 0.5*Lbox ;
      z[i] -= 0.5*Lbox ;
    }

/*--- Calculate cosmo distance ----------------------------------------------------*/
  zc=(double *) calloc(COSMO_DIST_SIZE ,sizeof(double));
  dc=(double *) calloc(COSMO_DIST_SIZE ,sizeof(double));

  Nzdc = set_cosmo_dist(OMEGA_M, OMEGA_L, zmax, COSMO_DIST_SIZE, zc, dc);

/*---Compute-cosmological-redshifts-for-galaxies----------------------------*/
  cz1=(double *) calloc(np,sizeof(double));
//  fprintf(stderr,"makemock> Computing cosmological redshifts\n") ;
  { 
      double cz_local ;
      for(i=0;i<np;i++)
        {
          cz_local = -1.0;
          r = (double)sqrt(sqr(x[i])+sqr(y[i])+sqr(z[i])) ;
          for(j=1;j<Nzdc;j++)
            {
              if(r<dc[j])
                {
                  cz_local = c*(zc[j] - (dc[j]-r)*(zc[j]-zc[j-1])/(dc[j]-dc[j-1])) ;
                  break ;
                }
            }
          if( cz_local > 0 ) { 
              cz1[i] = cz_local ;
          } else { 
              fprintf(stderr, "makemock> ERROR! couldn't set cosmological redshift for particle %d\n", i) ;
              exit(1) ;

          } 
        }
  }

/*---Put-in-redshift-space-with-observer-at-center--------------------------*/
  if(zspace==1)
    {
      for(i=0;i<np;i++)
	{
	  r = (double)sqrt(sqr(x[i])+sqr(y[i])+sqr(z[i])) ;
	  
	  vr = (double)(vx[i]*x[i]+vy[i]*y[i]+vz[i]*z[i])/r ; 

	  cz1[i] += vr + vr*cz1[i] / c; /* too many factors of c, have to remove one */
	}
      fprintf(stderr,"makemock> Put galaxies in redshift space\n") ;
    }

/*---Initialize-Mask--------------------------------------------------------*/
  if(geometry==1)
    {
//      fprintf(stderr,"makemock> Trim to SDSS geometry: filtering completeness < %g\n", fgot_min) ;
      InitializePolygonMask(pixfile) ;
    }

/*---Only-keep-galaxies-that-are-in-SDSS-volume-----------------------------*/

  ID=(int *) calloc(np,sizeof(int));
  ra=(double *) calloc(np,sizeof(double));       
  dec=(double *) calloc(np,sizeof(double));       
  cz=(double *) calloc(np,sizeof(double));       
  x1=(double *) calloc(np,sizeof(double));       
  y1=(double *) calloc(np,sizeof(double));       
  z1=(double *) calloc(np,sizeof(double));       
  comp=(double *) calloc(np,sizeof(double));

  Ngal=0 ;
  for(i=0;i<np;i++)
    {
      if(cz1[i]>=zmin*c && cz1[i]<=zmax*c)
	{
	  vec[0] = (double)x[i] ;
	  vec[1] = (double)y[i] ;
	  vec[2] = (double)z[i] ;
	  length = sqrt(sqr(vec[0])+sqr(vec[1])+sqr(vec[2])) ;
	  vec[0] /= length ;
	  vec[1] /= length ;
	  vec[2] /= length ;

	  rotate_x(rotanglex,vec) ;
	  rotate_y(rotangley,vec) ;
	  rotate_z(rotanglez,vec) ;

	  dec1 = 90. - (180./pi)*acos(vec[2]) ;
	  ra1 = (180./pi)*atan(vec[1]/vec[0]) ;
	  
	  if(vec[0]<0) 
	    ra1 += 180 ;
	  else if(vec[0]>=0 && vec[1]<0) 
	    ra1 += 360 ;

	  if(geometry==0)
	    {
	      comp1=1. ;
	    }
	  else if(geometry==1)
	    {
	      comp1 = FindCompleteness(ra1,dec1) ;
	    }

	  if(comp1 >= fgot_min)
	    {
	      ID[Ngal] = Ngal ;
	      cz[Ngal] = cz1[i] ;
	      dec[Ngal] = dec1 ;
	      ra[Ngal] = ra1 ;
	      comp[Ngal] = comp1 ;

              if(zspace == 1) 
                { 
                  double dist;
                  double z_local = (cz1[i] / c);

                  for(j=1;j<Nzdc;j++)
                  {
                      if(z_local < zc[j])
                      {
                          dist =  dc[j] - (zc[j] - z_local)*(dc[j]-dc[j-1])/(zc[j]-zc[j-1]) ;
                          break ;
                      }
                  }
                  x1[Ngal] = dist*vec[0] ;
                  y1[Ngal] = dist*vec[1] ;
                  z1[Ngal] = dist*vec[2] ;
                } 
              else 
                { 
                  x1[Ngal] = (double)x[i] ; 
                  y1[Ngal] = (double)y[i] ; 
                  z1[Ngal] = (double)z[i] ; 
                }

	      Ngal++ ;
	    }
	}
    }
//  fprintf(stderr,"makemock> Ngal=%d\n",Ngal) ;
  { 
    /* begin output */
    XDR xdrs;
    struct dump h;
    struct dark_particle dp;
  //  fprintf(stderr,"makemock> creating output in %s \n", tbin_out ? "tipsy binary format" : "ascii" );

    if(tbin_out) 
      { 
        /* Make TIPSY header */
        h.nbodies = Ngal ;
        h.ndark   = h.nbodies ;
        h.nstar   = 0 ;
        h.nsph    = 0 ;
        h.ndim    = 3 ;
        h.time    = 1.0 ;
        xdrstdio_create(&xdrs, stdout, XDR_ENCODE);
        if( xdr_header(&xdrs,&h) != 1 )
          { 
            fprintf(stderr, "Error writing tipsy binary header!");
            exit(2);
          }
        dp.mass = 1.0 ;
        for (i=0; i<3; ++i) 
          {
            dp.vel[i] = 0.0 ;
            dp.pos[i] = 0.0 ;
          }
        dp.phi = 0.0 ;
      }
    for(i=0;i<Ngal; i++) 
      { 
          if(tbin_out) 
            { 
              dp.pos[0] = x1[i] ;
              dp.pos[1] = y1[i] ;
              dp.pos[2] = z1[i] ;
              if( xdr_dark(&xdrs,&dp) != 1 )
                { 
                  fprintf(stderr, "Error writing tipsy binary data! (particle %d)",i);
                  exit(2);
                }
            } 
          else 
            { 
              fprintf(stdout,"%10.6f % 10.6f  %10.2f\n",ra[i],dec[i],cz[i]) ;
//               fprintf(stdout,"%15.6f %15.6f %15.6f \n",x1[i],y1[i],z1[i]) ;
// 	      fprintf(stdout,"%6d %10.6f %10.6f  %8.2f\n",ID[Ngal],ra[Ngal],dec[Ngal],cz[Ngal]) ;
            }
      } 
    if(tbin_out) 
      { 
        /* close XDR file */
        xdr_destroy(&xdrs);
      } 

  } 
  return 0 ;
}
Exemplo n.º 30
0
int main(void)
{
	int ch;
	int i=0;
	int x, y;
	cube_t c={
		{-1, -1, -1},
		{-1, -1,  1},
		{-1,  1, -1},
		{-1,  1,  1},
		{ 1, -1, -1},
		{ 1, -1,  1},
		{ 1,  1, -1},
		{ 1,  1,  1}
	};

	float mxp[3][3];
	float myp[3][3];
	float mzp[3][3];
	float mxn[3][3];
	float myn[3][3];
	float mzn[3][3];
	float (*m)[3];
	int height, width;
	float size_w, size_h;
	int off_x, off_y;

	initscr();
	noecho();
	cbreak();
	timeout(0);
	curs_set(0);

	getmaxyx(stdscr, height, width);
	if (width>height) {
		size_w=height/3;
		size_h=size_w*CHARACTER_ASPECT_RATIO;
	}
	else {
		size_w=width/3;
		size_h=size_w*CHARACTER_ASPECT_RATIO;
	}
	off_x=width/2;
	off_y=height/2;

	clear();
	
	rotate_x(mxp, .1f);
	rotate_y(myp, .1f);
	rotate_z(mzp, .1f);
	rotate_x(mxn, -.1f);
	rotate_y(myn, -.1f);
	rotate_z(mzn, -.1f);
	c=transform_cube(c, mxp);
	c=transform_cube(c, mxp);
	c=transform_cube(c, mzp);
	c=transform_cube(c, mzp);

	m=myp;

	while (1) {
		int p1xc, p1yc;
		int p2xc, p2yc;
		int p3xc, p3yc;
		int p4xc, p4yc;
		int p5xc, p5yc;
		int p6xc, p6yc;
		int p7xc, p7yc;
		int p8xc, p8yc;

		i++;
		c=transform_cube(c, m);
		clear();
		move(0,0);
		printw(
				"M/o/Vfuscator Spinning Cube Demo\n"
				"\n"
				"Trigonometric functions, transformation matrices,\n"
				"vector rotations, and floating point arithmetic,\n"
				"via an infinite stream of unconditional data transfers.\n"
				"\n"
				"Use w, a, s, d, q, e to move.\n"
				"Frame: %d  \n"
				, i);

		p1xc=(int)(c.p1.x*size_w)+off_x;
		p1yc=(int)(c.p1.y*size_h)+off_y;
		p2xc=(int)(c.p2.x*size_w)+off_x;
		p2yc=(int)(c.p2.y*size_h)+off_y;
		p3xc=(int)(c.p3.x*size_w)+off_x;
		p3yc=(int)(c.p3.y*size_h)+off_y;
		p4xc=(int)(c.p4.x*size_w)+off_x;
		p4yc=(int)(c.p4.y*size_h)+off_y;
		p5xc=(int)(c.p5.x*size_w)+off_x;
		p5yc=(int)(c.p5.y*size_h)+off_y;
		p6xc=(int)(c.p6.x*size_w)+off_x;
		p6yc=(int)(c.p6.y*size_h)+off_y;
		p7xc=(int)(c.p7.x*size_w)+off_x;
		p7yc=(int)(c.p7.y*size_h)+off_y;
		p8xc=(int)(c.p8.x*size_w)+off_x;
		p8yc=(int)(c.p8.y*size_h)+off_y;

#if LINE
		line(p1xc, p1yc, p2xc, p2yc);
		line(p2xc, p2yc, p4xc, p4yc);
		line(p4xc, p4yc, p3xc, p3yc);
		line(p3xc, p3yc, p1xc, p1yc);

		line(p5xc, p5yc, p6xc, p6yc);
		line(p6xc, p6yc, p8xc, p8yc);
		line(p8xc, p8yc, p7xc, p7yc);
		line(p7xc, p7yc, p5xc, p5yc);

		line(p1xc, p1yc, p5xc, p5yc);
		line(p2xc, p2yc, p6xc, p6yc);
		line(p3xc, p3yc, p7xc, p7yc);
		line(p4xc, p4yc, p8xc, p8yc);
#else
		move(p1yc,p1xc); addch('o');
		move(p2yc,p2xc); addch('o');
		move(p3yc,p3xc); addch('o');
		move(p4yc,p4xc); addch('o');
		move(p5yc,p5xc); addch('o');
		move(p6yc,p6xc); addch('o');
		move(p7yc,p7xc); addch('o');
		move(p8yc,p8xc); addch('o');
#endif

		refresh();
		ch=getch();
		if (ch=='w') {
			m=mxn;
		}
		else if (ch=='s') {
			m=mxp;
		}
		else if (ch=='a') {
			m=myp;
		}
		else if (ch=='d') {
			m=myn;
		}
		else if (ch=='e') {
			m=mzp;
		}
		else if (ch=='q') {
			m=mzn;
		}
	}
	endwin();
	
	return 0;
}