Beispiel #1
0
RenderComponent* RenderManager::CreateRenderComponent(std::string objectName)
{
	//Create a new render component and return it
	RenderComponent newComponent;

	if (objectName.compare("ball") == 0)
	{
		newComponent.SetDrawPrimitive(GL_LINES);
		newComponent.SetVertices(CreateSphere(glm::vec3(0, 0, 0), 1));
	}
	else if (objectName.compare("ground") == 0)
	{
		newComponent.SetDrawPrimitive(GL_TRIANGLES);
		newComponent.SetVertices(CreateBox(glm::vec3(0, 0, 0), 100, 6, 100));
		std::vector<glm::vec3> temp;
		temp.push_back(glm::vec3(0.f, 0.f, 1.f));
		newComponent.SetColor(temp);
	}
	else if (objectName.compare("car") == 0)
	{
		float wheelWidth = 0.4, connectionHeight = 0.5, wheelRadius = 0.4;

		newComponent.SetDrawPrimitive(GL_TRIANGLES);
		CarInfo carInfo;
		carInfo.wheelPositions.push_back(glm::vec3(1 - (0.3*wheelWidth), connectionHeight, 2 - wheelRadius));
		carInfo.wheelPositions.push_back(glm::vec3(-1 + (0.3*wheelWidth), connectionHeight, 2 - wheelRadius));
		carInfo.wheelPositions.push_back(glm::vec3(-1 + (0.3*wheelWidth),connectionHeight, -2 + wheelRadius));
		carInfo.wheelPositions.push_back(glm::vec3(1 - (0.3*wheelWidth), connectionHeight, -2 + wheelRadius));
		carInfo.bodyParameters[0] = 2.f;
		carInfo.bodyParameters[1] = 1.f;
		carInfo.bodyParameters[2] = 4.f;
		carInfo.wheelRadius = wheelRadius;
		carInfo.wheelWidth = wheelWidth;
		carInfo.wheelConnectionHeight = connectionHeight;
		newComponent.SetVertices(CreateCar(carInfo));
		std::vector<glm::vec3> color;
		color.push_back(glm::vec3(0.0f, 1.f, 0.f));
		newComponent.SetColor(color);
	}
	else
		return NULL;

	newComponent.SetProgram(m_program);

	m_renderComponents.push_back(newComponent);
	return &m_renderComponents[m_renderComponents.size() - 1];
}
Beispiel #2
0
RenderComponent* RenderManager::CreateRay(glm::vec3 start, glm::vec3 end)
{
	RenderComponent newComponent;
	std::vector<glm::vec3> temp;
	newComponent.SetDrawPrimitive(GL_LINES);

	temp.push_back(start);
	temp.push_back(end);
	newComponent.SetVertices(temp);

	temp.clear();
	temp.push_back(glm::vec3(1.f, 0.f, 0.f));
	newComponent.SetColor(temp);

	m_renderComponents.push_back(newComponent);
	return &m_renderComponents[m_renderComponents.size() - 1];
}