Esempio n. 1
0
 def updateStars(self, newCameraPos):
     # TODO: Add unit tests!
     self.stars.setPos(newCameraPos)
     cameraDeltaPos = tupleSegment(self.lastCameraPos,
                                   vec3ToTuple(newCameraPos))
     xRotation = Quat()
     xRotation.setFromAxisAngle(cameraDeltaPos[0] * .1, Vec3(0, 1, 0))
     yRotation = Quat()
     yRotation.setFromAxisAngle(-cameraDeltaPos[1] * .1, Vec3(1, 0, 0))
     newRotation = xRotation.multiply(yRotation)
     self.starsRotation *= newRotation
     self.stars.setQuat(self.starsRotation)
Esempio n. 2
0
def simulationTask(task):

    if vehicle != None and vehicle.chassiM != None:
        base.cam.lookAt(vehicle.chassiM.model)
    global text
    text.destroy()
    text = OnscreenText(text=('fps = ' +
                              str(globalClock.getAverageFrameRate())),
                        pos=(0, 0.9),
                        scale=0.07)

    if (keylistener.space):
        vehicle.goUp()
    if (keylistener.i):
        vehicle.goForward()
    if (keylistener.k):
        vehicle.goBackwards()
    if (keylistener.j):
        vehicle.turnLeft()
    if (keylistener.l):
        vehicle.turnRight()

    space.autoCollide()
    world.quickStep(globalClock.getDt())
    for np, body in objects:
        np.setPosQuat(render, body.getPosition(), Quat(body.getQuaternion()))
    contactgroup.empty()
    return task.cont
Esempio n. 3
0
 def placeBodies(self):
     for pair in self.odePandaRelationList:
         pandaNodePathGeom = pair[0]
         odeBody = pair[1]
         if pandaNodePathGeom:
             pandaNodePathGeom.setPos(odeBody.getPosition())
             pandaNodePathGeom.setQuat(Quat(odeBody.getQuaternion()[0], odeBody.getQuaternion()[1], odeBody.getQuaternion()[2], odeBody.getQuaternion()[3]))
Esempio n. 4
0
def vec_to_hpr(v):
    q = Quat()
    q.setX(v.getX())
    q.setY(v.getY())
    q.setZ(v.getZ())
    q.setW(v.getW())
    return q.getHpr()
Esempio n. 5
0
    def OnUpdate(self, task):

        # Position axes 30 pixels from top left corner
        self.axes.setPos(Vec3(30, 0, -30))

        # Set rotation to inverse of camera rotation
        cameraQuat = Quat(self.getQuat())
        cameraQuat.invertInPlace()
        self.axes.setQuat(cameraQuat)
Esempio n. 6
0
 def updatePlayer(self):
     '''
     Needs to get executed every Ode-Step
     '''
     self._vehicle.model.setPosQuat(
         render, self._vehicle.physics_model.getPosition(),
         Quat(self._vehicle.physics_model.getQuaternion()
              ))  #set new position
     self._camera.updateCam()
Esempio n. 7
0
 def synchronize(self, _pandaCJoint, _smrJoint):
     #_smrJoint.setRot(3.14/20.0,0,0);
     smrQuaternion = _smrJoint.getRot()
     pandaQuaternion = Quat()
     pandaQuaternion.setI(smrQuaternion.getX())
     pandaQuaternion.setJ(smrQuaternion.getY())
     pandaQuaternion.setK(smrQuaternion.getZ())
     pandaQuaternion.setR(smrQuaternion.getW())
     _pandaCJoint.setQuat(pandaQuaternion)
Esempio n. 8
0
 def synchronize(self, _pandaCJoint, _smrJoint):
     smrQuaternion = _smrJoint.getRot()
     pandaQuaternion = Quat()
     pandaQuaternion.setI(smrQuaternion.getX())
     pandaQuaternion.setJ(smrQuaternion.getY())
     pandaQuaternion.setK(smrQuaternion.getZ())
     pandaQuaternion.setR(smrQuaternion.getW())
     if not (pandaQuaternion.isNan()):
         _pandaCJoint.setQuat(pandaQuaternion)
Esempio n. 9
0
File: ode.py Progetto: gurgelff/Bast
def simulationTask(task):
  global groundImgChanged
  space.autoCollide() # Setup the contact joints
  # Step the simulation and set the new positions
  world.quickStep(globalClock.getDt())
  for np, geom, sound in balls:
    if not np.isEmpty():
      np.setPosQuat(render, geom.getBody().getPosition(), Quat(geom.getBody().getQuaternion()))
  contactgroup.empty() # Clear the contact joints
  # Load the image into the texture
  if groundImgChanged:
    groundTexture.load(groundImage)
    groundImgChanged = False
  return task.cont
Esempio n. 10
0
 def placeBodies(self):
     """Make the nodePaths match up to the physics bodies."""
     # lets see if a sphere can simulate a tire by just taking out P and R
     for pair in self.odePandaRelationList:
         pandaNodePathGeom = pair[0]
         odeBody = pair[1]
         if pandaNodePathGeom:
             pandaNodePathGeom.setPos(odeBody.getPosition())
             # rotation = (odeBody.getRotation() * (180.0/math.pi))
             pandaNodePathGeom.setQuat(
                 Quat(odeBody.getQuaternion()[0],
                      odeBody.getQuaternion()[1],
                      odeBody.getQuaternion()[2],
                      odeBody.getQuaternion()[3]))
             pandaNodePathGeom.setP(0)
             pandaNodePathGeom.setR(0)
             newQuat = pandaNodePathGeom.getQuat()
             odeBody.setQuaternion(newQuat)
