Raised This Month: $ Target: $400
 0% 

Calculate trajectory and point of exit


Post New Thread Reply   
 
Thread Tools Display Modes
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-17-2011 , 03:27   Re: Calculate trajectory and point of exit
Reply With Quote #11

Is it me or you're not using vecSprite2 at all ? :}

This works on shot origins too, right ?
__________________
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-17-2011 , 04:41   Re: Calculate trajectory and point of exit
Reply With Quote #12

It should have been vecSprite2 on the bottom and has been fixed.

What do you mean by shot origins?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-17-2011 , 05:14   Re: Calculate trajectory and point of exit
Reply With Quote #13

Well, if I shoot a wall, I'm comparing each portal origins with the shot ending origin.
So, if I shoot the sprite a little to the left, I want the shot to exit a little to the left on the other side too :} total redirection hole through space ! xD
__________________
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-17-2011 , 07:04   Re: Calculate trajectory and point of exit
Reply With Quote #14

I keep having ideas, but when I try to turn them into code, I get lost and not sure what to do.
I may leave this question for someone else to answer.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 04-17-2011 , 17:36   Re: Calculate trajectory and point of exit
Reply With Quote #15

I created complete script to calculate this using different approach. This is how you use it:

every time player successfully creates a portal and he has 2 valid portals you run this:
PHP Code:
portal_transf_init(portal_pair_idtop_vec1norm_vec1top_vec2norm_vec2
portal_pair_id is an id of pair of portals - it's value 0-MAX_PORTAL_PAIRS, if you want to allow every player to use single pair of portals then use player id as portal_pair_id
top_vec1 is a vector pointing from portal origin to the top of portal 1 sprite (it's parrallel to the surface of wall)
norm_vec1 is a vector normal to the surface of wall for portal 1
top_vec2 and norm_vec2 - accordingly same things for portal 2

every time bullet hits portal you run this:
PHP Code:
new bool:first_portal_hit did_bullet_hit_portal_1() //which one of 2 portals from pair was hit? returns true if it was first portal
new Float:hit_origin[3]
new 
Float:hit_vector_in[3], Float:hit_vector_out[3], Float:bullet_trajectory_in[3], Float:bullet_trajectory_out[3]

//set bullet_trajectory_in here - it's a vector of a bullet that was shot by a player and hit portal
//set hit_origin - it's an origin where portal hit ocurred

//if you have both portals origins stored in a single array then you will use cell index and the following code will be only 2 lines without "if"
if(first_portal_hit){
    for(new 
i=0i<3i++)
        
hit_vector_in[i] = hit_origin[i] - portal1_origin[i]
}else{
    for(new 
i=0i<3i++)
        
hit_vector_in[i] = hit_origin[i] - portal2_origin[i]
}

portal_shot(portal_pair_idbullet_trajectory_inhit_vector_inbullet_trajectory_outhit_vector_outfirst_portal_hit)

new 
Float:start_origin[3]
//if you have both portals origins stored in a single array then you will use cell index and the following code will be only 2 lines without "if"
if(first_portal_hit){
    for(new 
i=0i<3i++)
        
start_origin[i] = hit_vector_out[i] + portal2_origin[i]
}else{
    for(new 
i=0i<3i++)
        
start_origin[i] = hit_vector_out[i] + portal1_origin[i]
}

//start_origin is an origin of a point where bullet is supposed to come out of portal
//bullet_trajectory_out is a vector of bullet that comes out of portal 
Code you need to paste to your plugin:
PHP Code:

#define MAX_PORTAL_PAIRS 32
new Float:g_tm_traj[MAX_PORTAL_PAIRS+1][3][3]  //transformation matrix for bullet trajectory
new Float:g_tm_orig[MAX_PORTAL_PAIRS+1][3][3//transformation matrix for hit origin

new Float:g_tm_rev_traj[MAX_PORTAL_PAIRS+1][3][3//transformation matrix for bullet trajectory (reverse)
new Float:g_tm_rev_orig[MAX_PORTAL_PAIRS+1][3][3//transformation matrix for hit origin (reverse)

public vec3_exchange(Float:v1[3], Float:v2[3]){
    new 
Float:v[3]
    for(new 
i=0i<3i++){
        
v[i] = v1[i]
        
v1[i] = v2[i]
        
v2[i] = v[i]
    }
}

public 
vec3_mult(Float:v1[3], Float:v2[3], Float:vret[3]){
    
vret[0] = v1[1]*v2[2]-v1[2]*v2[1]
    
vret[1] = v1[2]*v2[0]-v1[0]*v2[2]
    
vret[2] = v1[0]*v2[1]-v1[1]*v2[0]
}

public 
vec3_normalize(Float:v[3]){
    new 
Float:len floatsqroot(v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
    for(new 
i=0i<3i++){
        
v[i] /= len
    
}
}

public 
matrix3_reverse(Float:m_in[3][3], Float:mret[3][3]){
    new 
i,j,k,maxiFloat:m[3][3], Float:ftmp
    
for(i=0i<3i++){
        for(
j=0j<3j++){
            if(
i==j)
                
mret[i][j] = 1.0
            
else
                
mret[i][j] = 0.0
            m
[i][j] = m_in[i][j]
        }
    }
    
    for(
i=0i<3i++){
        
maxi i
        
for(j=i+1j<3j++){
            if(
m[j][i] > m[maxi][i])
                
maxi j
        
}
        if(
maxi == i)
            continue
        
vec3_exchange(m[i],m[maxi])
        
vec3_exchange(mret[i], mret[maxi])
    }
                
    for(
i=0i<3i++){
        
ftmp m[i][i]
        for(
j=0j<3j++){
            
mret[i][j] /= ftmp
            m
[i][j] /= ftmp
        
}
        
        for(
j=0j<3j++){
            if(
i==j)
                continue
            
ftmp m[j][i]
            for(
k=0k<3k++){
                
mret[j][k] -= mret[i][k]*ftmp
                m
[j][k] -= m[i][k]*ftmp
            
}
        }            
    }
}

public 
matrix3_vec3_mult(Float:m[3][3], Float:v[3], Float:vret[3]){
    new 
ij
    
for(i=0i<3i++){
        
vret[i] = 0.0
        
for(j=0j<3j++){
            
vret[i] += m[i][j] * v[j]
        }
    }
}

public 
matrix3_mult(Float:m1[3][3], Float:m2[3][3], Float:mret[3][3]){
    new 
i,j,k
    
for(i=0;i<3;i++){
        for(
j=0;j<3;j++){
            
mret[i][j] = 0.0
            
for(k=0;k<3;k++)
                
mret[i][j] += m1[i][k]*m2[k][j]
        }
    }
}

public 
portal_transf_init(pair_idFloat:t1[3], Float:n1[3], Float:t2[3], Float:n2[3]){
    static 
Float:tm_refl_traj[3][3] = {{-1.0,0.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0}}
    static 
Float:tm_refl_orig[3][3] = {{1.0,0.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,-1.0}}
    
    new 
Float:m1[3][3], Float:m2[3][3], Float:mtmp1[3][3], Float:mtmp2[3][3]
    for(new 
i=0i<3i++){
        
m1[0][i] = t1[i]
        
m1[1][i] = n1[i]
        
m2[0][i] = t2[i]
        
m2[1][i] = n2[i]
    }
    
vec3_mult(m1[0],m1[1],m1[2])
    
vec3_mult(m2[0],m2[1],m2[2])
    for(new 
i=0i<3i++){
        
vec3_normalize(m1[i])
        
vec3_normalize(m2[i])
    }

    
matrix3_reverse(m2mtmp1)
    
    
matrix3_mult(mtmp1tm_refl_trajmtmp2)
    
matrix3_mult(mtmp2m1g_tm_traj[pair_id])

    
matrix3_mult(mtmp1tm_refl_origmtmp2)
    
matrix3_mult(mtmp2m1g_tm_orig[pair_id])    

    
matrix3_reverse(g_tm_traj[pair_id], g_tm_rev_traj[pair_id])
    
matrix3_reverse(g_tm_orig[pair_id], g_tm_rev_orig[pair_id])
}

public 
portal_shot(pair_idFloat:t[3], Float:o[3], Float:tret[3], Float:oret[3], bool:first_portal){
    if(
first_portal){
        
matrix3_vec3_mult(g_tm_traj[pair_id], ttret)
        
matrix3_vec3_mult(g_tm_orig[pair_id], ooret)
    }else{
        
matrix3_vec3_mult(g_tm_rev_traj[pair_id], ttret)
        
matrix3_vec3_mult(g_tm_rev_orig[pair_id], ooret)
    }
    for(new 
i=0i<3i++)
        
tret[i] = -tret[i]

__________________
Impossible is Nothing
Sylwester is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-17-2011 , 22:19   Re: Calculate trajectory and point of exit
Reply With Quote #16

Whoa, that's alot of stuff... next time I have time to script the portal plugin I'll see what I can use :} thanks.

Also, you're making functions that are already in xs.inc, what's up with that ?
__________________
Hunter-Digital is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 04-17-2011 , 23:56   Re: Calculate trajectory and point of exit
Reply With Quote #17

I never used xs before, so I just made what I needed and besides it would be only xs_vec_ normalize/cross and I also use not as a function sub/add/neg, but all those are simple compared to the rest.
__________________
Impossible is Nothing
Sylwester is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-18-2011 , 03:45   Re: Calculate trajectory and point of exit
Reply With Quote #18

Well, I just added your codes but results are weird, I only see the lines when one portal is einther on a slope or on a diagonal wall.

Okay so let me see if I get this right... all I have stored for portals is their origin and exit angles... so I think I can make the required things:
PHP Code:
        new Float:fTop[2][3]
        new 
Float:fToWall[2][3]

        
angle_vector(g_fPortalAngles[id][0], ANGLEVECTOR_UPfTop[0])
        
angle_vector(g_fPortalAngles[id][1], ANGLEVECTOR_UPfTop[1])

        
angle_vector(g_fPortalAngles[id][0], ANGLEVECTOR_FORWARDfToWall[0])
        
angle_vector(g_fPortalAngles[id][1], ANGLEVECTOR_FORWARDfToWall[1])

        
/* Towards wall */

        
fToWall[0][0] = -fToWall[0][0]
        
fToWall[0][1] = -fToWall[0][1]
        
fToWall[0][2] = -fToWall[0][2]

        
fToWall[1][0] = -fToWall[1][0]
        
fToWall[1][1] = -fToWall[1][1]
        
fToWall[1][2] = -fToWall[1][2]

        
portal_transf_init(idfTop[0], fToWall[0], fTop[1], fToWall[1]) 
That is where the portal is created and the other portal exists, I printed some messages, it triggers right.

I dunno if this is the problem or the shot code:
PHP Code:
    new Float:hit_origin[3]
    new 
Float:hit_vector_in[3]
    new 
Float:hit_vector_out[3]
    new 
Float:bullet_trajectory_in[3]
    new 
Float:bullet_trajectory_out[3]

    
hit_origin fTracerTarget // hit end from Ham_TraceAttack
    
bullet_trajectory_in fDir // direction from Ham_TraceAttack

    /* iPortal = the portal ID that's been shot, 0 = 1st portal, 1 = 2nd portal */

    
hit_vector_in[0] = hit_origin[0] - g_fPortalOrigin2[id][iPortal][0/* portal_origin2 = sprite's center origin */
    
hit_vector_in[1] = hit_origin[1] - g_fPortalOrigin2[id][iPortal][1]
    
hit_vector_in[2] = hit_origin[2] - g_fPortalOrigin2[id][iPortal][2]

    
portal_shot(idbullet_trajectory_inhit_vector_inbullet_trajectory_outhit_vector_out, (iPortal == 0))

    new 
Float:start_origin[3]

    
start_origin[0] = hit_vector_out[0] + g_fPortalOrigin2[id][iPortalOther][0]
    
start_origin[1] = hit_vector_out[1] + g_fPortalOrigin2[id][iPortalOther][1]
    
start_origin[2] = hit_vector_out[2] + g_fPortalOrigin2[id][iPortalOther][2]

    
//start_origin is an origin of a point where bullet is supposed to come out of portal
    //bullet_trajectory_out is a vector of bullet that comes out of portal  

    
fPortalOrigin start_origin

    fPortalTarget
[0] = fPortalOrigin[0] + (bullet_trajectory_out[0] * 8192.0)
    
fPortalTarget[1] = fPortalOrigin[1] + (bullet_trajectory_out[1] * 8192.0)
    
fPortalTarget[2] = fPortalOrigin[2] + (bullet_trajectory_out[2] * 8192.0)

    
line(fPortalOriginfPortalTarget, {0,0,255}) /* This draws a visible line */

    
engfunc(EngFunc_TraceLinefPortalOriginfPortalTarget, -1, -1tr)

    
get_tr2(trTR_vecEndPosfPortalTarget)

    
line(fPortalOriginfPortalTarget, {255,100,0}) /* This line goes to a TOTALLY different direction than the blue line */ 
I also printed messages on that one, it triggers but it doesn't seem to act right :/


PS: this is a quick addition to the code just to see if/how it works, I'll change the variable names/styles accordingly once I fully understand what's going on xD
__________________

Last edited by Hunter-Digital; 04-18-2011 at 03:49.
Hunter-Digital is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 04-18-2011 , 06:27   Re: Calculate trajectory and point of exit
Reply With Quote #19

My code works with any orientation.

Test everything with beams to make sure that all vectors are correct.
PHP Code:
//check if vectors used in portal_transf_init are correct: (for both portals)
line(portal_originportal_origin+top_vec*100, ...)
line(portal_originportal_origin+norm_vec*100, ...)

//check if input vectors for portal_shot are correct
//hit_vector_in - should point from portal origin, to where it was hit by bullet
line(portal_originportal_origin+hit_vector_in, ...)
//bullet_trajectory_in - should point in a direction from your screen to where portal was hit by bullet
//I assumed it's normalized, so multiply it by some value (ex. 100)
line(portal_origin+hit_vector_inportal_origin+hit_vector_in bullet_trajectory_in*100, ...)

//check output vectors
//hit_vector_out - compared to input, it should be reflected across plane created from vectors top_vec and norm_vec 
line(exit_portal_originexit_portal_origin+hit_vector_out, ...)
//bullet_trajectory_out - compared to input, it should be reflected across plane created from vectors norm_vec and (top_vec x norm_vec)
line(exit_portal_origin+hit_vector_outexit_portal_origin+hit_vector_out bullet_trajectory_out*100, ...) 
__________________
Impossible is Nothing

Last edited by Sylwester; 04-18-2011 at 06:30.
Sylwester 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 20:11.


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