Ejemplo n.º 1
0
Color Renderer::raytrace(Ray const& ronny,unsigned int depth) const
{
  depth --;

  Hit hit = calculateHit(ronny);

  if (hit.impact)
      {
        Color c{1,0,0};
        float ia = 0.10;
        float ip = 0, LN = 0, RV = 0;
        Material mat{hit.shape->getmat()};
        c.r = ia * mat.ka_.r; //die abmienten
        c.g = ia * mat.ka_.g; //terme werden
        c.b = ia * mat.ka_.b; //zugewiesen
        
          for (unsigned int i = 0 ; i < scene_.sizeLight ; i++)
          {
            if(illuminate(hit, scene_.lights[i]->pos))
            {
              ip = scene_.lights[i]->intensity; //intensität des lichts
              LN = skalar(glm::normalize(scene_.lights[i]->pos - hit.point) , glm::normalize(hit.normal)); //winkel normale / blickwinkel
              RV = skalar(glm::normalize(mirror(scene_.lights[i]->pos , Ray{hit.point, hit.normal})) , glm::normalize(ronny.origin - hit.point));

              if(LN < 0) LN = 0;
              if(RV < 0) RV = 0;
              c.r += ip * (LN * mat.kd_.r + mat.ks_.r * pow(RV,mat.m_));
              c.g += ip * (LN * mat.kd_.g + mat.ks_.g * pow(RV,mat.m_));
              c.b += ip * (LN * mat.kd_.b + mat.ks_.b * pow(RV,mat.m_));
            }
          }
        return c;
      } 

}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    int i, j, n, r, step;
    double s, time, ttime, *a, *b;

    n = atoi(argv[1]);
    r = atoi(argv[2]);
    step = atoi(argv[3]);
    a = (double *) malloc(step * n * sizeof(double));
    b = (double *) malloc(step * n * sizeof(double));

    time = wall_time();
    time = wall_time();
    for (i = 0; i < r; i++)
        empty();
    ttime = wall_time() - time;

    for (i = 0; i < n; i++) {
        a[i] = i;
        b[i] = 1.0 / (i + 1);
    }

    time = wall_time();
    for (j = 0; j < r; j++) {
        s = skalar(a, b, n, step);
    }
    time = wall_time() - time;

    printf("Skalarprodukt  : %f\n", s);
    printf("Laufzeit       : %f s\n", time);
    printf("Overhead       : %g s\n", ttime);
    printf("Zeit pro Wdhlg : %g s\n", time / r);
    printf("Overhead       : %g s\n", ttime / r);
//     printf("Rechenleistung : %6.1f MFlop/s\n", 2.0 * n * r * 1e-6 / (time - ttime));
    printf("Rechenleistung : %6.1f MFlop/s\n", 2.0 * (n/step+1) * r * 1e-6 / (time - ttime));

    free(a);
    free(b);
    return 0;
}
        bool FloatRect::intersects(const Line &line){
            float scalar;

            glm::vec2 ray(line.x2 - line.x1, line.y2 - line.y1);
            float rayLength = length(ray.x, ray.y);
            scalar = skalar(this->x - line.x1, this->y - line.y1, ray.x, ray.y);
            float rayPoint1 = scalar /rayLength;
            scalar = skalar((this->x + this->w) - line.x1, this->y - line.y1, ray.x, ray.y);
            float rayPoint2 = scalar /rayLength;
            scalar = skalar(this->x - line.x1, (this->y + this->h) - line.y1, ray.x, ray.y);
            float rayPoint3 = scalar /rayLength;
            scalar = skalar((this->x + this->w) - line.x1, (this->y + this->h) - line.y1, ray.x, ray.y);
            float rayPoint4 = scalar /rayLength;

            float maxRay = std::fmax(std::fmax(rayPoint1, rayPoint2), std::fmax(rayPoint3, rayPoint4));
            float minRay = std::fmin(std::fmin(rayPoint1, rayPoint2), std::fmin(rayPoint3, rayPoint4));
            if(maxRay < 0.f || minRay > rayLength) return false;

            glm::vec2 ortho(ray.y, -ray.x);
            float orthoLength = length(ortho.x, ortho.y);
            scalar = skalar(this->x - line.x1, this->y - line.y1, ortho.x, ortho.y);
            float orthoPoint1 = scalar / orthoLength;
            scalar = skalar((this->x + this->w) - line.x1, this->y - line.y1, ortho.x, ortho.y);
            float orthoPoint2 = scalar / orthoLength;
            scalar = skalar(this->x - line.x1, (this->y + this->h) - line.y1, ortho.x, ortho.y);
            float orthoPoint3 = scalar / orthoLength;
            scalar = skalar((this->x + this->w) - line.x1, (this->y + this->h) - line.y1, ortho.x, ortho.y);
            float orthoPoint4 = scalar / orthoLength;

            float maxOrtho = std::fmax(std::fmax(orthoPoint1, orthoPoint2), std::fmax(orthoPoint3, orthoPoint4));
            float minOrtho = std::fmin(std::fmin(orthoPoint1, orthoPoint2), std::fmin(orthoPoint3, orthoPoint4));
            if(maxOrtho < 0.f || minOrtho > 0.f) return false;

            glm::vec2 rectX(this->w, 0);
            float rectXLength = rectX.x;
            scalar = skalar(line.x1 - this->x, line.y1 - this->y, rectX.x, rectX.y);
            float rectXPoint1 = scalar / rectXLength;
            scalar = skalar(line.x2 - this->x, line.y2 - this->y, rectX.x, rectX.y);
            float rectXPoint2 = scalar / rectXLength;
            float maxRectX = std::fmax(rectXPoint1, rectXPoint2);
            float minRectX = std::fmin(rectXPoint1, rectXPoint2);
            if(maxRectX < 0.f || minRectX > rectXLength) return false;

            glm::vec2 rectY(0, this->h);
            float rectYLength = rectY.y;
            scalar = skalar(line.x1 - this->x, line.y1 - this->y, rectY.x, rectY.y);
            float rectYPoint1 = scalar / rectYLength;
            scalar = skalar(line.x2 - this->x, line.y2 - this->y, rectY.x, rectY.y);
            float rectYPoint2 = scalar / rectYLength;
            float maxRectY = std::fmax(rectYPoint1, rectYPoint2);
            float minRectY = std::fmin(rectYPoint1, rectYPoint2);
            if(maxRectY < 0.f || minRectY > rectYLength) return false;
            return true;
        }
Ejemplo n.º 4
0
	bool ortho(vektor* v) {
		if(skalar(v) == 0)
			return true;
		return false;
	};