def createConstraint(self, carObj):
        car_PhysicsID = carObj.getPhysicsId()
        vehicle_constraint = PhysicsConstraints.createConstraint(
            car_PhysicsID, 0, 11)
        self.vehicle_constraint = vehicle_constraint

        constraint_ID = vehicle_constraint.getConstraintId()
        vehicleWrapper = PhysicsConstraints.getVehicleConstraint(constraint_ID)

        self.wrapper = vehicleWrapper

        return vehicleWrapper
Exemplo n.º 2
0
def carHandler():
    vehicle = PC.getVehicleConstraint(G.car["cid"])

    ## calculate speed by using the back wheel rotation speed ##
    S = vehicle.getWheelRotation(2) + vehicle.getWheelRotation(3)
    G.car["speed"] = (S - G.car["dS"]) * 27.0

    ## apply engine force ##
    vehicle.applyEngineForce(G.car["force"], 0)
    vehicle.applyEngineForce(G.car["force"], 1)
    vehicle.applyEngineForce(G.car["force"], 2)
    vehicle.applyEngineForce(G.car["force"], 3)

    ## calculate steering with varying sensitivity ##
    if math.fabs(G.car["speed"]) < 15.0: s = 5.0
    elif math.fabs(G.car["speed"]) < 28.0: s = 4.5
    elif math.fabs(G.car["speed"]) < 40.0: s = 4.0
    else: s = 4.5

    ## steer front wheels
    vehicle.setSteeringValue(G.car["steer"] * s, 0)
    vehicle.setSteeringValue(G.car["steer"] * s, 1)

    ## slowly ease off gas and center steering ##
    G.car["steer"] *= 0.6
    G.car["force"] *= 0.9

    ## align car to Z axis to prevent flipping ##

    G.car.alignAxisToVect([0.0, 0.0, 1.0], 2, Stability)

    ## store old values ##
    G.car["dS"] = S
Exemplo n.º 3
0
def carHandler():
	vehicle = PC.getVehicleConstraint(G.car["cid"])

	## calculate speed by using the back wheel rotation speed ##
	S = vehicle.getWheelRotation(2)+vehicle.getWheelRotation(3)
	G.car["speed"] = (S - G.car["dS"])*27.0
	
	## apply engine force ##
	vehicle.applyEngineForce(G.car["force"],0)
	vehicle.applyEngineForce(G.car["force"],1)
	vehicle.applyEngineForce(G.car["force"],2)
	vehicle.applyEngineForce(G.car["force"],3)

	## calculate steering with varying sensitivity ##
	if math.fabs(G.car["speed"])<15.0: s = 5.0
	elif math.fabs(G.car["speed"])<28.0: s=4.5
	elif math.fabs(G.car["speed"])<40.0: s=4.0
	else: s=4.5

	## steer front wheels
	vehicle.setSteeringValue(G.car["steer"]*s,0)
	vehicle.setSteeringValue(G.car["steer"]*s,1)

	## slowly ease off gas and center steering ##
	G.car["steer"] *= 0.6
	G.car["force"] *= 0.9

	## align car to Z axis to prevent flipping ##
	
	G.car.alignAxisToVect([0.0,0.0,1.0], 2, Stability)
	
	## store old values ##
	G.car["dS"] = S
