fart/main/Scene.h
Josh Holtrop 01a713af98 added Scene::processForNode() to process for nodes
git-svn-id: svn://anubis/fart/branches/scene-file-scripting@332 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2010-10-04 21:26:12 +00:00

109 lines
4.0 KiB
C++

#ifndef SCENE_H
#define SCENE_H SCENE_H
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <stack>
#include "util/refptr.h"
#include "util/Ray.h"
#include "util/Color.h"
#include "util/Material.h"
#include "util/Polygon.h"
#include "shapes/shapes.h"
#include "parser/parser.h"
#include "parser/nodes.h"
#include "Light.h"
#define SCENE_FACTOR_THRESHOLD 0.02
class Scene
{
public:
Scene(const std::map<std::string, const char *> & options,
const char * filename);
~Scene();
void setWidth(int width) { m_width = width; }
void setHeight(int height) { m_height = height; }
void setMultisampleLevel(int level) { m_multisample_level = level; }
void setVFOV(double vfov) { m_vfov = vfov; }
void setAmbientLight(const Color & al) { m_ambient_light = al; }
void renderPixel(int x, int y, unsigned char * pixel);
void setMaxDepth(int d) { m_max_depth = d; }
int getWidth() { return m_width; }
int getHeight() { return m_height; }
int getMultisampleLevel() { return m_multisample_level; }
int getAmbientOcclusionLevel() { return m_ambient_occlusion_level; }
double getVFOV() { return m_vfov; }
int getMaxDepth() { return m_max_depth; }
protected:
/* private methods */
Color traceRay(const Ray & ray);
Color traceRayRecurse(const Ray & ray, int depth, double factor);
Shape::Intersection getRayClosestHit(const Ray & ray);
Color computePhong(const refptr<Material> material,
const Ray & viewRay,
const Vector & surfacePoint,
const Vector & surfaceNormal);
Color calculateLightContribution(const Ray & toLight,
const Vector & lightPosition);
Color calculateAmbientOcclusion(const Ray & surfaceNormal);
/* In Scene-load.cc */
void load(const char * filename);
void processNode(refptr<Node> node);
void processChildren(refptr<Node> node);
void processScene(refptr<Node> node);
refptr<Material> processMaterial(refptr<Node> node);
ShapeRef processBox(refptr<Node> node);
ShapeRef processCyl(refptr<Node> node);
refptr<Light> processLight(refptr<Node> node);
ShapeRef processPlane(refptr<Node> node);
ShapeRef processSphere(refptr<Node> node);
ShapeRef processShape(refptr<Node> node);
ShapeRef processBool(refptr<Node> node);
ShapeRef processExtrude(refptr<Node> node);
ShapeRef processShapeRef(refptr<Node> node);
refptr<Polygon> processPolygon(refptr<Node> node);
refptr<Polygon> processNGon(refptr<Node> node);
bool processTransforms(refptr<Node> node);
void processCamera(refptr<Node> node);
void processOptions(refptr<Node> node);
std::vector<ShapeRef> processTransformBlock(refptr<Node> node);
std::vector<ShapeRef> processGeneralItems(refptr<Node> node);
std::vector<ShapeRef> processForNode(refptr<Node> node);
void processMaterialDefinition(refptr<Node> node);
void processShapeDefinition(refptr<Node> node);
/* rendering parameters */
int m_width;
int m_height;
int m_multisample_level;
double m_vfov;
Color m_ambient_light;
int m_max_depth;
double m_exposure;
int m_ambient_occlusion_level;
/* private data */
std::vector<ShapeRef> m_shapes;
std::map<std::string, ShapeRef> m_shape_definitions;
std::vector< refptr<Light> > m_lights;
std::stack<Transform> m_transforms;
double m_view_plane_dist;
int m_multisample_level_squared;
double m_sample_span;
double m_half_sample_span;
std::map< std::string, refptr<Material> > m_materials;
};
#endif