Пример #1
0
void Add3DBoom(const Vec3f & position) {
	
	Vec3f poss = position;
	ARX_SOUND_PlaySFX(SND_SPELL_FIRE_HIT, &poss);
	
	float dist = fdist(player.pos - Vec3f(0, 160.f, 0.f), position);
	if(dist < 300) {
		Vec3f vect = (player.pos - position - Vec3f(0.f, 160.f, 0.f)) / dist;
		player.physics.forces += vect * ((300.f - dist) * 0.0125f);
	}
	
	for(size_t i = 0; i < entities.size(); i++) {
		const EntityHandle handle = EntityHandle(i);
		Entity * entity = entities[handle];
		
		if(!entity || entity->show != 1 || !(entity->ioflags & IO_ITEM)) {
			continue;
		}
		
		if(!entity->obj || !entity->obj->pbox) {
			continue;
		}
		
		for(long k = 0; k < entity->obj->pbox->nb_physvert; k++) {
			float dist = fdist(entity->obj->pbox->vert[k].pos, position);
			if(dist < 300.f) {
				entity->obj->pbox->active = 1;
				entity->obj->pbox->stopcount = 0;
				Vec3f vect = (entity->obj->pbox->vert[k].pos - position) / dist;
				entity->obj->pbox->vert[k].velocity += vect * ((300.f - dist) * 10.f);
			}
		}
	}
}
Пример #2
0
void ARX_SPECIAL_ATTRACTORS_ComputeForIO(const Entity & ioo, Vec3f & force) {
	
	force = Vec3f::ZERO;
	
	for(size_t i = 0; i < MAX_ATTRACTORS; i++) {
		
		if(attractors[i].ionum == -1 || !ValidIONum(attractors[i].ionum)) {
			continue;
		}
		
		const Entity & io = *entities[attractors[i].ionum];
		
		if(io.show != SHOW_FLAG_IN_SCENE || (io.ioflags & IO_NO_COLLISIONS)
			 || !(io.gameFlags & GFLAG_ISINTREATZONE)) {
			continue;
		}
		
		float power = attractors[i].power;
		float dist = fdist(ioo.pos, io.pos);
		
		if(dist > (ioo.physics.cyl.radius + io.physics.cyl.radius + 10.f) || power < 0.f) {
			
			float max_radius = attractors[i].radius; 
			
			if(dist < max_radius) {
				float ratio_dist = 1.f - (dist / max_radius);
				Vec3f vect = io.pos - ioo.pos;
				fnormalize(vect);
				power *= ratio_dist * 0.01f;
				force = vect * power;
			}
		}
		
	}
}
Пример #3
0
float PathFinder::getIlluminationCost(const Vec3f & pos) const {
	
	static const float STEALTH_LIGHT_COST = 300.0F;
	
	float cost = 0.0f;
	
	for(size_t i = 0; i < slight_c; i++) {
		
		if(!slight_l[i] || !slight_l[i]->exist || !slight_l[i]->status) {
			continue;
		}
		
		const EERIE_LIGHT & light = *slight_l[i];
		
		float dist = fdist(light.pos, pos);
		
		if(dist <= light.fallend) {
			
			float l_cost = STEALTH_LIGHT_COST;
			
			l_cost *= light.intensity * (light.rgb.r + light.rgb.g + light.rgb.b) * (1.0f / 3);
			
			if(dist > light.fallstart) {
				l_cost *= ((dist - light.fallstart) / (light.fallend - light.fallstart));
			}
			
			cost += l_cost;
		}
	}
	
	return cost;
}
Пример #4
0
void ApplyTileLights(EERIEPOLY * ep, const Vec2s & pos)
{

    Color3f lightInfraFactor = Color3f::white;
    if(player.m_improve) {
        lightInfraFactor.r = 4.f;
    }

    TILE_LIGHTS * tls = &tilelights[pos.x][pos.y];
    size_t nbvert = (ep->type & POLY_QUAD) ? 4 : 3;

    for(size_t j = 0; j < nbvert; j++) {

        if(tls->el.empty()) {
            ep->tv[j].color = ep->v[j].color;
            continue;
        }

        Color3f tempColor;
        Color c = Color::fromRGBA(ep->v[j].color);
        tempColor.r = c.r;
        tempColor.g = c.g;
        tempColor.b = c.b;

        Vec3f & position = ep->v[j].p;
        Vec3f & normal = ep->nrml[j];

        for(size_t i = 0; i < tls->el.size(); i++) {
            EERIE_LIGHT * light = tls->el[i];

            Vec3f vLight = glm::normalize(light->pos - position);

            float cosangle = glm::dot(normal, vLight);

            if(cosangle > 0.f) {
                float distance = fdist(light->pos, position);

                if(distance <= light->fallstart) {
                    cosangle *= light->intensity * GLOBAL_LIGHT_FACTOR;
                } else {
                    float p = ((light->fallend - distance) * light->falldiffmul);

                    if(p <= 0.f)
                        cosangle = 0.f;
                    else
                        cosangle *= p * (light->intensity * GLOBAL_LIGHT_FACTOR);
                }
                cosangle *= 0.5f;

                tempColor += light->rgb255 * lightInfraFactor * cosangle;
            }
        }

        u8 ir = clipByte255(tempColor.r);
        u8 ig = clipByte255(tempColor.g);
        u8 ib = clipByte255(tempColor.b);
        ep->tv[j].color = Color(ir, ig, ib, 255).toRGBA();
    }
}
Пример #5
0
void EERIE_COLLISION_SPHERES_Create(EERIE_3DOBJ * obj) {

	if(obj == NULL)
		return;

	EERIE_COLLISION_SPHERES_Release(obj);
	obj->sdata = new COLLISION_SPHERES_DATA();

	for(size_t k = 1; k < obj->grouplist.size(); k++) {
		long workon = GetFirstChildGroup(obj, k);

		if(workon != -1) {
			// Group origin pos
			Vec3f center = obj->vertexlist[obj->grouplist[k].origin].v;
			
			// Destination Group origin pos
			Vec3f dest = obj->vertexlist[obj->grouplist[workon].origin].v;
			
			// Direction Vector from Origin Group to Destination Origin Group
			Vec3f dirvect = dest - center;
			
			// Distance between those 2 pos
			float dista = fdist(dest, center);
			float tot = dista;
			float divdist = 1.f / dista;
			// Vector Normalization
			dirvect *= divdist;
	
			while(dista >= 0.f) { // Iterate along the whole distance
				// Compute required radius for this group and that pos
				float val = GetSphereRadiusForGroup(obj, center, dest, k, tot * 1.4f);

				if(val > 0.2f) {
					long idx = AddVertexToVertexList(obj, &center, k);

					if(idx > -1)
						AddCollisionSphere(obj, idx, val);

					val *= ( 1.0f / 2 );
				} else {
					val = 0.15f;
				}
			
				float inc = val;
				dista -= inc;
			
				center += dirvect * inc;
			}
		} else {
			AddCollisionSphere(obj, obj->grouplist[k].origin, obj->grouplist[k].siz * 18.f);
		}
	}

	if(obj->sdata->spheres.empty() == 0)
		EERIE_COLLISION_SPHERES_Release(obj);
}
Пример #6
0
ColorRGBA ApplyLight(const ShaderLight lights[],
                     const int lightsCount,
                     const glm::quat & quat,
                     const Vec3f & position,
                     const Vec3f & normal,
                     const ColorMod & colorMod,
                     float materialDiffuse
) {
	Color3f tempColor = colorMod.ambientColor;
	
	glm::quat inv = glm::inverse(quat);
	
	// Dynamic lights
	for(int l = 0; l != lightsCount; l++) {
		const ShaderLight & light = lights[l];
		
		Vec3f vLight = glm::normalize(light.pos - position);
		
		Vec3f Cur_vLights = inv * vLight;
		
		float cosangle = glm::dot(normal, Cur_vLights);
		
		// If light visible
		if(cosangle > 0.f) {
			float distance = fdist(position, light.pos);
			
			// Evaluate its intensity depending on the distance Light<->Object
			if(distance <= light.fallstart) {
				cosangle *= light.intensity * GLOBAL_LIGHT_FACTOR;
			} else {
				float p = ((light.fallend - distance) * light.falldiffmul);
				
				if(p <= 0.f)
					cosangle = 0.f;
				else
					cosangle *= p * (light.intensity * GLOBAL_LIGHT_FACTOR);
			}
			
			cosangle *= materialDiffuse;

			tempColor += light.rgb255 * cosangle;
		}
	}

	tempColor *= colorMod.factor;
	tempColor += colorMod.term;

	u8 ir = clipByte255(tempColor.r);
	u8 ig = clipByte255(tempColor.g);
	u8 ib = clipByte255(tempColor.b);

	return Color(ir, ig, ib, 255).toRGBA();
}
Пример #7
0
static float GetSphereRadiusForGroup(EERIE_3DOBJ * obj, const Vec3f & center, const Vec3f & dirvect,
                                     long group, float maxi) {
	
	float curradius = 0.f;
	float maxf = 0.f;
	float div = 0.f;
	long sel = -1;

	for(size_t i = 0; i < obj->selections.size(); i++) { // TODO iterator
		if(obj->selections[i].name == "mou") {
			sel = i;
			break;
		}
	}

	for(size_t i = 0; i < obj->grouplist[group].indexes.size(); i++) {
		if(!IsExclusiveGroupMember(obj, obj->grouplist[group].indexes[i], group))
			continue;

		if(sel > -1 && IsInSelection(obj, obj->grouplist[group].indexes[i], sel) >= 0)
			continue;

		Vec3f target = obj->vertexlist[obj->grouplist[group].indexes[i]].v;
		float distance = fdist(center, target);

		if(distance < 2.f)
			continue;

		if(distance < maxf)
			continue;

		Vec3f targvect = (target - center) * 1.f / distance;
		float val = glm::dot(dirvect, targvect);

		if(glm::abs(val) < 1.2f) {
			if(distance > maxi)
				distance = maxi;

			curradius += distance;
			div += 1.f;
			maxf = std::max(maxf, distance);
		}
	}

	if(div > 0.f) {
		curradius /= div;
	}

	return curradius;
}
Пример #8
0
void LevitateSpell::createDustParticle() {
	
	PARTICLE_DEF * pd = createParticle();
	if(!pd) {
		return;
	}
	
	float a = glm::radians(360.f * rnd());
	pd->ov = m_pos + Vec3f(m_baseRadius * std::cos(a), 0.f, m_baseRadius * std::sin(a));
	float t = fdist(pd->ov, m_pos);
	pd->move = Vec3f((5.f + 5.f * rnd()) * ((pd->ov.x - m_pos.x) / t), 3.f * rnd(),
	                 (5.f + 5.f * rnd()) * ((pd->ov.z - m_pos.z) / t));
	pd->siz = 30.f + 30.f * rnd();
	pd->tolive = 3000;
	pd->timcreation = -(long(arxtime) + 3000l); // TODO WTF
	pd->special = FIRE_TO_SMOKE | FADE_IN_AND_OUT | ROTATING | MODULATE_ROTATION | DISSIPATING;
	pd->fparam = 0.0000001f;
}
Пример #9
0
void LevitateSpell::createDustParticle() {
	
	PARTICLE_DEF * pd = createParticle();
	if(!pd) {
		return;
	}
	
	Vec2f pos = arx::circularRand(m_baseRadius);
	
	pd->ov = m_pos + Vec3f(pos.x, 0.f, pos.y);
	float t = fdist(pd->ov, m_pos);
	Vec3f moveFactor = arx::linearRand(Vec3f(5.f, 0.f, 5.f), Vec3f(10.f, 3.f, 10.f));
	pd->move = moveFactor * Vec3f((pd->ov.x - m_pos.x) / t, 1.f, (pd->ov.z - m_pos.z) / t);
	pd->siz = Random::getf(30.f, 60.f);
	pd->tolive = 3000;
	pd->timcreation = -(toMsi(g_gameTime.now()) + 3000l); // TODO WTF
	pd->m_flags = FIRE_TO_SMOKE | FADE_IN_AND_OUT | ROTATING | DISSIPATING;
	pd->m_rotation = 0.0000001f;
}
Пример #10
0
void MiniMap::revealPlayerPos(int showLevel) {
	
	float zoom = 250.f;
	float startX = 140.f;
	float startY = 120.f;
	float caseX = zoom / ((float)MINIMAP_MAX_X);
	float caseY = zoom / ((float)MINIMAP_MAX_Z);
	
	Vec2f playerPos = computePlayerPos(zoom, showLevel);
	playerPos.x += startX;
	playerPos.y += startY;
	
	// TODO this is inefficient - we don't really need to iterate over the whole minimap!
	// only the area around the player will be modified
	for(int j = 0; j < MINIMAP_MAX_Z; j++) {
		for(int i = 0; i < MINIMAP_MAX_X; i++) {
			
			float posx = startX + i * caseX;
			float posy = startY + j * caseY;
			
			float d = fdist(Vec2f(posx + caseX * 0.5f, posy), playerPos);
			if(d > 6.f) {
				continue;
			}
			
			float vv = (6 - d) * (1.f / 6);
			
			if(vv >= 0.5f) {
				vv = 1.f;
			} else if(vv > 0.f) {
				vv = vv * 2.f;
			} else {
				vv = 0.f;
			}
			
			int r = vv * 255.f;
			
			int ucLevel =  max(r, (int)m_levels[showLevel].m_revealed[i][j]);
			m_levels[showLevel].m_revealed[i][j] = checked_range_cast<unsigned char>(ucLevel);
		}
	}
}
Пример #11
0
void MiniMap::revealPlayerPos(int showLevel) {
	
	float zoom = 250.f;
	Vec2f start = Vec2f(140.f, 120.f);
	Vec2f cas;
	cas.x = zoom / MINIMAP_MAX_X;
	cas.y = zoom / MINIMAP_MAX_Z;
	
	Vec2f playerPos = computePlayerPos(zoom, showLevel);
	playerPos += start;
	
	// TODO this is inefficient - we don't really need to iterate over the whole minimap!
	// only the area around the player will be modified
	for(size_t z = 0; z < MINIMAP_MAX_Z; z++) {
	for(size_t x = 0; x < MINIMAP_MAX_X; x++) {
		
		Vec2f pos;
		pos.x = start.x + x * cas.x;
		pos.y = start.y + z * cas.y;
		
		float d = fdist(Vec2f(pos.x + cas.x * 0.5f, pos.y), playerPos);
		if(d > 6.f) {
			continue;
		}
		
		float vv = (6 - d) * (1.f / 6);
		
		if(vv >= 0.5f) {
			vv = 1.f;
		} else if(vv > 0.f) {
			vv = vv * 2.f;
		} else {
			vv = 0.f;
		}
		
		int r = vv * 255.f;
		
		int ucLevel = std::max(r, (int)m_levels[showLevel].m_revealed[x][z]);
		m_levels[showLevel].m_revealed[x][z] = checked_range_cast<unsigned char>(ucLevel);
	}
	}
}
Пример #12
0
//-----------------------------------------------------------------------------
// Spawns a Projectile using type, starting position/TargetPosition
void ARX_MISSILES_Spawn(Entity * io, ARX_SPELLS_MISSILE_TYPE type, const Vec3f & startpos, const Vec3f & targetpos) {
	
	long i(ARX_MISSILES_GetFree());

	if (i == -1) return;

	missiles[i].owner = (io == NULL) ? EntityHandle::Invalid : io->index();
	missiles[i].type = type;
	missiles[i].lastpos = missiles[i].startpos = startpos;

	float dist;

	dist = 1.0F / fdist(startpos, targetpos);
	missiles[i].velocity = (targetpos - startpos) * dist;
	missiles[i].lastupdate = missiles[i].timecreation = (unsigned long)(arxtime);

	switch (type)
	{
		case MISSILE_NONE: break;
		case MISSILE_FIREBALL:
		{
			missiles[i].tolive = 6000;
			missiles[i].velocity *= 0.8f;
			missiles[i].longinfo = GetFreeDynLight();

			if(lightHandleIsValid(missiles[i].longinfo)) {
				EERIE_LIGHT * light = lightHandleGet(missiles[i].longinfo);
				
				light->intensity = 1.3f;
				light->fallend = 420.f;
				light->fallstart = 250.f;
				light->rgb = Color3f(1.f, .8f, .6f);
				light->pos = startpos;
			}

			ARX_SOUND_PlaySFX(SND_SPELL_FIRE_WIND, &missiles[i].startpos, 2.0F);
			ARX_SOUND_PlaySFX(SND_SPELL_FIRE_LAUNCH, &missiles[i].startpos, 2.0F);
		}
	}
}
Пример #13
0
//-----------------------------------------------------------------------------
// Spawns a Projectile using type, starting position/TargetPosition
void ARX_MISSILES_Spawn(Entity * io, ARX_SPELLS_MISSILE_TYPE type, const Vec3f * startpos, const Vec3f * targetpos) {
	
	long i(ARX_MISSILES_GetFree());

	if (i == -1) return;

	missiles[i].owner = (io == NULL) ? -1 : io->index();
	missiles[i].type = type;
	missiles[i].lastpos = missiles[i].startpos = *startpos;

	float dist;

	dist = 1.0F / fdist(*startpos, *targetpos);
	missiles[i].velocity = (*targetpos - *startpos) * dist;
	missiles[i].lastupdate = missiles[i].timecreation = (unsigned long)(arxtime);

	switch (type)
	{
		case MISSILE_NONE: break;
		case MISSILE_FIREBALL:
		{
			missiles[i].tolive = 6000;
			missiles[i].velocity *= 0.8f;
			missiles[i].longinfo = GetFreeDynLight();

			if (missiles[i].longinfo != -1)
			{
				DynLight[missiles[i].longinfo].intensity = 1.3f;
				DynLight[missiles[i].longinfo].exist = 1;
				DynLight[missiles[i].longinfo].fallend = 420.f;
				DynLight[missiles[i].longinfo].fallstart = 250.f;
				DynLight[missiles[i].longinfo].rgb = Color3f(1.f, .8f, .6f);
				DynLight[missiles[i].longinfo].pos = *startpos;
			}

			ARX_SOUND_PlaySFX(SND_SPELL_FIRE_WIND, &missiles[i].startpos, 2.0F);
			ARX_SOUND_PlaySFX(SND_SPELL_FIRE_LAUNCH, &missiles[i].startpos, 2.0F);
		}
	}
}
void SecondaryInventoryHud::update() {
	Entity * io = getSecondaryOrStealInvEntity();
	if(io) {
		float dist = fdist(io->pos, player.pos + (Vec3f_Y_AXIS * 80.f));
		
		float maxDist = player.m_telekinesis ? 900.f : 350.f;
		
		if(dist > maxDist) {
			if(m_fadeDirection != Fade_left) {
				ARX_SOUND_PlayInterface(SND_BACKPACK, Random::getf(0.9f, 1.1f));
				
				m_fadeDirection = Fade_left;
				SendIOScriptEvent(io,SM_INVENTORY2_CLOSE);
				TSecondaryInventory=SecondaryInventory;
				SecondaryInventory=NULL;
			} else {
				if(player.Interface & INTER_STEAL) {
					player.Interface &= ~INTER_STEAL;
				}
			}
		}
	} else if(m_fadeDirection != Fade_left) {
		m_fadeDirection = Fade_left;
	}
	
	
	if(!(player.Interface & INTER_COMBATMODE) && (player.Interface & INTER_MINIBACK)) {
		// Pick All/Close Secondary Inventory
		if(TSecondaryInventory) {
			//These have to be calculated on each frame (to make them move).
			Rectf parent = Rectf(Vec2f(m_fadePosition, 0), m_defaultBackground->m_size.x * m_scale, m_defaultBackground->m_size.y * m_scale);
			
			m_pickAllButton.setScale(m_scale);
			m_closeButton.setScale(m_scale);
			
			m_pickAllButton.update(parent);
			m_closeButton.update(parent);
		}
	}
}
Пример #15
0
static void PrepareAnimatedObjectHalo(HaloInfo & haloInfo, const Vec3f & pos,
                                      Skeleton * obj, EERIE_3DOBJ * eobj) {
	
		Vec3f ftrPos = pos;
		//TODO copy-pase
		float mdist = ACTIVECAM->cdepth;
		mdist *= ( 1.0f / 2 );

		float ddist = mdist-fdist(ftrPos, ACTIVECAM->orgTrans.pos);
		ddist = ddist/mdist;
		ddist = std::pow(ddist, 6);
		ddist = glm::clamp(ddist, 0.25f, 0.9f);

		haloInfo.ddist = ddist;

		Cedric_PrepareHalo(eobj, obj);

		haloInfo.MAX_ZEDE = 0.f;
		for(size_t i = 0; i < eobj->vertexlist.size(); i++) {
			if(eobj->vertexlist3[i].vert.rhw > 0.f)
				haloInfo.MAX_ZEDE = std::max(eobj->vertexlist3[i].vert.p.z, haloInfo.MAX_ZEDE);
		}
}
Пример #16
0
void eseqclusteravg::finalize()
{
  while (incmaxit!=smatrix.end()){
    while (completemerges.size() && (incmaxit!=smatrix.end() && completemerges.begin()->dist>=incmaxdist || incmaxit==smatrix.end() && completemerges.begin()->dist>=lastdist)){
      if (completemerges.begin()->dist<thres) return;
      mergeComplete(lastdist);
    }
    double avgdist=0.0;
    std::list<long> &arr(incluster[incmaxit->x]);
    std::list<long> &arr2(incluster[incmaxit->y]);
    for (std::list<long>::iterator i=arr.begin(); i!=arr.end(); ++i){
      for (std::list<long>::iterator j=arr2.begin(); j!=arr2.end(); ++j){
//        cout << "dist: " << *i << "," << *j << ": " << fdist(*i,*j) << endl;
        avgdist+=fdist((*seqarr).values(*i),(*seqarr).values(*j),seqlen);
      }
    }
    avgdist=avgdist/(arr.size()*arr2.size());
    incmaxit->count=arr.size()*arr2.size();
    incmaxit->dist=avgdist;
    cout << "# calculating avg cluster distance: " << incmaxit->x << "," << incmaxit->y << " : " << incmaxdist << " : " << avgdist << endl;
    completemerges.insert(*incmaxit);
    getIncompleteMaxDist(lastdist,incmaxdist,incmaxit);
  }
}
Пример #17
0
static bool Quadable(EERIEPOLY * ep, EERIEPOLY * ep2, float tolerance) {

	long count=0;

	long ep_notcommon=-1;
	long ep2_notcommon=-1;

	if(ep2->type & POLY_QUAD)
		return false;

	if(ep->tex != ep2->tex)
		return false;

	long typ1=ep->type&(~POLY_QUAD);
	long typ2=ep2->type&(~POLY_QUAD);

	if(typ1!=typ2)
		return false;

	if((ep->type & POLY_TRANS) && ep->transval != ep2->transval)
		return false;

	ep->norm = CalcFaceNormal(ep->v);

	if(glm::abs(glm::dot(ep->norm, ep2->norm)) < 1.f - tolerance)
		return false;

	for (long i=0;i<3;i++)
	{
		long common=-1;
		long common2=-1;

		for (long j=0;j<3;j++)
		{
			if (   ( NearlyEqual(ep->v[i].p.x,ep2->v[j].p.x) )
				&& ( NearlyEqual(ep->v[i].p.y,ep2->v[j].p.y) )
				&& ( NearlyEqual(ep->v[i].p.z,ep2->v[j].p.z) )
				&& ( NearlyEqual(ep->v[i].uv.x,ep2->v[j].uv.x) )
				&& ( NearlyEqual(ep->v[i].uv.y,ep2->v[j].uv.y) )
				)
			{
				count++;
				common=j;
			}

			if (   ( NearlyEqual(ep->v[j].p.x,ep2->v[i].p.x) )
				&& ( NearlyEqual(ep->v[j].p.y,ep2->v[i].p.y) )
				&& ( NearlyEqual(ep->v[j].p.z,ep2->v[i].p.z) )
				&& ( NearlyEqual(ep->v[j].uv.x,ep2->v[i].uv.x) )
				&& ( NearlyEqual(ep->v[j].uv.y,ep2->v[i].uv.y) )
				)
			{
				common2=j;
			}
		}

		if (common2==-1) ep2_notcommon=i;

		if (common==-1) ep_notcommon=i;
	}

	if ((count>=2) && (ep_notcommon!=-1) && (ep2_notcommon!=-1))
	{
		ep2->type |= POLY_QUAD;

		switch (ep2_notcommon)
		{
			case 1:
				CopyVertices(ep2,3,0);
				CopyVertices(ep2,0,1);
				CopyVertices(ep2,1,2);
				CopyVertices(ep2,2,3);
			break;

			case 2:
				CopyVertices(ep2,3,0);
				CopyVertices(ep2,0,2);
				CopyVertices(ep2,2,1);
				CopyVertices(ep2,1,3);

			break;
		}

		CopyVertices(ep2,3,0);
		ep2->v[3].p = ep->v[ep_notcommon].p;
		ep2->tv[3].uv = ep2->v[3].uv = ep->v[ep_notcommon].uv;
		ep2->tv[3].color = ep2->v[3].color = Color::white.toRGB();
		ep2->tv[3].rhw = ep2->v[3].rhw = 1.f;

	ep2->center = (ep2->v[0].p + ep2->v[1].p + ep2->v[2].p + ep2->v[3].p) * 0.25f;
	ep2->max = glm::max(ep2->max, ep2->v[3].p);
	ep2->min = glm::min(ep2->min, ep2->v[3].p);

	ep2->norm2 = ep->norm;

	ep2->area += fdist((ep2->v[1].p + ep2->v[2].p) * .5f, ep2->v[3].p)
				 * fdist(ep2->v[3].p, ep2->v[1].p)*.5f; // should this be v[2] instead of v[3]?

		return true;
	}

	return false;
}
Пример #18
0
// source = -1 no source but valid pos
// source = 0  player
// source > 0  IO
static void ARX_DAMAGES_UpdateDamage(DamageHandle j, float tim) {
	
	DAMAGE_INFO & damage = damages[j];
	
	if(!damage.exist) {
		return;
	}
		
	if(damage.params.flags & DAMAGE_FLAG_FOLLOW_SOURCE) {
		if(damage.params.source == PlayerEntityHandle) {
			damage.params.pos = player.pos;
		} else if (ValidIONum(damage.params.source)) {
			damage.params.pos = entities[damage.params.source]->pos;
		}
	}
	
	float dmg;
	if(damage.params.flags & DAMAGE_NOT_FRAME_DEPENDANT) {
		dmg = damage.params.damages;
	} else if(damage.params.duration == -1) {
		dmg = damage.params.damages;
	} else {
		float FD = (float)framedelay;
		
		if(tim > damage.start_time + damage.params.duration) {
			FD -= damage.start_time + damage.params.duration - tim;
		}
		
		dmg = damage.params.damages * FD * ( 1.0f / 1000 );
	}
	
	bool validsource = ValidIONum(damage.params.source);
	float divradius = 1.f / damage.params.radius;
	
	// checking for IO damages
	for(size_t i = 0; i < entities.size(); i++) {
		const EntityHandle handle = EntityHandle(i);
		Entity * io = entities[handle];
		
		if(io
		   && (io->gameFlags & GFLAG_ISINTREATZONE)
		   && (io->show == SHOW_FLAG_IN_SCENE)
		   && (damage.params.source != long(i)
		   || (damage.params.source == long(i) && !(damage.params.flags & DAMAGE_FLAG_DONT_HURT_SOURCE)))
		){
			if(io->ioflags & IO_NPC) {
				if(   i != 0
				   && damage.params.source != PlayerEntityHandle
				   && validsource
				   && HaveCommonGroup(io, entities[damage.params.source])
				) {
					continue;
				}
				
				Sphere sphere;
				sphere.origin = damage.params.pos;
				sphere.radius = damage.params.radius - 10.f;
				
				if(CheckIOInSphere(sphere, EntityHandle(i), true)) {
					Vec3f sub = io->pos + Vec3f(0.f, -60.f, 0.f);
					
					float dist = fdist(damage.params.pos, sub);
					
					if(damage.params.type & DAMAGE_TYPE_FIELD) {
						if(float(arxtime) > io->collide_door_time + 500) {
							EVENT_SENDER = NULL;
							io->collide_door_time = (unsigned long)(arxtime); 
							char param[64];
							param[0] = 0;
							
							if(damage.params.type & DAMAGE_TYPE_FIRE)
								strcpy(param, "fire");
							
							if(damage.params.type & DAMAGE_TYPE_COLD)
								strcpy(param, "cold");
							
							SendIOScriptEvent(io, SM_COLLIDE_FIELD, param);
						}
					}
					
					switch(damage.params.area) {
						case DAMAGE_AREA: {
							float ratio = (damage.params.radius - dist) * divradius;
							ratio = glm::clamp(ratio, 0.f, 1.f);
							dmg = dmg * ratio + 1.f;
						}
						break;
						case DAMAGE_AREAHALF: {
							float ratio = (damage.params.radius - (dist * ( 1.0f / 2 ))) * divradius;
							ratio = glm::clamp(ratio, 0.f, 1.f);
							dmg = dmg * ratio + 1.f;
						}
						break;
						case DAMAGE_FULL:
						break;
					}
					
					if(dmg <= 0.f)
						continue;
					
					if(   (damage.params.flags & DAMAGE_FLAG_ADD_VISUAL_FX)
					   && (entities[handle]->ioflags & IO_NPC)
					   && (entities[handle]->_npcdata->lifePool.current > 0.f)
					) {
						ARX_DAMAGES_AddVisual(&damage, &sub, dmg, entities[handle]);
					}
					
					if(damage.params.type & DAMAGE_TYPE_DRAIN_MANA) {
						float manadrained;
						
						if(i == 0) {
							manadrained = std::min(dmg, player.manaPool.current);
							player.manaPool.current -= manadrained;
						} else {
							manadrained = dmg;
							
							if(io && io->_npcdata) {
								manadrained = std::min(dmg, io->_npcdata->manaPool.current);
								io->_npcdata->manaPool.current -= manadrained;
							}
						}
						
						if (damage.params.source == PlayerEntityHandle) {
							player.manaPool.current = std::min(player.manaPool.current + manadrained, player.Full_maxmana);
						} else {
							if(ValidIONum(damage.params.source) && (entities[damage.params.source]->_npcdata)) {
								entities[damage.params.source]->_npcdata->manaPool.current = std::min(entities[damage.params.source]->_npcdata->manaPool.current + manadrained, entities[damage.params.source]->_npcdata->manaPool.max);
							}
						}
					} else {
						float damagesdone;
						
						// TODO copy-paste
						if(i == 0) {
							if(damage.params.type & DAMAGE_TYPE_POISON) {
								if(rnd() * 100.f > player.m_misc.resistPoison) {
									// Failed Saving Throw
									damagesdone = dmg; 
									player.poison += damagesdone;
								} else {
									damagesdone = 0;
								}
							} else {
								if(   (damage.params.type & DAMAGE_TYPE_MAGICAL)
								   && !(damage.params.type & DAMAGE_TYPE_FIRE)
								   && !(damage.params.type & DAMAGE_TYPE_COLD)
								) {
									dmg -= player.m_miscFull.resistMagic * ( 1.0f / 100 ) * dmg;
									dmg = std::max(0.0f, dmg);
								}
								if(damage.params.type & DAMAGE_TYPE_FIRE) {
									dmg = ARX_SPELLS_ApplyFireProtection(entities.player(), dmg);
									ARX_DAMAGES_IgnitIO(entities.player(), dmg);
								}
								if(damage.params.type & DAMAGE_TYPE_COLD) {
									dmg = ARX_SPELLS_ApplyColdProtection(entities.player(), dmg);
								}
								damagesdone = ARX_DAMAGES_DamagePlayer(dmg, damage.params.type, damage.params.source);
							}
						} else {
							if(   (entities[handle]->ioflags & IO_NPC)
							   && (damage.params.type & DAMAGE_TYPE_POISON)
							) {
								if(rnd() * 100.f > entities[handle]->_npcdata->resist_poison) {
									// Failed Saving Throw
									damagesdone = dmg; 
									entities[handle]->_npcdata->poisonned += damagesdone;
								} else {
									damagesdone = 0;
								}
							} else {
								if(damage.params.type & DAMAGE_TYPE_FIRE) {
									dmg = ARX_SPELLS_ApplyFireProtection(entities[handle], dmg);
									ARX_DAMAGES_IgnitIO(entities[handle], dmg);
								}
								if(   (damage.params.type & DAMAGE_TYPE_MAGICAL)
								   && !(damage.params.type & DAMAGE_TYPE_FIRE)
								   && !(damage.params.type & DAMAGE_TYPE_COLD)
								) {
									dmg -= entities[handle]->_npcdata->resist_magic * ( 1.0f / 100 ) * dmg;
									dmg = std::max(0.0f, dmg);
								}
								if(damage.params.type & DAMAGE_TYPE_COLD) {
									dmg = ARX_SPELLS_ApplyColdProtection(entities[handle], dmg);
								}
								damagesdone = ARX_DAMAGES_DamageNPC(entities[handle], dmg, damage.params.source, true, &damage.params.pos);
							}
							if(damagesdone > 0 && (damage.params.flags & DAMAGE_SPAWN_BLOOD)) {
								ARX_PARTICLES_Spawn_Blood(&damage.params.pos, damagesdone, damage.params.source);
							}
						}
						if(damage.params.type & DAMAGE_TYPE_DRAIN_LIFE) {
							if(ValidIONum(damage.params.source))
								ARX_DAMAGES_HealInter(entities[damage.params.source], damagesdone);
						}
					}
				}
			} else if((io->ioflags & IO_FIX) && !(damage.params.type & DAMAGE_TYPE_NO_FIX)) {
				Sphere sphere;
				sphere.origin = damage.params.pos;
				sphere.radius = damage.params.radius + 15.f;
				
				if(CheckIOInSphere(sphere, EntityHandle(i))) {
					ARX_DAMAGES_DamageFIX(io, dmg, damage.params.source, true);
				}
			}
		}
	}
	
	if(damage.params.duration == -1)
		damage.exist = false;
	else if(tim > damage.start_time + damage.params.duration)
		damage.exist = false;
}
Пример #19
0
bool DoSphericDamage(const Vec3f & pos, float dmg, float radius, DamageArea flags, DamageType typ, EntityHandle numsource)
{
	bool damagesdone = false;
	
	if(radius <= 0.f)
		return damagesdone;
	
	float rad = 1.f / radius;
	bool validsource = ValidIONum(numsource);
	
	for(size_t i = 0; i < entities.size(); i++) {
		const EntityHandle handle = EntityHandle(i);
		Entity * ioo = entities[handle];
		
		if(!ioo || long(i) == numsource || !ioo->obj)
			continue;
			
		if ((i != 0) && (numsource != PlayerEntityHandle)
				&& validsource && (HaveCommonGroup(ioo, entities[numsource])))
			continue;
		
		if((ioo->ioflags & IO_CAMERA) || (ioo->ioflags & IO_MARKER))
			continue;
		
		long count = 0;
		long count2 = 0;
		float mindist = std::numeric_limits<float>::max();
		
		for(size_t k = 0; k < ioo->obj->vertexlist.size(); k += 1) {
			if(ioo->obj->vertexlist.size() < 120) {
				for(size_t kk = 0; kk < ioo->obj->vertexlist.size(); kk += 1) {
					if(kk != k) {
						Vec3f posi = (entities[handle]->obj->vertexlist3[k].v
									  + entities[handle]->obj->vertexlist3[kk].v) * 0.5f;
						float dist = fdist(pos, posi);
						if(dist <= radius) {
							count2++;
							if(dist < mindist)
								mindist = dist;
						}
					}
				}
			}
			
			{
			float dist = fdist(pos, entities[handle]->obj->vertexlist3[k].v);
			
			if(dist <= radius) {
				count++;
				
				if(dist < mindist)
					mindist = dist;
			}
			}
		}
		
		float ratio = ((float)count / ((float)ioo->obj->vertexlist.size() * ( 1.0f / 2 )));
		
		if(count2 > count)
			ratio = ((float)count2 / ((float)ioo->obj->vertexlist.size() * ( 1.0f / 2 )));
		
		if(ratio > 2.f)
			ratio = 2.f;
		
		if(ioo->ioflags & IO_NPC) {
			if(mindist <= radius + 30.f) {
				switch (flags) {
					case DAMAGE_AREA:
						dmg = dmg * (radius + 30 - mindist) * rad;
						break;
					case DAMAGE_AREAHALF:
						dmg = dmg * (radius + 30 - mindist * ( 1.0f / 2 )) * rad;
						break;
					case DAMAGE_FULL: break;
				}
				
				if(i == 0) {
					if(typ & DAMAGE_TYPE_FIRE) {
						dmg = ARX_SPELLS_ApplyFireProtection(ioo, dmg);
						ARX_DAMAGES_IgnitIO(entities.player(), dmg);
					}
					
					if(typ & DAMAGE_TYPE_COLD) {
						dmg = ARX_SPELLS_ApplyColdProtection(ioo, dmg);
					}
					
					ARX_DAMAGES_DamagePlayer(dmg, typ, numsource);
					ARX_DAMAGES_DamagePlayerEquipment(dmg);
				} else {
					if(typ & DAMAGE_TYPE_FIRE) {
						dmg = ARX_SPELLS_ApplyFireProtection(ioo, dmg * ratio);
						ARX_DAMAGES_IgnitIO(ioo, dmg);
					}
					
					if(typ & DAMAGE_TYPE_COLD) {
						dmg = ARX_SPELLS_ApplyColdProtection(ioo, dmg * ratio);
					}
					
					ARX_DAMAGES_DamageNPC(ioo, dmg * ratio, numsource, true, &pos);
				}
				
				if(dmg > 1)
					damagesdone = true;
			}
		} else {
			if(mindist <= radius + 30.f) {
				if(typ & DAMAGE_TYPE_FIRE) {
					dmg = ARX_SPELLS_ApplyFireProtection(ioo, dmg * ratio);
					ARX_DAMAGES_IgnitIO(entities[handle], dmg);
				}
				
				if(typ & DAMAGE_TYPE_COLD) {
					dmg = ARX_SPELLS_ApplyColdProtection(ioo, dmg * ratio);
				}
				
				if(entities[handle]->ioflags & IO_FIX)
					ARX_DAMAGES_DamageFIX(entities[handle], dmg * ratio, numsource, true);
				
				if(dmg > 0.2f)
					damagesdone = true;
			}
		}
	}
	
	if (typ & DAMAGE_TYPE_FIRE)
		CheckForIgnition(pos, radius, 1);
	
	return damagesdone;
}
Пример #20
0
// #include"reaction.h"
int main(){

////////Input Parameters of the potential (fit parameters) /////
std::string parameters_filename="Input.inp";

NuclearParameters Nu = read_nucleus_parameters( "Input/nca40.inp" );

double Ef=Nu.Ef;
int lmax=6;
double z0=20.0;
double zp0;
double A0=40.0;
double tz=-0.5;

int type=1;
int mvolume = 4;
int AsyVolume = 1;

double A = 40.0;

if (tz>0) { zp0=1;}
else {zp0=0;}

double ph_gap = Nu.ph_gap;
cout<<"ph_gap = "<<Nu.ph_gap<<endl;
double  rStart = .05;
double  rmax = 12.;
double  ham_pts = 180; 

double  rdelt = rmax / ham_pts;

//THIS IS ANOTHER CHANGE FROM THE OLD TOO////////////////
double  rdelt_p = rdelt / 1.025641026;

        // Construct Parameters Object
        Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, zp0 );

        // Construct Potential Object
        pot pottt = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
	pot * pott = &pottt;

        // store coulomb potential in order to compare with




 boundRspace initiate(rmax , ham_pts , Ef, ph_gap , lmax , Nu.Z , zp0 , Nu.A , pott);


  
 double Elower = -11.61818;
 double Eupper = -9.4;
 double jj = .5;
 int ll = 0;
 int Ifine = 1;
 initiate.searchNonLoc( Elower, Eupper, jj,  ll,  Ifine);
 initiate.exteriorWaveFunct(ll);
 initiate.normalizeWF();


