예제 #1
0
def draw():
    camera = scene.objects["Camera"]
    string = "BondCraft"
    ###draws bonds and changes text before frame load
    atoms = gdict["atoms"].copy()
    for atom in gdict["atoms"]:
        ###searches for everything connected to it and draws the bonds
        
        #prevents two line draws
        atoms.remove(atom)
        atom.bond.draw_bonds(atoms)
    for molecule in gdict["molecules"]:
        molecule.draw_text()
    for texture in gdict["textures"]:
        texture.refresh(True)
    if camera["laser"]:
        crosshairs = scene.objects["Crosshairs"]
        start = camera.worldPosition + camera.getAxisVect((1,-1,0))
        end = camera.worldPosition - camera.getAxisVect((0,0,1))
        
        render.drawLine(start,end,[0,1,0])
        obj,point, normal = camera.rayCast(crosshairs,None,2000)
        if obj:
            render.drawLine(point,point + normal * 10000,[0,1,0])
            obj.applyForce(-100 * normal)
예제 #2
0
    def debug_node_connections(self):

        for node in self.nodes:

            for neighbor in node.neighbors:

                render.drawLine(node.position, neighbor.position, [1, 0, 0])
예제 #3
0
    def draw_doubles(self):
        # draw and align p bonds in doubles
        particle = self.particle

        if "doubles" in particle and particle["doubles"]:
            for i, bond in enumerate(particle["doubles"]):
                if bond in self.queue:
                    self.draw_line(bond, [0.5, 1, 1])

                bondvector = bond.worldPosition - particle.worldPosition
                pos = particle.worldPosition

                for index, atom in enumerate(bond["doubles"]):
                    if particle is atom:
                        j = index
                if i == 0 and j == 0:
                    yaxis = particle.getAxisVect((0, 1, 0))
                    pbond = yaxis - yaxis.project(bondvector)
                    bond.alignAxisToVect(pbond, 1, 0.1)
                    if len(particle["doubles"]) == 1:
                        # checks if pbonds are in y axis
                        self.inverted = False
                else:
                    xaxis = particle.getAxisVect((1, 0, 0))
                    pbond = xaxis - xaxis.project(bondvector)
                    bond.alignAxisToVect(pbond, 0, 0.1)
                    if len(particle["doubles"]) == 1:
                        self.inverted = True

                render.drawLine(pos - pbond * 10, pos + pbond * 10,
                                [0.5, 1, 1])
예제 #4
0
def main(cont):
    own = cont.owner
    scene = logic.getCurrentScene()
    ray = cont.sensors["Ray"]
    #detector = cont.sensors["Detector"]
    reload = cont.sensors["Reload"]
    
    if reload.positive and own["Magazines"] > 0:
        own["Magazines"] += -1
        logic.sendMessage("Clips", str(own["Magazines"]))
        own["Bullets"] = 100
        logic.sendMessage("Ammo", "100") 
        cont.activate(cont.actuators["Reload"])
        
        
    if cont.sensors["Shoot"].positive:

        if own["Bullets"]>0:
            own["Bullets"] += -1
            logic.sendMessage("Ammo", str(own["Bullets"]))
            if ray.positive:
                #Add the laser targeting pointer to the scene
                own["Dist"] = own.getDistanceTo(ray.hitObject)
                render.drawLine(own.worldPosition,ray.hitPosition,[100,255,0])              
                hitObject = ray.hitObject
                bulletForce= scene.addObject("BulletForce",own,3)  
                bulletForce.worldPosition = Vector(ray.hitPosition) +(Vector(ray.hitNormal)*0.01) 
                #bulletForce.worldPosition = cont.ray.worldPosition
                bulletHole= scene.addObject("BulletHole",own,200)       
                #position the bullet baed on the ray, give a margin factor due to rendering collision
                bulletHole.worldPosition = Vector(ray.hitPosition) +(Vector(ray.hitNormal)*0.01)
                bulletHole.alignAxisToVect(ray.hitNormal,2)

            cont.activate(cont.actuators["Fire"])
            #cont.activate(cont.actuators["MuzzleFlash"])
예제 #5
0
    def debug_node_connections(self):

        for node in self.nodes:

            for neighbor in node.neighbors:

                render.drawLine(node.position, neighbor.position, [1, 0, 0])
