Raised This Month: $ Target: $400
 0% 

Getting a normal plane from a vector's tip


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-02-2011 , 15:56   Getting a normal plane from a vector's tip
Reply With Quote #1

After searching a bit i found out that the only way to retrieve a normal plane from a vectors tip is to use traceline and the get the normal plane by using (TR_vecnormal... etc)
But what if i m not using traceline (and dont want to!) and i want to get a normal plane from a vector's tip for eg:
I have this code:
Code:
static forvec[3]; // Get a forward vector in the direction of player's aim velocity_by_aim(player_id, 15, forvec)
now the forvec variable contains a vector of lenght 15 units which is pointing in the direction of player's aim, now i want to get a normal plane at the tip of the vector such that the plane will be infront of the player (in other words it will be perpendicular to the forvec)

The question is how can i get the normal to this vector without using the traceline function ?
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-02-2011 , 17:03   Re: Getting a normal plane from a vector's tip
Reply With Quote #2

What exactly are you trying to do?

There is no normal vector for a vector. The vector you have is the normal for the plane.
__________________
fysiks is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 07-02-2011 , 17:08   Re: Getting a normal plane from a vector's tip
Reply With Quote #3

PHP Code:
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 
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]
}

new 
Float:forvec[3]; 

// Get a forward vector in the direction of player's aim 
velocity_by_aim(player_id15forvec)

new 
Float:hvec[3], Float:vvec[3]
hvec[0] = forvec[1]
hvec[1] = forvec[0]
hvec[2] = 0.0

vec3_mult
(forvechvecvvec
First you make horizontal vector and then multiply both of them to get vertical vector.
Use vec3_normalize to change length of any vector to 1.

It will work assuming that forvec[1] and forvec[0] will never be equal 0.0 at the same time (I'm not sure if that can happen when aiming vertically up or down). Otherwise it may be safer to do it using angles.
__________________
Impossible is Nothing
Sylwester is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-03-2011 , 06:37   Re: Getting a normal plane from a vector's tip
Reply With Quote #4

Nvm i found another way of doing it. (angle_vector)
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
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:17.


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