#include "SM_CommonFXPCH.h"
#include "SM_Engine3DPCH.h"
#include "FXEscena3D.h"
#include "SM_ParticleSystem.h"

/*
class ParticulasFX : public SM_DemoEffect
{
public:              
  ParticulasFX(char const* pcName) : SM_DemoEffect(pcName)
  {
    m_pEscenaTarget=0;
    m_pcTargetName[0]=0;
  }

  virtual          ~ParticulasFX()
  {
  }

  int      Init(const char* pcCommand)
  {
    m_iShader=ShaderManager::LoadShader("particle");    
    m_ParticleSystem.Init();
    m_ParticleSystem.m_iShader=m_iShader;


    return (0);
  }

  int      Shutdown()
  {
    return (0);
  }

  int      Start(float fTime)
  {
    
    //MSurface s;
    //s.Load("data/textures/firework.bmp");
    return (0);
  }

  int      Stop()
  {
    return (0);
  }

  int      Reset()
  {
    m_ParticleSystem.Reset();
    return (0);
  }

  int      Run(float fTime)
  {
    RenderContext RC;   
    
    if (!m_pEscenaTarget)
    {
      return 0;
    }

    // Context
    float fSceneTime = m_pEscenaTarget->GetScene()->GetSceneTime(fTime);
    m_pEscenaTarget->GetScene()->UpdateRC(&RC, fSceneTime);
    
    // Render
    D3DMesh* pMesh=m_pEscenaTarget->GetScene()->GetMesh(m_pcTargetName);
    if (!pMesh)
    {
      SM_Main::OutputDebug("la escena asignada no tiene un objeto que se llame %s\n", m_pcTargetName);
      return -1;
    }
    
    Vector3D    v;
    Quaternion  q;

    Matrix4X4 m_Transform;
    pMesh->GetKeyFrame(fSceneTime , &v, &q);
    ToTransform(&m_Transform, &v, &q);            

    m_ParticleSystem.m_pAnimable = pMesh;
    m_ParticleSystem.m_fAnimableCurrentTime = fSceneTime;

    m_ParticleSystem.Render(&RC, -1);
    


    return (1);
  }

  int      Command           (float fTime, const char* pcCommand)
  {
    SM_DemoEffect::Command(fTime, pcCommand);

    char* pcToken;

    char* pcAux=new char[strlen(pcCommand)+1];
    strcpy(pcAux, pcCommand);

    pcToken=strtok(pcAux, " \t");    

    if (strcmp(pcToken, "SETTARGET")==0)
    {
      pcToken=strtok(0, " \t");

      m_pEscenaTarget=(Escena3D*) GetEffect(pcToken);
      if (!m_pEscenaTarget)
      {
        SM_Main::OutputDebug("Escena %s no existe!", pcToken);
        delete[] pcAux;
        return -1;
      }

      pcToken=strtok(0, " \t");
      if (pcToken)
      {
        strcpy(m_pcTargetName, pcToken);
      }
      else
      {
        strcpy(m_pcTargetName, "");
      }

      delete[] pcAux;
    }
    return (0);
  }  

  int m_iShader;
  //MBStaticList<Particle> ParticleList;
  RenderParticleSystem    m_ParticleSystem;
  Escena3D*               m_pEscenaTarget;
  char                    m_pcTargetName[256];
  
};

DEFINE_EFFECT(ParticulasFX)
ParticulasFX Particulas("PARTICULAS");
ParticulasFX Particulas2("PARTICULAS1");
ParticulasFX Particulas3("PARTICULAS2");
ParticulasFX Particulas4("PARTICULAS3");
*/