예제 #6
0
    def _drawMarker(self):

        #check for selected_flag and draw marker if needed
        if self.markerFlag:
            delta = Vector((0, 0, 1))
            delta.magnitude = 2.5
            render.drawLine(self.worldPosition, self.worldPosition + delta,
                            [255, 0, 0])
예제 #7
0
def main():

    cont = logic.getCurrentController()
    owner = cont.owner
    
    ray = cont.sensors["Ray"]
    
    if ray.positive:
        render.drawLine(owner.worldPosition, ray.hitPosition, [1,0,0])
예제 #8
0
def draw_circle(point, orientation, size, fraction=1.0, steps=36, colour=[1, 0, 0]):
    last_point = None
    shift = (2 * pi / steps)

    for step in range(int(steps / fraction) + 1):
        index = step * shift
        x = sin(index) * size
        z = cos(index) * size
        step_point = Vector((x, 0, z))

        step_point.rotate(orientation)
        step_point += point

        if last_point:
            render.drawLine(last_point, step_point, colour)

        last_point = step_point
예제 #9
0
def ribbonCheck():
    ray = logic.car.sensors["ribbonRay"]
    if logic.car["onGround"] == True:
        if ray.positive:
            logic.car["speedMult"]  = 1.0
            # Show ray when testing
            from bge import render as r
            r.drawLine(logic.car.worldPosition, ray.hitPosition, [1,0,0])
        #  Shape specific modifier when off the ribbons
        elif logic.car["activeShape"]  == 1:
            logic.car["speedMult"]  = 0.75
        elif logic.car["activeShape"]  == 2:
            logic.car["speedMult"]  = 1.0
        elif logic.car["activeShape"]  >= 5:
            logic.car["speedMult"]  = 0.25
        else:
            logic.car["speedMult"]  = 0.5
예제 #10
0
def draw_box(point, orientation, width=1, height=1, length=1, colour=[1, 1, 1]):
    axis_values = [-.5, .5]

    points = [Vector((x * width, y * length, z * height)) for x, y, z in product(*tee(axis_values, 3))]

    for point_a in points:
        for point_b in points:
            if point_a is point_b:
                continue

            if len(set(point_a).intersection(point_b)) != 2:
                continue

            a = point_a.copy()
            b = point_b.copy()

            a.rotate(orientation)
            b.rotate(orientation)

            render.drawLine(a + point, b + point, colour)
예제 #11
0
    def draw_triples(self):
        particle = self.particle

        if "triple" in particle and particle["triple"]:

            bond = particle["triple"]

            if bond in self.queue:
                self.draw_line(bond, [0, 1, 1])

            bondvector = bond.worldPosition - particle.worldPosition
            pos = particle.worldPosition

            yaxis = particle.getAxisVect((0, 1, 0))
            pbond = yaxis - yaxis.project(bondvector)
            bond.alignAxisToVect(pbond, 1, 0.1)
            render.drawLine(pos - pbond * 10, pos + pbond * 10, [0, 1, 1])

            xaxis = particle.getAxisVect((1, 0, 0))
            pbond2 = xaxis - xaxis.project(bondvector)
            bond.alignAxisToVect(pbond, 1, 0.1)
            render.drawLine(pos - pbond2 * 10, pos + pbond2 * 10, [0.5, 1, 1])
예제 #12
0
def draw_box(a, b):
    color = (1,1,1)
    
    a = gui_space(a)
    b = gui_space(b)

    p1 = Vector((a.x, a.y)).to_3d()
    p2 = Vector((b.x, a.y)).to_3d()
    p3 = Vector((b.x, b.y)).to_3d()
    p4 = Vector((a.x, b.y)).to_3d()


    render.drawLine(p1, p2, color)
    render.drawLine(p2, p3, color)
    render.drawLine(p3, p4, color)
    render.drawLine(p4, p1, color)
예제 #13
0
def draw_square_pyramid(point, orientation, angle=45, depth=1, colour=[1, 1, 1], pyramid=True, incline=True):
    points = []
    axis_values = [-1, 1]

    hypotenuse = depth if depth else 1
    angle = radians(angle)

    for x in axis_values:
        for z in axis_values:
            x_coordinate = hypotenuse * sin(angle) * x
            if incline:
                z += 1
            z_coordinate = hypotenuse * cos(angle) * z
            point_a = Vector((x_coordinate, depth, z_coordinate))
            points.append(point_a)

    for point_a in points:
        for point_b in points:

            if point_a is point_b:
                continue

            same_axis = [True for i in range(3) if point_a[i] == point_b[i]]

            if len(same_axis) < 2:
                continue

            a = point_a.copy()
            a.rotate(orientation)

            b = point_b.copy()
            b.rotate(orientation)

            render.drawLine(a + point, b + point, colour)

            if pyramid:
                render.drawLine(point, b + point, colour)
