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

Vecmins and vecmaxs based on angular rotation


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-20-2021 , 17:09   Vecmins and vecmaxs based on angular rotation
Reply With Quote #1

PHP Code:

GetEntPropVector
(entityProp_Data"m_vecAbsOrigin"Origin);
GetEntPropVector(entityProp_Data"m_vecMins"Mins);
GetEntPropVector(entityProp_Data"m_vecMaxs"Maxs);
GetEntPropVector(entityProp_Data"m_angAbsRotation"Rotation); 
Does someone know how to calculate the new mins and maxs based on entity rotation?
__________________

Last edited by Ilusion9; 01-20-2021 at 17:09.
Ilusion9 is offline
FroGeX
Senior Member
Join Date: Aug 2020
Old 01-23-2021 , 01:37   Re: Vecmins and vecmaxs based on angular rotation
Reply With Quote #2

Create same entity on same origin, parent two entities on this ent to mins and maxs position apply rotatiton from original ent, unparented parented ents and get their positions.
FroGeX is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-23-2021 , 06:02   Re: Vecmins and vecmaxs based on angular rotation
Reply With Quote #3

Thats not a solution.
__________________
Ilusion9 is offline
FroGeX
Senior Member
Join Date: Aug 2020
Old 01-23-2021 , 13:00   Re: Vecmins and vecmaxs based on angular rotation
Reply With Quote #4

Quote:
Originally Posted by Ilusion9 View Post
Thats not a solution.
it did exactly what you wrote
FroGeX is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 04-10-2021 , 10:08   Re: Vecmins and vecmaxs based on angular rotation
Reply With Quote #5

Quote:
Originally Posted by FroGeX View Post
it did exactly what you wrote
no, it didn't
childrens have same vecmins vecmaxs when parents are moving, only the origin is not the same (tested with trigger_hurt, physboxes are just fine, their mins and maxs are updated every frame when parent is moving).

Example here:
https://imgur.com/a/yNB3WlR

The green box which seems its not moving it's a trigger_hurt parented to the moving entity.

I wrote this code:
PHP Code:

void GetAngularMinsMaxs
(int entityClassname entityTypefloat vecMins[3], float vecMaxs[3], float vecOrigin[3])
{
    
RotationType rotationType;
    
    
float vecRotation[3];
    
GetEntPropVector(entityProp_Data"m_angAbsRotation"vecRotation);
    
    
float newMins[3];
    
float newMaxs[3];
    
    for (
int i 03i++)
    {
        
newMins[i] = vecMins[i];
        
newMaxs[i] = vecMaxs[i];
    }
    
    
int spawnFlags GetEntProp(entityProp_Data"m_spawnflags");
    if (
entityType == Func_Rotating)
    {
        if (
view_as<bool>(spawnFlags SF_BRUSH_ROTATE_X_AXIS))
        {
            
rotationType RotationType_Roll;
        }
        else if (
view_as<bool>(spawnFlags SF_BRUSH_ROTATE_Y_AXIS))
        {
            
rotationType RotationType_Pitch;
        }
    }
    else 
// func_door_rotating
    
{
        if (
view_as<bool>(spawnFlags SF_DOOR_ROTATE_ROLL))
        {
            
rotationType RotationType_Roll;
        }
        else if (
view_as<bool>(spawnFlags SF_DOOR_ROTATE_PITCH))
        {
            
rotationType RotationType_Pitch;
        }
    }
    
    switch (
rotationType)
    {
        case 
RotationType_Yaw:
        {
            
float angle vecRotation[1] * 3.14 180.0;
            
newMins[0] = Cosine(angle) * vecMins[0] - Sine(angle) * vecMins[1];
            
newMins[1] = Sine(angle) * vecMins[0] + Cosine(angle) * vecMins[1];
            
            
newMaxs[0] = Cosine(angle) * vecMaxs[0] - Sine(angle) * vecMaxs[1];
            
newMaxs[1] = Sine(angle) * vecMaxs[0] + Cosine(angle) * vecMaxs[1];
        }
        
        case 
RotationType_Roll:
        {
            
float angle vecRotation[2] * 3.14 180.0;
            
newMins[1] = Cosine(angle) * vecMins[1] - Sine(angle) * vecMins[2];
            
newMins[2] = Sine(angle) * vecMins[1] + Cosine(angle) * vecMins[2];
            
            
newMaxs[1] = Cosine(angle) * vecMaxs[1] - Sine(angle) * vecMaxs[2];
            
newMaxs[2] = Sine(angle) * vecMaxs[1] + Cosine(angle) * vecMaxs[2];
        }
        
        case 
RotationType_Pitch:
        {
            
float angle vecRotation[0] * 3.14 180.0;
            
newMins[0] = Cosine(angle) * vecMins[0] - Sine(angle) * vecMins[2];
            
newMins[2] = Sine(angle) * vecMins[0] + Cosine(angle) * vecMins[2];
            
            
newMaxs[0] = Cosine(angle) * vecMaxs[0] - Sine(angle) * vecMaxs[2];
            
newMaxs[2] = Sine(angle) * vecMaxs[0] + Cosine(angle) * vecMaxs[2];
        }
    }
    
    for (
int i 03i++)
    {
        
vecMins[i] = newMins[i] + vecOrigin[i];
        
vecMaxs[i] = newMaxs[i] + vecOrigin[i];
    }
    
    
GetMiddleOfABox(vecMinsvecMaxsvecOrigin);
}