Exemplo n.º 4
0
    def __init__(self, obj, parent=None):
        """ Constructor method.
            Receives the reference to the Blender object.
            Optionally it gets the name of the object's parent,
            but that information is not currently used for a robot. """
        # Call the constructor of the parent class
        logger.info('%s initialization' % obj.name)
        super(self.__class__, self).__init__(obj, parent)

        #
        #  This section runs only once to create the vehicle:
        #
        for child in obj.children:
            if 'wheel1' in child.name:
                wheel1 = child
                wheel1.removeParent()
            if 'wheel2' in child.name:
                wheel2 = child
                wheel2.removeParent()
            if 'wheel3' in child.name:
                wheel3 = child
                wheel3.removeParent()
            if 'wheel4' in child.name:
                wheel4 = child
                wheel4.removeParent()

        obj['init'] = 1
        physicsid = obj.getPhysicsId()
        vehicle = PhysicsConstraints.createConstraint(physicsid, 0, 11)
        obj['cid'] = vehicle.getConstraintId()
        self.vehicle = PhysicsConstraints.getVehicleConstraint(obj['cid'])

        # Wheel location from vehicle center
        wx = 1.3
        wy = 1.6
        wz = -.5

        #wheelAttachDirLocal:
        #Direction the suspension is pointing
        wheelAttachDirLocal = [0, 0, -1]

        #wheelAxleLocal:
        #Determines the rotational angle where the
        #wheel is mounted.
        wheelAxleLocal = [-1, 0, 0]

        #suspensionRestLength:
        #The length of the suspension when it's fully
        #extended:
        suspensionRestLength = .3

        #wheelRadius:
        #Radius of the Physics Wheel.
        #Turn on Game:Show Physics Visualization to see
        #a purple line representing the wheel radius.
        wheelRadius = .5

        #hasSteering:
        #Determines whether or not the coming wheel
        #assignment will be affected by the steering
        #value:	
        hasSteering = 1

        #
        #	Front wheels:
        #

        logger.debug(dir(wheel1))

        #Where the wheel is attached to the car based
        #on the vehicle's Center
        wheelAttachPosLocal = [wx, wy, wz]

        #creates the first wheel using all of the variables
        #created above:
        self.vehicle.addWheel(wheel1, wheelAttachPosLocal, wheelAttachDirLocal,
                                      wheelAxleLocal, suspensionRestLength,
                                      wheelRadius, hasSteering)

        #Positions this wheel on the opposite side of the car by using a
        #negative values for the x position.
        wheelAttachPosLocal = [-wx, wy, wz]

        #creates the second wheel:
        self.vehicle.addWheel(wheel2, wheelAttachPosLocal, wheelAttachDirLocal,
                                      wheelAxleLocal, suspensionRestLength,
                                      wheelRadius, hasSteering)

        #
        #	Rear Wheels:
        #

        #Change the hasSteering value to 0 so the rear wheels don't turn
        #when the steering value is changed.
        hasSteering = 0

        # Adjust the location the rear wheels are attached. 
        wx = 1.3
        wy = 2.3

        # Set the wheelAttachPosLocal to the new location for rear wheels:
        # -y moves the position toward the back of the car
        wheelAttachPosLocal = [wx, -wy, wz]

        #Creates the 3rd wheel (first rear wheel)
        self.vehicle.addWheel(wheel3, wheelAttachPosLocal, wheelAttachDirLocal,
                                      wheelAxleLocal, suspensionRestLength,
                                      wheelRadius, hasSteering)

        #Adjust the attach position for the next wheel:
        # changed to -x to place the wheel on the opposite side of the car
        # the same distance away from the vehicle's center
        wheelAttachPosLocal = [-wx, -wy, wz]

        #create the last wheel using the above variables:
        self.vehicle.addWheel(wheel4, wheelAttachPosLocal, wheelAttachDirLocal,
                                      wheelAxleLocal, suspensionRestLength,
                                      wheelRadius, hasSteering)

      #The Rolling Influence:
        #How easy it will be for the vehicle to roll over while turning:
        #0 = Little to no rolling over
        # .1 and higher easier to roll over
        #Wheels that loose contact with the ground will be unable to
        #steer the vehicle as well.
        #influence = 0.1
        influence = 0.05
        self.vehicle.setRollInfluence(influence, 0)
        self.vehicle.setRollInfluence(influence, 1)
        self.vehicle.setRollInfluence(influence, 2)
        self.vehicle.setRollInfluence(influence, 3)

        #Stiffness:
        #Affects how quickly the suspension will 'spring back'
        #0 = No Spring back
        # .001 and higher = faster spring back
        #stiffness = 10.0
        stiffness = 15
        self.vehicle.setSuspensionStiffness(stiffness, 0)
        self.vehicle.setSuspensionStiffness(stiffness, 1)
        self.vehicle.setSuspensionStiffness(stiffness, 2)
        self.vehicle.setSuspensionStiffness(stiffness, 3)

        #Dampening:
        #Determines how much the suspension will absorb the
        #compression.
        #0 = Bounce like a super ball
        #greater than 0 = less bounce
        damping = 10
        self.vehicle.setSuspensionDamping(damping, 0)
        self.vehicle.setSuspensionDamping(damping, 1)
        self.vehicle.setSuspensionDamping(damping, 2)
        self.vehicle.setSuspensionDamping(damping, 3)

        #Compression:
        #Resistance to compression of the overall suspension length.
        #0 = Compress the entire length of the suspension
        #Greater than 0 = compress less than the entire suspension length.
        #10 = almost no compression
        compression = 2
        self.vehicle.setSuspensionCompression(compression, 0)
        self.vehicle.setSuspensionCompression(compression, 1)
        self.vehicle.setSuspensionCompression(compression, 2)
        self.vehicle.setSuspensionCompression(compression, 3)

        #Friction:
        #Wheel's friction to the ground
        #How fast you can accelerate from a standstill.
        #Also affects steering wheel's ability to turn vehicle.
        #0 = Very Slow Acceleration:
        # .1 and higher = Faster Acceleration / more friction:
        friction = obj['friction']
        self.vehicle.setTyreFriction(friction, 0)
        self.vehicle.setTyreFriction(friction, 1)
        self.vehicle.setTyreFriction(friction, 2)
        self.vehicle.setTyreFriction(friction, 3)

        logger.info('Component initialized')