예제 #14
0
def draw_arrow(point, orientation, length=1.5, branch_length=0.4, angle=30, colour=[1, 0, 0]):
    left = Vector((sin(radians(angle)), -cos(radians(angle)), 0))
    right = Vector((-sin(radians(angle)), -cos(radians(angle)), 0))

    left.rotate(orientation)
    right.rotate(orientation)

    left.length = branch_length
    right.length = branch_length

    direction = Vector((0, 1, 0)) * length
    direction.rotate(orientation)

    render.drawLine(point, point + direction, colour)
    render.drawLine(point + direction, point + direction + right, colour)
    render.drawLine(point + direction, point + direction + left, colour)
예제 #15
0
def draw_vec(source, vec, color=(0, 255, 0)):
	render.drawLine(source, source + vec, color)	
예제 #16
0
 def draw_axis(axis):
     head_vec = (axis * size) + location
     tail_vec = (-axis * size) + location
     render.drawLine(head_vec, tail_vec, (0, 0, 255))
예제 #17
0
 def draw_line(self, second, color):
     render.drawLine(self.particle.worldPosition, second.worldPosition,
                     color)
예제 #18
0
def raycast_line(anglevect,
                 anglewidth,
                 topos,
                 frompos=None,
                 raynum=3,
                 center=1,
                 from_scalar=1.0,
                 to_scalar=1.0,
                 dist=0,
                 prop='',
                 face=1,
                 xray=1,
                 poly=0,
                 obj=None,
                 debug=False,
                 objdebug=None):
    """
    Casts several rays in a line, starting from frompos and going to topos, and then iterating along the line indicated by anglevect.

    The function returns a dictionary, consisting of four items:

    'rays': The return of the raycasts (either a hit, or an empty list, depending on what the rays hit; the output from a raycast() function, basically)
    'ray_end': The ending position of the last successful raycast, or None if there wasn't a successful raycast
    'ray_start' The starting position of the last successful raycast, or None if there wasn't a successful raycast
    'offset' The offset between the starting point of the successful ray cast and the provided starting ray cast position. Useful in case
    you want to reorient the position of an object from the ray cast (i.e. move to contact point), but still want to use the object's
    center position (don't move to where the ray hit, but move to where it hit relative to the object's center position).

    anglevect = The angle that the rays should be cast on.

    anglewidth = How wide the rays should be cast in Blender Units (i.e. a value of 1 means that from the left-most ray to the right-most ray is 1 BU).

    raynum = number of rays to cast

    center = if the rays should be centered on the anglevect Vector or not
    (i.e. treat frompos and topos as the center ray, or as the ray starting from anglevect)

    from / to_scalar = A percentage of the width to stretch (i.e. to have a wider end "edge" than starting "edge")

    dist = distance of each raycast; defaults to 0, which equals the distance between the from position and end position of the vectors

    prop = property to check for with each raycast; defaults = '', which detects any object

    face = whether to return a face if the ray hits something

    xray = whether to go through objects that don't match the property criteria (objects that don't have the property
    named by 'prop')

    poly = whether to return the polygon / UV hit; check the api documentation for more information

    obj = object to use for the ray casts; if left set to default (None), then it will use whatever object is calling
    the function.

    objdebug = default None; an object to use for debugging

    -----

    Okay, so now what is this actually used for? Mainly, to do kind of a 'ray cast wall'. An example would be if you
    want to cast multiple rays for a character in a platforming game. You would do this instead of using the built-in Bullet
    physics engine to handle gravity and collisions so that you could have partially impassable objects, for example.

    An example of using this function would look something like this:

    width = 0.6

    frompos = obj.worldPosition.copy()
    topos = frompos.copy()
    topos.z -= 1

    dist = 0.5 + abs(obj.worldLinearVelocity.z)

    ground = bghelper.RaycastLine(obj.worldOrientation.col[0], width, topos, frompos, 3, 1, dist, 'ground', debug = 1)[0]

    This will cast three rays in a straight line, with the center one being below the object's world position. Debug is on,
    so it will draw the lines visibly onscreen (barring a bug with the render engine about drawing lines with overlay or
    underlay scenes activated). It will return an object with the 'ground' property, if it finds one. If so, then it will
    return a list consisting of the successful raycast and its starting and ending position (i.e. [ray, topos, frompos]).
    Otherwise, it will return a list consisting of a list with a None in it, and two other Nones (i.e. [[None], None, None]).
    This way you can check: if bghelper.LineRayCast()[0] == None to see if the ray was successful (or any other index of the
    returned list).

    """

    anglevect = anglevect.copy()
    anglevect.magnitude = anglewidth

    if obj is None:
        obj = logic.getCurrentController().owner
    if frompos is None:
        frompos = obj.worldPosition.copy()

    if not isinstance(topos, mathutils.Vector):
        topos = mathutils.Vector(topos)
    if not isinstance(frompos, mathutils.Vector):
        frompos = mathutils.Vector(frompos)

    rtp = topos.copy()
    rfp = frompos.copy()

    rn = raynum - 1

    if rn <= 0:
        rn = 1

    ray = [None]

    if center:
        rtp -= (anglevect / 2) * to_scalar
        rfp -= (anglevect / 2) * from_scalar

    output = {}

    for x in range(raynum):

        ray = obj.rayCast(rtp, rfp, dist, prop, face, xray, poly)

        if debug:

            to = rtp - rfp
            to.magnitude = dist

            if ray[0]:
                render.drawLine(rfp, rfp + to, [0, 1, 0])
            else:
                render.drawLine(rfp, rfp + to, [1, 0, 0])

        if objdebug:

            to = rtp - rfp

            sce = logic.getCurrentScene()

            db = sce.addObject(objdebug, obj, 1)
            db.worldPosition = rfp
            db.alignAxisToVect(to, 0)
            db.worldScale = [to.magnitude, 1, 1]

            if ray[0]:
                db.color = [0, 1, 0, 1]
            else:
                db.color = [1, 0, 0, 1]

        if ray[0] is not None:

            if output == {}:
                output["rays"] = ray
                output["ray_start"] = rfp
                output["ray_end"] = rtp
                output["offset"] = rfp - frompos
            else:

                if (rfp - ray[1]).magnitude < (output['ray_end'] -
                                               output['rays'][1]).magnitude:
                    # Only overwrite previous raycast results if this one is closer
                    output["rays"] = ray
                    output["ray_start"] = rfp
                    output["ray_end"] = rtp
                    output["offset"] = rfp - frompos

        av = anglevect / rn

        rtp += av * to_scalar
        rfp += av * from_scalar

        # if not converge:
        #	rfp += av

    if output:
        return output

    return {'rays': ray, 'ray_start': None, 'ray_end': None, 'offset': None}
