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

[Metamod] Lie flat (to surface)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Rirre
Veteran Member
Join Date: Nov 2006
Old 07-17-2014 , 17:10   [Metamod] Lie flat (to surface)
Reply With Quote #1

Anyone have or can convert this for metamod?
Code:
    static Float:origin[3], Float:traceto[3], trace = 0, Float:fraction, Float:angles[3], Float:angles2[3]         pev(ent, pev_origin, origin)     pev(ent, pev_angles, angles)         // We want to trace downwards 10 units.     xs_vec_sub(origin, Float:{0.0, 0.0, 10.0}, traceto)         engfunc(EngFunc_TraceLine, origin, traceto, IGNORE_MONSTERS, ent, trace)         // Most likely if the entity has the FL_ONGROUND flag, flFraction will be less than 1.0, but we need to make sure.     get_tr2(trace, TR_flFraction, fraction)     if (fraction == 1.0) return         // Normally, once an item is dropped, the X and Y-axis rotations (aka roll and pitch) are set to 0, making them lie "flat."     // We find the forward vector: the direction the ent is facing before we mess with its angles.     static Float:original_forward[3]     angle_vector(angles, ANGLEVECTOR_FORWARD, original_forward)         // If your head was an entity, no matter which direction you face, these vectors would be sticking out of your right ear,     // up out the top of your head, and forward out from your nose.     static Float:right[3], Float:up[3], Float:fwd[3]         // The plane's normal line will be our new ANGLEVECTOR_UP.     get_tr2(trace, TR_vecPlaneNormal, up)         // This checks to see if the ground is flat. If it is, don't bother continuing.     if (up[2] == 1.0) return         // The cross product (aka vector product) will give us a vector, which is in essence our ANGLEVECTOR_RIGHT.     xs_vec_cross(original_forward, up, right)     // And this cross product will give us our new ANGLEVECTOR_FORWARD.     xs_vec_cross(up, right, fwd)         // Converts from the forward vector to angles. Unfortunately, vectors don't provide enough info to determine X-axis rotation (roll),     // so we have to find it by pretending our right anglevector is a forward, calculating the angles, and pulling the corresponding value     // that would be the roll.     vector_to_angle(fwd, angles)     vector_to_angle(right, angles2)         // Multiply by -1 because pitch increases as we look down.     angles[2] = -1.0 * angles2[0]         // Finally, we turn our entity to lie flat.     set_pev(ent, pev_angles, angles)
Can't get mine to work:
Code:
inline Vector DotProduct2(const Vector& a, const Vector& b) { return Vector(a.x-b.x,a.y-b.y,a.z-b.z); }

{
	TraceResult tr;
	Vector angles = pev->angles, angles2;

	// We want to trace downwards 10 units.
	Vector vecDot = DotProduct2( pev->origin, Vector ( 0, 0, 10 ) );

	UTIL_TraceLine( pev->origin, vecDot, ignore_monsters, ENT(pev), &tr );

	// Most likely if the entity has the FL_ONGROUND flag, flFraction will be less than 1.0, but we need to make sure.
	if ( tr.flFraction == 1.0 ) return;

	// Normally, once an item is dropped, the X and Y-axis rotations (aka roll and pitch) are set to 0, making them lie "flat."
	// We find the forward vector: the direction the ent is facing before we mess with its angles.
	Vector original_forward;
	UTIL_MakeVectorsPrivate( angles, original_forward, NULL, NULL );

	// If your head was an entity, no matter which direction you face, these vectors would be sticking out of your right ear,
	// up out the top of your head, and forward out from your nose.
	Vector right, forward;

	// The plane's normal line will be our new ANGLEVECTOR_UP.
	// This checks to see if the ground is flat. If it is, don't bother continuing.
	if ( tr.vecPlaneNormal.z == 1.0 ) return;

	// The cross product (aka vector product) will give us a vector, which is in essence our ANGLEVECTOR_RIGHT.
	right = CrossProduct( original_forward, tr.vecPlaneNormal );
	// And this cross product will give us our new ANGLEVECTOR_FORWARD.
	forward = CrossProduct( tr.vecPlaneNormal, right );

	// Converts from the forward vector to angles. Unfortunately, vectors don't provide enough info to determine X-axis rotation (roll),
	// so we have to find it by pretending our right anglevector is a forward, calculating the angles, and pulling the corresponding value
	// that would be the roll.
	forward = UTIL_VecToAngles( angles );
	right = UTIL_VecToAngles( angles2 );

	// Multiply by -1 because pitch increases as we look down.
	angles.z = -1.0 * angles2.x;

	// Finally, we turn our entity to lie flat.
	pev->angles = angles;
	(*g_engfuncs.pfnServerPrint)("Lie flat\n");
}

Last edited by Rirre; 07-17-2014 at 20:37.
Rirre is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-17-2014 , 17:38   Re: [Metamod] Lie flat (to surface)
Reply With Quote #2

angle_vector() uses g_engfuncs.pfnAngleVectors.
__________________
Arkshine is offline
Old 07-17-2014, 19:02
Rirre
This message has been deleted by Rirre.
Rirre
Veteran Member
Join Date: Nov 2006
Old 07-17-2014 , 20:35   Re: [Metamod] Lie flat (to surface)
Reply With Quote #3

