Raised This Month: $ Target: $400
 0% 

Get origin from ½ distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr.G
Senior Member
Join Date: Nov 2008
Old 03-04-2010 , 10:26   Get origin from ½ distance
Reply With Quote #1

Ok this is a bit hard to explain so i made a drawing that show what i need. See the attachment.

TIA. Cheers!
Attached Thumbnails
Click image for larger version

Name:	ScreenShot071.jpg
Views:	214
Size:	50.9 KB
ID:	60883  
__________________
Dr.G is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-04-2010 , 10:51   Re: Get origin from ½ distance
Reply With Quote #2

I may be wrong :

- You know the length between both points L, so to know the center you can do : ANGLE_FORWARD * ( L / 2 )
- Now you can do : -ANGLE_RIGHT * ( L / 0.6 ) to know the left point, or ANGLE_RIGHT * ( L / 6 ) the right point.
__________________
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-04-2010 , 12:31   Re: Get origin from ½ distance
Reply With Quote #3

Code:
new Float:vTraceStart[ 3 ]; new Float:vTraceEnd[ 3 ]; new Float:fDistance; // vTraceStart = "Trace Start" // vTraceEnd = "Trace End" // fDistance = "L" new Float:fOffset = floatmax( ( fDistance / 6.0 ), 76.0 ); new Float:fAngleFormedByPoint = floattan( ( fOffset / ( fDistance / 2.0 ) ), degrees ); new Float:vDirection[ 3 ]; xs_vec_sub( vTraceEnd, vTraceStart, vDirection ); new Float:vAngles[ 3 ]; vector_to_angle( vDirection, vAngles ); // for left fAngleFormedByPoint = vAngles[ 1 ] - fAngleFormedByPoint; while( fAngleFormedByPoint < -180.0 ) {     fAngleFormedByPoint += 360.0; } // end left // for right fAngleFormedByPoint = vAngles[ 1 ] + fAngleFormedByPoint; while( fAngleFormedByPoint > 180.0 ) {     fAngleFormedByPoint -= 360.0; } // end right vAngles[ 1 ] = fAngleFormedByPoint; angle_vector( vAngles, ANGLEVECTOR_FORWARD, vDirection ); new Float:fHypotenuse = floatsqroot( floatpower( fOffset, 2.0 ) + floatpower( ( fDistance / 2.0 ), 2.0 ) ); xs_vec_mul_scalar( vDirection, fHypotenuse, vDirection ); new Float:vCalcOrigin[ 3 ]; xs_vec_add( vTraceStart, vDirection, vCalcOrigin );

EDIT:

Here's Arkshine's method:
Code:
new Float:vTraceStart[ 3 ]; new Float:vTraceEnd[ 3 ]; new Float:fDistance; // vTraceStart = "Trace Start" // vTraceEnd = "Trace End" // fDistance = "L" new Float:fOffset = floatmax( ( fDistance / 6.0 ), 76.0 ); new Float:vDirection[ 3 ]; xs_vec_sub( vTraceEnd, vTraceStart, vDirection ); xs_vec_normalize( vDirection, vDirection ); xs_vec_mul_scalar( vDirection, ( fDistance / 2.0 ), vDirection ); new Float:vCenter[ 3 ]; xs_vec_add( vTraceStart, vDirection, vCenter ); new Float:vAngles[ 3 ]; vector_to_angle( vDirection, vAngles ); angle_vector( vAngles, ANGLEVECTOR_RIGHT, vDirection ); // left xs_vec_mul_scalar( vDirection, -fOffset, vDirection ); // right xs_vec_mul_scalar( vDirection, fOffset, vDirection ); new Float:vCalcOrigin[ 3 ]; xs_vec_add( vCenter, vDirection, vCalcOrigin );
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 03-04-2010 at 12:37.
Exolent[jNr] is offline
Dr.G
Senior Member
Join Date: Nov 2008
Old 03-04-2010 , 22:18   Re: Get origin from ½ distance
Reply With Quote #4

Exolent yours find below or above. Arkshines find right or left. But ok i guess i should have said that the picture was a plan view :) ...

Anyways, Amazing! Thanks you both!

PHP Code:
/* Plugin generated by AMXX-Studio */

