Ejemplo n.º 1
0
		gc_ptr<RangeScanlines> GenerateRangeScanlines(float maxrange)
		{
			gc_ptr<RangeScanlines> ret = new RangeScanlines;
			int height = ((int)floor(maxrange) << 1) + 1;
			int y_offset = (int)floor(maxrange);
			int x_min = -y_offset;
			int x_max = y_offset;
			ret->height = height;
			ret->yOffset = y_offset;
			ret->scanlines = new Scanline[height];
			for (int y = 0; y < height; y++)
			{
				int x;
				for (x = x_min; x <= x_max; x++)
				{
					if (Distance2D(x, y - y_offset) <= maxrange)
					{
						ret->scanlines[y].startX = x;
						break;
					}
				}
				for (x++; x <= x_max+1; x++)
				{
					if (Distance2D(x, y - y_offset) > maxrange)
					{
						ret->scanlines[y].endX = x-1;
						break;
					}
				}
			}
			return ret;
		}
Ejemplo n.º 2
0
bool SegmentsAffiliated(Segment* seg1, Segment* seg2, double epsilon)
{
	if(Distance2D(seg1->p2,seg2->p1) < epsilon || Distance2D(seg1->p1,seg2->p1) < epsilon || Distance2D(seg1->p2,seg2->p2) < epsilon || Distance2D(seg1->p1,seg2->p2) < epsilon)
			return true;

	return false;
}
Ejemplo n.º 3
0
//private
bool Slice::TestIntersection(QVector2D &vec,Segment* seg1, Segment* seg2)
{
	bool intersection;
	//	return false;
	intersection= SegmentIntersection(vec, seg1->p1, seg1->p2, seg2->p1, seg2->p2);
	if(intersection)
	{
		if(IsZero(Distance2D(seg1->p2, seg2->p1),0.001) || IsZero(Distance2D(seg1->p1, seg2->p2),0.001))
			return false;
		if(IsZero(Distance2D(seg1->p1, seg2->p1),0.001) || IsZero(Distance2D(seg1->p2, seg2->p2),0.001))
			return false;

		return true;
	}
	return false;
}
Ejemplo n.º 4
0
int Loop::NudgeSharedPoints()
{
    int nudges = 0;
    double ThisCross;
    unsigned int s1;
    unsigned int s2;
    for(s1=0; s1<segListp.size(); s1++)
    {
        for(s2=0; s2<segListp.size(); s2++)
        {
            if(s1 == s2)
                continue;
            if((segListp[s1]->leadingSeg == segListp[s2]) || (segListp[s1]->trailingSeg == segListp[s2]))
            {
                continue;
            }

            if(IsZero(Distance2D(segListp[s1]->p2, segListp[s2]->p2),0.001))//we need to nudge
            {
                segListp[s1]->p2 = segListp[s2]->p2;
                segListp[s1]->leadingSeg->p1 = segListp[s1]->p2;
                segListp[s1]->FormNormal();
                segListp[s1]->leadingSeg->FormNormal();


                QVector2D aveVec((segListp[s1]->normal.x() + segListp[s1]->leadingSeg->normal.x())/2.0, (segListp[s1]->normal.y() + segListp[s1]->leadingSeg->normal.y())/2.0);
                aveVec.normalize();

                ThisCross = (segListp[s1]->normal.x() * segListp[s1]->leadingSeg->normal.y()) - (segListp[s1]->normal.y() * segListp[s1]->leadingSeg->normal.x());

                if(fabs(ThisCross) < 0.001)
                {
                    aveVec = (segListp[s2]->normal + segListp[s2]->leadingSeg->normal)/2.0;
                    segListp[s1]->p2 += (aveVec*0.002);
                }
                else
                {
                    if(ThisCross > 0)
                    {
                        segListp[s1]->p2 += (aveVec*0.002);
                    }
                    else
                    {
                        segListp[s1]->p2 -= (aveVec*0.002);
                    }
                }

                segListp[s1]->leadingSeg->p1 = segListp[s1]->p2;

                segListp[s1]->FormNormal();
                segListp[s1]->leadingSeg->FormNormal();
                nudges++;
            }
        }
    }
    return nudges;
}
Ejemplo n.º 5
0
bool Loop::ThrowoutSmallestSegment()
{
    std::vector<Segment*> keepers;
    unsigned int s;
    double minsize = 1000000.0;
    double size;
    double dotwithlead;
    double dotwithtrail;
    Segment* throwout = NULL;
    if(segListp.size() <= 3)
        return false;
    for(s = 0; s < segListp.size(); s++)
    {
        size = Distance2D(segListp[s]->p1, segListp[s]->p1);
        if(size < minsize)
        {
            minsize = size;
            throwout = segListp[s];
        }
    }
    for(s = 0; s < segListp.size(); s++)
    {
        if(segListp[s] == throwout)
        {
            dotwithlead = (segListp[s]->normal.x() * segListp[s]->leadingSeg->normal.x()) + (segListp[s]->normal.y() * segListp[s]->leadingSeg->normal.y());
            dotwithtrail = (segListp[s]->normal.x() * segListp[s]->trailingSeg->normal.x()) + (segListp[s]->normal.y() * segListp[s]->trailingSeg->normal.y());

            segListp[s]->trailingSeg->leadingSeg = segListp[s]->leadingSeg;
            segListp[s]->leadingSeg->trailingSeg = segListp[s]->trailingSeg;

            if(dotwithlead < dotwithtrail)//we want to go on the leading side
            {
                segListp[s]->trailingSeg->p2 = segListp[s]->leadingSeg->p1;
                segListp[s]->trailingSeg->FormNormal();

            }
            else//we want to go on the trailing side
            {
                segListp[s]->leadingSeg->p1 = segListp[s]->trailingSeg->p2;
                segListp[s]->leadingSeg->FormNormal();
            }
            segListp[s]->trailingSeg = NULL;
            segListp[s]->leadingSeg = NULL;
        }
        else
        {
            keepers.push_back(segListp[s]);
        }
    }
    segListp = keepers;
    numSegs = segListp.size();
    return true;
}
Ejemplo n.º 6
0
	void KL2Map_Base::ComputePtListWithDistance(int_r fromx, int_r fromy, __NodeList_ByDistance& ptList)
	{	PERF_COUNTER(KL2Map_Base_ComputePtListWithDistance);

		ASSERT(mpSettings && mpSettings->mMapSize >= mpSettings->mBlockSize);
		ptList.clear();
		int_r blx, bhx, bly, bhy, bx, by;
		GetJointBlockPos(fromx, fromy, bx, by);
		// 窗口使用附近3x3个区域
		blx = bx - 1;
		bhx = bx + 1;
		bly = by - 1;
		bhy = by + 1;

		//如果窗口延伸超出当前512将被剪裁。使用大地图的时候可以考虑去掉这个限制。
		int_r nRate = mpSettings->mMapSize / mpSettings->mBlockSize;
		ASSERT(0 != nRate);
		bx /= nRate;
		by /= nRate;
		if (blx / nRate != bx)
		{
			blx++;
		}
		if (bhx / nRate != bx)
		{
			bhx--;
		}
		if (bly / nRate != by)
		{
			bly++;
		}
		if (bhy / nRate != by)
		{
			bhy--;
		}

		__DistanceInfo di;
		for (bx = blx; bx <= bhx; ++bx)
		{
			for (by = bly; by <= bhy; ++by)
			{
				int_r nSize = m_L2MapByBlock[bx][by].size();
				for (int_r i = 0; i < nSize; ++i)
				{
					int_r x = m_L2MapByBlock[bx][by][i]->x;
					int_r y = m_L2MapByBlock[bx][by][i]->y;
					di.first = Find(x, y);
					ASSERT(di.first);
					di.second = sqrtf(Distance2D(fromx,fromy,x,y));
					ptList.insert(di);
				}
			}
		}
	}
