C++ API

The C++ headers for ApertusVR are located in ApertusVR/common/include/ folder.

C++ Plugin interface

A C++ Plugin has to implement the IPlugin interface:

class IPlugin
{
public:
	virtual void Init() = 0;
	virtual void Run() = 0;
	virtual void Step() = 0;
	virtual void Stop() = 0;
	virtual void Suspend() = 0;
	virtual void Restart() = 0;
};

Constructor

The constructor takes care of member initializations.

Ape::ApeTesterPlugin::ApeTesterPlugin()
{
	mpSceneManager = Ape::ISceneManager::getSingletonPtr();
	mpEventManager = Ape::IEventManager::getSingletonPtr();
	
	mpEventManager->connectEvent(Ape::Event::Group::NODE, std::bind(&ApeTesterPlugin::eventCallBack, this, std::placeholders::_1));
	mInterpolators = std::vector<std::unique_ptr<Ape::Interpolator>>();
	mDemoObjectNode = Ape::NodeWeakPtr();
}

Init

This method is for initializing geometries, nodes, etc. for your plugin. The following example uses Init() to create lights and the skybox:

void Ape::ApeTesterPlugin::createLights()
{
	if (auto light = std::static_pointer_cast<Ape::ILight>(mpScene->createEntity("light1", Ape::Entity::LIGHT).lock()))
	{
		light->setLightType(Ape::Light::Type::DIRECTIONAL);
		light->setLightDirection(Ape::Vector3(0, -1, -1));
		light->setDiffuseColor(Ape::Color(0.35f, 0.35f, 0.35f));
		light->setSpecularColor(Ape::Color(0.35f, 0.35f, 0.35f));
	}
	if (auto light = std::static_pointer_cast<Ape::ILight>(mpScene->createEntity("light2", Ape::Entity::LIGHT).lock()))
	{
		light->setLightType(Ape::Light::Type::DIRECTIONAL);
		light->setLightDirection(Ape::Vector3(0, -1, 1));
		light->setDiffuseColor(Ape::Color(0.35f, 0.35f, 0.35f));
		light->setSpecularColor(Ape::Color(0.35f, 0.35f, 0.35f));
	}
}

void Ape::ApeTesterPlugin::createSkyBox()
{
	if (auto skyBoxMaterial = std::static_pointer_cast<Ape::IFileMaterial>(mpScene->createEntity("skyBox", Ape::Entity::MATERIAL_FILE).lock()))
	{
		skyBoxMaterial->setFileName("skyBox.material");
		skyBoxMaterial->setAsSkyBox();
	}
}

void Ape::ApeTesterPlugin::Init()
{
	createSkyBox();
	createLights();
}

Run

The Run() method can be used to implement loops until the Stop of the plugin. It is the place where animations, and other interactions can be used.

void Ape::ApeTesterPlugin::Run()
{
	while (true)
	{	
		if (!mInterpolators.empty())
		{
			for (std::vector<std::unique_ptr<Ape::Interpolator>>::iterator it = mInterpolators.begin(); it != mInterpolators.end();)
			{
				(*it)->iterateTopSection();
				if ((*it)->isQueueEmpty())
					it = mInterpolators.erase(it);
				else 
					it++;
			}
		}
		std::this_thread::sleep_for(std::chrono::milliseconds(40));
	}
}

Last updated