#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
int _tmain(int argc, _TCHAR* argv[])
{
try {
#if defined(WIN32)
#else
#endif
std::basic_string<TCHAR> sphereMatName(_T("SphereMaterial"));
std::basic_string<TCHAR> floorMatName(_T("FloorMaterial"));
ILBMeshHandle sphereMesh = bex::createSphere(bmh, _T(
"Sphere"), sphereMatName, 30, 15);
ILBMeshHandle floorMesh = bex::createPlane(bmh, _T(
"Floor"), floorMatName);
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));
}
ILBTextureHandle floorTex = bex::createXorTexture(bmh, _T(
"xorTexture"), bex::ColorRGB(.9f, .7f, .7f));
_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, 3.0f, 20.0f),
bex::Vec3(.1f, -0.3f, -1.0f),
bex::Vec3(0.0f, 1.0f, 0.0f)),
&camera));
bex::apiCall(
ILBSetFov(camera, static_cast<float>(M_PI) / 4.0f, 1.0f));
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;
}
}