Quote:
Originally Posted by Arkshine View Post
angle_vector() uses g_engfuncs.pfnAngleVectors.
Yea I know, that's UTIL_MakeVectorsPrivate. I do not remember what I had in my mind. But I figured it out.
I've finally converted it, but the entity do not align to the surface.
It print "Lie flat" just fine, but the entity is not aligned to the surface at all and I'm out of ideas why it won't work.
If I use the plugin itself within AMXX the entity is aligned to the surface so I know it can be. But I need it within the metamod module.
Edited my first post with the converted version.

Last edited by Rirre; 07-17-2014 at 20:55.
Rirre is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 07-18-2014 , 06:22   Re: [Metamod] Lie flat (to surface)
Reply With Quote #4

PHP Code:
    TraceResult pTrace;

    
Vector vecOriginvecAnglesvecAngles2vecTrace;

    
float flFlaction;

    
vecOrigin pEdict->v.origin;
    
vecAngles pEdict->v.angles;
    
    
// We want to trace downwards 10 units.

    #define xs_vec_sub( a, b, c ) ( c = a - b )

    
xs_vec_subvecOriginVector0.00.010.0 ), vecTrace );
    
    
TRACE_LINEvecOriginvecTraceignore_monsterspEdict, &pTrace );
    
    
// Most likely if the entity has the FL_ONGROUND flag, flFraction will be less than 1.0, but we need to make sure.
    
flFlaction pTrace.flFraction;

    if( 
flFlaction == 1.0 
        return;
    
    
// Normally, once an item is dropped, the X and Y-axis rotations (aka roll and pitch) are set to 0, making them lie "flat."
    // We find the forward vector: the direction the ent is facing before we mess with its angles.
    
Vector vecForward;
    
Vector v_anglesv_forwardv_rightv_upv_return;

    
v_angles vecAngles;
    
g_engfuncs.pfnAngleVectors(v_anglesv_forwardv_rightv_up);
    
v_return v_forward;

    
vecForward v_return;
    
    
// If your head was an entity, no matter which direction you face, these vectors would be sticking out of your right ear,
    // up out the top of your head, and forward out from your nose.
    
Vector vecRightvecUpvecFwd;
    
    
// The plane's normal line will be our new ANGLEVECTOR_UP.
    
vecUp pTrace.vecPlaneNormal;
    
    
// This checks to see if the ground is flat. If it is, don't bother continuing.
    
if( vecUp.== 1.0 
        return;
    
    
#define xs_vec_cross( a, b, c ) \
        
c.a.x*b.a.x*b.x; \
        
c.a.y*b.a.y*b.y; \
        
c.a.z*b.a.z*b.z; \

    
// The cross product (aka vector product) will give us a vector, which is in essence our ANGLEVECTOR_RIGHT.
    
xs_vec_crossvecForwardvecUpvecFwd );
    
// And this cross product will give us our new ANGLEVECTOR_FORWARD.
    
xs_vec_cross(vecUpvecRightvecFwd);
    
    
// Converts from the forward vector to angles. Unfortunately, vectors don't provide enough info to determine X-axis rotation (roll),
    // so we have to find it by pretending our right anglevector is a forward, calculating the angles, and pulling the corresponding value
    // that would be the roll.
    
VEC_TO_ANGLESvecFwdvecAngles );
    
VEC_TO_ANGLESvecRightvecAngles2 );
    
    
// Multiply by -1 because pitch increases as we look down.
    
vecAngles.= -1.0 vecAngles2.x;
    
    
// Finally, we turn our entity to lie flat.
    
pEdict->v.angles vecAngles
__________________

Last edited by Bos93; 07-18-2014 at 06:24.
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 07-24-2014 , 18:29   Re: [Metamod] Lie flat (to surface)
Reply With Quote #5

PHP Code:
    #define xs_vec_sub( a, b, c ) ( c = a - b )

    
xs_vec_subvecOriginVector0.00.010.0 ), vecTrace ); 

Why not?
PHP Code:
vecTrace vecOrigin Vector(0010); 
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 07-25-2014 , 04:26   Re: [Metamod] Lie flat (to surface)
Reply With Quote #6

Quote:
Originally Posted by PRoSToTeM@ View Post
PHP Code:
    #define xs_vec_sub( a, b, c ) ( c = a - b )

    
xs_vec_subvecOriginVector0.00.010.0 ), vecTrace ); 

Why not?
PHP Code:
vecTrace vecOrigin Vector(0010); 

Is there a difference? I mean, performance difference?
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 07-27-2014 , 16:18   Re: [Metamod] Lie flat (to surface)
Reply With Quote #7

Quote:
Originally Posted by claudiuhks View Post
Is there a difference? I mean, performance difference?
No, but that code looks better and simpler:
PHP Code:
vecTrace vecOrigin Vector(0010); 
If we write code in C++, then why should we write it as in Pawn?
And if we write code for MetaMod, then why should we write it as for AmxModX?
__________________

Last edited by PRoSToTeM@; 07-27-2014 at 16:23.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-27-2014 , 18:59   Re: [Metamod] Lie flat (to surface)
Reply With Quote #8

Quote:
Originally Posted by PRoSToTeM@ View Post
No, but that code looks better and simpler:
PHP Code:
vecTrace vecOrigin Vector(0010); 
If we write code in C++, then why should we write it as in Pawn?
And if we write code for MetaMod, then why should we write it as for AmxModX?
Just personal preference. Maybe he likes it more the other way.
klippy is offline
Reply



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 21:26.


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