#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 sphereSideCount = 3;
const float sphereRad = 2.0f;
const float sphereDist = 5.0f;
std::vector<ILBInstanceHandle> sphereInstances;
for(int gy = 0; gy < sphereSideCount; ++gy) {
for(int gx = 0; gx < sphereSideCount; ++gx) {
float offset = static_cast<float>(sphereSideCount - 1) * sphereDist / 2.0f;
float x = static_cast<float>(gx) * sphereDist - offset;
float z = static_cast<float>(gy) * sphereDist - offset;
bex::Matrix4x4 trans = bex::scaleTranslation(bex::Vec3(sphereRad, sphereRad, sphereRad),
bex::Vec3(x, -3.0f, z));
std::basic_stringstream<TCHAR> sphereName;
sphereName << _T("SphereInstance_") << gx << _T("_") << gy;
bex::apiCall(
ILBCreateInstance(scene, sphereMesh, sphereName.str().c_str(), &trans, &tempInstance));
sphereInstances.push_back(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));
bex::Vec3 camPos(10.0f, 20.0f, 10.0f);
bex::Vec3 lookAt(0.0f, -3.0f, 0.0f);
_T("Camera"),
&bex::setCameraMatrix(camPos,
normalize(lookAt - camPos),
bex::Vec3(0.0f, 0.0f, -1.0f)),
&camera));
bex::apiCall(
ILBSetFov(camera, static_cast<float>(M_PI) / 4.0f, 1.0f));
ILBTextureHandle tex = bex::createXorTexture(bmh, _T(
"Tex1"), bex::ColorRGB(.6f, .6f, .3f));
bex::ColorRGBA col2(.6f, .9f, .9f, 1.0f);
ILBTextureHandle tex2 = bex::createXorTexture(bmh, _T(
"Tex2"), bex::ColorRGB(1.0f, 0.2f, 0.2f));
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;
}
}