#define _USE_MATH_DEFINES // for M_PI
#include <cmath>
#include <iostream>
#include <sstream>
#include "vecmath.h"
#include "utils.h"
#include "primitives.h"
#include "textures.h"
#ifdef UNICODE
#define tcout std::wcout
#else
#define tcout std::cout
#endif
enum RunMode {
RM_CLEAR,
RM_GLOBAL,
RM_LOCAL,
};
RunMode getRunMode(const std::basic_string<TCHAR>& rm) {
if(rm == _T("clear")) {
return RM_CLEAR;
}
if(rm == _T("global")) {
return RM_GLOBAL;
}
if(rm == _T("local")) {
return RM_LOCAL;
}
throw std::runtime_error("Invalid runmode");
}
int _tmain(int argc, _TCHAR* argv[])
{
try {
std::vector<std::basic_string<TCHAR> > arguments(argv, argv + argc);
if(arguments.size() > 2) {
tcout << _T("Error, at most one argument") << std::endl;
tcout << _T("Supported arguments:") << std::endl;
tcout << _T(" clear : Clears the cache") << std::endl;
tcout << _T(" global : Does a rendering using a global cache, reusing assets if possible (default)") << std::endl;
tcout << _T(" local : Does a rendering using a local cache, won't reuse assets") << std::endl;
}
RunMode runmode = (arguments.size() == 1 ? RM_GLOBAL : getRunMode(arguments[1]));
#if defined(WIN32)
#else
#endif
std::basic_string<TCHAR> dir(_T("../../../temp/cacheTest"));
switch(runmode) {
case RM_CLEAR:
tcout << "Clearing cache...";
tcout << " Done!" << std::endl;
return 0;
case RM_GLOBAL:
tcout << "Creating a global cache!" << std::endl;
break;
case RM_LOCAL:
tcout << "Creating a local cache!" << std::endl;
break;
default:
throw std::runtime_error("Invalid runmode");
}
std::basic_string<TCHAR> sphereName(_T("Sphere"));
std::basic_string<TCHAR> floorName(_T("Floor"));
std::basic_string<TCHAR> sphereMatName(_T("SphereMaterial"));
std::basic_string<TCHAR> floorMatName(_T("FloorMaterial"));
if(!bex::findCachedMesh(bmh, sphereName, sphereMesh, tcout)){
sphereMesh = bex::createSphere(bmh, sphereName, sphereMatName, 600, 400);
}
if(!bex::findCachedMesh(bmh, floorName, floorMesh, tcout)) {
floorMesh = bex::createPlane(bmh, floorName, floorMatName);
}
std::basic_string<TCHAR> texName(_T("Mandelbrot"));
if(!bex::findCachedTexture(bmh, texName, texture, tcout)) {
texture = bex::createMandelbrotTexture(bmh, texName, bex::ColorRGB(1.0f, .7f, .7f), 1000, 1000);
}
bex::Matrix4x4 floorTrans = bex::scaleTranslation(bex::Vec3(10.0f, 1.0f, 10.0f),
bex::Vec3(0.0f, -5.0f, 0.0f));
bex::apiCall(
ILBCreateInstance(scene, floorMesh, _T(
"FloorInstance"), &floorTrans, &floorInstance));
const int spheres = 5;
const float sphereRad = 2.0f;
const float spherePosRadius = 5.0f;
for(int i = 0; i < spheres; ++i) {
float angle = static_cast<float>(M_PI) * 2.0f * static_cast<float>(i) / static_cast<float>(spheres);
float x = cosf(angle) * spherePosRadius;
float z = sinf(angle) * spherePosRadius;
bex::Matrix4x4 trans = bex::scaleTranslation(bex::Vec3(sphereRad, sphereRad, sphereRad),
bex::Vec3(x, -3.0f, z));
std::basic_stringstream<TCHAR> sphereName;
sphereName << _T("SphereInstance_") << i;
bex::apiCall(
ILBCreateInstance(scene, sphereMesh, sphereName.str().c_str(), &trans, &tempInstance));
}
_T("Sun"),
&bex::directionalLightOrientation(bex::Vec3(1.0, -1.0f, -1.0f)),
&bex::ColorRGB(1.0f, 1.0f, .8f),
&light));
_T("SkyLight"),
&bex::identity(),
&bex::ColorRGB(0.21f, 0.21f, 0.3f),
&skyLight));
_T("Camera"),
&bex::setCameraMatrix(bex::Vec3(.3f, .5f, 15.0f),
bex::Vec3(.1f, -0.3f, -1.0f),
bex::Vec3(0.0f, 1.0f, 0.0f)),
&camera));
bex::apiCall(
ILBCreateJob(bmh, _T(
"TestJob"), scene, _T(
"../../data/simpleFG.xml"), &job));
if(!bex::renderJob(job, tcout)) {
return 1;
}
return 0;
} catch(bex::Exception& ex) {
tcout << "Beast API error" << std::endl;
tcout << "Error: " << bex::convertStringHandle(errorString) << std::endl;
tcout << "Info: " << bex::convertStringHandle(extendedError) << std::endl;
return 1;
} catch(std::exception& ex) {
tcout << "Standard exception" << std::endl;
tcout << "Error: " << ex.what() << std::endl;;
return 1;
}
}