///////////////////////////////////////////////////////////////////////////////////////////////////
#include <amxmodx>
#include <fakemeta>
#include <xs>
////////////////////////////////////////////////////////////////////////////////////////////////////
#define PLUGIN     "YadaYada"
#define VERSION "1.0 by Dr.G"
#define AUTHOR     "AMXX DoD Team"
////////////////////////////////////////////////////////////////////////////////////////////////////
#define MAX_PLAYERS    32
////////////////////////////////////////////////////////////////////////////////////////////////////
#define Exolent     0
#define Arkshine     1
////////////////////////////////////////////////////////////////////////////////////////////////////
new beamSpr
////////////////////////////////////////////////////////////////////////////////////////////////////
new IsTesting[MAX_PLAYERS 1]
////////////////////////////////////////////////////////////////////////////////////////////////////
public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("CurWeapon","func_CurWeapon","be","1=1","3>0")
    
    
register_clcmd("say /test""OnOff"ADMIN_KICK)
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public plugin_precache()
{
    
beamSpr precache_model("sprites/laserbeam.spr");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public client_putinserver(id)
{
    
IsTesting[id] = 0
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public OnOff(id)
{
    if(
IsTesting[id])
        
IsTesting[id] = 0
    
    
else if(!IsTesting[id])
        
IsTesting[id] = 1
    
    client_print
(idprint_center"%s"IsTesting[id] !="Offline" "Online")
    
    return 
PLUGIN_HANDLED
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public func_CurWeapon(id)
{
    if(!
IsTesting[id])
        return
    
    if(
pev(id,pev_button) & IN_ATTACK)
    {
        
do_trace(id)
    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
#if Exolent
public do_trace(index
{
    new 
Float:vTraceStart[3]
    
//new Float:start[3], 
    
new Float:view_ofs[3]
    
pev(indexpev_originvTraceStart)
    
pev(indexpev_view_ofsview_ofs)
    
xs_vec_add(vTraceStartview_ofsvTraceStart)
    
    new 
Float:dest[3]
    
pev(indexpev_v_angledest)
    
engfunc(EngFunc_MakeVectorsdest)
    
global_get(glb_v_forwarddest)
    
xs_vec_mul_scalar(dest9999.0dest)
    
xs_vec_add(vTraceStartdestdest)
    
    
engfunc(EngFunc_TraceLinevTraceStartdest0index0)
    
    new 
Float:vTraceEnd[3]
    
get_tr2(0TR_vecEndPosvTraceEnd)
    
    
/////////////////////////////////////////////////////////////////////////////
    
    
new Float:fDistance get_distance_f(vTraceStartvTraceEnd)
    
    
do_beam(indexvTraceStartvTraceEnd)
    
    new 
Float:fOffset floatmax((fDistance 6.0), 76.0)
    new 
Float:fAngleFormedByPoint floattan((fOffset / (fDistance 2.0)), degrees)
    
    new 
Float:vDirection[3]
    
xs_vec_sub(vTraceEndvTraceStartvDirection)
    
    new 
Float:vAngles[3]
    
vector_to_angle(vDirectionvAngles)
    
    
/*
    // for left -> ignored one side for starters
    fAngleFormedByPoint = vAngles[1] - fAngleFormedByPoint
    while(fAngleFormedByPoint < -180.0)
    {
        fAngleFormedByPoint += 360.0;
    }
    // end left
    */
    
    // for right
    
fAngleFormedByPoint vAngles[1] + fAngleFormedByPoint
    
while(fAngleFormedByPoint 180.0)
    {
        
fAngleFormedByPoint -= 360.0
    
}
    
// end right
    
    
vAngles[1] = fAngleFormedByPoint
    angle_vector
(vAnglesANGLEVECTOR_FORWARDvDirection)
    
    new 
Float:fHypotenuse floatsqroot(floatpower(fOffset2.0) + floatpower(( fDistance 2.0 ), 2.0))
    
xs_vec_mul_scalar(vDirectionfHypotenusevDirection)
    
    new 
Float:vCalcOrigin[3]
    
xs_vec_add(vTraceStartvDirectionvCalcOrigin)
    
    
    
do_beam(indexvTraceStartvCalcOrigin)
}
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
#if Arkshine
public do_trace(index
{
    new 
Float:vTraceStart[3]
    new 
Float:view_ofs[3]
    
pev(indexpev_originvTraceStart)
    
pev(indexpev_view_ofsview_ofs)
    
xs_vec_add(vTraceStartview_ofsvTraceStart)
    
    new 
Float:dest[3]
    
pev(indexpev_v_angledest)
    
engfunc(EngFunc_MakeVectorsdest)
    
global_get(glb_v_forwarddest)
    
xs_vec_mul_scalar(dest9999.0dest)
    
xs_vec_add(vTraceStartdestdest)
    
    
engfunc(EngFunc_TraceLinevTraceStartdest0index0)
    
    new 
Float:vTraceEnd[3]
    
get_tr2(0TR_vecEndPosvTraceEnd)
    
    
/////////////////////////////////////////////////////////////////////////////
    
    
new Float:fDistance get_distance_f(vTraceStartvTraceEnd)
    
    
do_beam(indexvTraceStartvTraceEnd)
    
    new 
Float:fOffset floatmax((fDistance 6.0), 76.0)
    
    new 
Float:vDirection[3]
    
xs_vec_subvTraceEndvTraceStartvDirection )
    
xs_vec_normalize(vDirectionvDirection )
    
xs_vec_mul_scalar(vDirection, ( fDistance 2.0 ), vDirection)
    
    new 
Float:vCenter[3]
    
xs_vec_add(vTraceStartvDirectionvCenter)
    
    new 
Float:vAngles[3]
    
vector_to_angle(vDirectionvAngles)
    
    
angle_vector(vAnglesANGLEVECTOR_RIGHTvDirection)
    
// left
    //xs_vec_mul_scalar(vDirection, -fOffset, vDirection)
    // right
    
xs_vec_mul_scalarvDirectionfOffsetvDirection )
    
    new 
Float:vCalcOrigin[3]
    
xs_vec_add(vCentervDirectionvCalcOrigin)
    
    
do_beam(indexvTraceStartvCalcOrigin)
}
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
public do_beam(indexFloat:start[3], Float:end[3])
{
    
message_begin(MSG_ONE_UNRELIABLESVC_TEMPENTITY_index)
    
write_byte(TE_BEAMPOINTS)
    
write_coord(floatround(start[0]))
    
write_coord(floatround(start[1]))
    
write_coord(floatround(start[2]))
    
write_coord(floatround(end[0]))
    
write_coord(floatround(end[1]))
    
write_coord(floatround(end[2]))
    
write_short(beamSpr)
    
write_byte(0)
    
write_byte(0)
    
write_byte(50)
    
write_byte(10)
    
write_byte(0)
    
write_byte(0)
    
write_byte(255)
    
write_byte(0)
    
write_byte(200)
    
write_byte(0)
    
message_end()
}
//////////////////////////////////////////////////////////////////////////////////////////////////// 
__________________

Last edited by Dr.G; 03-04-2010 at 22:19. Reason: s
Dr.G 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 11:18.


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