double tol=.01;
double estart=Ef;

///// Making rmesh///

//THIS IS THE DIFFERENCE FROM SKYRMEOLD////////////////////////////////
//vector <double> rmesh_p = initiate.make_rmesh();
std::vector<double> rmesh_p= initiate.make_rmesh_point();
std::vector<double> rmesh= initiate.make_rmesh();

// Create momentum space grid
std::vector<double> kmesh;
std::vector<double> kweights;
double const kmax = 5.0;
int const kpts = rmesh.size();
kmesh.resize( kpts );
kweights.resize( kpts );
GausLeg( 0., kmax, kmesh, kweights );

double J =0.5;

double Emax=2*-4.7;
double Emin=-200.0 + Emax;

std::ofstream filee("waves/neutron/natural/wave.out");
std::cout<<Elower<<std::endl;

//Generating the propagator

std::vector< lj_eigen_t > bound_levels = initiate.get_bound_levels( rmesh, tol );

std::vector< mesh_t > emesh_vec =
        initiate.get_emeshes( rmesh, Emin, Emax, bound_levels );

cout<<"emesh_vec = "<<emesh_vec.size()<<endl;

std::vector< prop_t > prop_vec = initiate.get_propagators( rmesh, emesh_vec );

double onum=0.0;
double num=0.0;
double part=0;
double kpart=0;
vector<double> denk;
denk.assign( kmesh.size(), 0 );
vector<double> k_dist;
k_dist.assign( kmesh.size(), 0 );
vector <double> natden;
natden.assign(rmesh.size(),0);
vector <double> natdenk;
natdenk.assign(kmesh.size(),0);
vector <double> ktest;
ktest.assign(kmesh.size(),0);
vector <double> diag;
diag.assign(kmesh.size(),0);

