Shape.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   Shape.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Abstract representation of a shape in 3-space
00009    <!-------------------------------------------------------------------->**/
00010 
00011 #include "Shape.h"
00012 #include <SurfacePoint.h>
00013 #include <Material.h>
00014 #include <GL/gl.h>
00015 
00016 void Shape::initSurfacePoint(SurfacePoint &pt) const {
00017    ASSERT(m_material);
00018    
00019    _getUV(pt);
00020    
00021    if ((pt.normal.hasNormal = hasNormal()))
00022       _getGeometricNormal(pt);
00023    
00024    // fill in material properties (bsdf, emitter, normalS)
00025    m_material->initSurfacePoint(pt);
00026 }
00027 
00028 void Shape::init() {
00029    ASSERT(m_aabb.isValid());
00030    ASSERT(m_material);
00031    
00032    m_surfaceArea = _getSurfaceArea();
00033 }
00034 
00035 void Shape::preview() {
00036    ASSERT(m_material);
00037    m_material->preview(this);
00038 }
00039 
00040 bool Shape::hasNormal() const {
00041    return true;
00042 }
00043 
00044 void Shape::getRandomPoint(SurfacePoint &pt) {
00045    pt.uv.u = Random::sample(0, 1);
00046    pt.uv.v = Random::sample(0, 1);
00047    
00048    getPoint(pt, UV(Random::sample(0, 1), Random::sample(0, 1)));
00049 }
00050 
00051 void Shape::getPoint(SurfacePoint &pt, const UV &uv) {
00052    ASSERT(m_material);
00053    
00054    pt.shape    = this;
00055    pt.position = getPosition(uv);
00056    pt.uv       = uv;
00057    
00058    if ((pt.normal.hasNormal = hasNormal()))
00059       _getGeometricNormal(pt);
00060    
00061    // fill in material properties (bsdf, emitter, normalS)
00062    m_material->initSurfacePoint(pt);
00063 }
00064 
00065 Point3 Shape::getPosition(const UV &uv) {
00066    return Point3();
00067 }
00068 
00069 real_t Shape::getSurfaceArea() {
00070    return m_surfaceArea;
00071 }
00072 
00073 real_t Shape::_getSurfaceArea() {
00074    return 0;
00075 }
00076 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6