void CWaterSurfaceSceneNode::animateWaterSurface()
{
	if (!Mesh)
		return;
	s32 meshBufferCount = Mesh->getMeshBufferCount();
	f32 time = os::Timer::getTime() / WaveSpeed;

	for (s32 b=0; b<meshBufferCount; ++b)
	{
		s32 vtxCnt = Mesh->getMeshBuffer(b)->getVertexCount();

		switch(Mesh->getMeshBuffer(b)->getVertexType())
		{
		case video::EVT_STANDARD:
		{
			video::S3DVertex* v =
			        (video::S3DVertex*)Mesh->getMeshBuffer(b)->getVertices();

			video::S3DVertex* v2 =
			        (video::S3DVertex*)OriginalMesh->getMeshBuffer(b)->getVertices();

			for (s32 i=0; i<vtxCnt; ++i)
			{
				v[i].Pos.Y = v2[i].Pos.Y +
				             ((f32)FastSin(((v2[i].Pos.X/WaveLength) + time)) * WaveHeight) +
				             ((f32)FastCos(((v2[i].Pos.Z/WaveLength) + time)) * WaveHeight);

			}
//printf("water2c %d %d\n", os::Timer::getRealTime() -d, vtxCnt);
		}
			break;
		case video::EVT_2TCOORDS:
		{
			video::S3DVertex2TCoords* v =
			        (video::S3DVertex2TCoords*)Mesh->getMeshBuffer(b)->getVertices();

			video::S3DVertex2TCoords* v2 =
			        (video::S3DVertex2TCoords*)OriginalMesh->getMeshBuffer(b)->getVertices();

			for (s32 i=0; i<vtxCnt; ++i)
			{
				v[i].Pos.Y = v2[i].Pos.Y +
				             ((f32)FastSin(((v2[i].Pos.X/WaveLength) + time)) * WaveHeight) +
				             ((f32)FastCos(((v2[i].Pos.Z/WaveLength) + time)) * WaveHeight);
			}
//printf("water2c %d %d\n", os::Timer::getRealTime() -d, vtxCnt);

		}
			break;
		} // end switch

	} // end for all mesh buffers

	SceneManager->getMeshManipulator()->recalculateNormals(Mesh);
}
Example #2
0
void ParticleSystem::InitParticle(Particle &particle, bool random)
{
  if (random)
  {
    //random life
    particle.life = RandomNumber(0.0f, m_maxLife);
  }
  else
  {
    //full life
    particle.life = m_maxLife;
  }
  //random fade between min and max fade
  particle.fade = RandomNumber(m_minFade, m_maxFade);
  //zero position
  PointZero(particle.position);
  //perturb initial velocity by spread factor
  float s = FastSin(m_spread);
  particle.vX = m_vX + s * RandomNumber(-1.0f, 1.0f);
  particle.vY = m_vY + s * RandomNumber(-1.0f, 1.0f);
  particle.vZ = m_vZ + s * RandomNumber(-1.0f, 1.0f);
}