double dom=0;
double expo=0;

int Nmax=5;

string stable = "waves/neutron/natural/table.txt";
ofstream ftable(stable.c_str());

string presky = "waves/neutron/data/n";

vector<double> kdist;
kdist.assign(rmesh.size(),0);
lmax=0;
//Starting loop over L and J to go through all the orbitals
for(int L=0;L<lmax+1;L++){
	for(int s=0;s<2;s++){	
		J=L-0.5+s;
		if(J<0){
			J=0.5;
			s=1;
		}	
	
		cout<<"L = "<<L<<" J = "<<J<<endl;

		string jlab;
		if(J==0.5){
			jlab="12";
		}else if(J==1.5){
			jlab="32";
		}else if(J==2.5){
			jlab="52";
		}else if(J==3.5){
			jlab="72";
		}else if(J==4.5){
			jlab="92";
		}else if(J==5.5){
			jlab="112";
		}else if(J==6.5){
			jlab="132";
		}

		string llab;
		if(L==0){
			llab="s";
		}else if(L==1){
			llab="p";
		}else if(L==2){
			llab="d";
		}else if(L==3){
			llab="f";
		}else if(L==4){
			llab="g";
		}else if(L==5){
			llab="h";
		}else if(L==6){
			llab="i";
		}

/*
		int Nmax=10;
		if(L>1){
			Nmax=9;
		}
		if(L>3){
			Nmax=8;
		}
		if(L==6 && J == 5.5){
			Nmax=7;
		}	
*/
		Nmax=4;
		if(L>3) Nmax = 1;


		int Mmax=Nmax;


		ftable<<endl;
		ftable<<llab<<jlab<<endl;
		ftable<<"     ";
		for(int i=0;i<Mmax;i++){
			ftable<<i<<"            ";
		}
		ftable<<endl;

		string dest = "waves/neutron/natural/";

		int index=initiate.index_from_LJ(L,J);

		const prop_t &propE = prop_vec.at(index);

		const mesh_t &emesh = emesh_vec.at(index);

// Create Bessel Function matrix in k and r
    matrix_t bess_mtx( kmesh.size(), rmesh.size() );
		bess_mtx.clear();
		matrix_t bess_mtx_sky(kmesh.size(),rmesh.size());
		bess_mtx_sky.clear();
    for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
	    for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {
	      double rho = kmesh[nk] * rmesh_p[nr];
        bess_mtx( nk, nr ) = gsl_sf_bessel_jl( L, rho );
				bess_mtx_sky(nk,nr) = gsl_sf_bessel_jl(L, kmesh[nk]*rmesh[nr]);
      }
    }		

		matrix_t d_mtx( rmesh.size(), rmesh.size() ); // density matrix
		d_mtx.clear();

//Remember that propE is actually G*r*r'*rdelt
		for(unsigned int n=0;n<emesh.size();++n){	
			double Edelt=emesh[n].second;
		  for( unsigned int i = 0; i < rmesh.size(); ++i ) {
				for( unsigned int j = 0; j < rmesh.size(); ++j ) {
					d_mtx(i,j) -= Edelt * imag(propE[n](i,j)) / M_PI;  
				} 
			} 
		}		

		const lj_eigen_t &levels = bound_levels.at(index);


//this adds the QP peaks to the particle number
		for ( unsigned int N = 0; N < levels.size(); ++N ){   
    	if ( ( levels[N].first <= Ef ) && 
      ( levels[N].first > Emax ) ) {
      	double QPE = levels[N].first;
      	const std::vector<double> &QPF = levels[N].second;
      	double S = initiate.sfactor( rmesh, QPE, L, J, QPF );
				for ( unsigned int i = 0; i < rmesh.size(); ++i ) {
					for(int j=0;j<rmesh.size();j++){
	          d_mtx(i,j) +=  S * QPF[i] * QPF[j] * rmesh[i]*rmesh[j]*rdelt;
          }
				}
			}
		}

		

		matrix_t k_mtx( rmesh.size(), rmesh.size() ); // density matrix
		k_mtx.clear();
		matrix_t mtx(rmesh.size(),rmesh.size() );
		mtx.clear();
		matrix_t diff_mtx(rmesh.size(),rmesh.size());
		diff_mtx.clear();
		matrix_t r_mtx( rmesh.size(), rmesh.size() ); // testing to see if this is the same as the original
		r_mtx.clear();

		double maxR = rmesh[rmesh.size()-1];
		double minR = rmesh[0];

	/*		for(int i=0;i<rmesh.size();i++){
			for(int j=0;j<rmesh.size();j++){
				//d_mtx(i,j) = exp(-pow(rmesh[i]-rmesh[j],2));
				//mtx(i,j) = (1.0 / pow(kmesh[i]*kmesh[j],2) ) * (cos(kmesh[i]*maxR) - cos(kmesh[i]*minR) ) * (cos(kmesh[j]*maxR) - cos(kmesh[i]*minR) ) * (2.0/M_PI);
			}
			f4[i] = mtx(i,i);
		}  */

		for(int i=0;i<rmesh.size();i++){
			if(i%30==0) cout<<i<<endl;
			for(int j=0;j<rmesh.size();j++){
				double kd=0;
				double kr;
				double kr2;
				for(int ii=0;ii<rmesh.size();ii++){
					for(int jj=0;jj<rmesh.size();jj++){
						//dmtx already has r*r'*dr
						kd += d_mtx(ii,jj) * bess_mtx(i,ii) * bess_mtx(j,jj) /( rmesh[ii] * rmesh[jj] * rdelt) * pow( rdelt_p * rmesh_p[ii] * rmesh_p[jj], 2) * (2.0/M_PI);
						//kd += d_mtx(ii,jj) * bess_mtx(i,ii) * bess_mtx(j,jj) * pow(rdelt * rmesh[ii] * rmesh[jj],2) * (2.0/M_PI);
						kr = kmesh[i] * rmesh[ii];
						kr2 = kmesh[j] * rmesh[jj];
						//kd += d_mtx(ii,jj) * sin(kr)/kr * sin(kr2)/kr2 * pow(rdelt * rmesh[ii] * rmesh[jj], 2) * (2.0/M_PI);
						//kd += d_mtx(ii,jj) * sin(kr)/kr * sin(kr2)/kr2 / ( rmesh[ii] * rmesh[jj] * rdelt) * pow( rdelt_p * rmesh_p[ii] * rmesh_p[jj], 2) * (2.0/M_PI);
					}
				}
			//including this for diagonalization
			k_mtx(i,j) = kd * kmesh[i] * kmesh[j] * kweights[i];			
			}
			//f2[i] = k_mtx(i,i);
			kdist[i] += k_mtx(i,i) * (2*J+1) / (4*M_PI);
		}

		for(int i=0;i<rmesh.size();i++){
			if(i%30==0) cout<<i<<endl;
			for(int j=0;j<rmesh.size();j++){
				double kd=0;
				double kr;
				double kr2;
				for(int ii=0;ii<rmesh.size();ii++){
					for(int jj=0;jj<rmesh.size();jj++){
						//already includes kk'dk
						kd += k_mtx(ii,jj) * bess_mtx(ii,i) * bess_mtx(jj,j) * kmesh[ii] * kmesh[jj] * kweights[jj] * (2.0/M_PI);
					}
				}
			//including this for diagonalization
			r_mtx(i,j) = kd * rmesh[i] * rmesh[j] * rdelt;			
			}
		}


		vector <eigen_t> eig = initiate.real_eigvecs(d_mtx);
		vector <eigen_t> eigr = initiate.real_eigvecs(r_mtx);
		vector <eigen_t> eigk = initiate.real_eigvecs(k_mtx);
		vector <eigen_t> eigm = initiate.real_eigvecs(mtx);

		ofstream diff("waves/diff.txt");
		
		for(int i=0;i<rmesh.size();i++){
			diff<<rmesh[i]<<" "<<eig[rmesh.size()-1].second[i]/rmesh[i]<<" "<<eigr[rmesh.size()-1].second[i]/rmesh[i]<<endl;
		}


		cout<<"maxR = "<<maxR<<endl;
		cout<<"minR = "<<minR<<endl;
		cout<<"kmesh[10] = "<<kmesh[100]<<endl;

		double eignorm=0;
		double reignorm=0;
		double keignorm=0;

		ofstream feval("waves/evals.txt");
		for(int i=0;i<rmesh.size();i++){
			double spot=rmesh.size()-1-i;
			feval<<eig[spot].first<<" "<<eigr[spot].first<<endl;
			eignorm += pow(eig[spot].first,2);
			reignorm += pow(eigr[spot].first,2);
			keignorm += pow(eigk[spot].first,2);
		}

	//	cout<<"eigval d_mtx[0] = "<<eig[0].first<<endl;
		cout<<"eigval d_mtx[N] = "<<eig[rmesh.size()-1].first<<endl;
		cout<<"eigval r_mtx[N] = "<<eigr[rmesh.size()-1].first<<endl;
	//	cout<<"eigval k_mtx[0] = "<<eigk[0].first<<endl;
		cout<<"eigval k_mtx[N] = "<<eigk[rmesh.size()-1].first<<endl;
		cout<<"eigval mtx[N] = "<<eigm[rmesh.size()-1].first<<endl;
		cout<<"k_mtx(10,10) = "<<k_mtx(100,100)<<endl;
		cout<<"mtx(10,10) = "<<mtx(100,100)<<endl;

		vector <double> f(rmesh.size());
		vector <double> f2(rmesh.size());
		vector <double> f3(rmesh.size());
		vector <double> f4(rmesh.size());
		for(int i=0;i<rmesh.size();i++){
			f[i] = eig[rmesh.size()-1].second[i]/rmesh_p[i]; 
		}

		double fk;

		for(int i=0;i<rmesh.size();i++){
			fk=0;
			for(int j=0;j<rmesh.size();j++){
				fk += f[j] * sin(rmesh[j] * kmesh[i])/(rmesh[j]*kmesh[i]) * pow(rmesh[j],2) * rdelt * sqrt(2.0/M_PI);
			}
			f2[i] = fk;
			f4[i] = 1.0/pow(kmesh[i],2) * (cos(minR*kmesh[i]) - cos(maxR*kmesh[i]) );
		}

		for(int i=0;i<rmesh.size();i++){
			fk=0;
			for(int j=0;j<rmesh.size();j++){
				fk += f2[j] * sin(rmesh[i] * kmesh[j])/(rmesh[i]*kmesh[j]) * pow(kmesh[j],2) * kweights[j] * sqrt(2.0/M_PI);
			}
			f3[i] = fk;
		}
				
		ofstream compk("waves/compk.txt");
		for(int i=0;i<rmesh.size();i++){
			compk<<kmesh[i]<<" "<<f2[i]<<" "<<f4[i]<<endl;
		}

		ofstream compr("waves/compr.txt");
		for(int i=0;i<rmesh.size();i++){
			compr<<rmesh[i]<<" "<<f[i]<<" "<<f3[i]<<endl;
		}

		double ksum=0;
		double rsum=0;

		for(int i=0;i<kmesh.size()-1;i++){

			if(eigk[i].first > 0.5 && eigk[i].first < 2){
				cout <<"eigk = " << eig[i].first << endl;
			}

			rsum += eig[i].first;
			ksum += eigk[i].first;

		}

		rsum += eig[rmesh.size()-1].first;

		cout<<"ksum = "<<ksum<<endl;
		cout<<"rsum = "<<rsum<<endl;

		//Transforming natural orbits to k-space
			vector <double> knat;
			knat.assign(kmesh.size(),0);
			for(int ik=0;ik<kmesh.size();ik++){
				double kn=0;
				for(int ir=0;ir<rmesh.size();ir++){
					kn += rdelt_p * sqrt(2.0/M_PI) * bess_mtx(ik,ir) * eig[rmesh.size()-1].second[ir] / rmesh[ir]
					* pow(rmesh_p[ir],2);
				}
				knat[ik] = kn;		
			}
			
		double fnorm=0;
		double fnorm2=0;

		for(int i =0;i<rmesh.size();i++){
			fnorm += pow(knat[i] * kmesh[i],2) * kweights[i];
			fnorm2 += pow(eigk[kmesh.size()-1].second[i] * kmesh[i], 2) * kweights[i];
		}

		cout<<"fnorm = "<<fnorm<<endl;
		cout<<"fnorm2 = "<<fnorm2<<endl;



		string eiglab = dest + "eig" + llab+jlab+".txt";

		ofstream fval(eiglab.c_str());

		matrix_t sky_mtx(Mmax, Mmax); // density matrix
		sky_mtx.clear();


//Starting loop over N
		for(int N=0;N<Nmax;N++){
			string Nlab;
			ostringstream convert;
			convert << N;
			Nlab = convert.str();

			ftable<<Nlab<<"   ";

			double spot = rmesh.size()-N-1;

			double enorm=0;

			for(int i=0;i<rmesh.size();++i){
				enorm += rdelt * pow( eig[spot].second[i],2);
			}

			string veclab = dest + "eig" + llab + jlab + Nlab + ".txt";

			std::ofstream feig(veclab.c_str());

			//opening skyrme file which gives u(r)
			string skyfile0 = presky + llab + jlab + Nlab + ".txt";
			std::ifstream filein0(skyfile0.c_str());
			double sky0[rmesh.size()];
			std::string line0;
			int i;
			i=0;
			while(getline(filein0,line0)){
				sky0[i]=atof(line0.c_str());
				i++;
			}
			filein0.close();

		//flipping the natural orbits if they are upside down
		//	if((eig[spot].second[1]<0 && sky0[1]>0) || (eig[spot].second[1]>0 && sky0[1]<0)){	
			//	for(int i=0;i<rmesh.size();i++){
				//	eig[spot].second[i] *= -1.0;
				//}
			//}

			for(int i=0;i<rmesh.size();++i){
				//want to give R(r), so print out u(r)/r
				feig<<rmesh[i]<<" "<<eig[spot].second[i]/sqrt(enorm)/rmesh[i]<<" "<<sky0[i]/rmesh[i]<<endl;		
			}			

			//Transforming natural orbits to k-space
			vector <double> knat;
			knat.assign(kmesh.size(),0);
			for(int ik=0;ik<kmesh.size();ik++){
				double kn=0;
				for(int ir=0;ir<rmesh.size();ir++){
					kn += rdelt_p * sqrt(2.0/M_PI) * bess_mtx(ik,ir) * eig[spot].second[ir] / sqrt(enorm) / rmesh[ir]
					* pow(rmesh_p[ir],2);
				}
				knat[ik] = kn;		
			}

			double nnorm=0;
			for(int i=0;i<kmesh.size();i++){
				nnorm += pow(knat[i]*kmesh[i],2) * kweights[i];
			}
			
		//	double newnorm=0;

			//for(int i=0;i<kmesh.size();i++){
				//knat[i] /= sqrt(nnorm);
			//	newnorm += pow(knat[i],2);
			//}

			//cout<<"newnorm = "<<nnorm<<endl;

			for(int i=0;i<rmesh.size();i++){
				natden[i] += eig[spot].first*pow(eig[spot].second[i]/rmesh[i]/sqrt(enorm),2)*(2*J+1)/(4*M_PI);
				natdenk[i] += eig[spot].first * pow(knat[i],2) * (2*J+1) / (4*M_PI);
			} 

			vector <double> wave;
			wave.assign(kmesh.size(),0);
			vector <double> waver;
			waver.assign(rmesh.size(),0);
			double csquare=0;

//beginning loop over M to sum over skyrme wave functions
			for(int M=0;M<Mmax;M++){
				string Mlab;
				ostringstream convert;
				convert << M;
				Mlab = convert.str();
				
//opening skyrme file which gives u(r)
				string skyfile = presky + llab + jlab + Mlab + ".txt";
				std::ifstream filein(skyfile.c_str());
				double skyrme[rmesh.size()];
				std::string line;
				int i;
				i=0;
				while(getline(filein,line)){
					skyrme[i]=atof(line.c_str());
					i++;
				}
				filein.close();

		//Transforming skyrme wavefunctions to k-space
				vector <double> ksky;
				ksky.assign(kmesh.size(),0);
				for(int ik=0;ik<kmesh.size();ik++){
					double ks=0;
					for(int ir=0;ir<rmesh.size();ir++){
						ks += rdelt * sqrt(2.0/M_PI) * bess_mtx_sky(ik,ir) * skyrme[ir] * rmesh[ir];
					}
					ksky[ik] = ks;
				}

				if(M==N){
					string test = "waves/neutron/natural/wave" + llab + jlab + Mlab + ".txt";
					ofstream ftest(test.c_str());
					for(int i=0;i<kmesh.size();i++){
						ftest<<kmesh[i]<<" "<<knat[i]<<" "<<ksky[i]<<endl;
					}
				}

				int M2max=Mmax;

				double proj=0;
				for(int i=0;i<kmesh.size();i++){
					proj += ksky[i] * knat[i] * pow(kmesh[i],2) * kweights[i];
				}

				ftable<<proj<<"   ";
		
				for(int M2=0;M2<M2max;M2++){
					string M2lab;
					ostringstream convert;
					convert << M2;
					M2lab = convert.str();

					string skyfile2 = presky + llab + jlab + M2lab + ".txt";
					std::ifstream filein2(skyfile2.c_str());
					double skyrme2[rmesh.size()];
					std::string line2;
					int i;
					i=0;
					while(getline(filein2,line2)){
						skyrme2[i]=atof(line2.c_str());
						i++;
					}
					filein2.close();

					if(N==0){

					//creating matrix in skyrme space
					double sky=0;
					for(int i=0;i<rmesh.size();i++){
						for(int j=0;j<rmesh.size();j++){
							sky += skyrme[i] * skyrme2[j] * d_mtx(i,j) * rdelt;
						}
					}

					sky_mtx(M,M2) = sky;

					}

					//Transforming skyrme wavefunctions to k-space
					vector <double> ksky2;
					ksky2.assign(kmesh.size(),0);
					for(int ik=0;ik<kmesh.size();ik++){
						double ks2=0;
						for(int ir=0;ir<rmesh.size();ir++){
							ks2 += rdelt * sqrt(2.0/M_PI) * bess_mtx_sky(ik,ir) * skyrme2[ir] * rmesh[ir];
						}
						ksky2[ik] = ks2;		
					}

					double proj2=0;
					for(int i=0;i<kmesh.size();i++){
						proj2 += ksky2[i] * knat[i] * pow(kmesh[i],2) * kweights[i];
					}

					//if(M != M2){
						//cout<<"proj1 = "<<proj<<endl;
						//cout<<"proj2 = "<<proj2<<endl;
					//}

					for(int i=0;i<kmesh.size();i++){
						denk[i] += eig[spot].first * (2*J+1) / (4*M_PI) * ksky[i] * ksky2[i] * proj * proj2;
						if(M != M2){
							ktest[i] += eig[spot].first * (2*J+1) / (4*M_PI) * ksky[i] * ksky2[i] * proj * proj2;
						}							
					} 

				} //end loop over M2
				
				for(int i=0;i<kmesh.size();i++){
					wave[i] +=  skyrme[i] * proj;
				}

				csquare += pow(proj,2);

			} //ending loop over M

			ftable<<endl;

		if(L==0){
			dom += eig[spot].first * (2*J+1) / (4*M_PI) * pow(knat[0],2);
			expo += eig[spot].first * (2*J+1) / (4*M_PI) * pow(wave[0],2);
		}

			for(int i=0;i<kmesh.size();i++){
				diag[i] += eig[spot].first * (2*J+1) / (4*M_PI) * pow(wave[i],2);
			}

			double overlap=0;
			for(int i=0;i<kmesh.size();i++){
				overlap += knat[i] * wave[i] * pow(kmesh[i],2) * kweights[i];
			}
			//ut<<" N = "<<N<<" overlap = "<<overlap<<endl;
			//cout<<"N = "<<N<<" csquare = "<<csquare<<endl;

			string comp = "waves/neutron/natural/comp" + llab + jlab + Nlab + ".txt";
			ofstream fcomp(comp.c_str());

			double wavenorm=0;
			double natnorm=0;

			for(int i=0;i<rmesh.size();i++){
				wavenorm += pow(wave[i],2) * rdelt;
			}

			for(int i=0;i<kmesh.size();i++){
				fcomp<<rmesh[i]<<" "<<wave[i]/sqrt(wavenorm)/rmesh[i]<<endl;
			}

		} //ending loop over N
		//ftable.close();

		vector <eigen_t> eigsky = initiate.real_eigvecs(sky_mtx);

		cout<<"Mmax = "<<Mmax<<endl;

		for(int M=0;M<Mmax;M++){
			string Mlab;
			ostringstream convert;
			convert << M;
			Mlab = convert.str();

			int spot = Mmax - M - 1;

			string fname = "waves/eigvec" + llab + jlab + Mlab + ".txt";
			ofstream feigsky(fname.c_str());

			//the eigenvector is already normalized
			for(int i=0;i<Nmax;i++){
				feigsky << eigsky[spot].second[i] << endl;
			}

			cout << "eigval = " << eigsky[spot].first << endl;

			vector<double> qpf;
			qpf.assign(rmesh.size(),0);
		
			for(int j=0;j<Mmax;j++){
		
				string Nlab;
				ostringstream convert;
				convert << j;
				Nlab = convert.str();
				string skyfile = presky + llab + jlab + Nlab + ".txt";
				std::ifstream filein(skyfile.c_str());
				double skyrme[rmesh.size()];
				std::string line;
				int i;
				i=0;
				while(getline(filein,line)){
					skyrme[i]=atof(line.c_str());
					i++;
				}
				filein.close();
				for(int i=0;i<rmesh.size();i++){
					qpf[i] += eigsky[spot].second[j] * skyrme[i];
				}
			}

			string qpname = "waves/nat" + llab + jlab + Mlab + ".txt";
			ofstream qpfile(qpname.c_str());

			double norm=0;

			for(int i=0;i<rmesh.size();i++){
				norm += pow(qpf[i],2) * rdelt;
			}

			double fac;
		
			if(qpf[10] < 0){
				fac = -1.0;
			}else{
				fac = 1.0;
			}


			for(int i=0;i<rmesh.size();i++){
				qpfile << rmesh[i] <<" "<< qpf[i] / sqrt(norm) / rmesh[i] * fac << endl;
			}

		}



	}		//ending loop over j
} 		//ending loop over L

