116 lines
2.9 KiB
C++
116 lines
2.9 KiB
C++
|
|
#include "Scene.h"
|
|
#include <stdlib.h>
|
|
#include <string>
|
|
#include <map>
|
|
#include "BMP.h"
|
|
#include "shapes/Shape.h"
|
|
#include "shapes/Sphere.h"
|
|
using namespace std;
|
|
|
|
Scene::Scene(map<string, const char *> options,
|
|
const char * filename)
|
|
{
|
|
m_width = 800;
|
|
m_height = 600;
|
|
m_multisample_level = 1;
|
|
m_output_file_name = "fart.bmp";
|
|
m_vfov = 60.0;
|
|
m_verbose = false;
|
|
m_data = NULL;
|
|
|
|
load(filename);
|
|
|
|
/* after loading the scene file, apply any command-line render options */
|
|
for (map<string, const char *>::iterator it = options.begin();
|
|
it != options.end();
|
|
it++)
|
|
{
|
|
if (it->first == "width")
|
|
{
|
|
m_width = atoi(it->second);
|
|
}
|
|
else if (it->first == "height")
|
|
{
|
|
m_height = atoi(it->second);
|
|
}
|
|
else if (it->first == "multisample")
|
|
{
|
|
m_multisample_level = atoi(it->second);
|
|
}
|
|
else if (it->first == "field-of-view")
|
|
{
|
|
m_vfov = atof(it->second);
|
|
}
|
|
else if (it->first == "output-file")
|
|
{
|
|
m_output_file_name = it->second;
|
|
}
|
|
else if (it->first == "verbose")
|
|
{
|
|
m_verbose = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
Scene::~Scene()
|
|
{
|
|
if (m_data != NULL)
|
|
delete m_data;
|
|
for (vector<Shape *>::iterator it = m_shapes.begin();
|
|
it != m_shapes.end();
|
|
it++)
|
|
{
|
|
delete (*it);
|
|
}
|
|
}
|
|
|
|
void Scene::load(const char * filename)
|
|
{
|
|
/* TODO: parse file somehow */
|
|
Shape * shape = new Sphere(2.0);
|
|
m_transform.translate(2.0, 6.0, 1.0);
|
|
shape->setTransform(m_transform);
|
|
m_shapes.push_back(shape);
|
|
}
|
|
|
|
void Scene::render()
|
|
{
|
|
if (m_verbose)
|
|
{
|
|
cout << " *** Beginning scene render ***" << endl;
|
|
cout << "Parameters:" << endl;
|
|
cout << "----------------------------------------" << endl;
|
|
cout << " Width: " << m_width << endl;
|
|
cout << " Height: " << m_height << endl;
|
|
cout << " Multisample Level: " << m_multisample_level << endl;
|
|
cout << " Vertical Field of View: " << m_vfov << endl;
|
|
cout << "----------------------------------------" << endl;
|
|
}
|
|
|
|
m_data = new unsigned char[m_width * m_height * 3];
|
|
|
|
for (int i = 0; i < m_height; i++)
|
|
{
|
|
for (int j = 0; j < m_width; j++)
|
|
{
|
|
renderPixel(i, j, &m_data[3 * (m_width * i + j)]);
|
|
}
|
|
}
|
|
|
|
if (m_verbose)
|
|
{
|
|
cout << " *** Ending scene render ***" << endl;
|
|
cout << "Writing output file '" << m_output_file_name << '\'' << endl;
|
|
}
|
|
BMP outputImage(m_output_file_name.c_str(), m_width, m_height, m_data);
|
|
}
|
|
|
|
void Scene::renderPixel(int x, int y, unsigned char * pixel)
|
|
{
|
|
// TODO: um... real work
|
|
pixel[BMP_RED] = 0;
|
|
pixel[BMP_GREEN] = 0;
|
|
pixel[BMP_BLUE] = 0;
|
|
}
|