added jitter and radius parameters to light objects; not using them yet

git-svn-id: svn://anubis/fart/trunk@255 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2010-06-25 16:37:17 +00:00
parent bc27be0f85
commit 1af787b9ab
10 changed files with 53 additions and 11 deletions

View File

@ -1,11 +1,18 @@
#include "Light.h"
#include "util/Vector.h"
#include "util/Ray.h"
Light::Light()
{
m_position = Vector(0, 0, 0);
m_diffuse_color = Color::white;
m_specular_color = Color::white;
m_jitter = 1;
m_radius = 1.0;
}
Vector Light::getJitterPosition() const
{
return m_position + Vector::randomVector() * m_radius;
}

View File

@ -14,6 +14,8 @@ class Light
void setPosition(refptr<Vector> vec) { setPosition(*vec); }
const Vector & getPosition() const { return m_position; }
Vector getJitterPosition() const;
void setDiffuseColor(const Color & diffuse)
{
m_diffuse_color = diffuse;
@ -25,11 +27,15 @@ class Light
m_specular_color = specular;
}
const Color & getSpecularColor() const { return m_specular_color; }
void setJitter(int j) { m_jitter = j; }
int getJitter() const { return m_jitter; }
protected:
Vector m_position;
Color m_diffuse_color;
Color m_specular_color;
double m_radius;
int m_jitter;
};
#include "PointLight.h"

View File

@ -130,6 +130,12 @@ class ItemsNode : public Node
{
};
class JitterNode : public IntegerNode
{
public:
JitterNode(int i) : IntegerNode(i) {}
};
class LightNode : public Node
{
};

View File

@ -49,6 +49,7 @@ diffuse return DIFFUSE;
exposure return EXPOSURE;
height return HEIGHT;
intersect return INTERSECT;
jitter return JITTER;
light return LIGHT;
look_at return LOOKAT;
material return MATERIAL;

View File

@ -68,6 +68,7 @@ static refptr<Node> parsed_scene_node;
%token EXPOSURE;
%token HEIGHT;
%token INTERSECT;
%token JITTER;
%token LIGHT;
%token LOOKAT;
%token MATERIAL;
@ -190,6 +191,11 @@ intersect: INTERSECT LCURLY bool_items RCURLY {
}
;
jitter: JITTER number {
$$ = new JitterNode($2->getInteger());
}
;
light: LIGHT LCURLY light_items RCURLY {
$$ = new LightNode();
$$->addChildren($3);
@ -216,6 +222,12 @@ light_item: POSITION vector {
| COLOR vector {
$$ = new ColorNode($2->getVector());
}
| radius {
$$ = $1;
}
| jitter {
$$ = $1;
}
;
material: MATERIAL LCURLY material_items RCURLY {

View File

@ -15,6 +15,7 @@ scene
light
{
position <-1, -3, 4>
jitter 5
}
plane

View File

@ -18,14 +18,7 @@ Ray::Ray(const Vector & origin, const Vector & direction)
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 Ray(Vector(0, 0, 0), Vector::randomVector());
}
/*

View File

@ -1,7 +1,10 @@
#include <stdlib.h> /* rand() */
#include <math.h>
#include <iostream>
#include "Vector.h"
#include <iostream>
#include <math.h>
Vector::Vector()
{
@ -17,6 +20,18 @@ Vector::Vector(double x, double y, double z)
m_array[2] = z;
}
Vector Vector::randomVector()
{
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 Vector(x, y, z).normalize();
}
Vector & Vector::normalize()
{
double length = mag();

View File

@ -9,6 +9,7 @@ class Vector
public:
Vector();
Vector(double x, double y, double z);
static Vector randomVector();
double & operator[](int idx) { return m_array[idx]; }
double operator[](int idx) const { return m_array[idx]; }
Vector operator-() const;

View File

@ -10,7 +10,7 @@ endif
syn case match
syn keyword fartKeywords ambient color define diffuse exposure height look_at material max_depth multisample options position radius reflectance rotate scale shininess size specular translate transparency union up vfov width
syn keyword fartKeywords ambient color define diffuse exposure height jitter look_at material max_depth multisample options position radius reflectance rotate scale shininess size specular translate transparency union up vfov width
syn keyword fartObjects box camera cyl intersect light plane scene sphere subtract union
syn match fartNumber "\(^\|\W\)\@<=[+-]\=\(\d\+\)\=\.\=\d\+\([eE][+-]\=\d\+\)\="