Beispiel #1
0
void WaitingForYou::restoreDevice()
{
	//
	std::string heightFilePath = Buddha::FileSystem::getInstancePtr()->getDataDirectory() + "terrain\\height129.raw";
	std::ifstream f(heightFilePath, std::ios::binary);
	if (f.good())
	{
		int length = 0;
		f.seekg(0, std::ios::end);
		length = f.tellg();
		_vertexNumber = length;
		f.seekg(0, std::ios::beg);
		u8* buffer = new u8[length];
		f.read((char*)buffer, length);
		//
		{
			if(_vb)
			{
				_vb->create(length * sizeof(Euclid::sPositionTexture), Euclid::eUsage_WriteOnly, Euclid::ePool_Default);
			}
			else
			{
				_vb = _modules->getRenderEngine()->getBufferManager()->createVertexBuffer(length * sizeof(Euclid::sPositionTexture), Euclid::eUsage_WriteOnly, Euclid::ePool_Default);
			}
			_vertexNumber2GPU = length;
			void* data = _vb->lock(0, 0, Euclid::eLock_Null);
			Euclid::sPositionTexture* dataPos = (Euclid::sPositionTexture*)data;
			int width = Euler::Basic::Sqrt(length);
			_mapWidth = width;
			int half_width = width / 2;
			for (int i = 0; i != width; ++i)
				for (int j = 0; j != width; ++j)
				{
					Euclid::sPositionTexture p;
					p.position.x = i - half_width;
					p.position.z = j - half_width;
					p.position.y = (buffer[j + i * width]) * 0.25f;
					p.texcoord.x = (float)j / (float)(width - 1);
					p.texcoord.y = (float)i / (float)(width - 1);
					memcpy(dataPos, &p, sizeof(Euclid::sPositionTexture));
					++dataPos;
				}
				_vb->unLock();
		}
		delete buffer;
		buffer = NULL;
	}
	f.close();
	//
	toggleLOD();
	//
	if (_fx)
	{
		_fx->loadFromFile("shader\\PositionTextureLightmapping.fx");
		_fx->commitChanges();
	} 
	else
	{
		_fx = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionTextureLightmapping.fx");
	}
	//
	if (_fx_axis)
	{
		_fx_axis->loadFromFile("shader\\PositionColor.fx");
		_fx_axis->commitChanges();
	}
	else
	{
		_fx_axis = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionColor.fx");
	}
	//
	if (!_material)
	{
		_material = _modules->getRenderEngine()->getMaterialManager()->createMaterial(Euclid::eMaterialType_VertexTexture);
	}
	{
		_material->setVertexDeclaration(Euclid::eVertexDeclarationType_PositionTexture);
		Euclid::MaterialVertexTexture* mvt = static_cast<Euclid::MaterialVertexTexture*>(_material);
		mvt->setTexture("image/detailMap.tga");
		mvt->setLightmapping("image/lightmap.png");
	} 
	//
	//
	if (_font)
	{
		_font->create(std::string("freetype\\simkai.ttf"), 18, Euclid::eFontProperty_Normal);
	}
	else
	{
		//_modules->getRenderEngine()->getFontManager()->createFont(std::string("freetype\\simkai.ttf"), 18, Euclid::eFontProperty_Normal, "free");
		_font = _modules->getRenderEngine()->getFontManager()->getFont(std::string("free"));
	}
}
Beispiel #2
0
bool WaitingForYou::initGeometry()
{
	//
	createVB();
	fillVB();
	//
	createIB();
	fillIB();
	// axis
	{
		//
		static float scale = 100;
		//
		_axis_vertices[0].position = Vec3::ZERO * scale;
		_axis_vertices[0].color_ARGB = Euclid::Color::Red.getARGB();

		_axis_vertices[1].position = Vec3::UNIT_X * scale;
		_axis_vertices[1].color_ARGB = Euclid::Color::Red.getARGB();

		//
		_axis_vertices[2].position = Vec3::ZERO * scale;
		_axis_vertices[2].color_ARGB = Euclid::Color::Green.getARGB();

		_axis_vertices[3].position = Vec3::UNIT_Y * scale;
		_axis_vertices[3].color_ARGB = Euclid::Color::Green.getARGB();

		//
		_axis_vertices[4].position = Vec3::ZERO * scale;
		_axis_vertices[4].color_ARGB = Euclid::Color::Blue.getARGB();

		_axis_vertices[5].position = Vec3::UNIT_Z * scale;
		_axis_vertices[5].color_ARGB = Euclid::Color::Blue.getARGB();
	}
	// water
	{
		//
		static float scale = 1000;
		//
		_water_vertices[0].position = Vec3(-1.0f, 0.0f, -1.0f) * scale;
		_water_vertices[0].color_ARGB = Euclid::Color::Red.getARGB();
		_water_vertices[0].texcoord = Vec2(0.0f, 0.0f);

		_water_vertices[1].position = Vec3(-1.0f, 0.0f, 1.0f) * scale;
		_water_vertices[1].color_ARGB = Euclid::Color::Green.getARGB();
		_water_vertices[1].texcoord = Vec2(0.0f, 1.0f);

		_water_vertices[2].position = Vec3(1.0f, 0.0f, 1.0f) * scale;
		_water_vertices[2].color_ARGB = Euclid::Color::Blue.getARGB();
		_water_vertices[2].texcoord = Vec2(1.0f, 1.0f);

		_water_vertices[3].position = Vec3(1.0f, 0.0f, -1.0f) * scale;
		_water_vertices[3].color_ARGB = Euclid::Color::White.getARGB();
		_water_vertices[3].texcoord = Vec2(1.0f, 0.0f);
	}
	//
	{
		_water_fx = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionTextureColor.fx");
	}
	{
		_water_material = _modules->getRenderEngine()->getMaterialManager()->createMaterial(Euclid::eMaterialType_VertexTexture);
		_water_material->setVertexDeclaration(Euclid::eVertexDeclarationType_PositionColorTexture);
		Euclid::MaterialVertexTexture* mvt = static_cast<Euclid::MaterialVertexTexture*>(_water_material);
		mvt->setTexture("image/water.jpg");
	}
	//
	{
		_fx = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionTextureLightmapping.fx");
	}
	//
	
	{
		_fx_axis = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionColor.fx");
	}
	//
	{
		_material = _modules->getRenderEngine()->getMaterialManager()->createMaterial(Euclid::eMaterialType_VertexTexture);
		_material->setVertexDeclaration(Euclid::eVertexDeclarationType_PositionTexture);
		Euclid::MaterialVertexTexture* mvt = static_cast<Euclid::MaterialVertexTexture*>(_material);
		mvt->setTexture("image/water.JPG");
		mvt->setLightmapping("image/lightmap.png");
	} 
	//
	{
		_modules->getRenderEngine()->getFontManager()->createFont(std::string("freetype\\simkai.ttf"), 18, Euclid::eFontProperty_Normal, "free");
		_font = _modules->getRenderEngine()->getFontManager()->getFont(std::string("free"));
	}


	return true;
}
Beispiel #3
0
bool WaitingForYou::initGeometry()
{
	//
	std::string heightFilePath = Buddha::FileSystem::getInstancePtr()->getDataDirectory() + "terrain\\height128.raw";
	std::ifstream f(heightFilePath, std::ios::binary);
	if (f.good())
	{
		int length = 0;
		f.seekg(0, std::ios::end);
		length = f.tellg();
		_vertexNumber = length;
		f.seekg(0, std::ios::beg);
		u8* buffer = new u8[length];
		f.read((char*)buffer, length);
		//
		{
			_vb = _modules->getRenderEngine()->getBufferManager()->createVertexBuffer(length * sizeof(Euclid::sPositionTexture), Euclid::eUsage_WriteOnly, Euclid::ePool_Default);
			void* data = _vb->lock(0, 0, Euclid::eLock_Null);
			Euclid::sPositionTexture* dataPos = (Euclid::sPositionTexture*)data;
			int width = Euler::Basic::Sqrt(length);
			_mapWidth = width;
			int half_width = width / 2;
			for (int i = 0; i != width; ++i)
				for (int j = 0; j != width; ++j)
				{
					Euclid::sPositionTexture p;
					p.position.x = i - half_width;
					p.position.z = j - half_width;
					p.position.y = (buffer[j + i * width] - 128) * 0.25f;
					p.texcoord.x = (float)j / (float)(width - 1);
					p.texcoord.y = (float)i / (float)(width - 1);
					memcpy(dataPos, &p, sizeof(Euclid::sPositionTexture));
					++dataPos;
				}
				_vb->unLock();
				//
				{
					_ib = _modules->getRenderEngine()->getBufferManager()->createIndexBuffer((width - 1) * (width - 1) * 2 * 3 * sizeof(u16), Euclid::eUsage_WriteOnly, Euclid::eFormat_Index16,Euclid::ePool_Default);
					void* data = _ib->lock(0, 0, Euclid::eLock_Null);
					u16* dataIndex = (u16*)data;
					for (int i = 0; i != width - 1; ++i)
						for (int j = 0; j != width - 1; ++j)
						{
							u16 baseIndex = j + i * width;
							u16 indices[] = {
								baseIndex, baseIndex + width, baseIndex + 1, 
								baseIndex + width, baseIndex + 1 + width, baseIndex + 1};
								memcpy(dataIndex, indices, sizeof(u16) * 6);
								dataIndex += 6;
						}
						_ib->unLock();
				}
		}
		delete buffer;
		buffer = NULL;
	}
	f.close();
	//
	//
	_material = _modules->getRenderEngine()->getMaterialManager()->createMaterial(Euclid::eMaterialType_VertexTexture);
	if (_material)
	{
		_material->setVertexDeclaration(Euclid::eVertexDeclarationType_PositionTexture);
		Euclid::MaterialVertexTexture* mvt = static_cast<Euclid::MaterialVertexTexture*>(_material);
		mvt->setTexture("image/detailMap.tga");
		mvt->setLightmapping("image/lightmap.png");
	}

	//
	_fx = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionTextureLightmapping.fx");
	if (NULL == _fx)
	{
		return false;
	}
	//
	_fx_axis = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionColor.fx");
	if (NULL == _fx_axis)
	{
		return false;
	}
	// axis
	{
		//
		static float scale = 100;
		//
		_axis_vertices[0].position = Vec3::ZERO * scale;
		_axis_vertices[0].color_ARGB = Euclid::Color::Red.getARGB();

		_axis_vertices[1].position = Vec3::UNIT_X * scale;
		_axis_vertices[1].color_ARGB = Euclid::Color::Red.getARGB();

		//
		_axis_vertices[2].position = Vec3::ZERO * scale;
		_axis_vertices[2].color_ARGB = Euclid::Color::Green.getARGB();

		_axis_vertices[3].position = Vec3::UNIT_Y * scale;
		_axis_vertices[3].color_ARGB = Euclid::Color::Green.getARGB();

		//
		_axis_vertices[4].position = Vec3::ZERO * scale;
		_axis_vertices[4].color_ARGB = Euclid::Color::Blue.getARGB();

		_axis_vertices[5].position = Vec3::UNIT_Z * scale;
		_axis_vertices[5].color_ARGB = Euclid::Color::Blue.getARGB();
	}
	//
	_camera = new Euclid::Camera;
	_camera->setPosition(Vec3(0.0f, 0.0f, 50.0f));

	//
	_cameraController = new Euclid::CameraControllerThirdPerson(_camera);

	return true;
}
Beispiel #4
0
bool WaitingForYou::initGeometry()
{
	//
	createVB();
	fillVB();
	//
	createIB();
	fillIB();
	// axis
	{
		//
		static float scale = 100;
		//
		_axis_vertices[0].position = Vec3::ZERO * scale;
		_axis_vertices[0].color_ARGB = Euclid::Color::Red.getARGB();

		_axis_vertices[1].position = Vec3::UNIT_X * scale;
		_axis_vertices[1].color_ARGB = Euclid::Color::Red.getARGB();

		//
		_axis_vertices[2].position = Vec3::ZERO * scale;
		_axis_vertices[2].color_ARGB = Euclid::Color::Green.getARGB();

		_axis_vertices[3].position = Vec3::UNIT_Y * scale;
		_axis_vertices[3].color_ARGB = Euclid::Color::Green.getARGB();

		//
		_axis_vertices[4].position = Vec3::ZERO * scale;
		_axis_vertices[4].color_ARGB = Euclid::Color::Blue.getARGB();

		_axis_vertices[5].position = Vec3::UNIT_Z * scale;
		_axis_vertices[5].color_ARGB = Euclid::Color::Blue.getARGB();
	}
	// water
	{
		//
		static float scale = 1000;
		//
		_water_vertices[0].position = Vec3(-1.0f, 0.0f, -1.0f) * scale;
		_water_vertices[0].color_ARGB = Euclid::Color::White.getARGB();
		_water_vertices[0].texcoord = Vec2(0.0f, 0.0f);

		_water_vertices[1].position = Vec3(-1.0f, 0.0f, 1.0f) * scale;
		_water_vertices[1].color_ARGB = Euclid::Color::White.getARGB();
		_water_vertices[1].texcoord = Vec2(0.0f, 1.0f);

		_water_vertices[2].position = Vec3(1.0f, 0.0f, 1.0f) * scale;
		_water_vertices[2].color_ARGB = Euclid::Color::White.getARGB();
		_water_vertices[2].texcoord = Vec2(1.0f, 1.0f);

		_water_vertices[3].position = Vec3(1.0f, 0.0f, -1.0f) * scale;
		_water_vertices[3].color_ARGB = Euclid::Color::White.getARGB();
		_water_vertices[3].texcoord = Vec2(1.0f, 0.0f);
	}
	//
	{
		_water_fx = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionTextureColor.fx");
	}
	{
		_fx_skybox = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionTextureFogLinear.fx");
	}
	{
		_water_material = _modules->getRenderEngine()->getMaterialManager()->createMaterial(Euclid::eMaterialType_VertexTexture);
		_water_material->setVertexDeclaration(Euclid::eVertexDeclarationType_PositionColorTexture);
		Euclid::MaterialVertexTexture* mvt = static_cast<Euclid::MaterialVertexTexture*>(_water_material);
		mvt->setTexture("image/water00.jpg");
	}
	//
	{
		_fx = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionTextureLightmapping.fx");
	}
	//
	
	{
		_fx_axis = _modules->getRenderEngine()->getEffectManager()->createEffectFromFile("shader\\PositionColor.fx");
	}
	//
	{
		_material = _modules->getRenderEngine()->getMaterialManager()->createMaterial(Euclid::eMaterialType_VertexTexture);
		_material->setVertexDeclaration(Euclid::eVertexDeclarationType_PositionTexture);
		Euclid::MaterialVertexTexture* mvt = static_cast<Euclid::MaterialVertexTexture*>(_material);
		mvt->setTexture("image/rock.JPG");
		mvt->setLightmapping("image/lightmap.png");
	} 
	//
	{
		_modules->getRenderEngine()->getFontManager()->createFont(std::string("freetype\\simkai.ttf"), 18, Euclid::eFontProperty_Normal, "free");
		_font = _modules->getRenderEngine()->getFontManager()->getFont(std::string("free"));
	}
	//
	createRTT();
	// sky vertices
	{
		int i = 0; int j = 0;
		// +z
		_skybox[i][j].position = Vec3(+0.5f, +0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(0.f, 0.f); ++j;
		_skybox[i][j].position = Vec3(+0.5f, -0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(0.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, -0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(1.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, +0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(1.f, 0.f);
		// -z
		++i; j = 0;
		_skybox[i][j].position = Vec3(-0.5f, +0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(0.f, 0.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, -0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(0.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(+0.5f, -0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(1.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(+0.5f, +0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(1.f, 0.f);
		// +x
		++i; j = 0;
		_skybox[i][j].position = Vec3(+0.5f, +0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(0.f, 0.f); ++j;
		_skybox[i][j].position = Vec3(+0.5f, -0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(0.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(+0.5f, -0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(1.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(+0.5f, +0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(1.f, 0.f);
		// -x
		++i; j = 0;
		_skybox[i][j].position = Vec3(-0.5f, +0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(0.f, 0.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, -0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(0.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, -0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(1.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, +0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(1.f, 0.f);
		// +y
		++i; j = 0;
		_skybox[i][j].position = Vec3(+0.5f, +0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(0.f, 0.f); ++j;
		_skybox[i][j].position = Vec3(+0.5f, +0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(0.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, +0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(1.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, +0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(1.f, 0.f);
		// -y
		++i; j = 0;
		_skybox[i][j].position = Vec3(+0.5f, -0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(0.f, 0.f); ++j;
		_skybox[i][j].position = Vec3(+0.5f, -0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(0.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, -0.5f, +0.5f); _skybox[i][j].texcoord = Vec2(1.f, 1.f); ++j;
		_skybox[i][j].position = Vec3(-0.5f, -0.5f, -0.5f); _skybox[i][j].texcoord = Vec2(1.f, 0.f);
	}

	{
		_texture_skybox[0] = _modules->getRenderEngine()->getTextureManager()->createTextureFromFile("image/blue/+z.jpg");
		_texture_skybox[1] = _modules->getRenderEngine()->getTextureManager()->createTextureFromFile("image/blue/-z.jpg");
		//
		_texture_skybox[2] = _modules->getRenderEngine()->getTextureManager()->createTextureFromFile("image/blue/-x.jpg");
		_texture_skybox[3] = _modules->getRenderEngine()->getTextureManager()->createTextureFromFile("image/blue/+x.jpg");
		//
		_texture_skybox[4] = _modules->getRenderEngine()->getTextureManager()->createTextureFromFile("image/blue/+y.jpg");
		_texture_skybox[5] = _modules->getRenderEngine()->getTextureManager()->createTextureFromFile("image/blue/-y.jpg");
	}
	// skydome
	_segment_skydome = 16;
	_ring_skydome = 16;
	{
		float step_segment = Euler::TwoPI / (_segment_skydome - 1);
		float step_ring = 0.5f * Euler::PI / (_ring_skydome - 1);
		float radius = 1000.0f;
		Euclid::sPositionTexture vertex;
		for (u32 ring = 0; ring < _ring_skydome; ++ring)
		{
			float radian_ring = ring * step_ring;
			vertex.position.y = radius * Euler::Basic::Sin(radian_ring);
			vertex.texcoord.y = (float)ring / (float)(_ring_skydome - 1);
			for (u32 segment = 0; segment < _segment_skydome; ++segment)
			{
				float radian_segment = segment * step_segment;
				vertex.position.x = radius * Euler::Basic::Cos(radian_ring) * Euler::Basic::Cos(radian_segment);
				vertex.position.z = radius * Euler::Basic::Cos(radian_ring) * Euler::Basic::Sin(radian_segment);
				vertex.texcoord.x = (float)segment / (float)(_segment_skydome - 1);
				_vertices_skydome.push_back(vertex);
			}
		}
		{
			int offset = 1;
			for (int i = 0; i < _ring_skydome - 1;i += offset)
			{
				for (int j = 0; j < _segment_skydome - 1; j += offset)
				{
					u16 baseIndex = j + i * _segment_skydome;
					{
						//
						_indices_skydome.push_back(baseIndex);
						_indices_skydome.push_back(baseIndex + _segment_skydome * offset);
						_indices_skydome.push_back(baseIndex + offset);
						//
						_indices_skydome.push_back(baseIndex + _segment_skydome * offset);
						_indices_skydome.push_back(baseIndex + offset + _segment_skydome * offset);
						_indices_skydome.push_back(baseIndex + offset);
					}
				}
			}
		}
	}
	{
		_texture_skydome = _modules->getRenderEngine()->getTextureManager()->createTextureFromFile("image/dome/Sky_horiz_1_4096.jpg");
	}
	return true;
}