Jun 182011
 

To aid my never-ending quest to remember the things I learn about programming – I’ve decided to make this post as a place to leave little functions and crap that I always forget and are way too stupid to have to figure out more than once.

It’ll grow, I’m constantly learning things I forgot.

######################################
################ WARNING: ############
############## STUPID CODE ###########
######################################
#### PLEASE DO NOT LEARN ANYTHING ####
######################################

def sbh_within(x,y,d):
###---CHECK IF x-d <= y <= x+d
 if x-d <= y and x + d >= y:
 return True
 else: return False

def sbh_center2d(Ax, Ay, Bx, By):
###---GET CENTER BETWEEN TWO 2D POINTS
    Cx = Ax + (Bx - Ax)/2
    Cy = Ay + (By - Ay)/2
    return Cx, Cy

def sbh_dist2d(Ax, Ay, Bx, By):
###---GET DISTANCE BETWEEN TWO 2D POINTS
    Cx = Bx - Ax
    Cy = By - Ay
    return Cx, Cy

def sbh_hypot(a, b):
    c = sqrt(a*a+b*b)
    return c

def sbh_getAngle2d(A, B):
###---RETURNS HEADING FROM A TO B
    opp = B.y - A.y
    adj = B.x - A.x
    hyp = hypot(opp, adj)
    s = asin(opp/hyp)
    c = acos(adj/hyp)
    if B.x >= A.x and B.y >= A.y: r = s-pi/2
    if B.x <= A.x and B.y >= A.y: r = c-pi/2
    if B.x <= A.x and B.y <= A.y: r = (pi/2)-s
    if B.x >= A.x and B.y <= A.y: r = -(pi/2)-c
    return r

def sbh_si(num):
###---RETURNS SIGN OF A NUMBER
    if num>=0: return 1
    if num<0: return -1

def sbh_wrapAng(x):
###---WRAP EULER ANGLES (-pi <= a <= pi)
    p360 = pi*2
    f = x - (p360)*floor((x+pi)/p360)
    return f

—OTHER BLENDER PYTHON API NOTES—
Most of these are issues I’ve run into with and without solutions.

- Can not add game logic bricks via. python API. [SOLVED]
- Can not access poseLib data with bpy.data, only bpy.ops functions and none to read pose data.
- Voxel data files: .raw/.bvox – can’t use multi-frame data. Only 64x64x64 grid size works.

- active object – accessible with “bpy.context.scene.objects.active = ob”