Vecmath
From EventScripts Community Encyclopedia
|
[edit] Module: vecmath[edit] Module OverviewEventScripts version: 2.0 or greater [edit] Table of Contents
[edit] DescriptionVecmath provides a powerful way to handle and manipulate coordinates and vectors, being compatible with how the Source engine handles them. [edit] Quick ExampleShow kill beam: import es import vecmath import effectlib def player_death(event_var): # save the userids to local variables: victim = int(event_var['userid']) attacker = int(event_var['attacker']) if attacker: # get the player locations as vecmath.vectors for better manipulation victim_location = vecmath.vector(es.getplayerlocation(victim)) attacker_location = vecmath.vector(es.getplayerlocation(attacker)) # check attacker crouching state and adjust z coordinate accordingly attacker_flags = int(es.getplayerprop(attacker, 'CBasePlayer.m_fFlags')) if attacker_flags & 2: #attacker is crouching attacker_location['z'] += 44 else: #attacker is standing attacker_location['z'] += 64 # draw a beam using effectlib # note that you can do simple vector math inline, like adding values: effectlib.drawLine(attacker_location, victim_location + (0,0,96/2), seconds=5) [edit] Module Content[edit] Classes
[edit] Methods
>>> print vecmath.angle((10,20,30), (-20, 50, 30)) 0.742111027349 >>> print vecmath.angle((1,0,0), (0,1,0))/math.pi*180 90.0
>>> print vecmath.angles((1,0,0), (0,1,0)) [None, None, 1.5707963267948966]
>>> print vecmath.cp((1,0,0), (0,1,0)) 0.0,0.0,1.0
>>> print vecmath.ip((5,3,2), (0,5,-5)) 5 >>> print vecmath.ip((1,1,0), (-1,1,0)) 0
>>> print vecmath.length((3,0,4)) 5.0
>>> print vecmath.normalize(vecmath.vector("10,10,10")) 0.57735026919,0.57735026919,0.57735026919
>>> print vecmath.setlength(vecmath.vector([3,4,0]), 10) 6.0,8.0,0.0 [edit] Helper methodsThese methods are not directly vector manipulation, but rather to help some common tasks related to coordinates and vectors.
def player_death(event_var): victim = int(event_var['userid']) attacker = int(event_var['attacker']) if attacker: victim_location = vecmath.vector(es.getplayerlocation(victim)) attacker_location = vecmath.vector(es.getplayerlocation(attacker)) distance = vecmath.distance(victim_location, attacker_location) es.tell(victim,'You were killed from %f m'%(distance*0.0254))
>>> vecmath.isbetweenRect((10,10,10), (0,0,0), (20,20,20)) True >>> vecmath.isbetweenRect((10,30,10), (20,0,20), (0,20,0)) False
[edit] See Also |
|
