def _addCube(self, pos, cubeBounds=ogre.Vector3(0.3, 0.3, 0.3), tangentBundle=None): #cubeBounds=bullet.btVector3(0.3, 0.3, 0.3)): ent = self.sceneManager.createEntity("Bulletbox.mesh") ent.setMaterialName("GridNormalMap3") node = self.sceneManager.getRootSceneNode().createChildSceneNode() node.attachObject(ent) node.scale(cubeBounds) #node.scale(cubeBounds.getX(), cubeBounds.getY(), cubeBounds.getZ()) mass = 1.0 res = 0.01 bodyFriction = 0.2 fallInertia = bullet.btVector3(0, 0, 0) cubeIdx = len(self.bodies) cubeShape = bullet.btBoxShape(collisions.OgreBtConverter.to(cubeBounds)) cubeShape.calculateLocalInertia(mass, fallInertia) cubeMotionState = OgreMotionState(bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), bullet.btVector3(pos.x, pos.y, pos.z)), node, tb=tangentBundle) cubeBodyCI = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, cubeMotionState, cubeShape, fallInertia) cubeBody = bullet.btRigidBody(cubeBodyCI) cubeBody.setActivationState(4) #state is never deactivate cubeMotionState.rb = cubeBody self.world.addRigidBody(cubeBody) self.motionStates.append(cubeMotionState) """ cubeShape = collisions.BoxCollisionShape(cubeBounds) cubeBody = dynamics.RigidBody("cube" + str(cubeIdx), self.world) cubeBody.setShape(node, cubeShape, res, bodyFriction, mass, pos) cubeBody.getBulletRigidBody().setActivationState(4) """ self.bodies.append(cubeBody) self.shapes.append(cubeShape) return cubeBody
def createBoxShape(entity, unitScale=True): """Bullet Box Shape""" ## mesh extents e = MeshInfo.getBoundingBox(entity) size = bullet.btVector3(e.getHalfSize().x, e.getHalfSize().y, e.getHalfSize().z) print size.x(), size.y(), size.z() return bullet.btBoxShape(size)
def _create_collision_entity(self, entity): """Register a static entity for collision detection as a cube. This function returns the collision object created""" # cobj = bullet.btCollisionObject() size = entity.size / 2 cube = bullet.btBoxShape(bullet.btVector3(size, size, size)) # cobj.setCollisionShape(cube) # self.collision_objects.append(cobj) return cube
def register_collision_object(self, size, x, y, z, rotation=bullet.btQuaternion(0, 0, 0, 1), mass=0, motion_state=bullet.btDefaultMotionState): """Register a simple collision object with bullet.""" shape = bullet.btBoxShape(bullet.btVector3(size / 2, size / 2, size / 2)) transform = bullet.btTransform(rotation, bullet.btVector3(x, y, z)) inertia = bullet.btVector3(0, 0, 0) motion_state = motion_state(transform) construction = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, motion_state, shape, inertia) rigid_body = bullet.btRigidBody(construction) self.dynamics_world.addRigidBody(rigid_body, 1, 1) return rigid_body, motion_state, shape
def createCameraBody(self, camera, halfSize, mass): pos = camera.getPosition(); rot = camera.getOrientation(); # Skapa motion state motionState = bullet.btDefaultMotionState(bullet.btTransform( bullet.btQuaternion(0,0,0,1), bullet.btVector3(pos.x,pos.y,pos.z))); shape = bullet.btBoxShape(toBtVector3(halfSize)); inertia = bullet.btVector3(0,0,0); shape.calculateLocalInertia(mass, inertia); constructInfo = bullet.btRigidBody.btRigidBodyConstructionInfo( mass, motionState, shape, inertia); rigidBody = bullet.btRigidBody(constructInfo); self.bodies.append(PhysicsWorld.Body(shape, motionState, constructInfo, rigidBody)); self.world.addRigidBody(rigidBody); return rigidBody;
import sys sys.path.insert(0,'..') import PythonOgreConfig import ogre.renderer.OGRE as ogre import ogre.physics.bullet as bullet t = bullet.btTransform() ms = bullet.btDefaultMotionState (t) s = bullet.btBoxShape(bullet.btVector3(10,10,10)) body = bullet.btRigidBody(1, ms, s) print body collisionConfiguration = bullet.btDefaultCollisionConfiguration() dispatcher = bullet.btCollisionDispatcher (collisionConfiguration) worldAabbMin = bullet.btVector3(-1000,-1000,-1000) worldAabbMax = bullet.btVector3(1000,1000,1000) maxProxies = 32766 broadphase = bullet.btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies) solver = bullet.btSequentialImpulseConstraintSolver() world = bullet.btDiscreteDynamicsWorld(dispatcher, broadphase , solver, collisionConfiguration) world.getDispatchInfo().m_enableSPU = True world.setGravity(bullet.btVector3(0,-10,0)) print world print dir(world) print solver
import ogre.renderer.OGRE as ogre import ogre.physics.bullet as bullet from block import Block, materials import contract import vector BOX_COLLISION_SHAPE = bullet.btBoxShape(bullet.btVector3(Block.size / 2, Block.size / 2, Block.size / 2)) class Chunk: """A Chunk is a NxNxN cube of blocks. Use chunks in order to render each chunk at once. rebuild a mesh whenever a cube is added or destroyed. Use None to represent an empty block""" def __init__(self, scene_manager, physics_system, resource_group_name, size, x_off, y_off, z_off): self.size = size self.x_off = x_off self.y_off = y_off self.z_off = z_off self.resource_group_name = resource_group_name self.physics_system = physics_system self._blocks = {} self._physics_info = {} self.scene_manager = scene_manager self.mesh = "chunk%d%d%d_mesh" % (self.x_off, self.y_off, self.z_off) self.entity = None self.count = 0 self.cube_mesh = None self.block_count = 0 self.position = (x_off, y_off, z_off) self.chunk = self.scene_manager.createManualObject(self.mesh) self.node = self.scene_manager.getRootSceneNode().createChildSceneNode(self.position)