Ejemplo n.º 7
0
	bool KL2Map_Base::CreateOneRoad(int_r nID, const _Node_Lite * pBegin, const _Node_Lite * pEnd, bool bUnidirectional)
	{	PERF_COUNTER(KL2Map_Base_CreateOneRoad);

		mRoads[nID].m_Cost = sqrtf(Distance2D(pBegin->x, pBegin->y, pEnd->x, pEnd->y));
		mRoads[nID].push_back(pBegin);
		mRoads[nID].push_back(pEnd);
		mIDMap[pBegin->id][pEnd->id] = nID;
		if(!bUnidirectional)
		{
			mIDMap[pEnd->id][pBegin->id] = nID;
		}
		return true;
	}
Ejemplo n.º 8
0
void Loop::Simplify()
{
    unsigned int s;
    double length;
    unsigned int chuckouts = 0;
    double dotwithlead;
    double dotwithtrail;
    std::vector<Segment*> templist;
    if(segListp.size() <= 3)
    {
        return;
    }
    for(s=0; s < segListp.size(); s++)
    {
        length = Distance2D(segListp[s]->p1, segListp[s]->p2);
        if(IsZero(length, SIMPLIFY_THRESH) && (chuckouts <= segListp.size() - 3))
        {
            dotwithlead = (segListp[s]->normal.x() * segListp[s]->leadingSeg->normal.x()) + (segListp[s]->normal.y() * segListp[s]->leadingSeg->normal.y());
            dotwithtrail = (segListp[s]->normal.x() * segListp[s]->trailingSeg->normal.x()) + (segListp[s]->normal.y() * segListp[s]->trailingSeg->normal.y());

            segListp[s]->trailingSeg->leadingSeg = segListp[s]->leadingSeg;
            segListp[s]->leadingSeg->trailingSeg = segListp[s]->trailingSeg;

            if(dotwithlead < dotwithtrail)//we want to go on the leading side
            {
                segListp[s]->trailingSeg->p2 = segListp[s]->leadingSeg->p1;
                segListp[s]->trailingSeg->FormNormal();

            }
            else//we want to go on the trailing side
            {
                segListp[s]->leadingSeg->p1 = segListp[s]->trailingSeg->p2;
                segListp[s]->leadingSeg->FormNormal();
            }

            segListp[s]->trailingSeg = NULL;
            segListp[s]->leadingSeg = NULL;
            chuckouts++;
        }
        else
        {
            templist.push_back(segListp[s]);
        }
    }
    segListp.clear();
    segListp = templist;

    numSegs = segListp.size();
}
Ejemplo n.º 9
0
void Enemy4::Shoot()
{
	bulletLifetime = 30;

	EnemyBullet2* bullet = new EnemyBullet2();
	bullet->position = position;
	bullet->position.x += 20;
	bullet->position.y -= 10;
	bullet->vx = player->position.x - bullet->position.x;
	bullet->vy = player->position.y - bullet->position.y;
	double d = Distance2D(bullet->vx, bullet->vy);
	bullet->vx /= (float)d;
	bullet->vy /= (float)d;

	v.push_back(bullet);
}
Ejemplo n.º 10
0
void ARX_MINIMAP_ValidatePlayerPos()
{
	if (BLOCK_PLAYER_CONTROLS) return;

	float dist = Distance2D(AM_LASTPOS_x, AM_LASTPOS_z, player.pos.x, player.pos.z);
	float req;

	if ((player.Interface & INTER_MAP) && (!(player.Interface & INTER_COMBATMODE)) && (Book_Mode == 2))
		req = 20.f;
	else req = 80.f;

	if (dist > req)
	{
		AM_LASTPOS_x = player.pos.x;
		AM_LASTPOS_z = player.pos.z;
		ARX_MINIMAP_ValidatePos(&player.pos);
	}
}
Ejemplo n.º 11
0
		gc_ptr<RangeArray> GenerateRangeArray(float maxrange, float minrange)
		{
			gc_ptr<RangeArray> ret = new RangeArray;
			int size = ((int)floor(maxrange) << 1) + 1;
			int offset = (int)floor(maxrange);
			ret->size = size;
			ret->offset = offset;
			ret->array = new char*[size];
			for (int y = 0; y < size; y++)
			{
				ret->array[y] = new char[size];
				for (int x = 0; x < size; x++)
				{
					float distance = Distance2D(float(x - offset), float(y - offset));
					ret->array[y][x] = distance <= maxrange && distance >= minrange;
				}
			}
			return ret;
		}
