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 main
make -C parser make -C parser
$(CXX) -o $@ main/*.o util/*.o shapes/*.o parser/*.o $(CXXFLAGS) $(LDFLAGS) $(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: clean:
make -C test clean
make -C parser clean make -C parser clean
make -C main clean make -C main clean
make -C shapes clean make -C shapes clean

View File

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

View File

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

View File

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

View File

@ -191,7 +191,11 @@ shape_items: /* empty */
| material { $$ = $1; } | 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 sphere_items: shape_items

View File

@ -4,5 +4,5 @@
Shape::Shape() Shape::Shape()
{ {
m_transparency = 0.0; 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/Vector.h"
#include "util/Transform.h" #include "util/Transform.h"
#include "main/Material.h" #include "main/Material.h"
#include "util/refptr.h"
#include <vector> #include <vector>
class Shape class Shape
@ -28,14 +29,14 @@ class Shape
void setTransparency(double t) { m_transparency = t; } void setTransparency(double t) { m_transparency = t; }
double getTransparency() const { return m_transparency; } double getTransparency() const { return m_transparency; }
void setMaterial(Material * material) { m_material = material; } void setMaterial(refptr<Material> material) { m_material = material; }
Material * getMaterial() const { return m_material; } refptr<Material> getMaterial() const { return m_material; }
protected: protected:
Transform m_transform; Transform m_transform;
Transform m_inverse; Transform m_inverse;
double m_transparency; double m_transparency;
Material * m_material; refptr<Material> m_material;
}; };
#include "Sphere.h" #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=(const refptr<T> & orig);
refptr<T> & operator=(T * ptr); refptr<T> & operator=(T * ptr);
~refptr<T>(); ~refptr<T>();
T & operator*(); T & operator*() const;
T * operator->(); T * operator->() const;
private: private:
void cloneFrom(const refptr<T> & orig); 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; return *m_ptr;
} }
template <typename T> T * refptr<T>::operator->() template <typename T> T * refptr<T>::operator->() const
{ {
return m_ptr; return m_ptr;
} }