Hi again,
have some trouble to set up an dynamically render.drawLine - position the selection Circle at end of line for each circle (get only one position)
some Demo:
choice_test.blend (647 KB)
code:
'''
dynamically draw_line by the_cannibal
'''
from bge import logic, render
#from mathutils import * #nicht diesmal :)
def xrange(obj, start, stop, step):
if not "xrange" in obj:
obj["xrange"] = start
if obj["xrange"] < stop:
obj["xrange"] += step
return (obj["xrange"], False)
else:
obj["xrange"] = start
return (obj["xrange"], True)
def get_points(own, scene_objects, name):
point_list = []
for a in scene_objects:
if name in str(a):
point_list.append(str(a))
return sorted(point_list)
def draw_function(own, scene_obj, s_c_list, point1, point2):
if own["reverse"] == 0:
counter, indicator = xrange(own, 0.0, 1.0, 0.005)
elif own["reverse"] == 1:
counter, indicator = xrange(own, 0.0, 1.0, 0.005)
counter = ((counter/-1) +1)
if indicator == False:
draw_point = point1.lerp(point2, counter)
render.drawLine(draw_point, point2, (1.0, 1.0, 1.0))
for sc in s_c_list:
scene_obj.from_id(sc).worldPosition = draw_point
#print(draw_point)
return False
else:
return True
def draw_f_t(own, scene_obj, s_c_list, point1, point2, point3):
if own["reverse"] == 0:
if own["draw_system"] == 0:
back_drawn_1 = draw_function(own, scene_obj, s_c_list, point1, point2)
draw_line(point2, point3)
if back_drawn_1 == True:
own["draw_system"] = 1
if own["draw_system"] == 1:
back_drawn_2 = draw_function(own, scene_obj, s_c_list, point2, point3)
if back_drawn_2 == True:
own["draw_system"] = 2
return True
elif own["reverse"] == 1:
if own["draw_system"] == 0:
back_drawn_1 = draw_function(own, scene_obj, s_c_list, point2, point3)
if back_drawn_1 == True:
own["draw_system"] = 1
if own["draw_system"] == 1:
draw_line(point3, point2)
back_drawn_2 = draw_function(own, scene_obj, s_c_list, point1, point2)
if back_drawn_2 == True:
own["draw_system"] = 2
return True
def draw_line(point1, point2):
render.drawLine(point1, point2, (1.0, 1.0, 1.0))
def add_circle(own, scene_obj, add_obj, points, count):
if not "state_once" in own:
own["state_once"] = 0
own["selection_obj_list"] = []
if not own["state_once"] == count:
for a in points:
if "_C" in a:
new_obj = add_obj("choice_Circle", None, 0)
new_obj.worldPosition = scene_obj[a].worldPosition
own["selection_obj_list"].append(id(new_obj))
own["state_once"] += 1
return own["selection_obj_list"]
def draw_selection_circle(cont):
own = cont.owner
scene = logic.getCurrentScene()
scObj = scene.objects
addObj = scene.addObject
num_0 = cont.sensors["num_0"].positive
num_1 = cont.sensors["num_1"].positive
grouplist = ["main_color_Point", "spoiler_Point", "exhaust_Point", "suspension_Point", "hover_wheel_Point", "under_light_Point"]
# grouplist.remove("spoiler_Point")
if num_0:
own["acti"] = 0
elif num_1:
own["acti"] = 1
own["draw_system"] = 0
if own["acti"] == 0:
for p in grouplist:
points = get_points(own, scObj, p)
selection_circle_list = add_circle(own, scObj, addObj, points, len(grouplist))
point_1 = scObj[points[0]].worldPosition
point_2 = scObj[points[1]].worldPosition
point_3 = scObj[points[2]].worldPosition
stt = draw_f_t(own, scObj, selection_circle_list, point_1, point_2, point_3)
if stt == True:
own["acti"] = 1
else:
for p in grouplist:
points = get_points(own, scObj, p)
point_1 = scObj[points[0]].worldPosition
point_2 = scObj[points[1]].worldPosition
point_3 = scObj[points[2]].worldPosition
draw_line(point_1, point_2)
draw_line(point_2, point_3)