removed test directory, converted Shape's material handle to a refptr<Material> instead of a Material *, made refptr<T>::operator*() and operator->() const members

git-svn-id: svn://anubis/fart/trunk@96 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-10 01:09:07 +00:00
parent 2e82f9e2ea
commit 0fc1e468fe
10 changed files with 23 additions and 79 deletions

View File

@ -18,11 +18,8 @@ $(TARGET):
make -C main
make -C parser
$(CXX) -o $@ main/*.o util/*.o shapes/*.o parser/*.o $(CXXFLAGS) $(LDFLAGS)
make -C test
$(CXX) -o tests test/*.o util/*.o shapes/*.o parser/*.o $(CXXFLAGS) $(LDFLAGS)
clean:
make -C test clean
make -C parser clean
make -C main clean
make -C shapes clean

View File

@ -4,19 +4,19 @@
#include <iostream>
using namespace std;
Color Lighting::computePhong(const Material & material,
Color Lighting::computePhong(const refptr<Material> material,
const std::vector<Light *> & lights,
const Ray & viewRay,
const Vector & surfacePoint,
const Vector & surfaceNormal,
const Color & ambientLight)
{
Color result = ambientLight * material.getAmbientColor();
Color result = ambientLight * material->getAmbientColor();
Vector viewDirection = -viewRay.getDirection();
double shininess = material.getShininess();
const Color & diffuseColor = material.getDiffuseColor();
const Color & specularColor = material.getSpecularColor();
double shininess = material->getShininess();
const Color & diffuseColor = material->getDiffuseColor();
const Color & specularColor = material->getSpecularColor();
for (std::vector<Light *>::const_iterator it = lights.begin();
it != lights.end();

View File

@ -6,12 +6,13 @@
#include "Material.h"
#include "util/Ray.h"
#include "util/Color.h"
#include "util/refptr.h"
#include <vector>
class Lighting
{
public:
static Color computePhong(const Material & material,
static Color computePhong(const refptr<Material> material,
const std::vector<Light *> & lights,
const Ray & viewRay,
const Vector & surfacePoint,

View File

@ -176,13 +176,11 @@ Color Scene::traceRay(const Ray & ray)
it++)
{
/* compute the Phong lighting for each hit */
const Material * material = it->first->getMaterial();
if (material == NULL)
material = &Material::white;
refptr<Material> material = it->first->getMaterial();
Vector surfacePoint = ray[it->second];
color = Lighting::computePhong(*material,
color = Lighting::computePhong(material,
m_lights,
ray,
surfacePoint,

View File

@ -191,7 +191,11 @@ shape_items: /* empty */
| material { $$ = $1; }
;
sphere: SPHERE LPAREN number RPAREN LCURLY sphere_items RCURLY
sphere: SPHERE LPAREN number RPAREN LCURLY sphere_items RCURLY {
Sphere * sphere = new Sphere(*($3->the_double));
$$ = new Node();
$$->the_Shape = sphere;
}
;
sphere_items: shape_items

View File

@ -4,5 +4,5 @@
Shape::Shape()
{
m_transparency = 0.0;
m_material = NULL;
m_material = new Material(Material::white);
}

View File

@ -7,6 +7,7 @@
#include "util/Vector.h"
#include "util/Transform.h"
#include "main/Material.h"
#include "util/refptr.h"
#include <vector>
class Shape
@ -28,14 +29,14 @@ class Shape
void setTransparency(double t) { m_transparency = t; }
double getTransparency() const { return m_transparency; }
void setMaterial(Material * material) { m_material = material; }
Material * getMaterial() const { return m_material; }
void setMaterial(refptr<Material> material) { m_material = material; }
refptr<Material> getMaterial() const { return m_material; }
protected:
Transform m_transform;
Transform m_inverse;
double m_transparency;
Material * m_material;
refptr<Material> m_material;
};
#include "Sphere.h"

View File

@ -1,20 +0,0 @@
OBJS := $(patsubst %.cc,%.o,$(wildcard *.cc))
all: $(OBJS)
%.o: %.cc
$(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
# Make dependency files
%.dep: %.cc
@set -e; rm -f $@; \
$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
clean:
-$(RM) -f *.o *.dep
# Include dependency files
include $(OBJS:.o=.dep)

View File

@ -1,37 +0,0 @@
#include <iostream>
#include <cassert>
#include "util/Transform.h"
#include "shapes/Sphere.h"
#include "util/refptr.h"
using namespace std;
class S
{
public:
S(int val)
{
cout << "S constructor, val " << val << endl;
this->val = val;
}
~S() { cout << "S destructor, val " << val << endl; }
int val;
};
int main()
{
S * a = new S(42);
S * b = new S(33);
cout << "a: " << a << endl;
cout << "b: " << b << endl;
cout << "Creating arp" << endl;
refptr<S> arp(a);
cout << "Creating brp" << endl;
refptr<S> brp(b);
cout << "Going to assign brp to arp" << endl;
arp = brp;
cout << "Going to assign a new S to arp" << endl;
arp = new S(21);
cout << "ok, exiting" << endl;
return 0;
}

View File

@ -14,8 +14,8 @@ class refptr
refptr<T> & operator=(const refptr<T> & orig);
refptr<T> & operator=(T * ptr);
~refptr<T>();
T & operator*();
T * operator->();
T & operator*() const;
T * operator->() const;
private:
void cloneFrom(const refptr<T> & orig);
@ -88,12 +88,12 @@ template <typename T> void refptr<T>::destroy()
}
}
template <typename T> T & refptr<T>::operator*()
template <typename T> T & refptr<T>::operator*() const
{
return *m_ptr;
}
template <typename T> T * refptr<T>::operator->()
template <typename T> T * refptr<T>::operator->() const
{
return m_ptr;
}