Exemple #1
0
/**
  Compute the normal for a polygon.

  Basically, the method simply takes the first three vertices A, B, C and 
  computes the normal of that triangle.
  However, it is checked that A!=B and B!=C, so it is possible that more than
  three vertices are looked up.

  \param poly Polygon index
  \param[out] N Receives the resulting normal
 */
void PolyhedronGeom::computeNormal(int poly, vec3d& N)
{
  VertexLoop& loop = *(*polys[poly])[0];
  int size = loop.size();
  int i = 2;

  if (size<3)
    return;

  const vec3d* a = &(verts.getValue(loop[0]));
  const vec3d* b = &(verts.getValue(loop[1]));
  while(a==b)
  {
    if (i>=size)
      return;
    b = &(verts.getValue(loop[i]));
    i++;
  }
  const vec3d* c = &(verts.getValue(loop[i]));
  while(b==c)
  {
    if (i>=size)
      return;
    c = &(verts.getValue(loop[i]));
    i++;
  }

  N.cross((*b)-(*a), (*c)-(*a));
  try
  {
    N.normalize(N);
  }
  catch(...)
  {
    N.set(0,0,0);
  } 
}
Exemple #2
0
void ray::setDirection(const vec3d& direction)
{
  _direction = direction.normalize();
}
Exemple #3
0
//////////////////
// Constructors //
//////////////////
ray::ray(const vec3d& origin, const vec3d& direction)
{
  _origin = origin;
  _direction = direction.normalize();
}
Exemple #4
0
//this appears to be for a more mathematical xyz, where z is up
///TODO: rederive this to work with my coordinates
matrix getRotMatrix(vec3d u,double theta){
	u.normalize();
	const double c=cos(theta);
	return I*c+u.crossprodMatrix()*sin(theta)+u.tensorProd(u)*(1-c);
}
//////////////////
// Constructors //
//////////////////
directionalLightsource::directionalLightsource(const color& intensity, const vec3d& dir)
{
  _intensity = intensity;
  _direction = dir.normalize();
}