예제 #19
0
def main():

    scene = bge.logic.getCurrentScene()

    sumoRed = scene.objects['SumoRed']
    sumoBlue = scene.objects['SumoBlue']

    contRed = sumoRed.controllers['Or']
    contBlue = sumoBlue.controllers['Or']

    sensRed = contRed.sensors['Ray']
    sensRed1 = contRed.sensors['Ray1']
    sensRed2 = contRed.sensors['Ray2']
    sensBlue = contBlue.sensors['Ray']
    sensBlue1 = contBlue.sensors['Ray1']
    sensBlue2 = contBlue.sensors['Ray2']

    actuRed = contRed.actuators['Motion']
    actuBlue = contBlue.actuators['Motion']

    if sensRed.positive:
        render.drawLine(sumoRed.worldPosition, sensRed.hitPosition,
                        [255, 0, 0])
    if sensRed1.positive:
        render.drawLine(sumoRed.worldPosition, sensRed1.hitPosition,
                        [255, 0, 0])
    if sensRed2.positive:
        render.drawLine(sumoRed.worldPosition, sensRed2.hitPosition,
                        [255, 0, 0])

    if sensBlue.positive:
        render.drawLine(sumoBlue.worldPosition, sensBlue.hitPosition,
                        [0, 0, 255])
    if sensBlue1.positive:
        render.drawLine(sumoBlue.worldPosition, sensBlue1.hitPosition,
                        [0, 0, 255])
    if sensBlue2.positive:
        render.drawLine(sumoBlue.worldPosition, sensBlue2.hitPosition,
                        [0, 0, 255])

    posRed = sensRed.hitPosition
    posRed1 = sensRed1.hitPosition
    posRed2 = sensRed2.hitPosition
    posBlue = sensBlue.hitPosition
    posBlue1 = sensBlue1.hitPosition
    posBlue2 = sensBlue2.hitPosition

    xRed = (posRed[0] * sumoRed['prop0']) + (posRed[1] * sumoRed['prop1']) + (
        posRed[2] * sumoRed['prop2']
    ) + (posRed1[0] * sumoRed['prop3']) + (posRed1[1] * sumoRed['prop4']) + (
        posRed1[2] * sumoRed['prop5']) + (posRed2[0] * sumoRed['prop6']) + (
            posRed2[1] * sumoRed['prop7']) + (
                posRed2[2] * sumoRed['prop8']) + sumoRed['bias1']
    yRed = (posRed[0] * sumoRed['prop9']) + (posRed[1] * sumoRed['prop10']) + (
        posRed[2] * sumoRed['prop11']
    ) + (posRed1[0] * sumoRed['prop12']) + (posRed1[1] * sumoRed['prop13']) + (
        posRed1[2] * sumoRed['prop14']) + (posRed2[0] * sumoRed['prop15']) + (
            posRed2[1] * sumoRed['prop16']) + (
                posRed2[2] * sumoRed['prop17']) + sumoRed['bias2']

    xBlue = (posBlue[0] * sumoBlue['prop0']) + (
        posBlue[1] * sumoBlue['prop1']) + (posBlue[2] * sumoBlue['prop2']) + (
            posBlue1[0] *
            sumoBlue['prop3']) + (posBlue1[1] * sumoBlue['prop4']) + (
                posBlue1[2] *
                sumoBlue['prop5']) + (posBlue2[0] * sumoBlue['prop6']) + (
                    posBlue2[1] * sumoBlue['prop7']) + (
                        posBlue2[2] * sumoBlue['prop8']) + sumoBlue['bias1']
    yBlue = (posBlue[0] * sumoBlue['prop9']) + (
        posBlue[1] * sumoBlue['prop10']
    ) + (posBlue[2] *
         sumoBlue['prop11']) + (posBlue1[0] * sumoBlue['prop12']) + (
             posBlue1[1] *
             sumoBlue['prop13']) + (posBlue1[2] * sumoBlue['prop14']) + (
                 posBlue2[0] * sumoBlue['prop15']) + (
                     posBlue2[1] * sumoBlue['prop16']) + (
                         posBlue2[2] * sumoBlue['prop17']) + sumoBlue['bias2']

    actuRed.linV = [xRed, yRed, 0]
    actuBlue.linV = [xBlue, yBlue, 0]
