Beispiel #1
0
    def __init__(self, app_dir='.', parent_world=None, debug=False):
        soya.Camera.__init__(self, parent_world)
        self.debug = debug
        self.app_dir = app_dir

        self.speed = soya.Vector(self)
        self.rotation_y_speed = 0.0
        self.rotation_x_speed = 0.0
Beispiel #2
0
    def __init__(self, parent, light):
        soya.Camera.__init__(self, parent)

        self.speed = soya.Vector(self)
        self.rotation_x_speed = 0.0
        self.rotation_y_speed = 0.0
        self.rotation_z_speed = 0.0
        self.light = light
Beispiel #3
0
    def _create_models(self):
        rhomb_world = soya.World()
        centerVerticesLeft = []
        centerVerticesRight = []
        for i in range(self.rhomb_n):
            l = soya.Vertex(
                rhomb_world,
                self.rhomb_radius * math.sin(2.0 * math.pi * i / self.rhomb_n),
                0.0,
                self.rhomb_radius * math.cos(2.0 * math.pi * i / self.rhomb_n))
            r = soya.Vertex(
                rhomb_world,
                self.rhomb_radius * math.sin(2.0 * math.pi * i / self.rhomb_n),
                0.0,
                self.rhomb_radius * math.cos(2.0 * math.pi * i / self.rhomb_n))
            l.diffuse = self.rhomb_color1
            r.diffuse = self.rhomb_color2
            centerVerticesLeft.append(l)
            centerVerticesRight.append(r)
        for i in range(self.rhomb_n):
            leftVertex = soya.Vertex(rhomb_world, 0.0, -self.rhomb_left_size,
                                     0.0)
            rightVertex = soya.Vertex(rhomb_world, 0.0, self.rhomb_right_size,
                                      0.0)
            leftVertex.diffuse = self.rhomb_color1
            rightVertex.diffuse = self.rhomb_color2
            f = soya.Face(rhomb_world, [
                leftVertex, centerVerticesLeft[(i + 1) % self.rhomb_n],
                centerVerticesLeft[i]
            ])
            f.smooth_lit = 1
            f = soya.Face(rhomb_world, [
                rightVertex, centerVerticesRight[i],
                centerVerticesRight[(i + 1) % self.rhomb_n]
            ])
            f.smooth_lit = 1
        model_builder = soya.SimpleModelBuilder()
        model_builder.shadow = 1
        rhomb_world.model_builder = model_builder

        self.rhomb_model = rhomb_world.to_model()
        self.rhomb = MovingRotatingBody(self.scene, self.rhomb_model)
        self.rhomb.rotate_z(90)
        self.rhomb.current = RIGHT
        self.rhomb.speed = soya.Vector(self.scene, *self.rhomb_speed_xyz)

        self.rhomb.angle_x = 0
        self.rhomb.angle_y = 0
        self.rhomb.angle_z = 0

        self.rhomb.rotating = 0
        self.rhomb.angle = 0
Beispiel #4
0
    def __init__(self, parent, cam):
        soya.World.__init__(self, parent)

        # The object we are currently dragdroping (None => no dragdrop).
        self.dragdroping = None

        # The impact point
        self.impact = None

        self.speed = soya.Vector(self)
        self.rotation_y_speed = 0.0
        self.rotation_x_speed = 0.0

        self.cam = cam
        self.point = soya.Point(parent)
        self.point.set_xyz(0,0,0)
        self.debug = False
Beispiel #5
0
 def set_move(self, dx, dy, dz):
     self.move = soya.Vector(self, dx, dy, dz)
