Quote:hi peoples, here is a method to draw a line with the engine.
you will lose some fps on this method.
PHP Code:
float getAngle(DoublePoint self, DoublePoint target)
{
float dx = target[0] - self[0]; //calculate the distance to the target on the x-axis
float dy = target[1] - self[1]; //calculate the distance to the target on the y-axis
float dist = sqrt(pow(dx, 2) + pow(dy, 2)); //calculate distance to the target by using pythagoras
float dangle;
if (dy < 0) dangle = (M_PI * 2) - (acos(dx/dist));
else dangle = acos(dx/dist); //calculate the angle
return dangle;
}
PHP Code:
void cEngine::DrawLines()
{
float x, y;
float Screen[2];
DoublePoint dpLocal = {Refdef->Width/2, Refdef->Height};
for(int i=0; i<MAX_PLAYERS; i++)
{
CEntity* pEnt = getValidEnt();
if(WorldToScreen(pEnt->vOrig, &Screen)
{
DoublePoint dpTarget = {Screen[0], Screen[1]};
float fAngle = getAngle(dpLocal, dpTarget);
if(!fAngle)
continue;
float fDist = getDist();
int size = fdist/lineDist;
for(int i=0; i<size; i++)
{
if(i == 0)
{
x = (dpLocal[0] + lineDist * cos(fAngle));
y = (dpLocal[1] + lineDist * sin(fAngle));
CG_DrawPic(x, y, 10, 10, tRed, RegisterShader("compassping_enemyfiring", 7));
}else
{
x = (x + lineDist * cos(fAngle));
y = (y + lineDist * sin(fAngle));
CG_DrawPic(x, y, 10, 10, tRed, RegisterShader("compassping_enemyfiring", 7));
}
}
}
}
}
by editing the linedist you can also make it look like a real line, or you can use other shaders
Credits:
cardoow