integrantes: -carlos asmadt. - manuel perez.. creación del struct partícula: struct tparticle {...

13
Partícu las Integrantes: - Carlos Asmadt. - Manuel Perez.

Upload: eduarda-ledesma

Post on 23-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Partículas

Integrantes:-Carlos Asmadt.- Manuel Perez.

Page 2: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Implementacionde un sistemade particulas

Page 3: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Creación del struct partícula:

struct tParticle{    tParticle *prev,*next; // enlaces con otras partículas    tvector pos; // posición actual    tvector prevPos; // posición anterior    tvector dir; // dirección y velocidad actual    int life; // tiempo de vida    tColor color; // color actual    tColor prevColor; // color anterior    tColor deltaColor; // delta para cambio de color};

Page 4: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Creacion de la estructura del emisor:

struct tEmitter{    long id; // ID del emisor    char name[80]; // nombre del emisor    long flags; // banderas del emisor    // Información de enlaces    tEmitter *prev; // apuntador al padre    tEmitter *next; // apuntador al hijo    // Información de transformación    tvector pos; // posición XYZ    float yaw, yawVar; // Rotación en Y y variación    float pitch, pitchVar; // Rotación en X y variación    float speed,speedVar; // velocidad y variación de velocidad    // Partícula    tParticle *particle; // Lista enlazada terminada en NULL    int totalParticles; // Total emitidas en cualquier momento    int particleCount; // Total emitidas en este momento    int emitsPerFrame, emitVar; // Emitidas por frame y su variación    int life, lifeVar; // tiempo de vida y su variación    tColor startColor, startColorVar; // color actual    tColor endColor, endColorVar; // color actual    // Física    tvector force; //fuerza de gravedad, viento, etc.};

Page 5: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Proceso que dibuja la escena:

void drawScene(){

    //limpiar bufferes de profundidad y de color AQUI    glPushMatrix();        //Establecer posición y orientación del emisor AQUI        renderEmitter(&m_Emitter); //desplegar emisor    //limpiar y actualizar    glPopMatrix();    glFinish();    SwapBuffers(m_hDC);    UpdateStatus();}

Page 6: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Proceso que agrega una partícula al sistema:

BOOL addParticle(tEmitter *emitter){    /// Variables locales ///////////////////////////////////////////////////////////    tParticle *particle;    tColor start,end;    float yaw,pitch,speed;    ///////////////////////////////////////////////////////////////    // si hay un emisor y una partícula en el grupo ...    // ... y si no he emitido el máximo ....    if (emitter != NULL && m_ParticlePool != NULL && emitter->particleCount < emitter->totalParticles)    {        particle = m_ParticlePool; // La partícula actual        //Actualizar apuntadores        m_ParticlePool = m_ParticlePool->next;        if (emitter->particle != NULL) emitter->particle->prev = particle;        particle->next = emitter->particle;        particle->prev = NULL;        //agregarla al emisor        emitter->particle = particle;        //establecer su posición (relativa a la posición del emisor)        particle->pos.x = 0.0f;        particle->pos.y = 0.0f;        particle->pos.z = 0.0f;

Page 7: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

//guardar posición anterior para antialising        particle->prevPos.x = 0.0f;        particle->prevPos.y = 0.0f;        particle->prevPos.z = 0.0f;        // calcular vector dirección inicial        yaw = emitter->yaw + (emitter->yawVar * RandomNum());        pitch = emitter->pitch + (emitter->pitchVar * RandomNum());        // convertir las rotaciones a un vector        RotationToDirection(pitch,yaw,&particle->dir);        // Multiplicarlo en el factor de velocidad        speed = emitter->speed + (emitter->speedVar * RandomNum());        particle->dir.x *= speed;        particle->dir.y *= speed;        particle->dir.z *= speed;        // Calcular los colores        start.r = emitter->startColor.r+(emitter->startColorVar.r*RandomNum());        start.g = emitter->startColor.g+(emitter->startColorVar.g*RandomNum());        start.b = emitter->startColor.b+(emitter->startColorVar.b*RandomNum());        end.r = emitter->endColor.r + (emitter->endColorVar.r*RandomNum());        end.g = emitter->endColor.g + (emitter->endColorVar.g* RandomNum());        end.b = emitter->endColor.b + (emitter->endColorVar.b* RandomNum());        particle->color.r = start.r;        particle->color.g = start.g;        particle->color.b = start.b;        // Calcular tiempo de vida    

// Calcular tiempo de vida        particle->life=emitter->life+(int)((float)emitter->lifeVar* RandomNum());        // Crear la variación del color        particle->deltaColor.r = (end.r - start.r) / particle->life;        particle->deltaColor.g = (end.g - start.g) / particle->life;        particle->deltaColor.b = (end.b - start.b) / particle->life;        //aumentar contador de partículas        emitter->particleCount++;        return TRUE;    }    return FALSE;}

Page 8: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Se crea una función que actualice los parámetros de las partículas según el efecto que se desea modelar y se llama esa función numeradas veces hasta obtenerlo y así completar nuestro sistema de partículas.

Page 9: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Películas

Page 10: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

X men 2Prince of Persia

Page 11: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Video juegos

Page 12: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

Half lifeDirt 2

Mafia 2

Prototype

Page 13: Integrantes: -Carlos Asmadt. - Manuel Perez.. Creación del struct partícula: struct tParticle { tParticle *prev,*next; // enlaces con otras partículas

ImplementaciónEn Haskell