Example #1
0
Hit PhongMaterial::apply_material(Vector3D view, Light* light, Hit h) const {
  h.diffuse = Colour(0.0, 0.0, 0.0); 
  h.specular = Colour(0.0, 0.0, 0.0); 
  Vector3D l = light->position - h.intersection;
  Vector3D N = h.normal;
  double r = l.length();
  l.normalize(); N.normalize(); view.normalize();
  double ldotN = l.dot(N);
  Vector3D reflected = -l + (2 * ldotN * N);
  reflected.normalize();
  double attenuation = light->falloff[0] + light->falloff[1] * r + 
	light->falloff[2] * r * r;

  if ((m_kd.R() > 0.0 || m_kd.G() > 0.0 || m_kd.B() > 0.0) && l.dot(N) > 0.0) {
	attenuation = 1 / attenuation;
	h.diffuse = (1.0 - m_transparency) * ldotN * attenuation * light->colour * m_kd;
  }

  if ((m_ks.R() > 0.0 || m_ks.G() > 0.0 || m_ks.B() > 0.0) && l.dot(N) > 0.0) {
	Colour phong = phong_coefficient(l, reflected, view, N);
	h.specular = ldotN * attenuation * light->colour * phong * m_ks;
  }

  return h;
}
Example #2
0
void AreaLight::shade(Ray3D &ray) {
    if (ray.in_shadow) {
        // Don't shade the ray beyond its ambient component.
        return;
    }

    Vector3D N = ray.intersection.normal;
    Vector3D L = this->get_position() - ray.intersection.point;
    Vector3D V = -ray.dir;
    Vector3D R = 2.* (L.dot(N) * N) - L;

    N.normalize();
    L.normalize();
    V.normalize();
    R.normalize();

    Colour Ia = _col_ambient;
    Colour Id = _col_diffuse;
    Colour Is = _col_specular;
    Colour Ka = ray.intersection.mat->ambient;
    Colour Kd = ray.intersection.mat->diffuse;
    Colour Ks = ray.intersection.mat->specular;

    Colour ambient = (1) ? (Ka * Ia) : Colour(0,0,0);
    Colour diffuse = (1) ? (fmax(0, N.dot(L)) * Kd * Id) : Colour(0,0,0);
    Colour specular = (1) ? (pow(fmax(0, V.dot(R)), ray.intersection.mat->specular_exp) * Ks * Is) : Colour(0,0,0);

    ray.col = ambient + diffuse + specular;
Example #3
0
Matrix4x4 a4_get_unproject_matrix(int width, int height, double fov, double d, Point3D eye, Vector3D view, Vector3D up)
{
  double fov_r = fov * M_PI / 180.0;
  double h = 2.0*d*tan(fov_r / 2.0); // height of projection plane based field of view and distance to the plane
  
  // First translate the pixel so that it is centered at the origin in the projection plane (origin is in the middle of the screen)
  Matrix4x4 viewport_translate = Matrix4x4().translate(-(double)width / 2.0, -(double)height / 2.0, d);

  // Then scale it to the projection plane such that aspect ratio is maintained and we have a right handed coordinate system
  Matrix4x4 viewport_scale = Matrix4x4().scale(-h / (double)height, -h / (double)height, 1.0);

  // Calculate the basis for the view coordinate system
  view.normalize();
  up.normalize();
  Vector3D u = up.cross(view);
  u.normalize();
  Vector3D v = view.cross(u);
  v.normalize();

  // Create the view rotation and translation matrix
  Matrix4x4 view_rotate = Matrix4x4(Vector4D(u, 0.0), Vector4D(v, 0.0), Vector4D(view, 0.0), Vector4D(0.0, 0.0, 0.0, 1.0)).transpose();
  Matrix4x4 view_translate = Matrix4x4().translate(Vector3D(eye));

  // Now multiply these together to form the pixel to 3D point transformation matrix
  Matrix4x4 unproject = view_translate * view_rotate * viewport_scale * viewport_translate;

  return unproject;
}
Example #4
0
    /**
    * @brief Box3D general constructor
    * @param center_ The center of the box
    * @param x_base_ Firsr axis of the base
    * @param y_base_ Second axis of the base
    * @param sizes_ Size of the box
    */
    Box3D (const Vector3D& center_, const Vector3D &x_base_, const Vector3D &y_base_, const Vector3D &sizes_) : m_center (center_), m_extent(sizes_*0.5f) {
        m_axis[0] = x_base_.normalize();
        m_axis[1] = y_base_.normalize();
        m_axis[2] = m_axis[0].cross_product(m_axis[1]);
        m_axis[1] = m_axis[0].cross_product(m_axis[2]);

    }
Example #5
0
double SphereLight::GetIntensity(const SceneContainer* Scene, const Point3D& TestLoc, const double& Time)
{
    Vector3D Normal = TestLoc - position;
    Normal.normalize();

    Matrix4x4 Rot;
    Rot.rotate('x', 45); // Potential error if Normal = x axis

    Vector3D u = cross((Rot * Normal), Normal);
    u.normalize();
    u = radius * u;

    Vector3D v = cross(Normal, u);
    v.normalize();
    v = radius * v;

    int NumVisiblePoints = 0;
    double theta = 0.f, RingInc = 1.f / (double)NumRings, AngleInc = (2 * M_PI) / (double)RingPoints;

    // Sum up the intensity of the visible points on the light
    for (double i = RingInc; i < 1.f; i += RingInc)
    {
        for (int j = 0; j < 4; j++)
        {
            if (IsVisibleFrom(Scene, position + i * sin(theta)*u + i * cos(theta)*v, TestLoc, Time))
            {
                NumVisiblePoints++;
            }
            theta += AngleInc;
        }
        theta -= 3.f * (AngleInc);
    }
    return (double)NumVisiblePoints / ((double)RingPoints * NumRings);
}
/**
 * Phong Shading
 */
void PointLight::shade( Ray3D& ray ) {
	Intersection intPoint = ray.intersection;

	// construct vectors
	Vector3D n = intPoint.normal;
	Vector3D de = -ray.dir;
	Vector3D s = get_position() - intPoint.point; // light source
	Vector3D m = ((2 * n.dot(s)) * n) - s; // perfect mirror directions

	// normalize
	n.normalize();
	s.normalize();
	m.normalize();
	de.normalize();

	// do the diffuse shading
	do_diffuse(s, n, ray);

	// do the specular shading
	Colour specular(0, 0, 0);

	double mdde = m.dot(de);
	if ( mdde >= 0 ) {
		specular =
			pow(mdde, intPoint.mat->specular_exp)
			* intPoint.mat->specular * _col_specular;
	}

	if ( ray.shadowed ) {
		ray.col = ray.col + (_shadow_opacity * specular);
	} else {
		ray.col = ray.col + specular;
	}
}
Colour AreaLight::shade( Ray3D& ray ) {
    // Arealight shading routine. The shading routine for area lights is the same
    // as for point lights except we dont accumulate the ambient shade here. The
    // raytracer must add ambient light after computing the average of the specular
    // and diffuse lighting components.
    //
    // Also, color values are not clamped here.

    Material* mat = ray.intersection.mat;
    
    // Normal is assumed to be normalized.
    Vector3D normal = ray.intersection.normal;
    normal.normalize();

    Vector3D lightDir = _pos - ray.intersection.point;
    lightDir.normalize();
    
    Vector3D viewDir = ray.origin - ray.intersection.point;
    viewDir.normalize();

    // Compute diffuse component.
    double lightAngle = std::max(0.0,  lightDir.dot(normal));
    Colour diffuseShade = lightAngle * (_col_diffuse * mat->diffuse);

    // Compute specular component.
    Vector3D r = ((2 * (lightDir.dot(normal))) * normal) - lightDir;
    double specIntensity = pow(std::max(0.0, r.dot(viewDir)), mat->specular_exp);
    Colour specularShade = specIntensity * (mat->specular * _col_specular);
    
    return diffuseShade + specularShade;
}
Example #8
0
void AreaLight::shade(Ray3D &ray) {
    // Lighting is purely additive, and will be divided by number of samples, so don't clamp.
    Colour ambient(ray.intersection.mat->ambient);
    ambient = ambient * _col_ambient;

    ray.col = ray.col + ambient;

    if (ray.in_shadow) {
        // Don't shade the ray beyond its ambient component.
        return;
    }

    // Calculate the diffuse component.
    Vector3D s = (this->get_position() - ray.intersection.point);
    s.normalize();
    Vector3D n = ray.intersection.normal;
    n.normalize();
    Colour diffuse = max(0, s.dot(n)) * ray.intersection.mat->diffuse;
    diffuse = diffuse * _col_diffuse;

    // Calculate the specular component.
    Vector3D b = (ray.origin - ray.intersection.point);
    b.normalize();
    Vector3D r = -1 * s + 2 * (n.dot(s) * n);
    r.normalize();
    Colour specular = pow(max(0, r.dot(b)), ray.intersection.mat->specular_exp) * ray.intersection.mat->specular;
    specular = specular * _col_specular;

    ray.col = ray.col + diffuse + specular;
}
Example #9
0
Vector3D Light::specularLight (const Vector3D &rayOrigin, Shape object)
{
    //cout << object.getType() << "\n";
    //cout << object.intersection[0] << ", " << object.intersection[2] << ", " << object.intersection[3] << "\n";
    //cout << object.surfaceNormal[0] << ", " << object.surfaceNormal[2] << ", " << object.surfaceNormal[3] << "\n\n";
    Vector3D lightVector = object.intersection - position;
    lightVector.normalize();

    Vector3D reflectedVector = lightVector - ((2 * lightVector.dot(object.surfaceNormal)) * object.surfaceNormal);

    Vector3D viewportVector = rayOrigin - object.intersection;
    viewportVector.normalize();

    double rDotV = (reflectedVector.dot(viewportVector));
    if(object.getType() == 0){
        rDotV = -rDotV;
    }

    if(rDotV < 0.0){
        rDotV = 0;
    }
    //double rDotV = qMax(0.0, lightReflectedVector.dot(viewportVector));

    double positionIntensity = pow(rDotV, object.specularSpread);

    return positionIntensity * object.specularIntensity * (object.getSpecularColour() * colour);
}
Example #10
0
bool FishEyeCamera::gen_ray(double dx, double dy, Vector3D &ray_dir)
{
    Vector3D u = 1.0 * m_properties->m_left_dir;
    Vector3D v = 1.0 * m_properties->m_up_dir;
    Vector3D w = -1.0 * m_properties->m_view_dir;
    u.normalize();
    v.normalize();
    w.normalize();
    Point2D pn(m_properties->m_pixel_size * 2.0 / (m_properties->m_pixel_size * m_properties->m_screen_width) * dx,
               m_properties->m_pixel_size * 2.0 / (m_properties->m_pixel_size * m_properties->m_screen_height) * dy);
	double r_squared = pn[0] * pn[0] + pn[1] * pn[1];
    
	if (r_squared <= 1.0) {
		float r 		= sqrt(r_squared);
		float psi 		= r * m_psi_max * PI_ON_180;
		float sin_psi 	= sin(psi);
		float cos_psi 	= cos(psi);
		float sin_alpha = pn[1] / r;
		float cos_alpha = pn[0] / r;
		ray_dir = sin_psi * cos_alpha * u +  sin_psi * sin_alpha * v - cos_psi * w;
        
		return true;
	}
	return false;
}
Example #11
0
 void PointLight::shadeDiffuse(Ray3D & ray){
	Intersection intersectionPoint = ray.intersection;
	Vector3D normal = intersectionPoint.normal; // ~n
	normal.normalize();
	Vector3D reflectedDir = -ray.dir; //~c
	Vector3D lightSourceDir = _pos - intersectionPoint.point; //~s
	lightSourceDir.normalize();
	Vector3D pMSpecRefl = (2*lightSourceDir.dot(normal))*normal - lightSourceDir; //~m
	pMSpecRefl.normalize();
	Colour ambLight = (ray.intersection.mat->ambient) * _col_ambient;
	Colour diffLight;
	if (lightSourceDir.dot(normal) < 0)
	{
		diffLight = 0 * (ray.intersection.mat->diffuse) * _col_diffuse;
	}
	else
	{
		diffLight = lightSourceDir.dot(normal) * (ray.intersection.mat->diffuse) * _col_diffuse;
	}
	if (ray.inShadow){
		ray.col = ray.col + ambLight;
	}else{
		ray.col = ray.col + (diffLight + ambLight);
	}
 }
Example #12
0
Matrix4x4 pixel_from_vcs_to_wcs(int width, int height, double fov, double d, Point3D eye, Vector3D view, Vector3D up){
   Matrix4x4 step1_translate = Matrix4x4(
    Vector4D(1.0, 0.0, 0.0, -width/2),
    Vector4D(0.0, 1.0, 0.0, -height/2),
    Vector4D(0.0, 0.0, 1.0, d),
    Vector4D(0.0, 0.0, 0.0, 1.0));

 double h= 2.0 * d* tan(fov*M_PI / 360.0f);
// Matrix4x4 step2_scale = Matrix4x4().scale(-h / height, -h / height, 1.0);
  Matrix4x4 step2_scale = Matrix4x4(
    Vector4D(-h/width, 0.0, 0.0, 0.0),
    Vector4D(0.0, -h/height, 0.0, 0.0),
    Vector4D(0.0, 0.0, 1.0, 0.0),
    Vector4D(0.0, 0.0, 0.0, 1.0));
view.normalize();
 up.normalize();
Vector3D u = up.cross(view);
  u.normalize();
  Vector3D v = view.cross(u);


  v.normalize();
 
 // Matrix4x4 step3_rotate=Matrix4x4(Vector4D(u, 0.0), Vector4D(v, 0.0), Vector4D(view, 0.0), Vector4D(0.0, 0.0, 0.0, 1.0)).transpose();
Matrix4x4 step3_rotate=Matrix4x4(Vector4D(u[0], v[0], view[0], 0.0),Vector4D(u[1], v[1], view[1], 0.0),Vector4D(u[2], v[2], view[2], 0.0),Vector4D(0.0, 0.0, 0.0, 1.0));
 // Matrix4x4 step4_translate=Matrix4x4().translate(eye[0],eye[1],eye[2]);
 Matrix4x4 step4_translate= Matrix4x4(
    Vector4D(1.0, 0.0, 0.0, eye[0]),
  Vector4D(0.0, 1.0, 0.0, eye[1]),
    Vector4D(0.0, 0.0, 1.0, eye[2]),
    Vector4D(0.0, 0.0, 0.0, 1.0));

  return step4_translate* step3_rotate *step2_scale* step1_translate;
} 
Example #13
0
void PointLight::shade( Ray3D& ray ) {
	// TODO: implement this function to fill in values for ray.col
	// using phong shading.  Make sure your vectors are normalized, and
	// clamp colour values to 1.0.
	//
	// It is assumed at this point that the intersection information in ray
	// is available.  So be sure that traverseScene() is called on the ray
	// before this function.
    Vector3D N = ray.intersection.normal;
    Vector3D L = _pos - ray.intersection.point;
    Vector3D V = -ray.dir;
    Vector3D R = 2.* (L.dot(N) * N) - L;

    N.normalize();
    L.normalize();
    V.normalize();
    R.normalize();

    Colour Ia = _col_ambient;
    Colour Id = _col_diffuse;
    Colour Is = _col_specular;
    Colour Ka = ray.intersection.mat->ambient;
    Colour Kd = ray.intersection.mat->diffuse;
    Colour Ks = ray.intersection.mat->specular;

    Colour ambient = (1) ? (Ka * Ia) : Colour(0,0,0);
    Colour diffuse = (1) ? (fmax(0, N.dot(L)) * Kd * Id) : Colour(0,0,0);
    Colour specular = (1) ? (pow(fmax(0, V.dot(R)), ray.intersection.mat->specular_exp) * Ks * Is) : Colour(0,0,0);

    ray.col = ambient + diffuse + specular;
    ray.col.clamp();
}
Example #14
0
void DMDLeapfrogIntegrator::calculateDissipativeAndRandomForces() {
  Real sdv = 1;
  myRandomForces->zero();
  myDissipativeForces->zero();
  for (unsigned int i = 0; i < app->topology->angles.size(); i++) {
    int a1 = app->topology->angles[i].atom1;
    int a2 = app->topology->angles[i].atom2;
    int a3 = app->topology->angles[i].atom3;

    const Vector3D &posi1 = app->positions[a1];
    const Vector3D &posi2 = app->positions[a2];
    const Vector3D &posi3 = app->positions[a3];
    const Vector3D &vel1 = app->velocities[a1];
    const Vector3D &vel2 = app->velocities[a2];
    const Vector3D &vel3 = app->velocities[a3];

    //now handle atoms 1 and 2
    Vector3D unitVec = posi2 - posi1;   // now it is only a vector
    unitVec.normalize();
    // now the vector is unit vector, the dist is the length of the original
    // vector. We assume the weight, w1, and w2 to be 1 always, thus the 
    // following still holds true
    // w1 = w2^2;

    Real coeff = -myGamma * ((vel2 - vel1).dot(unitVec));
    (*myDissipativeForces)[a2] += unitVec * coeff;
    (*myDissipativeForces)[a1] -= unitVec * coeff;
    Real randNum = randomGaussian(sdv, mySeed);
    coeff = mySigma * randNum;
    (*myRandomForces)[a2] += unitVec * coeff;
    (*myRandomForces)[a1] -= unitVec * coeff;

    //now handle atoms 2 and 3
    unitVec = posi3 - posi2;   // now it is only a vector
    unitVec.normalize();

    coeff = -myGamma * ((vel3 - vel2).dot(unitVec));
    (*myDissipativeForces)[a3] += unitVec * coeff;
    (*myDissipativeForces)[a2] -= unitVec * coeff;
    randNum = randomGaussian(sdv, mySeed);
    coeff = mySigma * randNum;
    (*myRandomForces)[a3] += unitVec * coeff;
    (*myRandomForces)[a2] -= unitVec * coeff;

    //now handle atoms 1 and 3
    unitVec = posi3 - posi1;   // now it is only a vector
    unitVec.normalize();

    coeff = -myGamma * ((vel3 - vel1).dot(unitVec));
    (*myDissipativeForces)[a3] += unitVec * coeff;
    (*myDissipativeForces)[a1] -= unitVec * coeff;
    randNum = randomGaussian(sdv, mySeed);
    coeff = mySigma * randNum;
    (*myRandomForces)[a3] += unitVec * coeff;
    (*myRandomForces)[a1] -= unitVec * coeff;
  }
}
Example #15
0
void PointLight::shade( Ray3D& ray ) {
	// TODO: implement this function to fill in values for ray.col
	// using phong shading.  Make sure your vectors are normalized, and
	// clamp colour values to 1.0.
	//
	// It is assumed at this point that the intersection information in ray
	// is available.  So be sure that traverseScene() is called on the ray
	// before this function.

  // intersection normal
  if(!ray.intersection.none) {
	Vector3D N = ray.intersection.normal;
  N.normalize();

  // light direction
  Vector3D L = _pos - ray.intersection.point;
  L.normalize();

  Vector3D R = 2 * L.dot(N) * N - L;
  R.normalize();

  // view direction
  Vector3D D = -ray.dir;
  D.normalize();


    


  Colour ambient = ray.intersection.mat->ambient *_col_ambient;

  Colour diffuse = ray.intersection.mat->diffuse * (std::max(0.0, N.dot(L)) * _col_diffuse);

	double intensity = std::max(0.0, std::pow(D.dot(R),ray.intersection.mat->specular_exp));
  Colour specular = ray.intersection.mat->specular * (intensity * _col_specular);

  //signature
  //ray.col = ray.intersection.mat->diffuse;

  //diffuse and ambient
  //ray.col = diffuse + ambient;

  //Phong
  ray.col = diffuse + ambient + specular;


  ray.col.clamp();
}



}
Example #16
0
/**
 * Diffuse Shading
 */
void PointLight::shade_diffuse( Ray3D& ray ) {
	Intersection intPoint = ray.intersection;

	// construct vectors
	Vector3D n = intPoint.normal;
	Vector3D s = get_position() - intPoint.point;

	// normalize
	n.normalize();
	s.normalize();

	do_diffuse(s, n, ray);
}
Spectrum<constant::spectrumSamples> WhittedBRDF::shade(const Intersection& intersection,
                                                       const Ray& ray,
                                                       const int bounce,
                                                       const TracerSpectrum& tracer) const {
    
    Model* object = intersection.object;
    MaterialBRDF* material = static_cast<MaterialBRDF*>(object->material);
    
    //Calculate light direction.
    Vector3D wi = tracer.scene->light->origin - intersection.point;
    wi.normalize();
    
    //Viewer point direction.
    Vector3D wo = ray.origin - intersection.point;
    wo.normalize();
    
    //Shadow.
    float shadowPercentage = tracer.shadowCalculator->visiblePercentage(intersection.point);

    //Light.
    Spectrum<constant::spectrumSamples> Li = tracer.scene->light->spectrum;
    
    //BRDFs.
    Spectrum<constant::spectrumSamples> f = material->f(wi, wo, intersection);
    
    //SCLT doesn't use any change of coordinate system on
    //whitted model. For this reason we can't take the absolute value
    //of cosTetha attenuation factor: it must be setted to 0 if the
    //dot product is negative (point of surface not seen by the light
    //source).
    float cosI = wi.dot(intersection.normal);
    
    if(cosI <= 0.0f) {
        
        cosI = 0.0f;
    }
    
    //Rendering equation.
    Spectrum<constant::spectrumSamples> L = f * Li * cosI * shadowPercentage;
    
    //Limit bounce ray.
    if(bounce == 0) {
        
        return L;
    }
    
    deltaDiracBRDFSampling(ray, L, *material, intersection, tracer, bounce, Reflection);
    deltaDiracBRDFSampling(ray, L, *material, intersection, tracer, bounce, Transmission);
    
    return L;
}
Example #18
0
RGBColor
SV_Lambertian::sample_f(const ShadeRec& sr, const Vector3D& wo, Vector3D& wi) const {

	Vector3D w = sr.normal;
	Vector3D v = Vector3D(0.0034, 1, 0.0071) ^ w;
	v.normalize();
	Vector3D u = v ^ w;

	Point3D sp = sampler_ptr->sample_hemisphere();
	wi = sp.x * u + sp.y * v + sp.z * w;
	wi.normalize(); 	

	return (kd * cd->get_color(sr) * invPI); 
}
    /*!
     Generate a coorinate system from a vector.
     This method is useful for generate a tangent space coordinate system for isotropic BRDFs.
     
     @param vector1 vector from which the coordinate system is constructed. This must be normalized.
     @param vector2 second axis obtained.
     @param vector3 third axis obtained.
     */
    inline static void generateCoodinateSystem(const Vector3D& vector1, Vector3D& vector2, Vector3D& vector3) {

        if (std::fabs(vector1.x) > std::fabs(vector1.y)) {
            
            vector2 = Vector3D(vector1.z, 0, -vector1.x);
        } else {
            
            vector2 = Vector3D(0, -vector1.z, vector1.y);
        }
        
        vector2.normalize();
        
        vector3 = vector1.cross(vector2);
        vector3.normalize();
    }
Example #20
0
RGBColor Lambertian::sample_f(const ShadeRec& sr, const Vector3D& wo, Vector3D& wi, float& pdf) const {

	Vector3D w = sr.normal;
	Vector3D v = Vector3D(0.0034, 1, 0.0071) ^ w;
	v.normalize();
	Vector3D u = v ^ w;

	Point3D sp = sampler_ptr -> sample_hemisphere();
	wi = sp.x * u + sp.y * v + sp.z * w;
	wi.normalize();

	pdf = sr.normal * wi * invPI;

	return (kd * cd * invPI);
}
Example #21
0
 Vector3D computenormal(const Vector3D & p_) const{
     // compute the cone normal at point p_
     Vector3D e = p_ - m_vertex;
     Vector3D h = e.cross_product(m_axis);
     Vector3D n = e.cross_product(h);
     return n.normalize();
 }
Example #22
0
//Rotates the vector by the indicated number of degrees about the specified axis
Vector3D rotate(Vector3D v, Vector3D axis, float degrees) {
	axis.normalize();
	float radians = degrees * M_PI / 180;
	float s = sin(radians);
	float c = cos(radians);
	return c * v + (1 - c) * axis.dot(v) * axis + s * v.cross(axis);
}
Example #23
0
File: Matte.cpp Project: dicta/ray
Color Matte::shade(ShadeRecord& sr, const Ray& ray) {
   Vector3D wo = ray.direction * -1;
   Color L = ambientBRDF->rho(sr, wo) * LightManager::instance().getAmbientLight(sr);

   for(LightIter it = LightManager::instance().begin(); it != LightManager::instance().end(); it++) {
      Color power;
      Vector3D wis;

      for(int s = 0; s < (*it)->getNumLightSamples(); s++) {
         Vector3D wi = (*it)->getLightDirection(sr);
         wis += wi;
         float ndotwi = sr.normal.dot(wi);

         if(ndotwi > 0.0) {
            Ray shadowRay(sr.hitPoint, wi);
            bool inShadow = (*it)->inShadow(shadowRay, sr);

            if(!inShadow) {
               power += (*it)->L(sr) * (*it)->G(sr) * ndotwi / (*it)->pdf(sr);
            }
         }
      }

      power = power / (*it)->getNumLightSamples();
      wis.normalize();
      L += diffuseBRDF->f(sr, wo, wis) * power;
   }

   return L;
}
/**
 *  Draw Torso.
 *
 *  This function draws a box that represents the torso of the
 *  player.
 */
void NeutralModel :: drawTorso ()
{
    Vector3D a;
    Vector3D b;
    Vector3D c;
    Vector3D d;

    Vector3D ab;
    Vector3D ac;

    Vector3D n;

    a = Vector3D (joint[LSHOULDER]);
    b = Vector3D (joint[RSHOULDER]);
    c = Vector3D (joint[RHIP]);
    d = Vector3D (joint[LHIP]);

    ab = b - a;
    ac = c - a;

    n = ab.cross(ac);
    n.normalize();

    glPushMatrix();
        glBegin(GL_QUADS);
            glNormal3f(n.x, n.y, n.z);
            glVertex3f(a.x, a.y, a.z);
            glVertex3f(b.x, b.y, b.z);
            glVertex3f(c.x, c.y, c.z);
            glVertex3f(d.x, d.y, d.z);
        glEnd();
    glPopMatrix();
}
Example #25
0
unsigned ParticleRod::addContact(ParticleContact *contact,
                                  unsigned limit) const
{
    // Find the length of the rod
    double currentLen = currentLength();

    // Check if we're over-extended
    if (currentLen == length)
    {
        return 0;
    }

    // Otherwise return the contact
    contact->particle[0] = particle[0];
    contact->particle[1] = particle[1];

    // Calculate the normal
    Vector3D normal = particle[1]->getPosition() - particle[0]->getPosition();
    normal.normalize();

    // The contact normal depends on whether we're extending or compressing
    if (currentLen > length) {
        contact->contactNormal = normal;
        contact->penetration = currentLen - length;
    } else {
        contact->contactNormal = normal * -1;
        contact->penetration = length - currentLen;
    }

    // Always use zero restitution (no bounciness)
    contact->restitution = 0;

    return 1;
}
// The 'computeSliceSpacing' method
double LoadSeriesThread::computeSliceSpacing(OrthancClient::Series& series) const
{
    OrthancClient::Instance instance = series.GetInstance(0);
    instance.LoadTagContent("0020-0032"); // ImagePositionPatient
    QString pos1 = instance.GetLoadedTagContent().c_str();
    QStringList pos1s = pos1.split("\\");
    Vector3D pos1vector(pos1s.at(0).toDouble(), pos1s.at(1).toDouble(),
                        pos1s.at(2).toDouble());

    instance.LoadTagContent("0020-0037"); // ImageOrientationPatient
    QString or1 = instance.GetLoadedTagContent().c_str();
    QStringList or1s = or1.split("\\");
    Vector3D v(or1s.at(0).toDouble(), or1s.at(1).toDouble(), or1s.at(2).toDouble());
    Vector3D w(or1s.at(3).toDouble(), or1s.at(4).toDouble(), or1s.at(5).toDouble());

    Vector3D n = v.crossProduct(w);
    n.normalize();

    double min = -1;
    for(unsigned int i = 1 ; i < series.GetInstanceCount() ; i++) // TODO normally one can be enough but some bug forced me to search for the minest
    {
        OrthancClient::Instance instance2 = series.GetInstance(i);
        instance2.LoadTagContent("0020-0032");
        QString pos2 = instance2.GetLoadedTagContent().c_str();
        QStringList pos2s = pos2.split("\\");
        Vector3D pos2vector(pos2s.at(0).toDouble(), pos2s.at(1).toDouble(),
                            pos2s.at(2).toDouble());

        double dist = fabs(n.dotProduct(pos1vector-pos2vector));
        if(dist < min || min < 0)
            min = dist;
    }

    return min;
}
Example #27
0
Vector3D
Pinhole::get_direction(const Point2D& p) const {
	Vector3D dir = p.x * u + p.y * v - d * w;
	dir.normalize();
	
	return(dir);
}
Example #28
0
unsigned ParticleCableConstraint::addContact(ParticleContact *contact,
                                   unsigned limit) const
{
    // Find the length of the cable
    double length = currentLength();

    // Check if we're over-extended
    if (length < maxLength)
    {
        return 0;
    }

    // Otherwise return the contact
    contact->particle[0] = particle;
    contact->particle[1] = 0;

    // Calculate the normal
    Vector3D normal = anchor - particle->getPosition();
    normal.normalize();
    contact->contactNormal = normal;

    contact->penetration = length-maxLength;
    contact->restitution = restitution;

    return 1;
}
Example #29
0
void Solido::resuelveColision(Solido *s) {
    Vector3D vn = s->getP() - this->getP();
    vn.normalize();
    Vector3D vv = s->getV();
    Vector3D vr = vv.reflect(vn);
    s->setV(vr);
}
Point2D NonhierCylinder::mapUV(Point3D pos)
{
	Point2D uv;
	Vector3D C = m_ori;
	C.normalize();

	if (pos.v_[1] <= m_pos.v_[1] || pos.v_[1] >= (m_pos.v_[1]+m_height) ) // cap
	{
		uv.v_[0] = (m_radius - pos.v_[0])/ (2*m_radius);
		uv.v_[1] = (m_radius - pos.v_[2])/ (2*m_radius);
	}
	else
	{
		Vector3D temp = pos - m_pos;
		uv.v_[1] = temp.dot(C)/m_height;

		double tmp = (pos.v_[0] - m_pos.v_[0])/ m_radius; // [-1,1]
		if(tmp > 1)
			tmp = 1;
		else if (tmp < -1)
			tmp = -1;
		uv.v_[0] = acos(tmp) / (M_PI);
	}
	return uv;
}