src/scene.cc
branchpyrit
changeset 47 320d5d466864
parent 46 6493fb65f0b1
child 49 558fde7da82a
equal deleted inserted replaced
46:6493fb65f0b1 47:320d5d466864
     1 /*
     1 /*
     2  * scene.cc: classes for objects in scene
     2  * scene.cc: classes for objects in scene
     3  *
     3  *
     4  * This file is part of Pyrit Ray Tracer.
     4  * This file is part of Pyrit Ray Tracer.
     5  *
     5  *
     6  * Copyright 2006, 2007  Radek Brich
     6  * Copyright 2006, 2007, 2008  Radek Brich
     7  *
     7  *
     8  * Permission is hereby granted, free of charge, to any person obtaining a copy
     8  * Permission is hereby granted, free of charge, to any person obtaining a copy
     9  * of this software and associated documentation files (the "Software"), to deal
     9  * of this software and associated documentation files (the "Software"), to deal
    10  * in the Software without restriction, including without limitation the rights
    10  * in the Software without restriction, including without limitation the rights
    11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    26 
    26 
    27 #include <math.h>
    27 #include <math.h>
    28 
    28 
    29 #include "common.h"
    29 #include "common.h"
    30 #include "scene.h"
    30 #include "scene.h"
    31 
       
    32 int DefaultSampler::initSampleSet()
       
    33 {
       
    34 	if ( phase == 0 )
       
    35 	{
       
    36 		phase++;
       
    37 		return w*h;
       
    38 	}
       
    39 	else return 0;
       
    40 }
       
    41 
       
    42 Sample* DefaultSampler::nextSample(Sample *prev)
       
    43 {
       
    44 	DefaultSample *s = new DefaultSample;
       
    45 	if (prev)
       
    46 	{
       
    47 		DefaultSample *sp = static_cast<DefaultSample*>(prev);
       
    48 		s->sx = sp->sx + 1;
       
    49 		s->sy = sp->sy;
       
    50 		if (s->sx >= w)
       
    51 		{
       
    52 			s->sx = 0;
       
    53 			s->sy++;
       
    54 		}
       
    55 		if (s->sy >= h)
       
    56 		{
       
    57 			delete s;
       
    58 			return NULL;
       
    59 		}
       
    60 		s->x = (Float)s->sx/h - (Float)w/h/2.0;
       
    61 		s->y = (Float)s->sy/h - 0.5;
       
    62 	}
       
    63 	else
       
    64 	{
       
    65 		s->x = -(Float)w/h/2.0;
       
    66 		s->y = -0.5;
       
    67 		s->sx = 0;
       
    68 		s->sy = 0;
       
    69 	}
       
    70 	return s;
       
    71 }
       
    72 
       
    73 void DefaultSampler::saveSample(Sample *samp, Colour &col)
       
    74 {
       
    75 	DefaultSample *sp = static_cast<DefaultSample*>(samp);
       
    76 	Float *buf = buffer + 3*(sp->sy*w + sp->sx);
       
    77 	*(buf++) = col.r;
       
    78 	*(buf++) = col.g;
       
    79 	*(buf++) = col.b;
       
    80 }
       
    81 
    31 
    82 void Camera::rotate(const Quaternion &q)
    32 void Camera::rotate(const Quaternion &q)
    83 {
    33 {
    84 	/*
    34 	/*
    85 	//non-optimized
    35 	//non-optimized