예제 #1
0
int D3d_negate_z (double a[4][4], double b[4][4]){
   double neg[4][4] ;
  D3d_make_identity(neg);
  neg[2][2]=-1;
  D3d_mat_mult(a,neg,a);
  D3d_mat_mult(b,b, neg);
return 1;
}//finished
예제 #2
0
void D3d_negate_x (double a[4][4], double b[4][4]){

  double reflect[4][4];
  double reflect_inverse[4][4];

  reflect[0][0] = -1;
  reflect_inverse[0][0] = -1;

  D3d_mat_mult(a, reflect, a);
  D3d_mat_mult(b, b, reflect_inverse);

}
예제 #3
0
int D3d_scale (double a[4][4], double b[4][4], double sx, double sy, double sz){
  double scale[4][4] ;
  D3d_make_identity(scale);
  scale[0][0] = sx;
  scale[1][1] = sy;
  scale[2][2] = sz;
  D3d_mat_mult(a, scale, a);
  scale[0][0] = 1/sx;
  scale[1][1] = 1/sy;
  scale[2][2] = 1/sz;
  D3d_mat_mult(b, b, scale);
return 1;
}//Done
예제 #4
0
int D3d_translate (double a[4][4], double b[4][4], double dx, double dy, double dz)
// a = translation*a  
// b = b*translation_inverse  
{
  double t[4][4]; 
  D3d_make_identity(t) ;

  t[0][3] =  dx ;  t[1][3] = dy ;  t[2][3] = dz;
  D3d_mat_mult(a,  t,a) ;

  t[0][3] = -dx ;  t[1][3] = -dy ;t[2][3] = -dz;
  D3d_mat_mult(b,  b,t) ;

  return 1 ;
}//Finished
예제 #5
0
int D3d_cs_rotate_z (double a[4][4], double b[4][4], double cs, double sn){
    double rotate[4][4], r2[4][4] ;
  D3d_make_identity(rotate);
  D3d_make_identity(r2);
  rotate[0][0] = cs;
  rotate[0][1] = -sn;
  rotate[1][0] = sn;
  rotate[1][1] = cs;
  D3d_mat_mult(a, rotate, a);
  r2[0][0] = -cs;
  r2[0][1] = sn;
  r2[1][0] = -sn;
  r2[1][1] = -cs;
    D3d_mat_mult(b,b,r2 );
  return 1;
}
예제 #6
0
int D3d_rotate_z (double a[4][4], double b[4][4], double radians){
  double rotate[4][4], r2[4][4] ;
  D3d_make_identity(rotate);
  D3d_make_identity(r2);
  rotate[0][0] = cos(radians);
  rotate[0][1] = -sin(radians);
  rotate[1][0] = sin(radians);
  rotate[1][1] = cos(radians);
  D3d_mat_mult(a, rotate, a);
  r2[0][0] = cos(-radians);
  r2[0][1] = -sin(-radians);
  r2[1][0] = sin(-radians);
  r2[1][1] = cos(-radians);
    D3d_mat_mult(b,b,r2 );
  return 1;
}//finished
예제 #7
0
void D3d_cs_rotate_z (double a[4][4], double b[4][4], double sn, double cs){

  double rotate[4][4];
  double rotate_inverse[4][4];

  D3d_make_identity(rotate);
  D3d_make_identity(rotate_inverse);

  rotate[0][0] = cs;
  rotate[0][1] = -sn;
  rotate[1][0] = sn;
  rotate[1][1] = cs;

  rotate_inverse[0][0] = cs;
  rotate_inverse[0][1] = sn;
  rotate_inverse[1][0] = -sn;
  rotate_inverse[1][1] = cs;

  D3d_mat_mult(a, rotate, a);
  D3d_mat_mult(b, b, rotate_inverse);
}
예제 #8
0
void D3d_rotate_z (double a[4][4], double b[4][4], double radians){

  double rotate[4][4];
  double rotate_inverse[4][4];

  D3d_make_identity(rotate);
  D3d_make_identity(rotate_inverse);

  rotate[0][0] = cos(radians);
  rotate[0][1] = -sin(radians);
  rotate[1][0] = sin(radians);
  rotate[1][1] = cos(radians);

  rotate_inverse[0][0] = cos(radians);
  rotate_inverse[0][1] = sin(radians);
  rotate_inverse[1][0] = -sin(radians);
  rotate_inverse[1][1] = cos(radians);

  D3d_mat_mult(a, rotate, a);
  D3d_mat_mult(b, b, rotate_inverse);
}
예제 #9
0
void D3d_scale (double a[4][4], double b[4][4], double sx, double sy, double sz){

  double scale[4][4];
  double scale_inverse[4][4];

  D3d_make_identity(scale);
  D3d_make_identity(scale_inverse);

  scale[0][0] = sx;
  scale[1][1] = sy;
	scale[2][2] = sz;

  scale_inverse[0][0] = 1/sx;
  scale_inverse[1][1] = 1/sy;
	scale_inverse[2][2] = 1/sz;

// a = scale*a
// b = b*scale_inverse

  D3d_mat_mult(a, scale, a);
  D3d_mat_mult(b, b, scale_inverse);

}
예제 #10
0
void D3d_translate (double a[4][4], double b[4][4], double dx, double dy, double dz){

  double translate[4][4];
  double translate_inverse[4][4];

  D3d_make_identity(translate);
  D3d_make_identity(translate_inverse);

  translate[0][3] = dx;
  translate[1][3] = dy;
	translate[2][3] = dz;

  translate_inverse[0][3] = -dx;
  translate_inverse[1][3] = -dy;
	translate_inverse[2][3] = -dz;

  D3d_mat_mult(a, translate, a);
  D3d_mat_mult(b, b, translate_inverse);

// a = translation*a
// b = b*translation_inverse


}
int init_scene (int frame_number)
{
  // model variables
  double xcen[4],ycen[4],zcen[4],brad ; // four nodes of tetrahedron
  double ccx,ccy,ccz,ccr ; // location of center of center sphere and radius

  double degrees_of_half_angle = 25;
  double eye[3],coi[3],up[3] ;
  double light_position[3], amb, diff, spow ;
  double theta;
  int k, i, j;
  double V[4][4], Vi[4][4], manMatrix[4][4], invManMatrix[4][4], inherentRGB[3];
  double tempEye[3], tempCoi[3], tempUp[3], Vtemp[4][4], Vitemp[4][4], Len;


  //////////////////////////////////////////////
  //////////////////////////////////////////////
  // build a ball and stick model of a tetrahedron
  //////////////////////////////////////////////
  //////////////////////////////////////////////
  // 3 equally spaced pts around unit circle in the xz-plane 
  // form the base

  for (k = 0 ; k < 3 ; k++) {
    theta = 2*M_PI*k/3 ;
    xcen[k] = cos(theta) ;
    ycen[k] = 0 ;
    zcen[k] = sin(theta) ;
  }

  // you figure where the 4th node of the regular tetrahedron
  xcen[3] = 0 ; ycen[3] = 1 ; zcen[3] = 0 ;

  // also, figure out location of the 5th node of the model
  // which is at the center of mass of the tetrahedron
  for(i=0; i<4; i++){
    ccx = xcen[i];
    ccy = ycen[i]; 
    ccz = zcen[i];
  }

  ccx=ccx/4;
  ccy=ccy/4;
  ccz=ccz/4;

  brad = 0.08 ; // radius of the 4 verts of the tetrahedron
  ccr  = 0.20 ; // the radius of the center node of the model


  ////////////////////////////////////////////////////////////////
  ////////////////////////////////////////////////////////////////

  path (frame_number, eye) ;


  coi[0] = ccx ;
  coi[1] = ccy ;
  coi[2] = ccz ;

  path (frame_number + 1, up) ;

  // printf("eye = %lf %lf %lf\n",eye[0],eye[1],eye[2]) ;
  // printf("coi = %lf %lf %lf\n",coi[0],coi[1],coi[2]) ;
  // printf("up  = %lf %lf %lf\n",up[0],up[1],up[2]) ;

  //////////////////////////////////////////////
  //////////////////////////////////////////////
  for(i=0; i<600; i++){
    for(j=0; j<600; j++){
      z_Buffer[i][j]=100000000;
    }
  }

  path (frame_number + 10, light_position) ;
  amb  = 0.2 ;
  diff = 0.5 ;
  spow = 80 ;

  D3d_view(V, Vi, eye, coi, up);

  //center sphere
  inherentRGB[0]=.2; inherentRGB[1]=.4; inherentRGB[2]=.4;
  makeManMatrix(manMatrix, invManMatrix, ccr, ccr, ccr, 0, 0, 0, ccx, ccy, ccz);
  drawobject(1, eye, degrees_of_half_angle, light_position, V, inherentRGB, manMatrix, sphere);
  //verts of tetrahedron
  for(i=0; i<4; i++){
    //printf("xcen: %lf, ycen: %lf, zcen: %lf\n", xcen[i], ycen[i], zcen[i]);
    inherentRGB[0]=.8; inherentRGB[1]=.1; inherentRGB[2]=.1;
    makeManMatrix(manMatrix, invManMatrix, brad, brad, brad, 0, 0, 0, xcen[i], ycen[i], zcen[i]);
    drawobject(0, eye, degrees_of_half_angle, light_position, V, inherentRGB, manMatrix, sphere);
  }
  //translate hyperboloid up, then rotate to lay flat on z axis
  //use view inverse, with eye as starting sphere, and coi as ending sphere
  //hyperboloids
  inherentRGB[0]=.1; inherentRGB[1]=.8; inherentRGB[2]=.1;
  //sx, sy, sz, rx, ry, rz, tx, ty, tz
  for(i=0; i<4; i++){
    for(k=i; k<4; k++){
      if(i==k) continue;
        tempEye[0] = xcen[i];
        tempEye[1] = ycen[i];
        tempEye[2] = zcen[i];

        tempCoi[0] = xcen[k];
        tempCoi[1] = ycen[k];
        tempCoi[2] = zcen[k];

        tempUp[0] = xcen[i];
        tempUp[1] = ycen[i]+1;
        tempUp[2] = zcen[i];
        Len = sqrt(pow(xcen[k]-xcen[i],2) + pow(ycen[k]-ycen[i],2) + pow(zcen[k]-zcen[i],2)) ;
        D3d_view(Vtemp, Vitemp, tempEye, tempCoi, tempUp);
        makeManMatrix(manMatrix, invManMatrix, .03, Len/2, .03,   90, 0, 0,   0, 0, Len/2);
        D3d_mat_mult(manMatrix, Vitemp, manMatrix);
        drawobject(0, eye, degrees_of_half_angle, light_position, V, inherentRGB, manMatrix, hyperboloid);
    }
  }
//hyperboloids that connect center to verts
  tempEye[0] = ccx;
  tempEye[1] = ccy;
  tempEye[2] = ccz;

  tempUp[0] = ccx+.5;
  tempUp[1] = ccy+.3;
  tempUp[2] = ccz+.8;
  inherentRGB[0] = .1; inherentRGB[1] = .1; inherentRGB[2] = .8;
  for(i=0; i<4; i++){
    tempCoi[0] = xcen[i];
    tempCoi[1] = ycen[i];
    tempCoi[2] = zcen[i];
    Len = sqrt(pow(ccx-xcen[i],2) + pow(ccy-ycen[i],2) + pow(ccz-zcen[i],2)) ;
    D3d_view(Vtemp, Vitemp, tempEye, tempCoi, tempUp);
    makeManMatrix(manMatrix, invManMatrix, .02, Len/2, .02,   90, 0, 0,   0, 0, Len/2);
    D3d_mat_mult(manMatrix, Vitemp, manMatrix);
    drawobject(0, eye, degrees_of_half_angle, light_position, V, inherentRGB, manMatrix, hyperboloid);
  }
}