Esempio n. 1
0
TRANSFORM *Create_Transform()
{
	TRANSFORM *New;

	New = (TRANSFORM *)POV_MALLOC(sizeof (TRANSFORM), "transform");

	MIdentity (New->matrix);
	MIdentity (New->inverse);

	return (New);
}
Esempio n. 2
0
void Compute_Rotation_Transform (TRANSFORM *transform, const VECTOR vector)
{
	register DBL cosx, cosy, cosz, sinx, siny, sinz;
	MATRIX Matrix;
	VECTOR Radian_Vector;

	VScale (Radian_Vector, vector, M_PI_180);

	MIdentity (transform->matrix);

	cosx = cos (Radian_Vector[X]);
	sinx = sin (Radian_Vector[X]);
	cosy = cos (Radian_Vector[Y]);
	siny = sin (Radian_Vector[Y]);
	cosz = cos (Radian_Vector[Z]);
	sinz = sin (Radian_Vector[Z]);

	(transform->matrix) [1][1] = cosx;
	(transform->matrix) [2][2] = cosx;
	(transform->matrix) [1][2] = sinx;
	(transform->matrix) [2][1] = 0.0 - sinx;

	MTranspose (transform->inverse, transform->matrix);

	MIdentity (Matrix);

	Matrix [0][0] = cosy;
	Matrix [2][2] = cosy;
	Matrix [0][2] = 0.0 - siny;
	Matrix [2][0] = siny;

	MTimesA (transform->matrix, Matrix);

	MTranspose (Matrix);

	MTimesB (Matrix, transform->inverse);

	MIdentity (Matrix);

	Matrix [0][0] = cosz;
	Matrix [1][1] = cosz;
	Matrix [0][1] = sinz;
	Matrix [1][0] = 0.0 - sinz;

	MTimesA (transform->matrix, Matrix);

	MTranspose (Matrix);

	MTimesB (Matrix, transform->inverse);
}
Esempio n. 3
0
void Compute_Translation_Transform (TRANSFORM *transform, const VECTOR vector)
{
	MIdentity (transform->matrix);

	(transform->matrix)[3][0] = vector[X];
	(transform->matrix)[3][1] = vector[Y];
	(transform->matrix)[3][2] = vector[Z];

	MIdentity (transform->inverse);

	(transform->inverse)[3][0] = -vector[X];
	(transform->inverse)[3][1] = -vector[Y];
	(transform->inverse)[3][2] = -vector[Z];
}
Esempio n. 4
0
void Compute_Scaling_Transform (TRANSFORM *result, const VECTOR vector)
{
	MIdentity (result->matrix);

	(result->matrix)[0][0] = vector[X];
	(result->matrix)[1][1] = vector[Y];
	(result->matrix)[2][2] = vector[Z];

	MIdentity (result->inverse);

	(result->inverse)[0][0] = 1.0 / vector[X];
	(result->inverse)[1][1] = 1.0 / vector[Y];
	(result->inverse)[2][2] = 1.0 / vector[Z];
}
Esempio n. 5
0
void Compute_Axis_Rotation_Transform (TRANSFORM *transform, const VECTOR AxisVect, DBL angle)
{
	DBL cosx, sinx;
	VECTOR V1;

	VNormalize(V1, AxisVect);

	MIdentity(transform->matrix);

	cosx = cos(angle);
	sinx = sin(angle);

	transform->matrix[0][0] = V1[X] * V1[X] + cosx * (1.0 - V1[X] * V1[X]);
	transform->matrix[0][1] = V1[X] * V1[Y] * (1.0 - cosx) + V1[Z] * sinx;
	transform->matrix[0][2] = V1[X] * V1[Z] * (1.0 - cosx) - V1[Y] * sinx;

	transform->matrix[1][0] = V1[X] * V1[Y] * (1.0 - cosx) - V1[Z] * sinx;
	transform->matrix[1][1] = V1[Y] * V1[Y] + cosx * (1.0 - V1[Y] * V1[Y]);
	transform->matrix[1][2] = V1[Y] * V1[Z] * (1.0 - cosx) + V1[X] * sinx;

	transform->matrix[2][0] = V1[X] * V1[Z] * (1.0 - cosx) + V1[Y] * sinx;
	transform->matrix[2][1] = V1[Y] * V1[Z] * (1.0 - cosx) - V1[X] * sinx;
	transform->matrix[2][2] = V1[Z] * V1[Z] + cosx * (1.0 - V1[Z] * V1[Z]);

	MTranspose(transform->inverse, transform->matrix);
}
Esempio n. 6
0
WARP *Create_Warp (int Warp_Type)
{
 WARP *New;
 TURB *TNew;
 REPEAT *RNew;
 TRANS *TRNew;
 BLACK_HOLE *BNew;
 TOROIDAL *TorNew;
 SPHEREW *SNew;
 CYLW *CNew;
 PLANARW *PNew;
   
 New = NULL;

 switch (Warp_Type)
 {
   case CLASSIC_TURB_WARP:
   case EXTRA_TURB_WARP:
     
     TNew = (TURB *)POV_MALLOC(sizeof(TURB),"turbulence struct");

     Make_Vector(TNew->Turbulence,0.0,0.0,0.0);

     TNew->Octaves = 6;
     TNew->Omega = 0.5;
     TNew->Lambda = 2.0;

     New = (WARP *)TNew;

     break;
     
   case REPEAT_WARP:

     RNew = (REPEAT *)POV_MALLOC(sizeof(REPEAT),"repeat warp");

     RNew->Axis = -1;
     RNew->Width = 0.0;

     Make_Vector(RNew->Offset,0.0,0.0,0.0);
     Make_Vector(RNew->Flip,1.0,1.0,1.0);

     New = (WARP *)RNew;

     break;

   case BLACK_HOLE_WARP:
     BNew = (BLACK_HOLE *)POV_MALLOC (sizeof (BLACK_HOLE), "black hole warp") ;
     Make_Vector (BNew->Center, 0.0, 0.0, 0.0) ;
     Make_Vector (BNew->Repeat_Vector, 0.0, 0.0, 0.0) ;
     Make_Vector (BNew->Uncertainty_Vector, 0.0, 0.0, 0.0) ;
     BNew->Strength = 1.0 ;
     BNew->Power = 2.0 ;
     BNew->Radius = 1.0 ;
     BNew->Radius_Squared = 1.0 ;
     BNew->Inverse_Radius = 1.0 ;
     BNew->Inverted = false ;
     BNew->Type = 0 ;
     BNew->Repeat = false ;
     BNew->Uncertain = false ;
     New = (WARP *) BNew ;
     break ;

   case TRANSFORM_WARP:

     TRNew = (TRANS *)POV_MALLOC(sizeof(TRANS),"pattern transform");

     MIdentity (TRNew->Trans.matrix);
     MIdentity (TRNew->Trans.inverse);

     New = (WARP *)TRNew;

     break;

   case SPHERICAL_WARP:
     SNew = (SPHEREW *)POV_MALLOC(sizeof(SPHEREW),"cylindrical warp");
     Make_Vector (SNew->Orientation_Vector, 0.0, 0.0, 1.0) ;
     SNew->DistExp = 0.0;
     New = (WARP *)SNew;
     break;

   case PLANAR_WARP:
     PNew = (PLANARW *)POV_MALLOC(sizeof(PLANARW),"planar warp");
     Make_Vector (PNew->Orientation_Vector, 0.0, 0.0, 1.0) ;
     PNew->OffSet = 0.0;
     New = (WARP *)PNew;
     break;

   case CYLINDRICAL_WARP:
     CNew = (CYLW *)POV_MALLOC(sizeof(CYLW),"cylindrical warp");
     Make_Vector (CNew->Orientation_Vector, 0.0, 0.0, 1.0) ;
     CNew->DistExp = 0.0;
     New = (WARP *)CNew;
     break;

   case TOROIDAL_WARP:
     TorNew = (TOROIDAL *)POV_MALLOC(sizeof(TOROIDAL),"toroidal warp");
     TorNew->MajorRadius = 1.0 ;
     TorNew->DistExp = 0.0;
     Make_Vector (TorNew->Orientation_Vector, 0.0, 0.0, 1.0) ;
     New = (WARP *) TorNew;
     break;

   default:
     Error("Unknown Warp type %d.",Warp_Type);
  }
  
  New->Warp_Type = Warp_Type;
  New->Prev_Warp = NULL;
  New->Next_Warp = NULL;
  
  return(New);
}
Esempio n. 7
0
void Polygon::Compute_Polygon(int number, Vector3d *points)
{
    int i;
    DBL x, y, z, d;
    Vector3d o, u, v, w, N;
    MATRIX a, b;

    /* Create polygon data. */

    if (Data == NULL)
    {
        Data = reinterpret_cast<POLYGON_DATA *>(POV_MALLOC(sizeof(POLYGON_DATA), "polygon points"));

        Data->References = 1;

        Data->Number = number;

        Data->Points = reinterpret_cast<Vector2d *>(POV_MALLOC(number*sizeof(Vector2d), "polygon points"));
    }
    else
    {
        throw POV_EXCEPTION_STRING("Polygon data already computed.");
    }

    /* Get polygon's coordinate system (one of the many possible) */

    o = points[0];

    /* Find valid, i.e. non-zero u vector. */

    for (i = 1; i < number; i++)
    {
        u = points[i] - o;

        if (u.lengthSqr() > EPSILON)
        {
            break;
        }
    }

    if (i == number)
    {
        Set_Flag(this, DEGENERATE_FLAG);

;// TODO MESSAGE    Warning("Points in polygon are co-linear. Ignoring polygon.");
    }

    /* Find valid, i.e. non-zero v and w vectors. */

    for (i++; i < number; i++)
    {
        v = points[i] - o;

        w = cross(u, v);

        if ((v.lengthSqr() > EPSILON) && (w.lengthSqr() > EPSILON))
        {
            break;
        }
    }

    if (i == number)
    {
        Set_Flag(this, DEGENERATE_FLAG);

;// TODO MESSAGE    Warning("Points in polygon are co-linear. Ignoring polygon.");
    }

    u = cross(v, w);
    v = cross(w, u);

    u.normalize();
    v.normalize();
    w.normalize();

    MIdentity(a);
    MIdentity(b);

    a[3][0] = -o[X];
    a[3][1] = -o[Y];
    a[3][2] = -o[Z];

    b[0][0] =  u[X];
    b[1][0] =  u[Y];
    b[2][0] =  u[Z];

    b[0][1] =  v[X];
    b[1][1] =  v[Y];
    b[2][1] =  v[Z];

    b[0][2] =  w[X];
    b[1][2] =  w[Y];
    b[2][2] =  w[Z];

    MTimesC(Trans->inverse, a, b);

    MInvers(Trans->matrix, Trans->inverse);

    /* Project points onto the u,v-plane (3D --> 2D) */

    for (i = 0; i < number; i++)
    {
        x = points[i][X] - o[X];
        y = points[i][Y] - o[Y];
        z = points[i][Z] - o[Z];

        d = x * w[X] + y * w[Y] + z * w[Z];

        if (fabs(d) > ZERO_TOLERANCE)
        {
            Set_Flag(this, DEGENERATE_FLAG);

;// TODO MESSAGE      Warning("Points in polygon are not co-planar. Ignoring polygons.");
        }

        Data->Points[i][X] = x * u[X] + y * u[Y] + z * u[Z];
        Data->Points[i][Y] = x * v[X] + y * v[Y] + z * v[Z];
    }

    N = Vector3d(0.0, 0.0, 1.0);
    MTransNormal(S_Normal, N, Trans);

    S_Normal.normalize();

    Compute_BBox();
}
Esempio n. 8
0
void Compute_Polygon(POLYGON *Polyg, int Number, VECTOR *Points)
{
  int i;
  DBL x, y, z, d;
  VECTOR o, u, v, w, N;
  MATRIX a, b;

  /* Create polygon data. */

  if (Polyg->Data == NULL)
  {
    Polyg->Data = (POLYGON_DATA *)POV_MALLOC(sizeof(POLYGON_DATA), "polygon points");

    Polyg->Data->References = 1;

    Polyg->Data->Number = Number;

    Polyg->Data->Points = (UV_VECT *)POV_MALLOC(Number*sizeof(UV_VECT), "polygon points");
  }
  else
  {
    Error("Polygon data already computed.");
  }

  /* Get polygon's coordinate system (one of the many possible) */

  Assign_Vector(o, Points[0]);

  /* Find valid, i.e. non-zero u vector. */
  
  for (i = 1; i < Number; i++)
  {
    VSub(u, Points[i], o);

    if (VSumSqr(u) > EPSILON)
    {
      break;
    }
  }

  if (i == Number)
  {
    Set_Flag(Polyg, DEGENERATE_FLAG);

    Warning(0, "Points in polygon are co-linear. Ignoring polygon.");
  }

  /* Find valid, i.e. non-zero v and w vectors. */
  
  for (i++; i < Number; i++)
  {
    VSub(v, Points[i], o);
    
    VCross(w, u, v);

    if ((VSumSqr(v) > EPSILON) && (VSumSqr(w) > EPSILON))
    {
      break;
    }
  }

  if (i == Number)
  {
    Set_Flag(Polyg, DEGENERATE_FLAG);

    Warning(0, "Points in polygon are co-linear. Ignoring polygon.");
  }

  VCross(u, v, w);
  VCross(v, w, u);

  VNormalize(u, u);
  VNormalize(v, v);
  VNormalize(w, w);

  MIdentity(a);
  MIdentity(b);

  a[3][0] = -o[X];
  a[3][1] = -o[Y];
  a[3][2] = -o[Z];

  b[0][0] =  u[X];
  b[1][0] =  u[Y];
  b[2][0] =  u[Z];

  b[0][1] =  v[X];
  b[1][1] =  v[Y];
  b[2][1] =  v[Z];

  b[0][2] =  w[X];
  b[1][2] =  w[Y];
  b[2][2] =  w[Z];

  MTimesC(Polyg->Trans->inverse, a, b);

  MInvers(Polyg->Trans->matrix, Polyg->Trans->inverse);

  /* Project points onto the u,v-plane (3D --> 2D) */

  for (i = 0; i < Number; i++)
  {
    x = Points[i][X] - o[X];
    y = Points[i][Y] - o[Y];
    z = Points[i][Z] - o[Z];

    d = x * w[X] + y * w[Y] + z * w[Z];

    if (fabs(d) > ZERO_TOLERANCE)
    {
      Set_Flag(Polyg, DEGENERATE_FLAG);

      Warning(0, "Points in polygon are not co-planar. Ignoring polygons.");
    }

    Polyg->Data->Points[i][X] = x * u[X] + y * u[Y] + z * u[Z];
    Polyg->Data->Points[i][Y] = x * v[X] + y * v[Y] + z * v[Z];
  }
  
  Make_Vector(N, 0.0, 0.0, 1.0);
  MTransNormal(Polyg->S_Normal, N, Polyg->Trans);

  VNormalizeEq(Polyg->S_Normal);

  Compute_Polygon_BBox(Polyg);
}