#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
bex::Vec3 lookAt(0.0f, -2.0f, 0.0f);
switch(lsType) {
case 0:
{
_T("Light"),
&bex::directionalLightOrientation(bex::Vec3(1.0, -1.0f, -1.0f)),
&bex::ColorRGB(1.0f, 1.0f, .8f),
&lh));
break;
}
case 1:
{
_T("Light"),
&bex::translation(bex::Vec3(-1.0, 1.0f, 1.0f)),
&bex::ColorRGB(3.0f, 3.0f, 2.0f),
&lh));
break;
}
case 2:
{
bex::Vec3 pos = bex::Vec3(-1.0, 1.0f, 1.0f);
bex::Matrix4x4 spotMatrix = bex::setSpotlightMatrix(pos,
lookAt - pos);
_T("Light"),
&spotMatrix,
&bex::ColorRGB(3.0f, 3.0f, 2.0f),
&lh));
const float coneAngle = static_cast<float>(M_PI) / 3.0f;
break;
}
case 3:
{
bex::Vec3 pos = bex::Vec3(-1.0, 1.0f, 1.0f);
bex::Matrix4x4 matrix = bex::setAreaLightMatrix(pos,
lookAt - pos,
bex::Vec3(0.0f, 1.0f, 0.0f),
bex::Vec2(2.0f, 5.0f));
_T("Light"),
&matrix,
&bex::ColorRGB(3.0f, 3.0f, 2.0f),
&lh));
break;
}
case 4:
{
bex::Vec3 pos = bex::Vec3(-1.0, 1.0f, 1.0f);
bex::Matrix4x4 matrix = bex::setAreaLightMatrix(pos,
lookAt - pos,
bex::Vec3(0.0f, 1.0f, 0.0f),
bex::Vec2(3.0f, 1.0f));
_T("Light"),
&matrix,
&bex::ColorRGB(.4f, .4f, .3f),
&lh));
break;
}
case 5:
{
bex::Matrix4x4 transform = bex::scaleTranslation(bex::Vec3(17.0f, 17.0f, 17.0f), bex::Vec3(-1.0, 1.0f, 1.0f));
_T("Light"),
&transform,
&bex::ColorRGB(1.0f, 1.0f, 1.0f),
&lh));
const int rampColors = 10;
for(int i = 0; i < rampColors; ++i) {
bex::ColorRGBA randCol = bex::randomRGBA(3.0f);
bex::apiCall(
ILBSetLightRampEntry(lh, static_cast<float>(i) / static_cast<float>(rampColors - 1), &randCol.toColorRGB()));
}
break;
}
case 6:
{
bex::Vec3 pos = bex::Vec3(-1.0, 1.0f, 1.0f);
bex::Matrix4x4 spotMatrix = bex::setSpotlightMatrix(pos,
lookAt - pos);
_T("Light"),
&spotMatrix,
&bex::ColorRGB(3.0f, 3.0f, 2.0f),
&lh));
const float coneAngle = static_cast<float>(M_PI) / 3.0f;
break;
}
case 7:
{
_T("Light"),
&bex::scaleTranslation(bex::Vec3(4.0, 5.0f, 5.0f), bex::Vec3(4.0f, 0.0f, 0.0f)),
&bex::ColorRGB(0.5f, 0.0f, 0.0f),
&lh));
break;
}
default:
throw std::runtime_error("Incorrect light source type");
}
return lh;
}
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);
goboTex = bex::createXorTexture(bmh, _T("xorTex"), bex::ColorRGB(1.0f, 1.0f, 1.0f));
int lsTypes = 8;
std::vector<ILBSceneHandle> scenes;
std::vector<ILBCameraHandle> cameras;
scenes.reserve(lsTypes);
for(int lightType = 0; lightType < lsTypes; ++lightType) {
std::basic_stringstream<TCHAR> sceneName;
sceneName << _T("SphereInstance_") << lightType;
bex::apiCall(
ILBBeginScene(bmh, sceneName.str().c_str(), &scene));
_T("SkyLight"),
&bex::identity(),
&bex::ColorRGB(0.21f, 0.21f, 0.3f),
&skyLight));
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));
float x = 0.0f;
float z = 0.0f;
const float sphereRad = 2.0f;
bex::Matrix4x4 trans = bex::scaleTranslation(bex::Vec3(sphereRad, sphereRad, sphereRad),
bex::Vec3(x, -3.0f, z));
std::basic_stringstream<TCHAR> sphereName;
sphereName << _T("SphereInstance_") << lightType;
bex::apiCall(
ILBCreateInstance(scene, sphereMesh, sphereName.str().c_str(), &trans, &tempInstance));
bex::Vec3 camPos = bex::Vec3(3.0f, 3.0f, 20.0f);
bex::Vec3 lookAt = bex::Vec3(0.0f, -2.0f, 0.0f);
_T("Camera"),
&bex::setCameraMatrix(camPos,
lookAt - camPos,
bex::Vec3(0.0f, 1.0f, 0.0f)),
&camera));
cameras.push_back(camera);
bex::apiCall(
ILBSetFov(camera, static_cast<float>(M_PI) / 4.0f, 1.0f));
scenes.push_back(scene);
}
for(size_t lightType = 0; lightType < scenes.size(); ++lightType) {
std::basic_stringstream<TCHAR> jobName;
jobName << _T("TestJob_") << lightType;
bex::apiCall(
ILBCreateJob(bmh, jobName.str().c_str(), scenes[lightType], _T(
"../../data/simpleFG.xml"), &job));
bex::apiCall(
ILBCreateCameraTarget(job, _T(
"cameraTarget"), cameras[lightType], 640, 480, &cameraTarget));
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;
}
}