Vecmath.vector
From EventScripts Community Encyclopedia
|
[edit] Class: vecmath.vectorNote: Requires EventScripts 2.0
Module: vecmath [edit] Overview[edit] DescriptionA class representing a vector object that has methods for doing simple and complex vector mathematical operations as well as importing and exporting the data in multiple formations such as vectorstrings or lists. [edit] Quick ExampleAn example script showing "attract" effect. import es import vecmath push_modifier = es.ServerVar('push_modifier', 0.5) def load(): es.doblock('corelib/noisy_on') def unload(): es.doblock('corelib/noisy_off') def bullet_impact(event_var): userid = int(event_var['userid']) # vectors can be constructed from tuples and lists: bullet_location = vecmath.vector(( event_var['x'], event_var['y'], event_var['z'] )) # vectors can also be constructed from vectorstrings player_location = vecmath.vector( es.getplayerlocation(userid) ) # you can do simple calculations with vectors directly: push_vector = (bullet_location - player_location) * float(push_modifier) # vectors can be quickly returned as vectorstrings also: es.setplayerprop(userid, 'CBasePlayer.localdata.m_vecBaseVelocity', str(push_vector) ) [edit] Methods
myvector = vecmath.vector( [-2, 0, 1.5] )
mylist = list(myvector)
mydict = myvector.getdict()
es.setplayerprop( userid, 'CBaseEntity.m_vecOrigin', str(myvector) )
es.server.queuecmd( 'es_xsetpos %d %s'%(userid, myvector.getstr(' ')) )
es.dbgmsg(0, '%d vector components'% len(myvector))
sumvector = vector1 + vector2
diffvector = vector1 - vector2
doublevector = myvector * 2
halfvector = myvector / 2
xvalue = myvector['x'] yvalue = myvector[1]
myvector[0] = 0 myvector[1] = 0 myvector['z'] += 64
oppositevector = -myvector
backupvector = myvector.copy() # Note, the above is NOT the same as backupvector = myvector
# These two are exactly the same functionality: product = myvector.ip(vector2) product = vecmath.ip(myvector, vector2)
# These two are exactly the same functionality: pervector = myvector.cp(vector2) pervector = vecmath.cp(myvector, vector2)
# These two are exactly the same functionality: angle = myvector.angle(vector2) angle = vecmath.angle(myvector, vector2)
# These two are exactly the same functionality: angles = myvector.angles(vector2) angles = vecmath.angles(myvector, vector2)
distance = (vector2 - vector1).length()
shortvector = myvector.setlength(2)
# These two are the same: direction = myvector.setlength(1) direction = myvector.normalize() [edit] AttributesNone are directly usable. Get and set component values with vector[index] notation. [edit] Notes(None) [edit] See Also |
|