Esempio n. 11
0
    def alignBodyTo2d(self):
        body = self.ballBody

        # Constrain position of the body
        oldPos = body.getPosition()
        newPos = oldPos
        newPos[0] = 0
        newPos[1] = oldPos[1]
        newPos[2] = oldPos[2]

        # Constrain quaternion of the body
        oldQuat = body.getQuaternion()
        newQuat = oldQuat
        newQuat[0] = oldQuat[0]
        newQuat[1] = oldQuat[1]
        newQuat[2] = 0
        newQuat[3] = 0

        # Set new position and quaternion of the body
        body.setPosition(newPos)
        body.setQuaternion(Quat(newQuat))
Esempio n. 12
0
	def setFrom(self, snapshot):
		self.pos = Vec3(snapshot.pos)
		self.quat = Quat(snapshot.quat)
		self.time = engine.clock.time
		self.empty = snapshot.empty
 def updatePosFromPhysics(self):
     if self.body != None:
         self.node.setPosQuat(render, self.body.getPosition(),
                              Quat(self.body.getQuaternion()))
Esempio n. 14
0
def hpr_to_quat(hpr):
    q = Quat()
    q.setHpr(hpr)
    return q
Esempio n. 15
0
 def quat(self):
     """ return the current quaternion representation of the attitude """
     return Quat(self.ode_body.getQuaternion())
Esempio n. 16
0
	def takeSnapshot(self, entity):
		self.pos = entity.getPosition()
		self.quat = Quat(entity.getQuaternion())
		self.time = engine.clock.time
		self.empty = False
Esempio n. 17
0
	def __init__(self):
		self.pos = Vec3()
		self.quat = Quat()
		self.time = 0
		self.empty = True
Esempio n. 18
0
	def getFrom(iterator):
		return Quat(net.StandardFloat.getFrom(iterator), net.StandardFloat.getFrom(iterator), net.StandardFloat.getFrom(iterator), net.StandardFloat.getFrom(iterator))
Esempio n. 19
0
    def updateModelNode(self):
        ''' Update objects after one physics iteration '''
        now = globalClock.getLongTime()
        body = self.ballBody
        g = self.world.getGravity()

        if self.limitedYMovement:
            if body.getPosition().getY() > self.limitedYCoords[1]:
                self.ballBody.setLinearVel(Vec3(0, -10, 0))
            if body.getPosition().getY() < self.limitedYCoords[0]:
                self.ballBody.setLinearVel(Vec3(0, 10, 0))
        if self.limitedZMovement:
            if body.getPosition().getZ() > self.limitedZCoords[1]:
                messenger.send(EventType.RESTART)
                return
            if body.getPosition().getZ() < self.limitedZCoords[0]:
                messenger.send(EventType.RESTART)
                return

        if Ball.MOVEMENT_DEBUG and now - self.lastDrawTime2 > 0.2:
            v = body.getLinearVel()
            v2 = self.perpendicularUnitVec3WithFixedX(v)
            self.lines.reset()
            self.lines3.reset()
            x = body.getPosition().getX(
            ) + 1.2  # This will bring the line in front of the ball
            y = body.getPosition().getY()
            z = body.getPosition().getZ()
            self.lines.drawLines([((x, y, z), (x + v.getX(), y + v.getY(),
                                               z + v.getZ()))])
            self.lines3.drawLines([((x, y, z), (x + v2.getX(), y + v2.getY(),
                                                z + v2.getZ()))])
            self.lines.create()
            self.lines3.create()
            self.lastDrawTime2 = 0.0
        ''' Can move better when on (touching) something, moving in the air is harder '''
        divisor = 3.5
        if self.isColliding() and self.lastCollisionIsGround:
            divisor = 1.0

        if self.moveLeft or self.moveRight:
            factor = 1.0
            if self.moveLeft:
                factor = -1.0

            # Limit speed to some constant
            v3 = self.perpendicularUnitVec3WithFixedX(g)
            v3 *= factor * Ball.FORCE / divisor
            lv = self.ballBody.getLinearVel()
            lv.setX(0.0)
            lv.setZ(0.0)
            if self.haveRoughlySameDirection(
                    lv, v3) and abs(lv.length()) > self.MAX_MOVEMENT_SPEED:
                factor = 0.0

            v3 = self.perpendicularUnitVec3WithFixedX(g)
            v3 *= factor * Ball.FORCE / divisor

            self.ballBody.setForce(y=v3.getY(), x=v3.getX(), z=v3.getZ())
            v3 = self.perpendicularUnitVec3WithFixedX(g)
            v3 *= factor * Ball.TORQUE / divisor
            self.ballBody.setTorque(y=v3.getY(), x=v3.getX(), z=v3.getX())
        ''' This is still really crappy, will revise later '''
        if self.jumping == True:
            g = -g
            g /= g.length()
            if Ball.STATIC_JUMP:
                g *= Ball.STATIC_JUMP_FORCE
                self.ballBody.setForce(y=g.getY(), x=g.getX(), z=g.getZ())
                self.jumping = False
            else:
                elapsed = now - self.jumpStarted
                if elapsed > 0.0 and elapsed < Ball.MAX_JUMP_REACH_TIME:
                    g *= Ball.JUMP_FORCE
                    self.ballBody.setForce(y=g.getY(), x=g.getX(), z=g.getZ())
                elif elapsed > Ball.MAX_JUMP_REACH_TIME:
                    self.jumping = False

        # Keep the body in 2d position
        self.alignBodyTo2d()

        # Set the new position
        self.modelNode.setPos(render, self.ballBody.getPosition())
        self.modelNode.setQuat(render, Quat(self.ballBody.getQuaternion()))