Ejemplo n.º 1
0
void CViewWindow::onIdle()
{
	if (RenderEngineImp::isNull()) 
	{
		return;
	}
	static u32 oldTime = GetTickCount();
	u32 currentTime = GetTickCount();
	float delta = currentTime - oldTime;
	oldTime = currentTime;
	//_camera.lookAt(Vec3::ZERO);
	Vec3 pos = _cameraRelativeShpereCoordination.getPosition();
	_camera.setPosition(pos);
	float s = Zen::Basic::Sin(_cameraRelativeShpereCoordination.mAngleUpFromXZ);
	//进入球的背面
	Vec3 lookTaTarget = _cameraRelativeShpereCoordination.mOrigion;
	if (s < 0)
	{
		_camera.lookAt(lookTaTarget, Vec3::NEGATIVE_UNIT_Y);
	}
	else
	{
		_camera.lookAt(lookTaTarget);
	}
	_camera.update();
	Mat4 m = _camera.getProjectionMatrix() * _camera.getViewMatrix();
	if (_model)
	{
		_model->setMatrix("gWorldViewProj", m);
		Mat4 w = Mat4::IDENTITY;
		_model->setMatrix("gWorld", w);
		_model->setMatrix("gWorldInverseTranspose", w);
		_model->setMatrix("gView", _camera.getViewMatrix());
		_model->setMatrix("gProjection", _camera.getProjectionMatrix());
		//
		{
			Zen::Effect* fx = RenderEngineImp::getInstancePtr()->getRenderEngine()->getEffectManager()->getEffectByFile("shader/aPTSkin.fx");
			if (fx)
			{
				Vec3 l = _light.mPosition.getPosition();
				l.normalise();
				Vec4 p(l.x, l.y, l.z, 0);
				fx->setVector("gLightPosition", &p);
			}
		}
		//
		_model->update(delta);
	}
	Zen::Effect* fx = _material->getEffect();
	if (fx)
	{
		fx->setMatrix("g_mWorldViewProjection", m);
	}

	//
	{
		if (gTerrain.getMaterial())
		{
			Zen::Effect* fx = gTerrain.getMaterial()->getEffect();
			if (fx)
			{
				fx->setMatrix("g_mViewProjection", m);
			}
		}
	}
	//
	{
		if (mSculptor.mMaterial)
		{
			Zen::Effect* fx = mSculptor.mMaterial->getEffect();
			if (fx)
			{
				fx->setMatrix("g_mViewProjection", m);
			}
		}
	}
	_calcFPS();
	//
	RenderEngineImp::getInstancePtr()->getRenderEngine()->getRenderSystem()->clear(0, NULL, Zen::eClearFlags_Target | Zen::eClearFlags_ZBuffer, Zen::Color::Black, 1.0f, 0L);
	RenderEngineImp::getInstancePtr()->getRenderEngine()->getRenderSystem()->beginScene();
	//
	_render();
	//
	RenderEngineImp::getInstancePtr()->getRenderEngine()->getRenderSystem()->endScene();
	RenderEngineImp::getInstancePtr()->getRenderEngine()->getRenderSystem()->present(NULL, NULL, NULL);
}
Ejemplo n.º 2
0
void Chunks::render()
{
	//
	if (NULL == mMaterial)
	{
		return;
	}
	Zen::Effect* fx = mMaterial->getEffect();
	if (NULL == fx)
	{
		return;
	}
	for (size_t i = 0; i != mChunks.size(); ++i)
	{
		Chunk* c = mChunks[i];
		if (c)
		{
			Mat4 m;
			m.makeTransform(mPosition + Vec3(scChunkSize * c->mPostion.x, 0.0f, -scChunkSize * c->mPostion.y), Vec3(scChunkSize, 1.0f, scChunkSize), Quaternion::IDENTITY);
			fx->setMatrix("g_mWorld", m);
			{
				// 用颜色来区分邻居chunk
				Vec4 p;
				if ((int)c->mPostion.x % 2 == 0)
				{
					p.x = 0.0f;
				}
				else
				{
					p.x = 1.0f;
				}
				
				//
				if ((int)c->mPostion.y % 2 == 0)
				{
					p.z = 0.0f;
				}
				else
				{
					p.z = 1.0f;
				}
				//
				p.y = 2 - (p.x + p.z);
				p.y /= 2.0f;
				//
				p.w = 1.0f;
				fx->setVector("gAmbient", &p);
			}

			mMaterial->apply();
			u32 passes = 0;
			fx->begin(&passes);
			for (u32 i = 0; i != passes; ++i)
			{
				fx->beginPass(i);
				if (i == 0)
				{
					c->render();
				}
				fx->endPass();
			}
			fx->end();
		}
	}
	
}