예제 #20
0
 def draw_text(self):
     if self.text.text:
         render.drawLine(self.center.worldPosition, self.text.worldPosition,
                         [1, 1, 1])
예제 #21
0
파일: mouse.py 프로젝트: folkrav/rts-b51
 def draw_square():
     render.drawLine((self.x1, self.y1, z), (self.x2, self.y1, z), (1, 0, 0))
     render.drawLine((self.x1, self.y1, z), (self.x1, self.y2, z), (1, 0, 0))
     render.drawLine((self.x2, self.y2, z), (self.x2, self.y1, z), (1, 0, 0))
     render.drawLine((self.x2, self.y2, z), (self.x1, self.y2, z), (1, 0, 0))
예제 #22
0
파일: car.py 프로젝트: rodarima/blender
def draw_vec(pos, vec, color=[1,1,1]):
    render.drawLine(pos, pos+vec, color)
예제 #23
0
파일: Player.py 프로젝트: Chiur/tankbot
	def Laser():
		ray = obj.rayCast(aim, rInit, 500, '', 1, 0)[1]
		hitPos = [ray[0], ray[1], ray[2]]
		render.drawLine(rInit.worldPosition, hitPos, [1.0, 0.0, 0.0])
		scene.objects['LaserPoint'].worldPosition = (mathutils.Vector((hitPos[0], hitPos[1], hitPos[2])) + (obj.rayCast(aim, rInit, 500, '', 1, 0)[2]*.25))
예제 #24
0
def draw_line(v0, v1):
    render.drawLine(v0, v1, (1, 1, 1))