double knum=0;
double kdiag=0;
double kdistnum=0;

ofstream fdiag("waves/neutron/natural/diagk.txt");
ofstream sdenk("waves/neutron/natural/skydenk.txt");
ofstream fdenr("waves/neutron/natural/natden.txt");
ofstream fdenk("waves/neutron/natural/natdenk.txt");
ofstream fdist("waves/kdist.txt");

double k_part=0;
kpart=0;
for(int i=0;i<kmesh.size();i++){
	kpart += denk[i] * pow(kmesh[i],2) * kweights[i] * 4 * M_PI;
	knum += ktest[i] * pow(kmesh[i],2) * kweights[i] * 4 * M_PI;
	k_part += natdenk[i] * kweights[i] * pow(kmesh[i],2) * 4 * M_PI;
	kdiag += diag[i] * kweights[i] * pow(kmesh[i],2) * 4 * M_PI;
	kdistnum += kdist[i] * pow(kmesh[i],2) * kweights[i] * 4 * M_PI;
}

for(int i=0;i<kmesh.size();i++){
	sdenk<<kmesh[i]<<" "<<denk[i]<<endl;
	fdenk<<kmesh[i]<<" "<<natdenk[i]<<endl;
	fdiag<<kmesh[i]<<" "<<diag[i]/kdiag<<endl;
	fdist<<kmesh[i]<<" "<<kdist[i]/kdistnum<<endl;
}

