Raised This Month: $12 Target: $400
 3% 

Solved Math problem help!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NC.svtrade
Senior Member
Join Date: Nov 2015
Old 01-23-2021 , 17:35   Math problem help!
Reply With Quote #1

I'm making a function which detects if player can see other player or not.
I want to fetch out the percentile of ' how much can player see other player '

This is my current function.

PHP Code:
bool ViewThingy(int clientint victim)
{
    
float m_target[3], eye[3], ang[3], fwd[3];
    
GetClientEyePosition(clienteye);
    
GetClientEyePosition(victimm_target);
    
GetClientEyeAngles(clientang);
    
GetAngleVectors(angfwdNULL_VECTORNULL_VECTOR);
    
    
float path[3];
    
SubtractVectors(m_targeteyepath);
    
float distance GetVectorLength(path);
    
NormalizeVector(pathpath);
    
float dot GetVectorDotProduct(fwdpath);
    
    if( 
dot )
        return 
false;
    
    
bool doTrace false;
    
    
float fov 75.0 2.0;
    
float cosfov Cosine(fov 3.141592653589793 180.0);
    
    
float d distance 1000.0;
    
clamp(Pow(d0.4), cosfov0.996);
    
doTrace = ( dot );
    
    if(
doTrace)
    {
        
Handle dp CreateDataPack();
        
        
WritePackCell(dpclient);
        
WritePackCell(dpvictim);
        
        
Handle tr TR_TraceRayFilterEx(eyem_targetCONTENTS_OPAQUE|CONTENTS_SOLID|CONTENTS_MOVEABLE|CONTENTS_DEBRIS|MASK_OPAQUE_AND_NPCSRayType_EndPointCTraceFilterSkipTwoEntitiesdp);
        
        
PrintToChatAll("%.1f"TR_GetFraction(tr))
        
        if ( 
TR_GetFraction(tr) == 1.0 )
        {
            
CloseHandle(dp);
            return 
true;
        }
        
CloseHandle(dp);
    }
    
    return 
false;
}

public 
bool CTraceFilterSkipTwoEntities(int entityint contentsMaskDataPack dp) {
    
ResetPack(dp);
    
int client ReadPackCell(dp);
    
int victim ReadPackCell(dp);
    
    if(
entity == client || entity == victim)
        return 
false;
    
    return 
true;
}

float clamp(float insidefloat lowfloat high) {
    return 
inside high high : (inside low low inside);

I want to make the function can return the percentage, not the true or false.

For example if you can see half of the body, it will return 0.5 .
If you can see only arm or tip toe it will return 0.1~0.3 .

Please help! I would be really appreciated.

Last edited by NC.svtrade; 01-24-2021 at 13:52.
NC.svtrade is offline
FroGeX
Senior Member
Join Date: Aug 2020
Old 01-24-2021 , 01:53   Re: Math problem help!
Reply With Quote #2

Maybe can try this https://forums.alliedmods.net/showthread.php?t=210080
FroGeX is offline
NC.svtrade
Senior Member
Join Date: Nov 2015
Old 01-24-2021 , 06:44   Re: Math problem help!
Reply With Quote #3

Quote:
Originally Posted by FroGeX View Post
I appreciated your answer, but this is not the solution I wanted.
I want to get the function which returns ' how much can player see another player '
in 0~1 value.
NC.svtrade is offline
FroGeX
Senior Member
Join Date: Aug 2020
Old 01-24-2021 , 07:12   Re: Math problem help!
Reply With Quote #4

You mean how much percent from player hull?
FroGeX is offline
NC.svtrade
Senior Member
Join Date: Nov 2015
Old 01-24-2021 , 07:33   Re: Math problem help!
Reply With Quote #5

Quote:
Originally Posted by FroGeX View Post
You mean how much percent from player hull?
yes
NC.svtrade is offline
FroGeX
Senior Member
Join Date: Aug 2020
Old 01-24-2021 , 07:47   Re: Math problem help!
Reply With Quote #6

I don't think this is possible. All I can think of is forming a group Tracerays from players eyes and based on the player's distance, set the angles between each traceray and then track the number of tracerays to hit the player.

Sorry for my english
FroGeX is offline
NC.svtrade
Senior Member
Join Date: Nov 2015
Old 01-24-2021 , 08:03   Re: Math problem help!
Reply With Quote #7

Quote:
Originally Posted by FroGeX View Post
I don't think this is possible. All I can think of is forming a group Tracerays from players eyes and based on the player's distance, set the angles between each traceray and then track the number of tracerays to hit the player.

Sorry for my english
ahh okok thank you for the help anyways! :)
NC.svtrade is offline
NC.svtrade
Senior Member
Join Date: Nov 2015
Old 01-24-2021 , 13:53   Re: Math problem help!
Reply With Quote #8