Beispiel #6
0
    def advance_time(self, proportion):
        global z_ax_glob, camera, v_orig, scene, pole, ball
        global frcpball, vecgrav, vecfor, vecgravlp, vecforlp, vecgravlzMp
        global pauseState
        yrotaxVect = soya.Vector(scene, 0, 1, 0)

        if (pauseState == 1):
            self.next()
            return

        # Calls the super implementation of advance_time.
        soya.World.advance_time(self, proportion)

        frcpball[0].set_xyz(self.bp.x, self.bp.y, self.bp.z)
        frcpball[0].endp = (self.frepx.x, self.frepx.y, self.frepx.z)
        frcpball[1].set_xyz(self.bp.x, self.bp.y, self.bp.z)
        frcpball[1].endp = (self.frepy.x, self.frepy.y, self.frepy.z)
        frcpball[2].set_xyz(self.bp.x, self.bp.y, self.bp.z)
        frcpball[2].endp = (self.frepz.x, self.frepz.y, self.frepz.z)

        vecgrav.set_xyz(self.bp1.x, self.bp1.y, self.bp1.z)
        vecgrav.endp = (self.epg.x, self.epg.y, self.epg.z)

        vecfor.set_xyz(self.bp2.x, self.bp2.y, self.bp2.z)
        vecfor.endp = (self.epfor.x, self.epfor.y, self.epfor.z)

        vecgravlp[0].set_xyz(self.bp1.x, self.bp1.y, self.bp1.z)
        vecgravlp[0].endp = (self.epgx.x, self.epgx.y, self.epgx.z)
        vecgravlp[1].set_xyz(self.bp1.x, self.bp1.y, self.bp1.z)
        vecgravlp[1].endp = (self.epgy.x, self.epgy.y, self.epgy.z)
        vecgravlp[2].set_xyz(self.bp1.x, self.bp1.y, self.bp1.z)
        vecgravlp[2].endp = (self.epgz.x, self.epgz.y, self.epgz.z)

        vecforlp[0].set_xyz(self.bp2.x, self.bp2.y, self.bp2.z)
        vecforlp[0].endp = (self.epforx.x, self.epforx.y, self.epforx.z)
        vecforlp[1].set_xyz(self.bp2.x, self.bp2.y, self.bp2.z)
        vecforlp[1].endp = (self.epfory.x, self.epfory.y, self.epfory.z)
        vecforlp[2].set_xyz(self.bp2.x, self.bp2.y, self.bp2.z)
        vecforlp[2].endp = (self.epforz.x, self.epforz.y, self.epforz.z)

        if (self.coordMpState == 1):
            vecgravlzMp[0].visible = 1
            vecgravlzMp[1].visible = 1
            vecgravlzMp[2].visible = 1
            vecgravlzMp[0].set_xyz(self.bp1b.x, self.bp1b.y, self.bp1b.z)
            vecgravlzMp[0].endp = (self.epglzx.x, self.epglzx.y, self.epglzx.z)
            vecgravlzMp[1].set_xyz(self.bp1b.x, self.bp1b.y, self.bp1b.z)
            vecgravlzMp[1].endp = (self.epglzy.x, self.epglzy.y, self.epglzy.z)
            vecgravlzMp[2].set_xyz(self.bp1b.x, self.bp1b.y, self.bp1b.z)
            vecgravlzMp[2].endp = (self.epglzz.x, self.epglzz.y, self.epglzz.z)
        elif (self.coordMpState == 0):
            vecgravlzMp[0].visible = 0
            vecgravlzMp[1].visible = 0
            vecgravlzMp[2].visible = 0

        # Rotates the object around Y axis.
        #~ self.rotate_y(proportion * 2.0)
        #~ z_ax_glob.x += proportion*0.1;
        #~ camera.rotate_z(proportion)
        # rotate_axis - vector via 0,0,0; but local
        # rotate is ok - around a point; not even look_at needed!
        self.next()
        if (self.right_key_down):
            camera.rotate(proportion, Point(scene, 0, 0, 0), yrotaxVect)
            camera.look_at(pole)  #(v_orig)
        elif (self.left_key_down):
            camera.rotate(-proportion, Point(scene, 0, 0, 0), yrotaxVect)
            camera.look_at(pole)  #(v_orig)
        elif (self.up_key_down):  # translate
            camera.add_mul_vector(0.5 * proportion, Vector(camera, 0, 0, -1))
            camera.look_at(pole)  #(v_orig)
        elif (self.down_key_down):  # translate
            camera.add_mul_vector(0.5 * proportion, Vector(camera, 0, 0, 1))
            camera.look_at(pole)  #(v_orig)
