home *** CD-ROM | disk | FTP | other *** search
- #include "LightEffectsParticleClusters.h"
-
- #include "Game.h"
- #include "Mesh.h"
- #include "RendererInfo.h"
- #include "Network.h"
- #include "intersection.h"
- #include "GameObject.h"
-
-
- DynamicLightParticleCluster::DynamicLightParticleCluster(vec3_t pos, vec3_t col, float radius, unsigned long lifetime):ParticleCluster(lifetime){
-
- this->gameObject = NULL;
- this->colAnim = NULL;
- this->radius = radius;
-
- vectorCopy3d(pos, this->pos);
- vectorCopy3d(col, this->col);
-
- nextUpdateMillis = 0;
- // numMeshes = 0;
- // meshes = NULL;
- // colors = NULL;
-
-
- createAndAssignColors();
- }
-
- DynamicLightParticleCluster::DynamicLightParticleCluster(GameObject* obj, vec3_t col, float radius, unsigned long lifetime):ParticleCluster(lifetime){
-
- this->gameObject=obj;
- obj->attachDynamicLightParticleCluster(this);
- this->colAnim = NULL;
- this->radius=radius;
-
- vectorCopy3d(obj->pos, this->pos);
- vectorCopy3d(col, this->col);
-
- nextUpdateMillis = 0;
- // meshes=NULL;
- // colors=NULL;
-
- createAndAssignColors();
- }
-
- DynamicLightParticleCluster::~DynamicLightParticleCluster(){
- freeAndRevertColors();
-
- if( gameObject != NULL ){
- gameObject->detachDynamicLightParticleCluster(this);
- }
- // if(meshes!=NULL)
- // delete[] meshes;
-
- }
-
-
- void DynamicLightParticleCluster::createAndAssignColors(){
- unsigned int i,j;
-
- freeAndRevertColors();
- // if(meshes != NULL)
- // delete[] meshes;
- meshes.clear();
-
- vec3_t min, max;
- vectorInit3d(pos[0]-radius*2.0f, pos[1]-radius*2.0f, pos[2]-radius*2.0f, min);
- vectorInit3d(pos[0]+radius*2.0f, pos[1]+radius*2.0f, pos[2]+radius*2.0f, max);
-
- vector<SpacePartitioningTreeNode*> nodes = Game::arena->sptree->getLeafNodesIntersectingAABB(min, max);
-
- // light arena
- for(i=0; i<nodes.size(); i++){
- // generate and assign colors
- Mesh* mesh = nodes[i]->mesh;
- if( mesh == NULL )
- continue;
-
- meshes.push_back( mesh );
- GLfloat* colArray = new GLfloat[mesh->numSecondaryColors*3];
- meshColors.push_back( colArray );
- for(j=0;j<(unsigned int)mesh->numSecondaryColors;j++){
- float f = vectorPointDistance3d(pos, &mesh->vertices[j*3])/radius;
- f = f > 1.0f ? 1.0f : f;
- vectorScale3d(1.0f - f, col, &colArray[j*3]);
- vectorAdd3d(&mesh->secondaryColors[j*3], &colArray[j*3], &mesh->secondaryColors[j*3]);
- }
- if(mesh->secondaryColorVBOName != 0)
- mesh->updateSecondaryColorVBO();
- }
-
- // light vehicles
- vectorInit3d(pos[0]-radius, pos[1]-radius, pos[2]-radius, min);
- vectorInit3d(pos[0]+radius, pos[1]+radius, pos[2]+radius, max);
- for(i=0;i<GAME_MAX_VEHICLES;i++){
- if( Game::vehicles[i] == NULL )
- continue;
-
- Vehicle* v = Game::vehicles[i];
- vec3_t v_min, v_max;
- vectorAdd3d(v->pos, v->moveAABB.min, v_min);
- vectorAdd3d(v->pos, v->moveAABB.max, v_max);
- if( AABBIntersectsAABB(min, max, v_min, v_max) ){
- vehicles.push_back(v);
- v->addDynamicLightParticleCluster(this);
- }
- }
- }
-
- void DynamicLightParticleCluster::freeAndRevertColors(){
- unsigned int i, j;
-
- for(i=0;i<meshes.size();i++){
- for(j=0;j<(unsigned int)meshes[i]->numSecondaryColors;j++){
- vectorSub3d(&meshes[i]->secondaryColors[j*3], &meshColors[i][j*3], &meshes[i]->secondaryColors[j*3]);
- }
- if(meshes[i]->secondaryColorVBOName != 0)
- meshes[i]->updateSecondaryColorVBO();
- delete[] meshColors[i];
- }
- meshColors.clear();
-
- while( !vehicles.empty() ){
- list<Vehicle*>::iterator iter = vehicles.begin();
- (*iter)->removeDynamicLightParticleCluster(this);
- vehicles.pop_front();
- }
- }
-
- void DynamicLightParticleCluster::move(){
- unsigned long currentMillis = SDL_GetTicks();
- if(gameObject!=NULL && Renderer::info.var.useDynamicLighting && currentMillis > nextUpdateMillis ){
- vectorCopy3d(gameObject->pos, pos); // update pos
- createAndAssignColors();
- nextUpdateMillis = currentMillis + 30;
- }
- }
- void DynamicLightParticleCluster::render(){
- }
-