AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [1 solution found] Calculating an entities mins/maxs according to the entityangles (https://forums.alliedmods.net/showthread.php?t=55735)

regalis 05-28-2007 12:47

[1 solution found] Calculating an entities mins/maxs according to the entityangles
 
Code:

// Here the angles are read
ent_angles[ent_count][0] = str_to_float(str_value[0]);
ent_angles[ent_count][1] = str_to_float(str_value[1]);
ent_angles[ent_count][2] = str_to_float(str_value[2]);

// And here the entities angles is set
set_pev(ent, pev_angles, ent_angles[ent_count]);

This mins/maxs are correct for this angle: (0.0, 270.0, 0.0)
Code:

new Float:mins[3] = {-11.0, -2.0, 27.0};
new Float:maxs[3] = {11.0, 2.0, 71.0};
engfunc(EngFunc_SetSize, ent, mins, maxs);
ent_count++;

But if the angle is like this: (0.0, 90.0, 0.0) the mins/maxs are not correct.
I have no skills in 3D math so the only thing i could do is hardcode the mins/maxs for nearly every angle...*omg*

Does anyone know a function to calc the mins/maxs corresponding to the angles?

Thanks in advance
regalis

Zenith77 05-28-2007 13:01

Re: Calculating an entities mins/maxs according to the entityangles
 
Just out of curiosity, why would you need to calculate an entities size based on their angles? Just never heard of it being done before.

regalis 05-28-2007 13:11

Re: Calculating an entities mins/maxs according to the entityangles
 
For my Health/Armor Stations plugin...
When you place a station on the wall it have an angle...
Now the entity size have to be as big as the model to get the entID through get_user_aiming()
(because if the entity is too small you have to search for it "inside" the model)
Also the main problem: the entity have to be solid to get the ID through aiming.. :(

Thats why i need a function which translates the coordinates of the size according to the angle the model have..
Or does anyone know how to get the entID through get_user_aiming() if the entity is not solid?

Cheap_Suit 05-28-2007 14:00

Re: Calculating an entities mins/maxs according to the entityangles
 
Try this out. It runs EngFunc_FindEntityInSphere on where you aim, and return's the ent's id if found.

PHP Code:

stock get_aim_radius(indexFloat:radius
{
 static 
Float:start[3], Float:view_ofs[3]
 
pev(indexpev_originstart)
 
pev(indexpev_view_ofsview_ofs)
 
xs_vec_add(startview_ofsstart)
 
 static 
Float:dest[3]
 
pev(indexpev_v_angledest)
 
engfunc(EngFunc_MakeVectorsdest)
 
global_get(glb_v_forwarddest)
 
 
xs_vec_mul_scalar(dest9999.0dest)
 
xs_vec_add(startdestdest)
 
 
engfunc(EngFunc_TraceLinestartdest0index0)
 
 static 
Float:origin[3]
 
get_tr2(0TR_vecEndPosorigin)
 
 new 
ent = -1
 
while((ent engfunc(EngFunc_FindEntityInSphereentoriginradius)) != 0)
  return 
ent
 
return 0



regalis 05-28-2007 14:05

Re: Calculating an entities mins/maxs according to the entityangles
 
OMG !!!!
I'm so dumb :( *hitting my head on the plate*

Thank you very much for this idea!

Thats it...no complicated math *hrhr*

(But if anyone got bored and would like to tell us the solution...feel free...i'm though interested in how to calculate that..0o)

greetz regalis

VEN 05-31-2007 03:05

Re: [1 solution found] Calculating an entities mins/maxs according to the entityangle
 
I didn't get two things: why not solid and why sphere? Isn't it should be solid parallelepiped?

regalis 05-31-2007 09:43

Re: [1 solution found] Calculating an entities mins/maxs according to the entityangle
 
Quote:

Originally Posted by VEN (Post 483983)
I didn't get two things: why not solid and why sphere? Isn't it should be solid parallelepiped?

no no, the entity have to be solid that i can get its ID by get_user_aiming() function (to remove it)

Why not sphere? It works realy got with find_ent_in_sphere()...do you suggest using a other function?
The only thing other i can think of is ent_distance()...

Quote:

Isn't it should be solid parallelepiped?
Don't know what you mean...has this to do with 3D math !?


Btw.: i found functions to rotate a point around a axis...but it doesn't work :(
Code:

stock rotate_point_by_angle(const Float:angle[3],Float:point[3])
{
    log_amx("before point : %f - %f - %f", point[0], point[1], point[2]);
    point[0] = (point[0] * floatcos(angle[1], degrees)) - (point[1] * floatsin(angle[1], degrees));
    point[1] = (point[1] * floatcos(angle[1], degrees)) + (point[0] * floatsin(angle[1], degrees));
    log_amx("after1 point : %f - %f - %f", point[0], point[1], point[2]);
    point[0] = (point[0] * floatcos(angle[2], degrees)) - (point[2] * floatsin(angle[2], degrees));
    point[2] = (point[2] * floatcos(angle[2], degrees)) + (point[0] * floatsin(angle[2], degrees));
    log_amx("after2 point : %f - %f - %f", point[0], point[1], point[2]);
    point[1] = (point[1] * floatcos(angle[0], degrees)) - (point[2] * floatsin(angle[0], degrees));
    point[2] = (point[2] * floatcos(angle[0], degrees)) + (point[1] * floatsin(angle[0], degrees));
    log_amx("after3 point : %f - %f - %f", point[0], point[1], point[2]);
    return 1;
}

I get weird server crashes... got an error window "backward mins/maxs"
Does anyone know what i did wrong?
I found out that floatcos()/floatsin() need a flag with degrees otherwise it returns radians..0o
But that also crashes the server...

Thanks VEN for responding!
greetz regalis

VEN 05-31-2007 14:26

Re: [1 solution found] Calculating an entities mins/maxs according to the entityangle
 
I think you didn't get my point.

Quote:

For my Health/Armor Stations plugin...
When you place a station on the wall
......
if the entity is not solid?
I thought that Health/Armor Station should be solid and it isn't spherical but simple box (parallelepiped)? Why do you trying to check sphere? Why station isn't solid? I'm confused...

regalis 05-31-2007 14:48

Re: [1 solution found] Calculating an entities mins/maxs according to the entityangle
 
Right it should be solid and it is solid. But unfortunately i can only create a small entity in the middle of the model.
Because if the angle of the model changes the entity keeps its angle which is set by the mins/maxs :(
Therefore i try to rotate the mins/maxs that i can fill the whole model with the entity to make it real solid.

i can post a little screenshot if my explanation is to confusing ;)
[IMG]http://img523.**************/img523/8641/screenierx5.th.jpg[/IMG]

vittu 09-26-2007 06:14

Re: [1 solution found] Calculating an entities mins/maxs according to the entityangle
 
regalis, did you ever find a solution to this, I'm wanting to do something similar and not recalling what to do to get the mins/maxs to shift with different angles.


All times are GMT -4. The time now is 10:40.

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