void GetMiddleOfABox(float vecMins[3], float vecMaxs[3], float vecOrigin[3])
{
    
float middle[3];
    
MakeVectorFromPoints(vecMinsvecMaxsmiddle);
    
    for (
int i 03i++)
    {
        
middle[i] /= 2.0;
    }
    
    
AddVectors(vecMinsmiddlevecOrigin);
    
SubtractVectors(vecMinsvecOriginvecMins);
    
SubtractVectors(vecMaxsvecOriginvecMaxs);
    
    for (
int i 03i++)
    {
        if (
vecMins[i] > 0.0)
        {
            
vecMins[i] *= -1.0;
        }
        
        if (
vecMaxs[i] < 0.0)
        {
            
vecMaxs[i] *= -1.0;
        }
    }

For some entities, everything is fine, but for others, something strange happens.
https://imgur.com/a/2JZLYSo
A square becomes a rectangle and a square again (the rectangle will have a side very small, close to 1 - 10 units).

The green lines represents the mins and maxs calculated with this function. For rectangles everything seems fine, but for squares - like the door_rotating from picture - this strange bug occurs.
__________________

Last edited by Ilusion9; 04-10-2021 at 10:15.
Ilusion9 is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 04-14-2021 , 03:11   Re: Vecmins and vecmaxs based on angular rotation
Reply With Quote #6

Found another solution:

PHP Code:

void GetEntityCoordinates
(int entityfloat vecMins[3], float vecMaxs[3], float vecOrigin[3])
{
    
GetEntPropVector(entityProp_Data"m_vecAbsOrigin"vecOrigin);
    
GetEntPropVector(entityProp_Data"m_vecMins"vecMins);
    
GetEntPropVector(entityProp_Data"m_vecMaxs"vecMaxs);
    
    
float buffer[3];
    
float points[8][3];
    
float coordinateFrame[3][3];
    
    
coordinateFrame[0][0] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"0);
    
coordinateFrame[0][1] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"1);
    
coordinateFrame[0][2] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"2);
    
coordinateFrame[1][0] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"4);
    
coordinateFrame[1][1] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"5);
    
coordinateFrame[1][2] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"6);
    
coordinateFrame[2][0] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"8);
    
coordinateFrame[2][1] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"9);
    
coordinateFrame[2][2] = GetEntPropFloat(entityProp_Data"m_rgflCoordinateFrame"10);
    
    
points[0][0] = vecMins[0];
    
points[0][1] = vecMins[1];
    
points[0][2] = vecMins[2];

    
points[1][0] = vecMins[0];
    
points[1][1] = vecMaxs[1];
    
points[1][2] = vecMins[2];
    
    
points[2][0] = vecMaxs[0];
    
points[2][1] = vecMaxs[1];
    
points[2][2] = vecMins[2];
    
    
points[3][0] = vecMaxs[0];
    
points[3][1] = vecMins[1];
    
points[3][2] = vecMins[2];
    
    
points[4][0] = vecMins[0];
    
points[4][1] = vecMins[1];
    
points[4][2] = vecMaxs[2];
    
    
points[5][0] = vecMins[0];
    
points[5][1] = vecMaxs[1];
    
points[5][2] = vecMaxs[2];
    
    
points[6][0] = vecMaxs[0];
    
points[6][1] = vecMaxs[1];
    
points[6][2] = vecMaxs[2];
    
    
points[7][0] = vecMaxs[0];
    
points[7][1] = vecMins[1];
    
points[7][2] = vecMaxs[2];
    
    for (
int i 08i++)
    {
        
buffer points[i];
        for (
int j 03j++)
        {
            
points[i][j] = GetVectorDotProduct(buffercoordinateFrame[j]);
        }
    }
    
    
vecMins points[0];
    
vecMaxs points[0];

    for (
int i 18i++)
    {
        for (
int j 03j++)
        {
            if (
points[i][j] < vecMins[j])
            {
                
vecMins[j] = points[i][j];
            }
            
            if (
points[i][j] > vecMaxs[j])
            {
                
vecMaxs[j] = points[i][j];
            }
        }
    }

But the box expands too much sometimes:
https://imgur.com/a/oGI8aEL

When angRotation % 360 is close to 0, the bounding box is correct.
__________________
Ilusion9 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 19:48.


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