used this solution.

PHP Code:
bool:IsRectangleVisible(const Float:start[3], const Float:end[3], const Float:mins[3], const Float:maxs[3], Float:scale=1.0)
{
    new 
Float:ZpozOffset maxs[2];
    new 
Float:ZnegOffset mins[2];
    new 
Float:WideOffset = ((maxs[0] - mins[0]) + (maxs[1] - mins[1])) / 4.0;

    
// This rectangle is just a point!
    
if (ZpozOffset == 0.0 && ZnegOffset == 0.0 && WideOffset == 0.0)
    {
        return 
IsPointVisible(startend);
    }

    
// Adjust to scale.
    
ZpozOffset *= scale;
    
ZnegOffset *= scale;
    
WideOffset *= scale;
    
    
// Prepare rotation matrix.
    
decl Float:angles[3], Float:fwd[3], Float:right[3];

    
SubtractVectors(startendfwd);
    
NormalizeVector(fwdfwd);

    
GetVectorAngles(fwdangles);
    
GetAngleVectors(anglesfwdrightNULL_VECTOR);

    
decl Float:vRectangle[4][3], Float:vTemp[3];

    
// If the player is on the same level as us, we can optimize by only rotating on the z-axis.
    
if (FloatAbs(fwd[2]) <= 0.7071)
    {
        
ScaleVector(rightWideOffset);
        
        
// Corner 1, 2
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
AddVectors(vTemprightvRectangle[0]);
        
SubtractVectors(vTemprightvRectangle[1]);
        
        
// Corner 3, 4
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
AddVectors(vTemprightvRectangle[2]);
        
SubtractVectors(vTemprightvRectangle[3]);
        
    }
    else if (
fwd[2] > 0.0// Player is below us.
    
{
        
fwd[2] = 0.0;
        
NormalizeVector(fwdfwd);
        
        
ScaleVector(fwdscale);
        
ScaleVector(fwdWideOffset);
        
ScaleVector(rightWideOffset);
        
        
// Corner 1
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
AddVectors(vTemprightvTemp);
        
SubtractVectors(vTempfwdvRectangle[0]);
        
        
// Corner 2
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
SubtractVectors(vTemprightvTemp);
        
SubtractVectors(vTempfwdvRectangle[1]);
        
        
// Corner 3
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
AddVectors(vTemprightvTemp);
        
AddVectors(vTempfwdvRectangle[2]);
        
        
// Corner 4
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
SubtractVectors(vTemprightvTemp);
        
AddVectors(vTempfwdvRectangle[3]);
    }
    else 
// Player is above us.
    
{
        
fwd[2] = 0.0;
        
NormalizeVector(fwdfwd);
        
        
ScaleVector(fwdscale);
        
ScaleVector(fwdWideOffset);
        
ScaleVector(rightWideOffset);

        
// Corner 1
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
AddVectors(vTemprightvTemp);
        
AddVectors(vTempfwdvRectangle[0]);
        
        
// Corner 2
        
vTemp end;
        
vTemp[2] += ZpozOffset;
        
SubtractVectors(vTemprightvTemp);
        
AddVectors(vTempfwdvRectangle[1]);
        
        
// Corner 3
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
AddVectors(vTemprightvTemp);
        
SubtractVectors(vTempfwdvRectangle[2]);
        
        
// Corner 4
        
vTemp end;
        
vTemp[2] += ZnegOffset;
        
SubtractVectors(vTemprightvTemp);
        
SubtractVectors(vTempfwdvRectangle[3]);
    }

    
// Run traces on all corners.
    
for (new 04i++)
    {
        if (
IsPointVisible(startvRectangle[i]))
        {
            return 
true;
        }
    }

    return 
false;

NC.svtrade is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode