# C++ API

The C++ headers for ApertusVR are located in *ApertusVR/common/include/* folder.<br>

## 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));
	}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apertus.gitbook.io/vr/developers/api/cpp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