Beispiel #7
0
    def begin_round(self):
        global j1, j2, pend, scene, pole, ball, grabScreens, frNum
        global pauseState
        damping = 0.1

        if (pauseState == 1):
            self.next()
            return

        # Calls the super implementation.
        soya.World.begin_round(self)
        #~ print(j1.getFeedback(), "#", j2.getFeedback()) # (force1, torque1, force2, torque2) : ((0.0, 332.9216613769531, -257.0126647949219), (180.77870178222656, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)) ..... (((0.0, 426.10772705078125, -1055.581298828125), (-5704.71435546875, 0.0, 0.0), (1.1854985008187952e-42, 2.312142466135948e-43, 9.164491956684304e-43), (1.4461400151832112e-42, 7.777206477002735e-43, 7.903323338791968e-43)), '#', ((0.0, 173.71861267089844, -6280.154296875), (-96.6642074584961, 0.0, 0.0), (0.0, -173.71861267089844, 6280.154296875), (-504.1296081542969, 0.0, 0.0)))

        self.j1f = j1.getFeedback()
        self.j2f = j2.getFeedback()
        frc1 = self.j2f[0]  #[0]
        # note - vector should be referenced to scene, NOT pend,
        #   for the damping to work!
        dampvect = Vector(scene, -damping * frc1[0], -damping * frc1[1],
                          -damping * frc1[2])
        pend.add_force(dampvect)
        #~ j1fp = j1.getFeedback() # same as j1f
        #~ print(frc1, "#", j1fp[0])
        self.dj1fp = Vector(scene, frc1[0], frc1[1], frc1[2]) + dampvect
        #~ print(frc1, "#", self.dj1fp)

        #~ print(bp)
        #~ frep=bp+0.1*self.dj1fp # float required; no parse
        #~ frep=bp.add_mul_vector(0.1, self.dj1fp) # awful
        #~ frep=bp+self.dj1fp.__mul__(0.000001) # ??
        #~ frep=Vector(ball,0,0,2) # ref to ball don't seem to matter!
        # AH - for these kind of transform with convert_to, should have Point, not Vector!
        # frcpball coord syst: 2 units in each direction, moved 1 unit along x so as not to be hidden by ball
        movx = 0
        if (self.coordViewState == 0):
            self.bp = ball.position().add_vector(soya.Vector(ball, movx, 0, 0))
            self.bp1 = self.bp
            self.bp2 = self.bp1
        if (self.coordViewState == 1):
            movx = 1
            self.bp = ball.position().add_vector(soya.Vector(ball, movx, 0, 0))
            self.bp1 = self.bp
            self.bp2 = self.bp1
        elif (self.coordViewState == 2):
            movx = 1
            self.bp = ball.position().add_vector(soya.Vector(ball, movx, 0, 0))
            self.bp1 = ball.position().add_vector(soya.Vector(ball, 2, 0, 1))
            self.bp2 = self.bp1
        elif (self.coordViewState == 3):
            movx = 1
            self.bp = ball.position().add_vector(soya.Vector(ball, movx, 0, 0))
            self.bp1 = ball.position().add_vector(soya.Vector(ball, 2, 0, 1))
            self.bp2 = ball.position().add_vector(soya.Vector(ball, 3, 0, 2))

        self.bp1b = self.bp1.copy().add_vector(soya.Vector(ball, -0.5, 0, 0))

        self.frepx = Point(ball, 2 + movx, 0, 0)
        self.frepy = Point(ball, movx, 2, 0)
        self.frepz = Point(ball, movx, 0, 2)
        self.frepx.convert_to(scene)
        self.frepy.convert_to(scene)
        self.frepz.convert_to(scene)

        # scaled so they're approx the same
        scale_grav = scene.gravity.__mul__(0.5)
        scale_dfor = self.dj1fp.__mul__(0.03)
        self.epg = self.bp1 + scale_grav
        self.epfor = self.bp2 + scale_dfor

        tp = Vector(ball, 2, 0,
                    0)  # convert_to must go separate! can be vector
        tp.convert_to(scene)  # IN PLACE
        grav_lx = self.vecProjectionAontoB(scale_grav, tp)
        tp = Vector(ball, 0, 2, 0)
        tp.convert_to(scene)
        grav_ly = self.vecProjectionAontoB(scale_grav, tp)
        tp = Vector(ball, 0, 0, 2)
        tp.convert_to(scene)
        grav_lz = self.vecProjectionAontoB(scale_grav, tp)
        self.epgx = self.bp1 + grav_lx
        self.epgy = self.bp1 + grav_ly
        self.epgz = self.bp1 + grav_lz

        tp = Vector(ball, 2, 0, 0)
        tp.convert_to(scene)
        dfor_lx = self.vecProjectionAontoB(scale_dfor, tp)
        tp = Vector(ball, 0, 2, 0)
        tp.convert_to(scene)
        dfor_ly = self.vecProjectionAontoB(scale_dfor, tp)
        tp = Vector(ball, 0, 0, 2)
        tp.convert_to(scene)
        dfor_lz = self.vecProjectionAontoB(scale_dfor, tp)
        self.epforx = self.bp2 + dfor_lx
        self.epfory = self.bp2 + dfor_ly
        self.epforz = self.bp2 + dfor_lz

        tp = Vector(scene, 2, 0, 0)
        grav_lz_mx = self.vecProjectionAontoB(grav_lz, tp)
        tp = Vector(scene, 0, 2, 0)
        grav_lz_my = self.vecProjectionAontoB(grav_lz, tp)
        tp = Vector(scene, 0, 0, 2)
        grav_lz_mz = self.vecProjectionAontoB(grav_lz, tp)
        self.epglzx = self.bp1b + grav_lz_mx
        self.epglzy = self.bp1b + grav_lz_my
        self.epglzz = self.bp1b + grav_lz_mz

        if (grabScreens):
            frNum += 1
            tfname = "/dev/shm/soya-pend%05d.png" % (frNum)
            soya.screenshot(filename=tfname, use_back_buffer=False)
