added Ray::randomRay() to generated a ray with origin at (0,0,0) and a random direction
git-svn-id: svn://anubis/fart/trunk@254 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
5eeee5fd90
commit
bc27be0f85
10
main/fart.cc
10
main/fart.cc
@ -1,15 +1,19 @@
|
|||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h> /* sysconf() */
|
#include <unistd.h> /* sysconf() */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h> /* rand(), srand() */
|
||||||
|
#include <time.h> /* time() */
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <sys/time.h> /* gettimeofday() */
|
#include <sys/time.h> /* gettimeofday() */
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
#include "distrib/distrib.h"
|
#include "distrib/distrib.h"
|
||||||
#include "BMP.h"
|
#include "BMP.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void usage(const char * progname)
|
void usage(const char * progname)
|
||||||
@ -163,6 +167,8 @@ int main(int argc, char * argv[])
|
|||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
const char * filename = argv[optind];
|
const char * filename = argv[optind];
|
||||||
client_options.push_back(filename);
|
client_options.push_back(filename);
|
||||||
Scene scene(scene_options, filename);
|
Scene scene(scene_options, filename);
|
||||||
|
17
util/Ray.cc
17
util/Ray.cc
@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
|
#include <stdlib.h> /* rand() */
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "Ray.h"
|
#include "Ray.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
Ray::Ray()
|
Ray::Ray()
|
||||||
{
|
{
|
||||||
@ -13,6 +16,18 @@ Ray::Ray(const Vector & origin, const Vector & direction)
|
|||||||
m_direction.normalize();
|
m_direction.normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ray Ray::randomRay()
|
||||||
|
{
|
||||||
|
double x, y, z;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
x = 2.0 * rand() / RAND_MAX - 1.0;
|
||||||
|
y = 2.0 * rand() / RAND_MAX - 1.0;
|
||||||
|
z = 2.0 * rand() / RAND_MAX - 1.0;
|
||||||
|
} while (x*x + y*y + z*z <= 1.0);
|
||||||
|
return Ray(Vector(0, 0, 0), Vector(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return a vector for the point at distance dist
|
* return a vector for the point at distance dist
|
||||||
* from the ray's origin point, along its direction.
|
* from the ray's origin point, along its direction.
|
||||||
|
@ -10,6 +10,7 @@ class Ray
|
|||||||
public:
|
public:
|
||||||
Ray();
|
Ray();
|
||||||
Ray(const Vector & origin, const Vector & direction);
|
Ray(const Vector & origin, const Vector & direction);
|
||||||
|
static Ray randomRay();
|
||||||
const Vector & getOrigin() const { return m_origin; }
|
const Vector & getOrigin() const { return m_origin; }
|
||||||
const Vector & getDirection() const { return m_direction; }
|
const Vector & getDirection() const { return m_direction; }
|
||||||
Vector getPositionAt(double dist) const;
|
Vector getPositionAt(double dist) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user