示例#1
0
GLUSboolean initGame(GLUSvoid)
{
	if (!initEngine(GLUS_LOG_INFO, 7))
	{
		return GLUS_FALSE;
	}

	OctreeFactory octreeFactory;
	OctreeSP octree = octreeFactory.createOctree(6, 1024, Point4(), 256.0f, 256.0f, 256.0f);
	ModelEntityManager::getInstance()->setOctree(octree);
	//octree->setDebug(true);

	PrimitiveEntityFactory primitiveEntityFactory;

	FbxEntityFactory entityFactory;

	ModelEntitySP entity;

	SurfaceMaterialFactory surfaceMaterialFactory;
	SurfaceMaterialSP surfaceMaterial;

	AnimationLayerSP animationLayer;
	vector<AnimationStackSP> allAnimStacks;

	Point4 position;

	string filename;

	// Post processor

	PostProcessor2DSP postProcessor2D = PostProcessor2DSP(new PostProcessor2D(GL_RGB16F, GL_RGB, GL_BYTE));
	postProcessor2D->setUseDoF(useDepthOfField);
	postProcessor2D->setAperture(aperture);
	postProcessor2D->setFocal(focal);
	postProcessor2D->setFocusedObject(focusedObject);

	PostProcessor2DManager::getInstance()->addPostProcessor("PostProcessor", postProcessor2D);

	// Post processor with multisample

	PostProcessor2DMultisampleSP postProcessor2DMultisample = PostProcessor2DMultisampleSP(new PostProcessor2DMultisample(4, GL_RGB16F, false));
	postProcessor2DMultisample->setUseDoF(useDepthOfField);
	postProcessor2DMultisample->setAperture(aperture);
	postProcessor2DMultisample->setFocal(focal);
	postProcessor2DMultisample->setFocusedObject(focusedObject);

	PostProcessor2DMultisampleManager::getInstance()->addPostProcessor("PostProcessorMultisample", postProcessor2DMultisample);

	// Sky sphere

	SkySP sky = SkySP(new SkySphere(100.0f, 100.0f, 100.0f, "LobbyCube.dds"));
	SkyManager::getInstance()->setSky("Lobby", sky);

	SkyManager::getInstance()->setActiveSky("Lobby");

	// Monkey

	surfaceMaterial = surfaceMaterialFactory.createSurfaceMaterial("Diamond", Color::BLACK, Color::BLACK, Color::BLACK, Color::BLACK, 0.0f, Color::WHITE, Color::WHITE, RI_DIAMOND, 0.0f);

	filename = "monkey.fbx";
	entity = entityFactory.loadFbxFile("Monkey", filename, 1.0f, false, surfaceMaterial);
	if (!entity.get())
	{
		glusLogPrint(GLUS_LOG_ERROR, "File not found %s", filename.c_str());

		return GLUS_FALSE;
	}
	position = Point4(0.0f, 1.0f, -5.0f);
	entity->setPosition(position);

	ModelEntityManager::getInstance()->updateEntity(entity);

	// Plane

	filename = "seymourplane_triangulate.fbx";
	entity = entityFactory.loadFbxFile("Plane0", filename, 0.1f);
	if (!entity.get())
	{
		glusLogPrint(GLUS_LOG_ERROR, "File not found %s", filename.c_str());

		return GLUS_FALSE;
	}
	position = Point4(5.0f, 2.0f, -5.0f);
	entity->setPosition(position);
	entity->setAnimation(0, 0);

	// Light up the material a little bit
	for (int32_t i = 0; i < entity->getModel()->getSurfaceMaterialCount(); i++)
	{
		entity->getModel()->getSurfaceMaterialAt(i)->setAmbient(Color(0.5f, 0.5f, 0.5f));
	}

	ModelEntityManager::getInstance()->updateEntity(entity);

	// ...

	position = Point4(4.0f, 1.0f, -2.0f);

	entity = entity->getNewInstance("Plane1");
	entity->setPosition(position);
	entity->setAnimation(0, 0);

	ModelEntityManager::getInstance()->updateEntity(entity);

	// ...

	position = Point4(6.0f, 3.0f, -8.0f);

	entity = entity->getNewInstance("Plane2");
	entity->setPosition(position);
	entity->setAnimation(0, 0);

	ModelEntityManager::getInstance()->updateEntity(entity);

	// Duck

	filename = "duck_triangulate.fbx";
	entity = entityFactory.loadFbxFile("Duck", filename, 0.01f);
	if (!entity.get())
	{
		glusLogPrint(GLUS_LOG_ERROR, "File not found %s", filename.c_str());

		return GLUS_FALSE;
	}
	position = Point4(-5.0f, 0.0f, -20.0f);
	entity->setPosition(position);

	// Light up the material a little bit
	for (int32_t i = 0; i < entity->getModel()->getSurfaceMaterialCount(); i++)
	{
		entity->getModel()->getSurfaceMaterialAt(i)->setAmbient(Color(0.5f, 0.5f, 0.5f));
	}

	ModelEntityManager::getInstance()->updateEntity(entity);

	// Lights

	Color ambient(0.25f, 0.25f, 0.25f, 1.0f);
	Color specular(0.5f, 0.5f, 0.5f, 1.0f);

	LightSP directionalLight = LightSP(new DirectionalLight(Vector3(1.0f, 1.0f, 1.0f), ambient, Color::WHITE, specular));
	LightManager::getInstance()->setLight("DirectionalLight", directionalLight);
	LightSP pointLight = LightSP(new PointLight(Point4(0.0f, 0.0f, 5.0f), 1.0f, 0.0f, 0.0f, ambient, Color::WHITE, specular));
	LightManager::getInstance()->setLight("PointLight", pointLight);
	LightSP spotLight = LightSP(new SpotLight(Vector3(0.0f, 0.0f, -1.0f), 0.5f, 2.0f, Point4(0.0f, 0.0f, 10.0f), 1.0f, 0.0f, 0.0f, ambient, Color::WHITE, specular));
	LightManager::getInstance()->setLight("SpotLight", spotLight);

	ProgramManagerProxy::setLightByType(ProgramManager::DEFAULT_PROGRAM_TYPE, directionalLight);

	//

    glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glClearColor(0.9f, 0.9f, 0.9f, 0.0f);
	glClearDepth(1.0f);

	return GLUS_TRUE;
}
示例#2
0
GLUSboolean initGame(GLUSvoid)
{
	if (!initEngine(GLUS_LOG_INFO, 7))
	{
		return GLUS_FALSE;
	}

	OctreeFactory octreeFactory;
	OctreeSP octree = octreeFactory.createOctree(6, 1024, Point4(), 256.0f, 256.0f, 256.0f);
	GeneralEntityManager::getInstance()->setOctree(octree);
	//octree->setDebug(true);

	PrimitiveEntityFactory primitiveEntityFactory;

	FbxEntityFactory entityFactory;

	ModelEntitySP entity;

	SurfaceMaterialFactory surfaceMaterialFactory;
	SurfaceMaterialSP surfaceMaterial;

	AnimationLayerSP animationLayer;
	vector<AnimationStackSP> allAnimStacks;

	Point4 position;

	string filename;

	// Sky sphere

	SkySP sky = SkySP(new SkySphere(100.0f, 100.0f, 100.0f, "SwedishRoyalCastle", "SwedishRoyalCastle_posx.jpg", "SwedishRoyalCastle_negx.jpg", "SwedishRoyalCastle_posy.jpg", "SwedishRoyalCastle_negy.jpg", "SwedishRoyalCastle_posz.jpg", "SwedishRoyalCastle_negz.jpg"));
	SkyManager::getInstance()->setSky("SwedishRoyalCastle", sky);

	SkyManager::getInstance()->setActiveSky("SwedishRoyalCastle");

	//
	//
	//

	// Textured, transparent cube with rotation animation

	Texture2DSP cubeTexture = Texture2DManager::getInstance()->createTexture("Glass.bmp");
	surfaceMaterial = surfaceMaterialFactory.createSurfaceMaterial("Glass", Color::WHITE, Color::BLACK_TRANSPARENT, Color::BLACK_TRANSPARENT, cubeTexture, Color::BLACK_TRANSPARENT, 0.0f);
	surfaceMaterial->setTransparency(0.5f);
	position = Point4(0.0f, 1.0f, -10.0f);

	animationLayer = AnimationLayerSP(new AnimationLayer());
	animationLayer->addRotationValue(AnimationLayer::Y, 0.0f, 0.0f, LinearInterpolator::interpolator);
	animationLayer->addRotationValue(AnimationLayer::Y, 5.0f, 360.0f, LinearInterpolator::interpolator);
	allAnimStacks.clear();
	allAnimStacks.push_back(AnimationStackSP(new AnimationStack("Rotation", 0.0f, 5.0f)));
	allAnimStacks[0]->addAnimationLayer(animationLayer);

	entity = primitiveEntityFactory.createCubePrimitiveEntity("GlassCube", 2.0f, 2.0f, 2.0f, surfaceMaterial, allAnimStacks);
	entity->setPosition(position);
	entity->setAnimation(0, 0);
	entity->getModel()->getRootNode()->setTransparentRecursive(true);

	GeneralEntityManager::getInstance()->updateEntity(entity);

	// Path animation

	PathSP path = PathSP(new OrientedLinePath(Quaternion(), entity->getPosition(), entity->getPosition() + Vector3(5.0f, 5.0f, -5.0f)));
	PathEntityManager::getInstance()->addEntity(entity, path);
	path->setSpeed(4.0f);
	path->setLooping(true);
	path->startPath();

	//
	//
	//

	// Astro Boy

	filename = "astroBoy_walk.fbx";
	entity = entityFactory.loadFbxModelFile("AstroBoy", filename, 0.2f);
	if (!entity.get())
	{
		glusLogPrint(GLUS_LOG_ERROR, "File not found %s", filename.c_str());

		return GLUS_FALSE;
	}
	position = Point4(0.0f, 0.0f, -20.0f);
	entity->setPosition(position);
	entity->setAnimation(0, 0);

	GeneralEntityManager::getInstance()->updateEntity(entity);

	// Path animation

	Quaternion baseRotation(90.0f, Vector3(0.0f, 1.0f, 0.0f));

	path = PathSP(new OrientedCirclePath(baseRotation, entity->getPosition(), entity->getPosition() + Vector3(0.0f, 0.0f, -5.0f), false));
	PathEntityManager::getInstance()->addEntity(entity, path);
	path->setSpeed(2.5f);
	path->setLooping(true);
	path->startPath();

	//
	//
	//

	// Air plane

	filename = "seymourplane_triangulate.fbx";
	entity = entityFactory.loadFbxModelFile("Plane0", filename, 0.1f);
	if (!entity.get())
	{
		glusLogPrint(GLUS_LOG_ERROR, "File not found %s", filename.c_str());

		return GLUS_FALSE;
	}
	position = Point4(-5.0f, 4.0f, -12.0f);
	entity->setPosition(position);
	entity->setAnimation(0, 0);

	GeneralEntityManager::getInstance()->updateEntity(entity);

	//

	baseRotation = Quaternion(-90.0f, Vector3(1.0f, 1.0f, 0.0f));

	path = PathSP(new OrientedCirclePath(baseRotation, entity->getPosition(), entity->getPosition() + Vector3(0.0f, 0.0f, -3.0f), true, Vector3(1.0f, 1.0f, 0.0f)));
	PathEntityManager::getInstance()->addEntity(entity, path);
	path->setSpeed(5.0f);
	path->setLooping(true);
	path->startPath();

	//
	//
	//

	entity = entity->getNewInstance("Plane1");
	position = Point4(-5.0f, 4.0f, -11.0f);
	entity->setPosition(position);
	entity->setAnimation(0, 0);

	GeneralEntityManager::getInstance()->updateEntity(entity);

	//

	baseRotation = Quaternion(90.0f, Vector3(-1.0f, 1.0f, 0.0f));

	path = PathSP(new OrientedCirclePath(baseRotation, entity->getPosition(), entity->getPosition() + Vector3(0.0f, 0.0f, -4.0f), false, Vector3(-1.0f, 1.0f, 0.0f)));
	PathEntityManager::getInstance()->addEntity(entity, path);
	path->setSpeed(3.0f);
	path->setLooping(true);
	path->startPath();

	//
	//
	//

	// Full reflecting sphere with dynamic environment

	surfaceMaterial = surfaceMaterialFactory.createSurfaceMaterial("FullReflection", Color::BLACK, Color::BLACK, Color::BLACK, Color::BLACK, 0.0f, Color::WHITE, Color::BLACK, RI_VACUUM, 0.0f);
	position = Point4(-5.0f, 4.0f, -15.0f);

	entity = primitiveEntityFactory.createSpherePrimitiveEntity("FullReflectionSphere", 2.0f, 2.0f, 2.0f, surfaceMaterial);
	entity->setPosition(position);
	entity->setRefractiveIndex(RI_NOTHING);

	GeneralEntityManager::getInstance()->updateEntity(entity);

	//

	FrameBufferCubeMapSP framebufferCubeMap = DynamicEnvironmentManager::getInstance()->createCubeMap(entity, 1024);
	surfaceMaterial->setDynamicCubeMapTexture(framebufferCubeMap->getCubeMapTexture());

	//
	//
	//

	// Entity exclude list

	entityExcludeList = EntityListSP(new EntityList());

	GeneralEntityManager::getInstance()->setEntityExcludeList(entityExcludeList);

	//
	//
	//

	// Lights

	Color ambient(0.25f, 0.25f, 0.25f, 1.0f);

	LightManager::getInstance()->setAmbientLightColor(ambient);

	Color specular(0.5f, 0.5f, 0.5f, 1.0f);

	LightSP directionalLight = LightSP(new DirectionalLight("DirectionalLight", Color::WHITE, specular));
	LightManager::getInstance()->setLight("DirectionalLight", directionalLight);

	ProgramManagerProxy::setLightByType(ProgramManager::DEFAULT_PROGRAM_TYPE, 0, directionalLight, Point4(0.0f, 0.0f, 10.0f), Quaternion(45, Vector3(1.0f, 0.0f, -1.0f)));
	ProgramManagerProxy::setNumberLightsByType(ProgramManager::DEFAULT_PROGRAM_TYPE, 1);
	ProgramManagerProxy::setAmbientLightColorByType(ProgramManager::DEFAULT_PROGRAM_TYPE);
	ProgramManagerProxy::setNoShadowByType(ProgramManager::DEFAULT_PROGRAM_TYPE);
	ProgramManagerProxy::setLightByType(ProgramManager::RENDER_TO_CUBEMAP_PROGRAM_TYPE, 0, directionalLight, Point4(0.0f, 0.0f, 10.0f), Quaternion(45, Vector3(1.0f, 0.0f, -1.0f)));
	ProgramManagerProxy::setNumberLightsByType(ProgramManager::RENDER_TO_CUBEMAP_PROGRAM_TYPE, 1);
	ProgramManagerProxy::setAmbientLightColorByType(ProgramManager::RENDER_TO_CUBEMAP_PROGRAM_TYPE);
	ProgramManagerProxy::setNoShadowByType(ProgramManager::RENDER_TO_CUBEMAP_PROGRAM_TYPE);

	// Basic OpenGL settings

    glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glClearDepth(1.0f);

	return GLUS_TRUE;
}