Beispiel #8
0
# adding the hinge masses stabilises hinging - even without them being placed (transl) specifically anywhere?!
pole_mass_main = soya.BoxedMass(100, 1, 10, 1)
pend_mass_main = soya.BoxedMass(5, 0.2, 5, 0.2)
pole_mass_hinge = soya.SphericalMass(1)
pend_mass_hinge = soya.SphericalMass(3, 1)
pend_mass_hinge2 = soya.SphericalMass(3, 1)
# sizes 10,5 - so half of size translate, for correct!
pole_mass_hinge.translate((1.1, 4.2, 0))
pend_mass_hinge.translate((0, 2.5, 0))
pend_mass_hinge2.translate((0, -2.5, 0))
pole.mass = pole_mass_main + pole_mass_hinge
pend.mass = pend_mass_main + pend_mass_hinge + pend_mass_hinge2

# set gravity
scene.gravity = soya.Vector(scene, 0, -9.8, 0)
pole.ode = True
pend.ode = True
hing.ode = True
ball.ode = True

######
#placing bodys
# note: #~ pole.translate((0,-1,0)) # Body' object has no attribute 'translate
# also note - if body enters hinge point, it starts to "oscillate"
# actually that seems to happen due collision?

hgxpos = 3.5
ground.set_xyz(
    0, -40, 0
)  #~ ground.y-= 39; push down (y axis) else we're probably inside this cube :)