double nat=0;
for(int i=0;i<rmesh.size();i++){
	nat += natden[i] * rdelt_p * pow(rmesh_p[i],2) * 4*M_PI;
}

for(int i=0;i<rmesh.size();i++){
	fdenr<<rmesh_p[i]<<" "<<natden[i]/nat<<endl;
}

cout<<"expoansion = "<<expo/kpart<<endl;
cout<<"natural = "<<dom/k_part<<endl;
cout<<"ktest = "<<knum<<endl;
cout<<"kdiag = "<<kdiag<<endl;
cout<<"particle number from sky density (k) = "<<kpart<<endl;
cout<<"particle number from natural (r) = "<<nat<<endl;
cout<<"particle number from natural (k) = "<<k_part<<endl;
cout<<"particle number from kdist (k) = "<<kdistnum<<endl;

}
Пример #21
0
float GetColorz(const Vec3f &pos) {

    UpdateLlights(pos, true);

    Color3f ff = Color3f(0.f, 0.f, 0.f);

    for(long k = 0; k < MAX_LLIGHTS; k++) {
        EERIE_LIGHT * el = llights[k];

        if(el) {
            float dd = fdist(el->pos, pos);

            if(dd < el->fallend) {
                float dc;

                if(dd <= el->fallstart) {
                    dc = el->intensity * GLOBAL_LIGHT_FACTOR;
                } else {
                    float p = ((el->fallend - dd) * el->falldiffmul);

                    if(p <= 0.f)
                        dc = 0.f;
                    else
                        dc = p * el->intensity * GLOBAL_LIGHT_FACTOR;
                }

                dc *= 0.4f * 255.f;
                ff.r = std::max(ff.r, el->rgb.r * dc);
                ff.g = std::max(ff.g, el->rgb.g * dc);
                ff.b = std::max(ff.b, el->rgb.b * dc);
            }
        }
    }


    EERIEPOLY * ep;
    float needy;
    ep = CheckInPoly(pos, &needy);

    if(ep != NULL) {
        Color3f _ff = Color3f(0.f, 0.f, 0.f);

        long to = (ep->type & POLY_QUAD) ? 4 : 3;
        float div = (1.0f / to);

        EP_DATA & epdata = portals->rooms[ep->room].epdata[0];
        ApplyTileLights(ep, epdata.p);

        for(long i = 0; i < to; i++) {
            Color col = Color::fromRGBA(ep->tv[i].color);
            _ff.r += float(col.r);
            _ff.g += float(col.g);
            _ff.b += float(col.b);
        }

        _ff.r *= div;
        _ff.g *= div;
        _ff.b *= div;
        float ratio, ratio2;
        ratio = glm::abs(needy - pos.y) * ( 1.0f / 300 );
        ratio = (1.f - ratio);
        ratio2 = 1.f - ratio;
        ff.r = ff.r * ratio2 + _ff.r * ratio;
        ff.g = ff.g * ratio2 + _ff.g * ratio;
        ff.b = ff.b * ratio2 + _ff.b * ratio;
    }

    return (std::min(ff.r, 255.f) + std::min(ff.g, 255.f) + std::min(ff.b, 255.f)) * (1.f/3);
}
Пример #22
0
void AddFixedObjectHalo(const EERIE_FACE & face, const TransformInfo & t, const Entity * io, TexturedVertex * tvList, const EERIE_3DOBJ * eobj)
{
	float mdist=ACTIVECAM->cdepth;
	float ddist = mdist-fdist(t.pos, ACTIVECAM->orgTrans.pos);
	ddist = ddist/mdist;
	ddist = std::pow(ddist, 6);

	ddist = clamp(ddist, 0.25f, 0.9f);

	float tot=0;
	float _ffr[3];

	for(long o = 0; o < 3; o++) {
		Vec3f temporary3D;
		temporary3D = t.rotation * eobj->vertexlist[face.vid[o]].norm;

		float power = 255.f-(float)EEfabs(255.f*(temporary3D.z)*( 1.0f / 2 ));

		power = clamp(power, 0.f, 255.f);

		tot += power;
		_ffr[o] = power;

		u8 lfr = io->halo.color.r * power;
		u8 lfg = io->halo.color.g * power;
		u8 lfb = io->halo.color.b * power;
		tvList[o].color = ((0xFF << 24) | (lfr << 16) | (lfg << 8) | (lfb));
	}

	if(tot > 150.f) {
		long first;
		long second;
		long third;

		if(_ffr[0] >= _ffr[1] && _ffr[1] >= _ffr[2]) {
			first = 0;
			second = 1;
			third = 2;
		} else if(_ffr[0] >= _ffr[2] && _ffr[2] >= _ffr[1]) {
			first = 0;
			second = 2;
			third = 1;
		} else if(_ffr[1] >= _ffr[0] && _ffr[0] >= _ffr[2]) {
			first = 1;
			second = 0;
			third = 2;
		} else if(_ffr[1] >= _ffr[2] && _ffr[2] >= _ffr[0]) {
			first = 1;
			second = 2;
			third = 0;
		} else if(_ffr[2] >= _ffr[0] && _ffr[0] >= _ffr[1]) {
			first = 2;
			second = 0;
			third = 1;
		} else {
			first = 2;
			second = 1;
			third = 0;
		}

		if(_ffr[first] > 70.f && _ffr[second] > 60.f) {
			TexturedVertex vert[4];

			vert[0] = tvList[first];
			vert[1] = tvList[first];
			vert[2] = tvList[second];
			vert[3] = tvList[second];

			float siz = ddist * (io->halo.radius * 1.5f * (EEsin(arxtime.get_frame_time() * .01f) * .1f + .7f)) * .6f;

			Vec3f vect1;
			vect1.x = tvList[first].p.x - tvList[third].p.x;
			vect1.y = tvList[first].p.y - tvList[third].p.y;
			float len1 = 1.f / ffsqrt(vect1.x * vect1.x + vect1.y * vect1.y);

			if(vect1.x < 0.f)
				len1 *= 1.2f;

			vect1.x *= len1;
			vect1.y *= len1;

			Vec3f vect2;
			vect2.x = tvList[second].p.x - tvList[third].p.x;
			vect2.y = tvList[second].p.y - tvList[third].p.y;
			float len2 = 1.f / ffsqrt(vect2.x * vect2.x + vect2.y * vect2.y);

			if(vect2.x < 0.f)
				len2 *= 1.2f;

			vect2.x *= len2;
			vect2.y *= len2;

			vert[1].p.x += (vect1.x + 0.2f - rnd() * 0.1f) * siz;
			vert[1].p.y += (vect1.y + 0.2f - rnd() * 0.1f) * siz;
			vert[1].color = 0xFF000000;

			vert[0].p.z += 0.0001f;
			vert[3].p.z += 0.0001f;
			vert[1].rhw *= .8f;
			vert[2].rhw *= .8f;

			vert[2].p.x += (vect2.x + 0.2f - rnd() * 0.1f) * siz;
			vert[2].p.y += (vect2.y + 0.2f - rnd() * 0.1f) * siz;

			if(io->halo.flags & HALO_NEGATIVE)
				vert[2].color = 0x00000000;
			else
				vert[2].color = 0xFF000000;

			Halo_AddVertices(vert);
		}
	}
}
Пример #23
0
/*--------------------------------------------------------------------------*/
float CLevitate::Render()
{
	if (this->key > 1) return 0;

	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
	GRenderer->SetRenderState(Renderer::DepthWrite, false);

	//calcul du cone
	TexturedVertex d3dvs, *d3dv;
	Vec3f	* vertex;
	int			nb, nbc, col;
	float		ddu = this->ang;
	float		u = ddu, du = .99999999f / (float)this->def;

	switch (this->key)
	{
		case 0:
			nbc = 2;

			while (nbc--)
			{
				vertex = this->cone[nbc].conevertex;
				d3dv = this->cone[nbc].coned3d;
				nb = (this->cone[nbc].conenbvertex) >> 1;

				while (nb)
				{
					d3dvs.p.x = this->pos.x + (vertex + 1)->x + ((vertex->x - (vertex + 1)->x) * this->scale);
					d3dvs.p.y = this->pos.y + (vertex + 1)->y + ((vertex->y - (vertex + 1)->y) * this->scale);
					d3dvs.p.z = this->pos.z + (vertex + 1)->z + ((vertex->z - (vertex + 1)->z) * this->scale);
					
					EE_RT2(&d3dvs, d3dv);


					float fRandom	= rnd() * 80.f;

					col = checked_range_cast<int>(fRandom);

					if (!arxtime.is_paused()) d3dv->color = Color::grayb(col).toBGR(col);

					d3dv->uv.x = u;
					d3dv->uv.y = 0.f;
					vertex++;
					d3dv++;

					d3dvs.p.x = this->pos.x + vertex->x;
					d3dvs.p.y = this->pos.y;
					d3dvs.p.z = this->pos.z + vertex->z;
					
					EE_RT2(&d3dvs, d3dv);


					fRandom = rnd() * 80.f;

					col = checked_range_cast<int>(fRandom);


					if (!arxtime.is_paused()) d3dv->color = Color::black.toBGR(col);

					d3dv->uv.x = u;
					d3dv->uv.y = 0.9999999f;
					vertex++;
					d3dv++;

					u += du;
					nb--;
				}

				u = ddu;
				du = -du;
			}

			nbc = 3;
			while(nbc--) {
				
				PARTICLE_DEF * pd = createParticle();
				if(!pd) {
					break;
				}
				
				float a = radians(360.f * rnd());
				pd->ov = pos + Vec3f(rbase * EEcos(a), 0.f, rbase * EEsin(a));
				float t = fdist(pd->ov, pos);
				pd->move = Vec3f((5.f + 5.f * rnd()) * ((pd->ov.x - pos.x) / t), 3.f * rnd(),
				                 (5.f + 5.f * rnd()) * ((pd->ov.z - pos.z) / t));
				pd->siz = 30.f + 30.f * rnd();
				pd->tolive = 3000;
				pd->timcreation = -(long(arxtime) + 3000l); // TODO WTF
				pd->special = FIRE_TO_SMOKE | FADE_IN_AND_OUT | ROTATING | MODULATE_ROTATION
				              | DISSIPATING;
				pd->fparam = 0.0000001f;
			}
			break;
		
		case 1:
			nbc = 2;

			while (nbc--)
			{
				vertex = this->cone[nbc].conevertex;
				d3dv = this->cone[nbc].coned3d;
				nb = (this->cone[nbc].conenbvertex) >> 1;

				while (nb)
				{
					d3dvs.p = this->pos + *vertex;
	
					EE_RT2(&d3dvs, d3dv);
					col = Random::get(0, 80);

					if (!arxtime.is_paused()) d3dv->color = Color::grayb(col).toBGR(col);

					d3dv->uv.x = u;
					d3dv->uv.y = 0.f;
					vertex++;
					d3dv++;

					d3dvs.p.x = this->pos.x + vertex->x;
					d3dvs.p.y = this->pos.y;
					d3dvs.p.z = this->pos.z + vertex->z;

					EE_RT2(&d3dvs, d3dv);
					col = Random::get(0, 80);

					if (!arxtime.is_paused()) d3dv->color = Color::black.toBGR(col);

					d3dv->uv.x = u;
					d3dv->uv.y = 1; 
					vertex++;
					d3dv++;

					u += du;
					nb--;
				}

				u = ddu;
				du = -du;
			}
			
			nbc = 10;
			while(nbc--) {
				
				PARTICLE_DEF * pd = createParticle();
				if(!pd) {
					break;
				}
				
				float a = radians(360.f * rnd());
				pd->ov = pos + Vec3f(rbase * EEcos(a), 0.f, rbase * EEsin(a));
				float t = fdist(pd->ov, pos);
				pd->move = Vec3f((5.f + 5.f * rnd()) * ((pd->ov.x - pos.x) / t), 3.f * rnd(),
				                 (5.f + 5.f * rnd()) * ((pd->ov.z - pos.z) / t));
				pd->siz = 30.f + 30.f * rnd();
				pd->tolive = 3000;
				pd->timcreation = -(long(arxtime) + 3000l); // TODO WTF
				pd->special = FIRE_TO_SMOKE | FADE_IN_AND_OUT | ROTATING | MODULATE_ROTATION
				              | DISSIPATING;
				pd->fparam = 0.0000001f;
			}
			
			break;
	}

	//tracé du cone back
	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
	GRenderer->GetTextureStage(0)->SetWrapMode(TextureStage::WrapMirror);

	GRenderer->SetTexture(0, tsouffle);

	GRenderer->SetCulling(Renderer::CullCW);
	int i = cone[1].conenbfaces - 2;
	int j = 0;

	while (i--)
	{
		ARX_DrawPrimitive(&cone[1].coned3d[j],
		                             &cone[1].coned3d[j+1],
		                             &cone[1].coned3d[j+2]);
		j++;
	}

	i = cone[0].conenbfaces - 2;
	j = 0;

	while (i--)
	{
		ARX_DrawPrimitive(&cone[0].coned3d[j],
		                             &cone[0].coned3d[j+1],
		                             &cone[0].coned3d[j+2]);
		j++;
	}

	//tracé du cone front
	GRenderer->SetCulling(Renderer::CullCCW);
	
	i = cone[1].conenbfaces - 2;
	j = 0;

	while (i--)
	{
		ARX_DrawPrimitive(&cone[1].coned3d[j],
		                             &cone[1].coned3d[j+1],
		                             &cone[1].coned3d[j+2]);
		j++;
	}

	i = cone[0].conenbfaces - 2;
	j = 0;

	while (i--)
	{
		ARX_DrawPrimitive(&cone[0].coned3d[j],
		                             &cone[0].coned3d[j+1],
		                             &cone[0].coned3d[j+2]);
		j++;
	}

	//tracé des pierres
	GRenderer->SetBlendFunc(Renderer::BlendSrcAlpha, Renderer::BlendInvSrcAlpha);
	this->DrawStone();

	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendZero);
	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
	GRenderer->SetRenderState(Renderer::DepthWrite, true);

	return 0;
}
Пример #24
0
float GetColorz(const Vec3f & pos) {

	ShaderLight lights[llightsSize];
	size_t lightsCount;
	UpdateLlights(lights, lightsCount, pos, true);
	
	Color3f ff = Color3f(0.f, 0.f, 0.f);
	
	for(size_t k = 0; k < lightsCount; k++) {
		const ShaderLight & light = lights[k];
		
		float dd = fdist(light.pos, pos);
		
		if(dd < light.fallend) {
			float dc;
			
			if(dd <= light.fallstart) {
				dc = light.intensity * GLOBAL_LIGHT_FACTOR;
			} else {
				float p = ((light.fallend - dd) * light.falldiffmul);
				
				if(p <= 0.f)
					dc = 0.f;
				else
					dc = p * light.intensity * GLOBAL_LIGHT_FACTOR;
			}
			
			dc *= 0.4f * 255.f;
			ff.r = std::max(ff.r, light.rgb.r * dc);
			ff.g = std::max(ff.g, light.rgb.g * dc);
			ff.b = std::max(ff.b, light.rgb.b * dc);
		}
	}


	EERIEPOLY * ep;
	float needy;
	ep = CheckInPoly(pos, &needy);

	if(ep != NULL) {
		Color3f _ff = Color3f(0.f, 0.f, 0.f);
		
		long to = (ep->type & POLY_QUAD) ? 4 : 3;
		float div = (1.0f / to);

		EP_DATA & epdata = portals->rooms[ep->room].epdata[0];
		ApplyTileLights(ep, epdata.tile);

		for(long i = 0; i < to; i++) {
			Color col = Color::fromRGBA(ep->color[i]);
			_ff.r += float(col.r);
			_ff.g += float(col.g);
			_ff.b += float(col.b);
		}

		_ff.r *= div;
		_ff.g *= div;
		_ff.b *= div;
		float ratio, ratio2;
		ratio = glm::abs(needy - pos.y) * (1.0f / 300);
		ratio = (1.f - ratio);
		ratio2 = 1.f - ratio;
		ff.r = ff.r * ratio2 + _ff.r * ratio;
		ff.g = ff.g * ratio2 + _ff.g * ratio;
		ff.b = ff.b * ratio2 + _ff.b * ratio;
	}
	
	return (std::min(ff.r, 255.f) + std::min(ff.g, 255.f) + std::min(ff.b, 255.f)) * (1.f / 3);
}
Пример #25
0
// euclidean distance between the vectors x and y
static float fdist(float *x, float *y, int n)
{
	return n ? hypot(*x - *y, fdist(x + 1, y + 1, n - 1)) : 0;
}
Пример #26
0
static float ARX_THROWN_ComputeDamages(long thrownum, EntityHandle source,
                                       EntityHandle target) {
	
	float distance_limit = 1000.f;
	Entity * io_target = entities[target];
	Entity * io_source = entities[source];

	SendIOScriptEvent(io_target, SM_AGGRESSION);

	float distance = fdist(Thrown[thrownum].position, Thrown[thrownum].initial_position);
	float distance_modifier = 1.f;

	if(distance < distance_limit * 2.f) {
		distance_modifier = distance / distance_limit;

		if(distance_modifier < 0.5f)
			distance_modifier = 0.5f;
	} else {
		distance_modifier = 2.f;
	}

	float attack, dmgs, backstab, ac;

	backstab = 1.f;
	bool critical = false;

	if(source == 0) {
		attack = Thrown[thrownum].damages;

		if(Random::getf(0.f, 100.f) <= float(player.m_attributeFull.dexterity - 9) * 2.f
						   + float(player.m_skillFull.projectile * 0.2f)) {
			if(SendIOScriptEvent(io_source, SM_CRITICAL, "bow") != REFUSE)
				critical = true;
		}

		dmgs = attack;

		if(io_target->_npcdata->npcflags & NPCFLAG_BACKSTAB) {
			if(Random::getf(0.f, 100.f) <= player.m_skillFull.stealth) {
				if(SendIOScriptEvent(io_source, SM_BACKSTAB, "bow") != REFUSE)
					backstab = 1.5f;
			}
		}
	} else {
		// TODO treat NPC !!!

		ARX_DEAD_CODE();
		attack = 0;
		dmgs = 0;
	}

	float absorb;

	if(target == 0) {
		ac = player.m_miscFull.armorClass;
		absorb = player.m_skillFull.defense * .5f;
	} else {
		ac = ARX_INTERACTIVE_GetArmorClass(io_target);
		absorb = io_target->_npcdata->absorb;
	}

	char wmat[64];

	std::string _amat = "flesh";
	const std::string * amat = &_amat;

	strcpy(wmat, "dagger");

	if(!io_target->armormaterial.empty()) {
		amat = &io_target->armormaterial;
	}

	if(io_target == entities.player()) {
		if(ValidIONum(player.equiped[EQUIP_SLOT_ARMOR])) {
			Entity * io = entities[player.equiped[EQUIP_SLOT_ARMOR]];
			if(io && !io->armormaterial.empty()) {
				amat = &io->armormaterial;
			}
		}
	}

	float power;
	power = dmgs * ( 1.0f / 20 );

	if(power > 1.f)
		power = 1.f;

	power = power * 0.15f + 0.85f;

	ARX_SOUND_PlayCollision(*amat, wmat, power, 1.f, Thrown[thrownum].position, io_source);

	dmgs *= backstab;
	dmgs -= dmgs * (absorb * ( 1.0f / 100 ));

	float chance = 100.f - (ac - attack);
	float dice = Random::getf(0.f, 100.f);

	if(dice <= chance) {
		if(dmgs > 0.f) {
			if(critical)
				dmgs *= 1.5f;

			dmgs *= distance_modifier;
			return dmgs;
		}
	}

	return 0.f;
}
Пример #27
0
//-----------------------------------------------------------------------------
void CIncinerate::Create(Vec3f _eSrc, float _fBeta)
{
    SetDuration(ulDuration);
    SetAngle(_fBeta);

    eSrc.x = _eSrc.x;
    eSrc.y = _eSrc.y - 20;
    eSrc.z = _eSrc.z;

    eTarget.x = eSrc.x - fBetaRadSin * 500;
    eTarget.y = eSrc.y;
    eTarget.z = eSrc.z + fBetaRadCos * 500;

    fSize = 1;

    iMax = iNumber;
    Vec3f s, e, h;

    s.x = eSrc.x;
    s.y = eSrc.y - 20;
    s.z = eSrc.z;
    e.x = eSrc.x;
    e.y = eSrc.y - 20;
    e.z = eSrc.z;

    e.x = s.x - fBetaRadSin * 900;
    e.y = s.y;
    e.z = s.z + fBetaRadCos * 900;

    float fd;

    if (!Visible(&s, &e, NULL, &h))
    {
        e.x = h.x + fBetaRadSin * 20;
        e.y = h.y;
        e.z = h.z - fBetaRadCos * 20;
    }

    fd = fdist(s, e);


    float fDur = ulDuration * (fd / 900.0f);
    SetDuration(checked_range_cast<unsigned long>(fDur));

    float fCalc = (fd / 900.0f) * iMax;

    iNumber = checked_range_cast<int>(fCalc);

    int end = 40;
    tv1a[0].p.x = s.x;
    tv1a[0].p.y = s.y;
    tv1a[0].p.z = s.z;
    tv1a[end].p.x = e.x;
    tv1a[end].p.y = e.y;
    tv1a[end].p.z = e.z;

    Split(tv1a, 0, end, 10, 1, 0, 1, 10, 1);

    ParticleParams cp;
    cp.iNbMax = 250;
    cp.fLife = 1000;
    cp.fLifeRandom = 500;
    cp.p3Pos.x = 0;
    cp.p3Pos.y = 10;
    cp.p3Pos.z = 0;
    cp.p3Direction.x = + fBetaRadSin * 4;
    cp.p3Direction.y = 0;
    cp.p3Direction.z = - fBetaRadCos * 4;
    cp.fAngle = radians(1);
    cp.fSpeed = 0;
    cp.fSpeedRandom = 20;
    cp.p3Gravity.x = 0;
    cp.p3Gravity.y = 0;
    cp.p3Gravity.z = 0;
    cp.fFlash = 0;
    cp.fRotation = 0;
    cp.bRotationRandomDirection = false;
    cp.bRotationRandomStart = false;

    cp.fStartSize = 5;
    cp.fStartSizeRandom = 5;
    cp.fStartColor[0] = 80;
    cp.fStartColor[1] = 80;
    cp.fStartColor[2] = 0;
    cp.fStartColor[3] = 20;
    cp.fStartColorRandom[0] = 81;
    cp.fStartColorRandom[1] = 81;
    cp.fStartColorRandom[2] = 51;
    cp.fStartColorRandom[3] = 51;
    cp.bStartLock = true;

    cp.fEndSize = 1;
    cp.fEndSizeRandom = 5;
    cp.fEndColor[0] = 50;
    cp.fEndColor[1] = 0;
    cp.fEndColor[2] = 0;
    cp.fEndColor[3] = 20;
    cp.fEndColorRandom[0] = 50;
    cp.fEndColorRandom[1] = 50;
    cp.fEndColorRandom[2] = 50;
    cp.fEndColorRandom[3] = 20;
    cp.bEndLock = true;
    cp.bTexLoop = true;

    cp.iBlendMode = 3;

    pPSStream.SetParams(cp);
    pPSStream.ulParticleSpawn = 0;

    pPSStream.SetTexture("graph/particles/smallfire", 4, 10);

    pPSStream.fParticleFreq = 250;
    pPSStream.bParticleFollow = false;
    pPSStream.SetPos(eSrc);
    pPSStream.Update(0);



    // Hit
    cp.iNbMax = 150;
    cp.fLife = 2000;
    cp.fLifeRandom = 1000;
    cp.p3Pos.x = 80;
    cp.p3Pos.y = 10;
    cp.p3Pos.z = 80;
    cp.p3Direction.x = 0;
    cp.p3Direction.y = 2;
    cp.p3Direction.z = 0;
    cp.fAngle = 0;
    cp.fSpeed = 0;
    cp.fSpeedRandom = 0;
    cp.p3Gravity.x = 0;
    cp.p3Gravity.y = 0;
    cp.p3Gravity.z = 0;
    cp.fFlash = 0;
    cp.fRotation = 0;
    cp.bRotationRandomDirection = false;
    cp.bRotationRandomStart = false;

    cp.fStartSize = 10;
    cp.fStartSizeRandom = 3;
    cp.fStartColor[0] = 25;
    cp.fStartColor[1] = 25;
    cp.fStartColor[2] = 25;
    cp.fStartColor[3] = 50;
    cp.fStartColorRandom[0] = 51;
    cp.fStartColorRandom[1] = 51;
    cp.fStartColorRandom[2] = 51;
    cp.fStartColorRandom[3] = 101;
    cp.bStartLock = false;

    cp.fEndSize = 10;
    cp.fEndSizeRandom = 3;
    cp.fEndColor[0] = 25;
    cp.fEndColor[1] = 25;
    cp.fEndColor[2] = 25;
    cp.fEndColor[3] = 50; //0
    cp.fEndColorRandom[0] = 0;
    cp.fEndColorRandom[1] = 0;
    cp.fEndColorRandom[2] = 0;
    cp.fEndColorRandom[3] = 100; //0
    cp.bEndLock = false;
    cp.bTexLoop = true;

    cp.iBlendMode = 0;

    pPSHit.SetParams(cp);
    pPSHit.ulParticleSpawn = 0;

    pPSHit.SetTexture("graph/particles/firebase", 4, 100);

    pPSHit.fParticleFreq = -1;
    pPSHit.SetPos(eSrc);
    pPSHit.Update(0);

}
Пример #28
0
static void loadObjectData(EERIE_3DOBJ * eerie, const char * adr, size_t * poss, long version) {
	
	LogWarning << "loadObjectData";
	
	size_t pos = *poss;
	
	const THEO_OFFSETS * to = reinterpret_cast<const THEO_OFFSETS *>(adr + pos);
	pos += sizeof(THEO_OFFSETS);
	
	const THEO_NB * tn = reinterpret_cast<const THEO_NB *>(adr + pos);
	
	LogDebug("Nb Vertex " << tn->nb_vertex << " Nb Action Points " << tn->nb_action_point
	         << " Nb Lines " << tn->nb_lines);
	LogDebug("Nb Faces " << tn->nb_faces << " Nb Groups " << tn->nb_groups);
	
	eerie->vertexlist.resize(tn->nb_vertex);
	eerie->vertexlist3.resize(tn->nb_vertex);
	
	eerie->facelist.resize(tn->nb_faces);
	eerie->grouplist.resize(tn->nb_groups);
	eerie->actionlist.resize(tn->nb_action_point);
	
	eerie->ndata = NULL;
	eerie->pdata = NULL;
	eerie->cdata = NULL;
	eerie->sdata = NULL;
	
	// read vertices
	
	pos = to->vertex_seek;
	
	if(tn->nb_vertex > 65535) {
		LogError << ("Warning Vertex Number Too High...");
	}
	
	for(long i = 0; i < tn->nb_vertex; i++) {
		const THEO_VERTEX * ptv = reinterpret_cast<const THEO_VERTEX *>(adr + pos);
		pos += sizeof(THEO_VERTEX);
		eerie->vertexlist[i].v = ptv->pos.toVec3();
		eerie->cub.xmin = std::min(eerie->cub.xmin, ptv->pos.x);
		eerie->cub.xmax = std::max(eerie->cub.xmax, ptv->pos.x);
		eerie->cub.ymin = std::min(eerie->cub.ymin, ptv->pos.y);
		eerie->cub.ymax = std::max(eerie->cub.ymax, ptv->pos.y);
		eerie->cub.zmin = std::min(eerie->cub.zmin, ptv->pos.z);
		eerie->cub.zmax = std::max(eerie->cub.zmax, ptv->pos.z);
	}

	// Lecture des FACES THEO
	pos = to->faces_seek;

	for(long i = 0; i < tn->nb_faces; i++) {
		
		THEO_FACES_3006 tf3006;
		const THEO_FACES_3006 * ptf3006;
		if(version >= 3006) {
			ptf3006 = reinterpret_cast<const THEO_FACES_3006 *>(adr + pos);
			pos += sizeof(THEO_FACES_3006);
		} else {
			memset(&tf3006, 0, sizeof(THEO_FACES_3006));
			const THEO_FACES * ptf = reinterpret_cast<const THEO_FACES *>(adr + pos);
			pos += sizeof(THEO_FACES);
			tf3006.color = ptf->color;
			tf3006.index1 = ptf->index1;
			tf3006.index2 = ptf->index2;
			tf3006.index3 = ptf->index3;
			tf3006.ismap = ptf->ismap;
			tf3006.liste_uv = ptf->liste_uv;
			tf3006.element_uv = ptf->element_uv;
			tf3006.num_map = ptf->num_map;
			tf3006.tile_x = ptf->tile_x;
			tf3006.tile_y = ptf->tile_y;
			tf3006.user_tile_x = ptf->user_tile_x;
			tf3006.user_tile_y = ptf->user_tile_y;
			tf3006.flag = ptf->flag;
			tf3006.collision_type = ptf->collision_type;
			tf3006.rgb = ptf->rgb;
			tf3006.rgb1 = ptf->rgb1;
			tf3006.rgb2 = ptf->rgb2;
			tf3006.rgb3 = ptf->rgb3;
			tf3006.double_side = ptf->double_side;
			tf3006.transparency = ptf->transparency;
			tf3006.trans = ptf->trans;
			ptf3006 = &tf3006;
		}
		
		eerie->facelist[i].vid[0] = (unsigned short)ptf3006->index1;
		eerie->facelist[i].vid[1] = (unsigned short)ptf3006->index2;
		eerie->facelist[i].vid[2] = (unsigned short)ptf3006->index3;
		
		s32 num_map = ((size_t)ptf3006->num_map >= eerie->texturecontainer.size()) ? -1 : ptf3006->num_map;
		
		if(ptf3006->ismap) {
			eerie->facelist[i].texid = (short)num_map;
			eerie->facelist[i].facetype = POLY_NO_SHADOW;
			
			if(num_map >= 0 && eerie->texturecontainer[num_map] && (eerie->texturecontainer[num_map]->userflags & POLY_NOCOL)) {
				eerie->facelist[i].facetype |= POLY_NOCOL;
			}
		} else {
			eerie->facelist[i].texid = -1;
		}
		
		switch(ptf3006->flag) {
			case 0:
				eerie->facelist[i].facetype |= POLY_GLOW;
				break;
			case 1:
				eerie->facelist[i].facetype |= POLY_NO_SHADOW;
				break;
			case 4:
				eerie->facelist[i].facetype |= POLY_METAL;
				break;
			case 10:
				eerie->facelist[i].facetype |= POLY_NOPATH;
				break;
			case 11:
				eerie->facelist[i].facetype |= POLY_CLIMB;
				break;
			case 12:
				eerie->facelist[i].facetype |= POLY_NOCOL;
				break;
			case 13:
				eerie->facelist[i].facetype |= POLY_NODRAW;
				break;
			case 14:
				eerie->facelist[i].facetype |= POLY_PRECISE_PATH;
				break;
			case 16:
				eerie->facelist[i].facetype |= POLY_NO_CLIMB;
				break;
		}
		
		eerie->facelist[i].ou[0] = (short)ptf3006->liste_uv.u1;
		eerie->facelist[i].ov[0] = (short)ptf3006->liste_uv.v1;
		eerie->facelist[i].ou[1] = (short)ptf3006->liste_uv.u2;
		eerie->facelist[i].ov[1] = (short)ptf3006->liste_uv.v2;
		eerie->facelist[i].ou[2] = (short)ptf3006->liste_uv.u3;
		eerie->facelist[i].ov[2] = (short)ptf3006->liste_uv.v3;
		
		if(ptf3006->double_side) {
			eerie->facelist[i].facetype |= POLY_DOUBLESIDED;
		}
		
		if(ptf3006->transparency > 0) {
			if(ptf3006->transparency == 2) {
				// NORMAL TRANS 0.00001 to 0.999999
				if(ptf3006->trans < 1.f) {
					eerie->facelist[i].facetype |= POLY_TRANS;
					eerie->facelist[i].transval = ptf3006->trans;
				}
			}
			else if (ptf3006->transparency == 1) {
				if(ptf3006->trans < 0.f) {
					// SUBTRACTIVE -0.000001 to -0.999999
					eerie->facelist[i].facetype |= POLY_TRANS;
					eerie->facelist[i].transval = ptf3006->trans;
				} else {
					// ADDITIVE 1.000001 to 1.9999999
					eerie->facelist[i].facetype |= POLY_TRANS;
					eerie->facelist[i].transval = ptf3006->trans + 1.f;
				}
			} else {
				// MULTIPLICATIVE 2.000001 to 2.9999999
				eerie->facelist[i].facetype |= POLY_TRANS;
				eerie->facelist[i].transval = ptf3006->trans + 2.f;
			}
		}
		
		if(eerie->facelist[i].texid != -1 && !eerie->texturecontainer.empty() && eerie->texturecontainer[eerie->facelist[i].texid] != NULL) {
			
			if(eerie->texturecontainer[eerie->facelist[i].texid]->userflags & POLY_TRANS) {
				if(!(eerie->facelist[i].facetype & POLY_TRANS)) {
					eerie->facelist[i].facetype |= POLY_TRANS;
					eerie->facelist[i].transval = ptf3006->trans;
				}
			}
			
			if(eerie->texturecontainer[eerie->facelist[i].texid]->userflags & POLY_WATER) {
				eerie->facelist[i].facetype |= POLY_WATER;
			}
			
			if(eerie->texturecontainer[eerie->facelist[i].texid]->userflags & POLY_LAVA) {
				eerie->facelist[i].facetype |= POLY_LAVA;
			}
			
			if(eerie->texturecontainer[eerie->facelist[i].texid]->userflags & POLY_FALL) {
				eerie->facelist[i].facetype |= POLY_FALL;
			}

			if(eerie->texturecontainer[eerie->facelist[i].texid]->userflags & POLY_CLIMB) {
				eerie->facelist[i].facetype |= POLY_CLIMB;
			}
		}
		
	}
	
	// Groups Data
	pos = to->groups_seek;
	
	for(long i = 0; i < tn->nb_groups; i++) {
		
		THEO_GROUPS_3011 tg3011;
		const THEO_GROUPS_3011 * ptg3011;
		if(version >= 3011) {
			ptg3011 = reinterpret_cast<const THEO_GROUPS_3011 *>(adr + pos);
			pos += sizeof(THEO_GROUPS_3011);
		} else {
			const THEO_GROUPS * ltg = reinterpret_cast<const THEO_GROUPS *>(adr + pos);
			pos += sizeof(THEO_GROUPS);
			memset(&tg3011, 0, sizeof(THEO_GROUPS_3011));
			tg3011.origin = ltg->origin;
			tg3011.nb_index = ltg->nb_index;
			ptg3011 = &tg3011;
		}
		
		eerie->grouplist[i].origin = ptg3011->origin;
		eerie->grouplist[i].indexes.resize(ptg3011->nb_index);
		
		std::copy((const long*)(adr + pos), (const long*)(adr + pos) + ptg3011->nb_index, eerie->grouplist[i].indexes.begin());
		pos += ptg3011->nb_index * sizeof(long);
		
		eerie->grouplist[i].name = boost::to_lower_copy(util::loadString(adr + pos, 256));
		pos += 256;
		eerie->grouplist[i].siz = 0.f;
		
		for(long o = 0; o < ptg3011->nb_index; o++) {
			eerie->grouplist[i].siz = std::max(eerie->grouplist[i].siz,
			                              fdist(eerie->vertexlist[eerie->grouplist[i].origin].v,
			                                           eerie->vertexlist[eerie->grouplist[i].indexes[o]].v));
		}
		
		eerie->grouplist[i].siz = ffsqrt(eerie->grouplist[i].siz) * (1.f/16);
		
	}

	// SELECTIONS
	s32 THEO_nb_selected = *reinterpret_cast<const s32 *>(adr + pos);
	pos += sizeof(s32);
	
	eerie->selections.resize(THEO_nb_selected);
	for(long i = 0; i < THEO_nb_selected; i++) {
		
		const THEO_SELECTED * pts = reinterpret_cast<const THEO_SELECTED *>(adr + pos);
		pos += sizeof(THEO_SELECTED);
		
		eerie->selections[i].name = boost::to_lower_copy(util::loadString(pts->name));
		eerie->selections[i].selected.resize(pts->nb_index);
		
		if(pts->nb_index > 0) {
			std::copy((const long*)(adr + pos), (const long*)(adr + pos) + pts->nb_index, eerie->selections[i].selected.begin());
			pos += sizeof(long) * pts->nb_index;
		}
	}
	
	// Theo Action Points Read
	pos = to->action_point_seek;

	for(long i = 0; i < tn->nb_action_point; i++) {
		
		const THEO_ACTION_POINT * ptap = reinterpret_cast<const THEO_ACTION_POINT *>(adr + pos);
		pos += sizeof(THEO_ACTION_POINT);
		
		eerie->actionlist[i].act = ptap->action;
		eerie->actionlist[i].sfx = ptap->num_sfx;
		eerie->actionlist[i].idx = ptap->vert_index;
		eerie->actionlist[i].name = boost::to_lower_copy(util::loadString(ptap->name));
	}
	
	eerie->angle = Anglef::ZERO;
	eerie->pos = Vec3f_ZERO;
	
	// Now Interpret Extra Data chunk
	pos = to->extras_seek + 4;
	
	if(version >= 3005) {
		
		const THEO_EXTRA_DATA_3005 * pted3005 = reinterpret_cast<const THEO_EXTRA_DATA_3005 *>(adr + pos);
		pos += sizeof(THEO_EXTRA_DATA_3005);
		
		eerie->pos = pted3005->pos.toVec3();
		
		eerie->angle.setYaw((float)(pted3005->angle.alpha & 0xfff) * THEO_ROTCONVERT);
		eerie->angle.setPitch((float)(pted3005->angle.beta & 0xfff) * THEO_ROTCONVERT);
		eerie->angle.setRoll((float)(pted3005->angle.gamma & 0xfff) * THEO_ROTCONVERT);
		
		eerie->point0 = eerie->vertexlist[pted3005->origin_index].v;
		eerie->origin = pted3005->origin_index;
		
		eerie->quat = pted3005->quat;
	
	} else {
		
		const THEO_EXTRA_DATA * pted = reinterpret_cast<const THEO_EXTRA_DATA *>(adr + pos);
		pos += sizeof(THEO_EXTRA_DATA);
		
		eerie->pos = pted->pos.toVec3();
		
		eerie->angle.setYaw((float)(pted->angle.alpha & 0xfff) * THEO_ROTCONVERT);
		eerie->angle.setPitch((float)(pted->angle.beta & 0xfff) * THEO_ROTCONVERT);
		eerie->angle.setRoll((float)(pted->angle.gamma & 0xfff) * THEO_ROTCONVERT);
		
		eerie->point0 = eerie->vertexlist[pted->origin_index].v;
		eerie->origin = pted->origin_index;
	}
	
	*poss = pos;
	
	eerie->vertexlist3 = eerie->vertexlist;
	ReCreateUVs(eerie);
	EERIE_Object_Precompute_Fast_Access(eerie);
}
Пример #29
0
void MiniMap::drawDetectedEntities(int showLevel, float startX, float startY, float zoom) {
	
	float caseX = zoom / ((float)MINIMAP_MAX_X);
	float caseY = zoom / ((float)MINIMAP_MAX_Z);
	float ratio = zoom / 250.f;
	
	if(!m_pTexDetect) {
		m_pTexDetect = TextureContainer::Load("graph/particles/flare");
	}
	
	// Computes playerpos
	float ofx = m_miniOffsetX[m_currentLevel];
	float ofx2 = m_levels[showLevel].m_ratioX;
	float ofy = m_miniOffsetY[m_currentLevel];
	float ofy2 = m_levels[showLevel].m_ratioY;
	
	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
	
	const EntityManager &ents = *m_entities; // for convenience
	for(size_t lnpc = 1; lnpc < ents.size(); lnpc++) {
		Entity * npc = ents[lnpc];
		
		if(!npc || !(npc->ioflags & IO_NPC)) {
			continue; // only NPCs can be detected
		}
		
		if(npc->_npcdata->life < 0.f) {
			continue; // don't show dead NPCs
		}
		
		if((npc->gameFlags & GFLAG_MEGAHIDE) || npc->show != SHOW_FLAG_IN_SCENE) {
			continue; // don't show hidden NPCs
		}
		
		if(npc->_npcdata->fDetect < 0) {
			continue; // don't show undetectable NPCs
		}
		
		if(player.Full_Skill_Etheral_Link < npc->_npcdata->fDetect) {
			continue; // the player doesn't have enough skill to detect this NPC
		}
		
		float fpx = startX + ((npc->pos.x - 100 + ofx - ofx2) * ( 1.0f / 100 ) * caseX
		+ m_miniOffsetX[m_currentLevel] * ratio * m_modX) / m_modX; 
		float fpy = startY + ((m_mapMaxY[showLevel] - ofy - ofy2) * ( 1.0f / 100 ) * caseY
		- (npc->pos.z + 200 + ofy - ofy2) * ( 1.0f / 100 ) * caseY + m_miniOffsetY[m_currentLevel] * ratio * m_modZ) / m_modZ;
		
		float d = fdist(Vec2f(m_player->pos.x, m_player->pos.z), Vec2f(npc->pos.x, npc->pos.z));
		if(d > 800 || fabs(ents.player()->pos.y - npc->pos.y) > 250.f) {
			continue; // the NPC is too far away to be detected
		}
		
		float col = 1.f;
		
		if(d > 600.f) {
			col = 1.f - (d - 600.f) * ( 1.0f / 200 );
		}
		
		fpx *= Xratio;
		fpy *= Yratio;
		EERIEDrawBitmap(fpx, fpy, 5.f * ratio, 5.f * ratio, 0, m_pTexDetect,
		Color3f(col, 0, 0).to<u8>());
	}
	
	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
}
Пример #30
0
//-----------------------------------------------------------------------------
void CIceProjectile::Create(Vec3f aeSrc, float afBeta)
{
	SetDuration(ulDuration);
	SetAngle(afBeta);

	fSize = 1;

	float xmin, ymin, zmin;

	Vec3f s, e, h;

	s.x					= aeSrc.x;
	s.y					= aeSrc.y - 100;
	s.z					= aeSrc.z;
	float fspelldist	= static_cast<float>(iMax * 15);

	fspelldist = min(fspelldist, 200.0f);
	fspelldist = max(fspelldist, 450.0f);
	e.x = aeSrc.x - fBetaRadSin * fspelldist;
	e.y = aeSrc.y - 100;
	e.z = aeSrc.z + fBetaRadCos * fspelldist;

	float fd;

	if (!Visible(&s, &e, NULL, &h))
	{
		e.x = h.x + fBetaRadSin * 20;
		e.y = h.y;
		e.z = h.z - fBetaRadCos * 20;
	}

	fd = fdist(s, e);

	float fCalc = ulDuration * (fd / fspelldist);
	SetDuration(checked_range_cast<unsigned long>(fCalc));

	float fDist = (fd / fspelldist) * iMax ;

	iNumber = checked_range_cast<int>(fDist);

	int end = iNumber / 2;
	tv1a[0].p = s + Vec3f(0.f, 100.f, 0.f);
	tv1a[end].p = e + Vec3f(0.f, 100.f, 0.f);

	Split(tv1a, 0, end, 80, 0.5f, 0, 1, 80, 0.5f);

	for (int i = 0; i < iNumber; i++)
	{
		float t = rnd();

		if (t < 0.5f)
			tType[i] = 0;
		else
			tType[i] = 1;

		tSize[i] = Vec3f::ZERO;
		tSizeMax[i] = randomVec() + Vec3f(0.f, 0.2f, 0.f);

		if (tType[i] == 0)
		{
			xmin = 1.2f;
			ymin = 1;
			zmin = 1.2f;
		}
		else
		{
			xmin = 0.4f;
			ymin = 0.3f;
			zmin = 0.4f;
		}

		if (tSizeMax[i].x < xmin)
			tSizeMax[i].x = xmin;

		if (tSizeMax[i].y < ymin)
			tSizeMax[i].y = ymin;

		if (tSizeMax[i].z < zmin)
			tSizeMax[i].z = zmin;

		int iNum = static_cast<int>(i / 2);

		if (tType[i] == 0)
		{
			tPos[i].x = tv1a[iNum].p.x + frand2() * 80;
			tPos[i].y = tv1a[iNum].p.y;
			tPos[i].z = tv1a[iNum].p.z + frand2() * 80;
		}
		else
		{
			tPos[i].x = tv1a[iNum].p.x + frand2() * 40;
			tPos[i].y = tv1a[iNum].p.y;
			tPos[i].z = tv1a[iNum].p.z + frand2() * 40;
		}

		long ttt = ARX_DAMAGES_GetFree();
		if(ttt != -1) {
			damages[ttt].pos = tPos[i];
			damages[ttt].radius = 60.f;
			damages[ttt].damages = 0.1f * spells[spellinstance].caster_level;
			damages[ttt].area = DAMAGE_FULL;
			damages[ttt].duration = ulDuration;
			damages[ttt].source = spells[spellinstance].caster;
			damages[ttt].flags = DAMAGE_FLAG_DONT_HURT_SOURCE;
			damages[ttt].type = DAMAGE_TYPE_MAGICAL | DAMAGE_TYPE_COLD;
			damages[ttt].exist = true;
		}
	}

	fColor = 1;
}