Exemplo n.º 5
0
def carInit():

    ## setup aliases for Blender API access ##
    cont = G.getCurrentController()
    G.scene = G.getCurrentScene()
    G.car = cont.owner

    ## setup general vehicle characteristics ##
    wheelAttachDirLocal = [0, 0, -1]
    wheelAxleLocal = [-1, 0, 0]

    ## setup vehicle physics ##
    vehicle = PC.createConstraint(G.car.getPhysicsId(), 0, 11)
    G.car["cid"] = vehicle.getConstraintId()
    vehicle = PC.getVehicleConstraint(G.car["cid"])

    ## initialize temprary per-car variables ##
    G.car["dS"] = 0.0

    ## attached wheel based on actuator name ##
    act0 = cont.actuators["wheel0"]
    wheel0 = act0.owner
    wheelAttachPosLocal = [wheelBaseWide, wheelFrontOffset, AttachHeightLocal]
    vehicle.addWheel(wheel0, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 1)

    act1 = cont.actuators["wheel1"]
    wheel1 = act1.owner
    wheelAttachPosLocal = [-wheelBaseWide, wheelFrontOffset, AttachHeightLocal]
    vehicle.addWheel(wheel1, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 1)

    act2 = cont.actuators["wheel2"]
    wheel2 = act2.owner
    wheelAttachPosLocal = [wheelBaseWide, wheelBackOffset, AttachHeightLocal]
    vehicle.addWheel(wheel2, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 0)

    act3 = cont.actuators["wheel3"]
    wheel3 = act3.owner
    wheelAttachPosLocal = [-wheelBaseWide, wheelBackOffset, AttachHeightLocal]
    vehicle.addWheel(wheel3, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 0)

    ## set vehicle roll tendency ##
    vehicle.setRollInfluence(influence, 0)
    vehicle.setRollInfluence(influence, 1)
    vehicle.setRollInfluence(influence, 2)
    vehicle.setRollInfluence(influence, 3)

    ## set vehicle suspension hardness ##
    vehicle.setSuspensionStiffness(stiffness, 0)
    vehicle.setSuspensionStiffness(stiffness, 1)
    vehicle.setSuspensionStiffness(stiffness, 2)
    vehicle.setSuspensionStiffness(stiffness, 3)

    ## set vehicle suspension dampness ##
    vehicle.setSuspensionDamping(damping, 0)
    vehicle.setSuspensionDamping(damping, 1)
    vehicle.setSuspensionDamping(damping, 2)
    vehicle.setSuspensionDamping(damping, 3)

    ## set vehicle suspension compression ratio ##
    vehicle.setSuspensionCompression(compression, 0)
    vehicle.setSuspensionCompression(compression, 1)
    vehicle.setSuspensionCompression(compression, 2)
    vehicle.setSuspensionCompression(compression, 3)

    ## set vehicle tire friction ##
    vehicle.setTyreFriction(friction, 0)
    vehicle.setTyreFriction(friction, 1)
    vehicle.setTyreFriction(friction, 2)
    vehicle.setTyreFriction(friction, 3)