Ejemplo n.º 12
0
void Scn_Test::MouseMove(D3DXVECTOR2 &vPosition)
{
	vPosition = DEVICE_POSITION(vPosition.x, vPosition.y);

	if( !m_isPlayStart ) return;

	if( Distance2D( m_vShiftPos, vPosition) >= 50 
		&& m_isShiftKeyDown && m_isShiftClick)
	{
		m_NoteData[m_noteMax++] = Note_Info(
			m_vShiftPos, 
			vPosition,
			(float)m_Sound->GetPosition() - 0.3f,
			(float)m_Sound->GetPosition(),
			NOTETYPE_SPECIAL);

		m_noteNum->SetValue(m_noteMax);
		m_vShiftPos = vPosition;

		m_Jud[m_judNum++%10].Action(NOTETYPE_SPECIAL, D3DXVECTOR2(102,102) + vPosition);
	}
}
Ejemplo n.º 13
0
void Slice::ConnectSegmentNeighbors()
{
	unsigned int s;
    unsigned int potential;
    unsigned int s2;
	double potentialangle;
	double potentialDist;
	double minDist = 10000.0;

	Segment* thisSeg = NULL;
	Segment* thatSeg = NULL;
    QVector2D* thisPoint = NULL;

    QVector2D* thatPoint = NULL;

    std::vector<Segment*> sameXStripSegs;
    std::vector<Segment*> potentialLeadSegs;

    Segment* finalLeadSeg = NULL;

	for(s = 0; s < segmentList.size(); s++)//compare from every segment
	{
		thisSeg = segmentList[s];
		thisPoint = &thisSeg->p2;//compare from the 2nd point on "this" segment

		if(thisSeg->leadingSeg)//no need to add a connection if there already is one!
			continue;
		
		potentialLeadSegs.clear();//clear out the potentials list
		

        GetSegmentsAroundX(sameXStripSegs, thisPoint->x());


        //////////////////////////////////////
        for(s2 = 0; s2 < sameXStripSegs.size(); s2++)//to every other segment in ring
		{
			//make sure its not the same segment
			if(s == s2)
			{continue;}
			
            thatSeg = sameXStripSegs[s2];
			if(thatSeg->trailingSeg)//already connected to a trailing segment...
				continue;
			
			thatPoint = &thatSeg->p1;//to the first point of "that" segment
            if(IsZero(Distance2D(*thisPoint, *thatPoint),0.03))//they are close enough to each other
            {
				potentialLeadSegs.push_back(thatSeg);
            }
		}
        //////////////////////////////////////

		//sort through and pick from the potential pile
		//we want to pick a segment with the sharpest change in direction!
		//
		//
		//1>>>>>>>>>A>>>>>>>>2 1>>>>>>>>B>>>>>>>>>2
		//                    ^
		//             large delta angle/ Right Wieghted
		minDist = 100000.0;
		finalLeadSeg = NULL;
		potentialangle = 0.0;
		for(potential = 0; potential < potentialLeadSegs.size(); potential++)
		{
			thatSeg = potentialLeadSegs[potential];
			//potentialDot = (thisSeg->normal.x() * thatSeg->normal.x()) + (thisSeg->normal.y() * thatSeg->normal.y()); //gives a number indicating how sharp the angle is, -1 is the sharpest (-1,1)
			//potentialCross = (thisSeg->normal.x() * thatSeg->normal.y()) - (thisSeg->normal.y() * thatSeg->normal.x());//gives a number indicating a right or left turn. (uphill is positive), (downhill is negative) (-1,1)
			potentialDist = Distance2D(thisSeg->p2, thatSeg->p1);
			
			if(potentialDist < minDist)
			{
				minDist = potentialDist;
				finalLeadSeg = potentialLeadSegs[potential];
			}
			
		}
		if(finalLeadSeg)
		{
			thisSeg->leadingSeg = finalLeadSeg;
			finalLeadSeg->trailingSeg = thisSeg;

			thisSeg->p2 = finalLeadSeg->p1;
			thisSeg->FormNormal();
		}
	}
}
Ejemplo n.º 14
0
void CGeometry::LookAt(D3DVECTOR &Target,D3DVECTOR &Position,D3DVECTOR &Rotation)
{
	Rotation.y = DEGREES(atan2(Position.x-Target.x ,Position.z-Target.z)+M_PI);
	Rotation.x = DEGREES(atan2(Position.y-Target.y ,Distance2D(Position.x-Target.x,Position.z-Target.z))+M_PI) - 180.0F;
}
Ejemplo n.º 15
0
//-----------------------------------------------------------------------------
void ARX_MINIMAP_Show(LPDIRECT3DDEVICE7 m_pd3dDevice, long SHOWLEVEL, long flag, long fl2)
{
	float sstartx, sstarty;

	if (!pTexDetect)
	{
		GetTextureFile("Graph\\particles\\flare.bmp");
		char temp[256];
		MakeDir(temp, "Graph\\particles\\flare.bmp");
		pTexDetect = D3DTextr_GetSurfaceContainer(temp);
	}

	//	SHOWLEVEL=8;
	// First Load Minimap TC & DATA if needed
	if (minimap[SHOWLEVEL].tc == NULL)
	{
		ARX_MINIMAP_GetData(SHOWLEVEL);
	}

	if ((minimap[SHOWLEVEL].tc) && (minimap[SHOWLEVEL].tc->m_pddsSurface))
	{
		float startx, starty, casex, casey, ratiooo;
		float mod_x = (float)MAX_BKGX / (float)MINIMAP_MAX_X;
		float mod_z = (float)MAX_BKGZ / (float)MINIMAP_MAX_Z;

		if (flag == 1)
		{


			startx = 0;
			starty = 0;
			casex = (900) / ((float)MINIMAP_MAX_X);
			casey = (900) / ((float)MINIMAP_MAX_Z);
			ratiooo = 900.f / 250.f;

			if (fl2)
			{
				casex = (600) / ((float)MINIMAP_MAX_X);
				casey = (600) / ((float)MINIMAP_MAX_Z);
				ratiooo = 600.f / 250.f;
			}

		}
		else
		{
			startx = (140); 
			starty = (120);
			casex = (250) / ((float)MINIMAP_MAX_X);
			casey = (250) / ((float)MINIMAP_MAX_Z);
			ratiooo = 1.f;
		}

		sstartx = startx;
		sstarty = starty;


		float ofx, ofx2, ofy, ofy2, px, py;
		px = py = 0.f;

		ofx		= mini_offset_x[CURRENTLEVEL];
		ofx2	= minimap[SHOWLEVEL].xratio;
		ofy		= mini_offset_y[CURRENTLEVEL];
		ofy2	= minimap[SHOWLEVEL].yratio;

		if ((SHOWLEVEL == ARX_LEVELS_GetRealNum(CURRENTLEVEL)) || (flag == 2))
		{
			// Computes playerpos
			ofx = mini_offset_x[CURRENTLEVEL];
			ofx2 = minimap[SHOWLEVEL].xratio;
			ofy = mini_offset_y[CURRENTLEVEL];
			ofy2 = minimap[SHOWLEVEL].yratio;
		
			px = startx + ((player.pos.x + ofx - ofx2) * DIV100 * casex
			               + mini_offset_x[CURRENTLEVEL] * ratiooo * mod_x) / mod_x ; //DIV100*2;
			py = starty + ((mapmaxy[SHOWLEVEL] - ofy - ofy2) * DIV100 * casey
			               - (player.pos.z + ofy - ofy2) * DIV100 * casey + mini_offset_y[CURRENTLEVEL] * ratiooo * mod_z) / mod_z ;    //DIV100*2;

			if (flag == 1)
			{
				sstartx = startx;
				sstarty = starty;

				startx = 490.f - px;
				starty = 220.f - py;
				px += startx;
				py += starty;
			}
		}


		D3DTLVERTEX verts[4];
		SETTC(m_pd3dDevice, minimap[SHOWLEVEL].tc);

		for (long k = 0; k < 4; k++)
		{
			verts[k].color = 0xFFFFFFFF;
			verts[k].rhw = 1;
			verts[k].sz = 0.00001f;
		}

		float div = DIV25;
		TextureContainer * tc = minimap[SHOWLEVEL].tc;
		float dw = 1.f / (float)max(tc->m_dwDeviceWidth, tc->m_dwOriginalWidth); 
		float dh = 1.f / (float)max(tc->m_dwDeviceHeight, tc->m_dwOriginalHeight);
		
		float vx2 = 4.f * dw * mod_x;
		float vy2 = 4.f * dh * mod_z;

		float _px;
		RECT boundaries;
		float MOD20, MOD20DIV, divXratio, divYratio;

		boundaries.bottom = boundaries.left = boundaries.right = boundaries.top = 0;
		MOD20 = MOD20DIV = divXratio = divYratio = 0.f;

		if (flag != 2)
		{

			if (flag == 1)
			{
				MOD20 = 20.f * Xratio;
				MOD20DIV = 1.f / (MOD20);
				//@PERF do if(fl2){}else{} to make 4 and not 8 flot op if fl2.

				ARX_CHECK_LONG((360 + MOD20)*Xratio);
				ARX_CHECK_LONG((555 - MOD20)*Xratio);
				ARX_CHECK_LONG((85 + MOD20)*Yratio);
				ARX_CHECK_LONG((355 - MOD20)*Yratio);

				//CAST
				boundaries.left		=	ARX_CLEAN_WARN_CAST_LONG((360 + MOD20) * Xratio);
				boundaries.right	=	ARX_CLEAN_WARN_CAST_LONG((555 - MOD20) * Xratio);
				boundaries.top		=	ARX_CLEAN_WARN_CAST_LONG((85 + MOD20) * Yratio);
				boundaries.bottom	=	ARX_CLEAN_WARN_CAST_LONG((355 - MOD20) * Yratio);

				if (fl2)
				{
					//CHECK (DEBUG)
					ARX_CHECK_LONG((390 + MOD20)*Xratio);
					ARX_CHECK_LONG((590 - MOD20)*Xratio);
					ARX_CHECK_LONG((135 + MOD20)*Yratio);
					ARX_CHECK_LONG((295 - MOD20)*Yratio);

					//CAST
					boundaries.left		=	ARX_CLEAN_WARN_CAST_LONG((390 + MOD20) * Xratio);
					boundaries.right	=	ARX_CLEAN_WARN_CAST_LONG((590 - MOD20) * Xratio);
					boundaries.top		=	ARX_CLEAN_WARN_CAST_LONG((135 + MOD20) * Yratio);
					boundaries.bottom	=	ARX_CLEAN_WARN_CAST_LONG((295 - MOD20) * Yratio);
				}
			}

			SETALPHABLEND(m_pd3dDevice, TRUE);
			m_pd3dDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ZERO);
			m_pd3dDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCCOLOR);
			m_pd3dDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS);
			SETTEXTUREWRAPMODE(m_pd3dDevice, D3DTADDRESS_CLAMP);

			if (fl2)
			{
				m_pd3dDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ONE);
				m_pd3dDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCCOLOR);
			}
		}
		else
		{
			divXratio = 1.f / Xratio;
			divYratio = 1.f / Yratio;
		}

		for (long j = -2; j < MINIMAP_MAX_Z + 2; j++)
		{
			for (long i = -2; i < MINIMAP_MAX_X + 2; i++)
			{
				float vx, vy, vxx, vyy;
				vxx = ((float)i * (float)ACTIVEBKG->Xdiv * mod_x);
				vyy = ((float)j * (float)ACTIVEBKG->Zdiv * mod_z);
				vx = (vxx * div) * dw;
				vy = (vyy * div) * dh;

				long okay = 1;
				float posx = (startx + i * casex) * Xratio;
				float posy = (starty + j * casey) * Yratio;

				if (flag == 1)
				{

					if	((posx < 360 * Xratio)
					        ||	(posx > 555 * Xratio)
					        ||	(posy < 85 * Yratio)
					        ||	(posy > 355 * Yratio))
						okay = 0;

					if (fl2)
					{
						okay = 1;

						if	((posx < 390 * Xratio)
						        ||	(posx > 590 * Xratio)
						        ||	(posy < 135 * Yratio)
						        ||	(posy > 295 * Yratio))
							okay = 0;
					}

				}
				else
				{
					if ((posx > 345 * Xratio)
					        ||	(posy > 290 * Yratio))
						okay = 0;
				}

				if (okay)
				{
					if ((flag == 2)
					        && (i >= 0) && (i < MINIMAP_MAX_X)
					        && (j >= 0) && (j < MINIMAP_MAX_Z))
					{
						float d = Distance2D(posx * divXratio + casex * DIV2, posy * divYratio /*-casey * 2 * Yratio*/, px, py);

						if (d <= 6.f)
						{
							long r;
							float vv = (6 - d) * DIV6;

							if (vv >= 0.5f)
								vv = 1.f;
							else if (vv > 0.f)
								vv = vv * 2.f;
							else
								vv = 0.f;

							F2L((float)(vv * 255.f), &r);


							long ucLevel =  __max(r, minimap[SHOWLEVEL].revealed[i][j]);
							ARX_CHECK_UCHAR(ucLevel);

							minimap[SHOWLEVEL].revealed[i][j] = ARX_CLEAN_WARN_CAST_UCHAR(ucLevel);


						}
					}

					if (!FOR_EXTERNAL_PEOPLE)
					{
						if ((i >= 0) && (i < MINIMAP_MAX_X)
						        &&	(j >= 0) && (j < MINIMAP_MAX_Z))
						{
							minimap[SHOWLEVEL].revealed[i][j] = 255;
						}
					}

					verts[3].sx = verts[0].sx = (posx);
					verts[1].sy = verts[0].sy = (posy);
					verts[2].sx = verts[1].sx = posx + (casex * Xratio);
					verts[3].sy = verts[2].sy = posy + (casey * Yratio);

					verts[3].tu = verts[0].tu = vx;
					verts[1].tv = verts[0].tv = vy;
					verts[2].tu = verts[1].tu = vx + vx2;
					verts[3].tv = verts[2].tv = vy + vy2;

					if (flag != 2)
					{
						float v;
						float oo = 0.f;

						if ((i < 0) || (i >= MINIMAP_MAX_X) || (j < 0) || (j >= MINIMAP_MAX_Z)) v = 0;
						else v = ((float)minimap[SHOWLEVEL].revealed[i][j]) * DIV255;

						if (flag == 1)
						{
							long vert = 0;
							_px = verts[vert].sx - boundaries.left;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = boundaries.right - verts[vert].sx;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = verts[vert].sy - boundaries.top;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = boundaries.bottom - verts[vert].sy;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;
						}

						if (fl2) verts[0].color = D3DRGB(v * DIV2, v * DIV2, v * DIV2);
						else
							verts[0].color = D3DRGB(v, v, v);

						oo += v;

						if ((i + 1 < 0) || (i + 1 >= MINIMAP_MAX_X) || (j < 0) || (j >= MINIMAP_MAX_Z)) v = 0;
						else v = ((float)minimap[SHOWLEVEL].revealed[__min(i+1, MINIMAP_MAX_X-1)][j]) * DIV255;

						if (flag == 1)
						{
							long vert = 1;
							_px = verts[vert].sx - boundaries.left;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = boundaries.right - verts[vert].sx;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = verts[vert].sy - boundaries.top;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = boundaries.bottom - verts[vert].sy;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;
						}

						if (fl2) verts[1].color = D3DRGB(v * DIV2, v * DIV2, v * DIV2);
						else
							verts[1].color = D3DRGB(v, v, v);

						oo += v;

						if ((i + 1 < 0) || (i + 1 >= MINIMAP_MAX_X) || (j + 1 < 0) || (j + 1 >= MINIMAP_MAX_Z)) v = 0;
						else v = ((float)minimap[SHOWLEVEL].revealed[__min(i+1, MINIMAP_MAX_X-1)][__min(j+1, MINIMAP_MAX_Z-1)]) * DIV255;

						if (flag == 1)
						{
							long vert = 2;
							_px = verts[vert].sx - boundaries.left;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = boundaries.right - verts[vert].sx;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = verts[vert].sy - boundaries.top;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = boundaries.bottom - verts[vert].sy;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;
						}
						

						if (fl2) verts[2].color = D3DRGB(v * DIV2, v * DIV2, v * DIV2);
						else
							verts[2].color = D3DRGB(v, v, v);

						oo += v;

						if ((i < 0) || (i >= MINIMAP_MAX_X) || (j + 1 < 0) || (j + 1 >= MINIMAP_MAX_Z)) v = 0;
						else v = ((float)minimap[SHOWLEVEL].revealed[i][__min(j+1, MINIMAP_MAX_Z-1)]) * DIV255;

						if (flag == 1)
						{
							long vert = 3;
							_px = verts[vert].sx - boundaries.left;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = boundaries.right - verts[vert].sx;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = verts[vert].sy - boundaries.top;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;

							_px = boundaries.bottom - verts[vert].sy;

							if (_px < 0.f) v = 0.f;
							else if (_px < MOD20) v *= _px * MOD20DIV;
						}

						if (fl2) verts[3].color = D3DRGB(v * DIV2, v * DIV2, v * DIV2);
						else
							verts[3].color = D3DRGB(v, v, v);

						oo += v;

						if (oo > 0.f)
						{
							if (fl2)
							{
								verts[0].sx += DECALX * Xratio;
								verts[0].sy += DECALY * Yratio;
								verts[1].sx += DECALX * Xratio;
								verts[1].sy += DECALY * Yratio;
								verts[2].sx += DECALX * Xratio;
								verts[2].sy += DECALY * Yratio;
								verts[3].sx += DECALX * Xratio;
								verts[3].sy += DECALY * Yratio;
							}

							EERIEDRAWPRIM(GDevice, D3DPT_TRIANGLEFAN, D3DFVF_TLVERTEX | D3DFVF_DIFFUSE, verts, 4, 0);
						}
					}
				}
			}
		}

		if (flag != 2)
		{
			m_pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESS , D3DTADDRESS_WRAP);
			m_pd3dDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);

			SETALPHABLEND(m_pd3dDevice, FALSE);

			if ((SHOWLEVEL == ARX_LEVELS_GetRealNum(CURRENTLEVEL)))
			{
				// Now Draws Playerpos/angle
				verts[0].color = 0xFFFF0000;
				verts[1].color = 0xFFFF0000;
				verts[2].color = 0xFFFF0000;
				float val;

				if (flag == 1) val = 6.f;
				else val = 3.f;

				float rx = 0.f;
				float ry = -val * 1.8f;
				float rx2 = -val * DIV2;
				float ry2 = val;
				float rx3 = val * DIV2;
				float ry3 = val;

				float angle = DEG2RAD(player.angle.b);
				float ca = EEcos(angle);
				float sa = EEsin(angle);

				verts[0].sx = (px + rx2 * ca + ry2 * sa) * Xratio;
				verts[0].sy = (py + ry2 * ca - rx2 * sa) * Yratio;
				verts[1].sx = (px + rx * ca + ry * sa) * Xratio;
				verts[1].sy = (py + ry * ca - rx * sa) * Yratio;
				verts[2].sx = (px + rx3 * ca + ry3 * sa) * Xratio;
				verts[2].sy = (py + ry3 * ca - rx3 * sa) * Yratio;

				SETTC(GDevice, NULL);

				if (fl2)
				{
					SETALPHABLEND(m_pd3dDevice, TRUE);
					verts[0].sx += DECALX * Xratio;
					verts[0].sy += DECALY * Yratio;
					verts[1].sx += DECALX * Xratio;
					verts[1].sy += DECALY * Yratio;
					verts[2].sx += DECALX * Xratio;
					verts[2].sy += DECALY * Yratio;
				}

				EERIEDRAWPRIM(GDevice, D3DPT_TRIANGLEFAN, D3DFVF_TLVERTEX | D3DFVF_DIFFUSE, verts, 3, 0);

				if (fl2) SETALPHABLEND(m_pd3dDevice, FALSE);
			}
		}

		// tsu
		for (long lnpc = 1; lnpc < inter.nbmax; lnpc++)
		{
			if ((inter.iobj[lnpc] != NULL) && (inter.iobj[lnpc]->ioflags & IO_NPC))
			{
				if (inter.iobj[lnpc]->_npcdata->life > 0.f)
					if (!((inter.iobj[lnpc]->GameFlags & GFLAG_MEGAHIDE) ||
					        (inter.iobj[lnpc]->show == SHOW_FLAG_MEGAHIDE))
					        && (inter.iobj[lnpc]->show == SHOW_FLAG_IN_SCENE))
						if (!(inter.iobj[lnpc]->show == SHOW_FLAG_HIDDEN))
							if (inter.iobj[lnpc]->_npcdata->fDetect >= 0)
							{
								if (player.Full_Skill_Etheral_Link >= inter.iobj[lnpc]->_npcdata->fDetect)
								{
									float fpx;
									float fpy;
								
									fpx = sstartx + ((inter.iobj[lnpc]->pos.x - 100 + ofx - ofx2) * DIV100 * casex
									                 + mini_offset_x[CURRENTLEVEL] * ratiooo * mod_x) / mod_x; 
									fpy = sstarty + ((mapmaxy[SHOWLEVEL] - ofy - ofy2) * DIV100 * casey
									                 - (inter.iobj[lnpc]->pos.z + 200 + ofy - ofy2) * DIV100 * casey + mini_offset_y[CURRENTLEVEL] * ratiooo * mod_z) / mod_z; 

									if (flag == 1)
									{

										fpx = startx + ((inter.iobj[lnpc]->pos.x - 100 + ofx - ofx2) * DIV100 * casex
										                + mini_offset_x[CURRENTLEVEL] * ratiooo * mod_x) / mod_x; 
										fpy = starty + ((mapmaxy[SHOWLEVEL] - ofy - ofy2) * DIV100 * casey
										                - (inter.iobj[lnpc]->pos.z + 200 + ofy - ofy2) * DIV100 * casey + mini_offset_y[CURRENTLEVEL] * ratiooo * mod_z) / mod_z; 


									}

									float d = Distance2D(player.pos.x, player.pos.z, inter.iobj[lnpc]->pos.x, inter.iobj[lnpc]->pos.z);

		
									if ((d <= 800) && (fabs(inter.iobj[0]->pos.y - inter.iobj[lnpc]->pos.y) < 250.f))
									{
										float col = 1.f;

										if (d > 600.f)
										{
											col = 1.f - (d - 600.f) * DIV200;
										}

										if (!fl2)
										{
											SETALPHABLEND(m_pd3dDevice, true);
											m_pd3dDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ONE);
											m_pd3dDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
										}
										else
											SETALPHABLEND(m_pd3dDevice, true);

										if (fl2)
										{
											fpx += DECALX * Xratio;
											fpy += (DECALY + 15) * Yratio;
										}

										fpx *= Xratio;
										fpy *= Yratio;
										EERIEDrawBitmap(GDevice, fpx, fpy,
										                5.f * ratiooo, 5.f * ratiooo, 0, pTexDetect, D3DRGB(col, 0, 0));

										if (!fl2)
											SETALPHABLEND(m_pd3dDevice, false);
									}
								}
							}
			}
		}

		if (flag == 0)
			for (long i = 0; i < Nb_Mapmarkers; i++)
			{
				if (Mapmarkers[i].lvl == SHOWLEVEL + 1)
				{
					float pos_x = Mapmarkers[i].x * 8 * ratiooo * ACTIVEBKG->Xmul * casex + startx;
					float pos_y = Mapmarkers[i].y * 8 * ratiooo * ACTIVEBKG->Zmul * casey + starty;
					float size = 5.f * ratiooo;
					verts[0].color = 0xFFFF0000;
					verts[1].color = 0xFFFF0000;
					verts[2].color = 0xFFFF0000;
					verts[3].color = 0xFFFF0000;
					verts[0].sx = (pos_x - size) * Xratio;
					verts[0].sy = (pos_y - size) * Yratio;
					verts[1].sx = (pos_x + size) * Xratio;
					verts[1].sy = (pos_y - size) * Yratio;
					verts[2].sx = (pos_x + size) * Xratio;
					verts[2].sy = (pos_y + size) * Yratio;
					verts[3].sx = (pos_x - size) * Xratio;
					verts[3].sy = (pos_y + size) * Yratio;
					verts[0].tu = 0.f;
					verts[0].tv = 0.f;
					verts[1].tu = 1.f;
					verts[1].tv = 0.f;
					verts[2].tu = 1.f;
					verts[2].tv = 1.f;
					verts[3].tu = 0.f;
					verts[3].tv = 1.f;

					if ((!fl2)
					        && (MouseInRect(verts[0].sx, verts[0].sy, verts[2].sx, verts[2].sy)))
					{
						if (!Mapmarkers[i].tstring)
						{
							_TCHAR output[4096];
							MakeLocalised(Mapmarkers[i].string, output, 4096, 0);
							Mapmarkers[i].tstring = (_TCHAR *)malloc((_tcslen(output) + 1) * sizeof(_TCHAR));
							ZeroMemory(Mapmarkers[i].tstring, (_tcslen(output) + 1)*sizeof(_TCHAR));
							_tcscpy(Mapmarkers[i].tstring, output);
						}

						if (Mapmarkers[i].tstring)
						{
							RECT rRect, bRect;
							SetRect(&bRect	, (140),	(290)
							        , (140 + 205),	(358));

							float fLeft		= (bRect.left) * Xratio ;
							float fRight	= (bRect.right) * Xratio ;
							float fTop		= (bRect.top) * Yratio ;
							float fBottom	= (bRect.bottom) * Yratio ;
							ARX_CHECK_INT(fLeft);
							ARX_CHECK_INT(fRight);
							ARX_CHECK_INT(fTop);
							ARX_CHECK_INT(fBottom);

							SetRect(&rRect
							        , ARX_CLEAN_WARN_CAST_INT(fLeft)
							        , ARX_CLEAN_WARN_CAST_INT(fTop)
							        , ARX_CLEAN_WARN_CAST_INT(fRight)
							        , ARX_CLEAN_WARN_CAST_INT(fBottom));


							long lLengthDraw = ARX_UNICODE_ForceFormattingInRect(
							                       hFontInGameNote, Mapmarkers[i].tstring, 0, rRect);

							danaeApp.DANAEEndRender();
							_TCHAR	Page_Buffer[256];
							_tcsncpy(Page_Buffer, Mapmarkers[i].tstring, lLengthDraw);
							Page_Buffer[lLengthDraw] = _T('\0');

							DrawBookTextInRect(ARX_CLEAN_WARN_CAST_FLOAT(bRect.left), ARX_CLEAN_WARN_CAST_FLOAT(bRect.top),
							                   ARX_CLEAN_WARN_CAST_FLOAT(bRect.right), ARX_CLEAN_WARN_CAST_FLOAT(bRect.bottom),
							                   Page_Buffer, 0, 0x00FF00FF,
							                   hFontInGameNote);


							danaeApp.DANAEStartRender();
						}
					}

					if (MapMarkerTc == NULL)
					{
						MapMarkerTc = MakeTCFromFile("Graph\\interface\\icons\\mapmarker.bmp");
					}

					SETTC(GDevice, MapMarkerTc);

					if (fl2)
					{
						verts[0].sx += DECALX * Xratio;
						verts[0].sy += DECALY * Yratio;
						verts[1].sx += DECALX * Xratio;
						verts[1].sy += DECALY * Yratio;
						verts[2].sx += DECALX * Xratio;
						verts[2].sy += DECALY * Yratio;
						verts[3].sx += DECALX * Xratio;
						verts[3].sy += DECALY * Yratio;
					}

					EERIEDRAWPRIM(GDevice, D3DPT_TRIANGLEFAN, D3DFVF_TLVERTEX | D3DFVF_DIFFUSE, verts, 4, 0);
				}
			}

	}
}