src/scene.cc
branchpyrit
changeset 46 6493fb65f0b1
parent 44 3763b26244f0
child 47 320d5d466864
equal deleted inserted replaced
45:76b254ce92cf 46:6493fb65f0b1
    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 }
    31 
    81 
    32 void Camera::rotate(const Quaternion &q)
    82 void Camera::rotate(const Quaternion &q)
    33 {
    83 {
    34 	/*
    84 	/*
    35 	//non-optimized
    85 	//non-optimized
    73 void Camera::move(const Float fw, const Float left, const Float up)
   123 void Camera::move(const Float fw, const Float left, const Float up)
    74 {
   124 {
    75 	eye = eye + fw*p + left*u + up*v;
   125 	eye = eye + fw*p + left*u + up*v;
    76 }
   126 }
    77 
   127 
       
   128 Ray Camera::makeRay(Sample *samp)
       
   129 {
       
   130 	Vector3 dir = p + u*(0.5/f)*samp->x + v*(-0.5/f)*samp->y;
       
   131 	dir.normalize();
       
   132 	return Ray(eye, dir);
       
   133 }
       
   134 
    78 /* http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm */
   135 /* http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm */
    79 bool BBox::intersect(const Ray &ray, Float &a, Float &b)
   136 bool BBox::intersect(const Ray &ray, Float &a, Float &b)
    80 {
   137 {
    81 	register Float tnear = -Inf;
   138 	register Float tnear = -Inf;
    82 	register Float tfar = Inf;
   139 	register Float tfar = Inf;