Exemplo n.º 6
0
def carInit():

	## setup aliases for Blender API access ##
	cont = G.getCurrentController()
	G.scene = G.getCurrentScene()
	G.car  = cont.owner

	## setup general vehicle characteristics ##
	wheelAttachDirLocal = [0,0,-1]
	wheelAxleLocal = [-1,0,0]

	## setup vehicle physics ##
	vehicle = PC.createConstraint(G.car.getPhysicsId(),0,11)
	G.car["cid"] = vehicle.getConstraintId()
	vehicle = PC.getVehicleConstraint(G.car["cid"])

	## initialize temprary per-car variables ##
	G.car["dS"] = 0.0

	## attached wheel based on actuator name ##
	act0 = cont.actuators["wheel0"]
	wheel0 = act0.owner
	wheelAttachPosLocal = [wheelBaseWide ,wheelFrontOffset, AttachHeightLocal]
	vehicle.addWheel(wheel0,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionLength,wheelRadius,1)

	act1 = cont.actuators["wheel1"]
	wheel1 = act1.owner
	wheelAttachPosLocal = [-wheelBaseWide ,wheelFrontOffset, AttachHeightLocal]
	vehicle.addWheel(wheel1,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionLength,wheelRadius,1)

	act2 = cont.actuators["wheel2"]
	wheel2 = act2.owner
	wheelAttachPosLocal = [wheelBaseWide ,wheelBackOffset, AttachHeightLocal]
	vehicle.addWheel(wheel2,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionLength,wheelRadius,0)

	act3 = cont.actuators["wheel3"]
	wheel3 = act3.owner
	wheelAttachPosLocal = [-wheelBaseWide ,wheelBackOffset, AttachHeightLocal]
	vehicle.addWheel(wheel3,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionLength,wheelRadius,0)

	## set vehicle roll tendency ##
	vehicle.setRollInfluence(influence,0)
	vehicle.setRollInfluence(influence,1)
	vehicle.setRollInfluence(influence,2)
	vehicle.setRollInfluence(influence,3)

	## set vehicle suspension hardness ##
	vehicle.setSuspensionStiffness(stiffness,0)
	vehicle.setSuspensionStiffness(stiffness,1)
	vehicle.setSuspensionStiffness(stiffness,2)
	vehicle.setSuspensionStiffness(stiffness,3)

	## set vehicle suspension dampness ##
	vehicle.setSuspensionDamping(damping,0)
	vehicle.setSuspensionDamping(damping,1)
	vehicle.setSuspensionDamping(damping,2)
	vehicle.setSuspensionDamping(damping,3)

	## set vehicle suspension compression ratio ##
	vehicle.setSuspensionCompression(compression,0)
	vehicle.setSuspensionCompression(compression,1)
	vehicle.setSuspensionCompression(compression,2)
	vehicle.setSuspensionCompression(compression,3)

	## set vehicle tire friction ##
	vehicle.setTyreFriction(friction,0)
	vehicle.setTyreFriction(friction,1)
	vehicle.setTyreFriction(friction,2)
	vehicle.setTyreFriction(friction,3)
Exemplo n.º 7
0
import bge
import bpy
import PhysicsConstraints

#print(dir(PhysicsConstraints))

#print(dir(bpy.data.objects['GHOST']))

print("COL")

PhysicsConstraints.exportBulletFile("output.bullet")
Exemplo n.º 8
0
# get object physics ID
phido = obj.getPhysicsId()

# get root physics ID
phidr = root.getPhysicsId()

# want to use point constraint type
constraint_type = 1

# Use bottom right front corner of object for point constraint position
point_pos_x = 1.0
point_pos_y = -1.0
point_pos_z = -1.0

# create a point constraint
const =	PhysicsConstraints.createConstraint( phido, phidr, constraint_type, point_pos_x, point_pos_y, point_pos_z)

# stores the new constraint ID to be used later
obj["constraint_ID"] = const.getConstraintId()	



#  Removing a point constraint  #
#################################

# import BGE internal module
import PhysicsConstraints

# get object list
obj_list = bge.logic.getCurrentScene().objects