# -*- test-case-name: mv3d.test.test_ -*- # Copyright (C) 2012 Mortal Coil Games # See LICENSE for details. """ Interfaces for the Physics API. To implement a new physics engine, you'll need to implement these. @author: mike """ from zope.interface import Interface class ICollider(Interface): """ This is the interface to a collision primitive object. """ def build(body=None, space=None): #@NoSelf """ Create this collider in space (if provided) and attach it to body (if provided) """ def destroy(): #@NoSelf """ Destroy this collider """ class IBoxCollider(ICollider): """ A collider in the shape of a box. """ class ISphereCollider(ICollider): """ A collider in the shape of a sphere. """ class IPlaneCollider(ICollider): """ A collider that represents a plane. """ class ICylinderCollider(ICollider): """ A collider that represents a cylinder """ class IMeshCollider(ICollider): """ A collider built from a triangle mesh. """ class IMeshGenCollider(IMeshCollider): """ A mesh collider that can be built from a mesh generator. """ class ISpace(ICollider): """ This is the interface for a space which can hold colliders. """ def castRay(space, startPosition, endPosition, ignoreColliders=None, #@NoSelf hitOnlyColliders=None): """ Cast a ray in space from startPosition to endPosition. Any colliders in ignoreColliders will be ignored. If hitOnlyColliders is specified result will only include colliders from that list. Returns an instance of an IRayCast class """ def getBoundingBox(): #@NoSelf """ Returns the bounding box of the space. """ class IRayCast(Interface): """ Defines the result of a raycast. """ class IBody(Interface): """ Represents a body in the physics world. """ def getPosition(): #@NoSelf """ Returns the current position """ def setPosition(position): #@NoSelf """ Sets the current position """ def getOrientation(): #@NoSelf """ Returns the current orientation as a quaternion """ def setOrientation(orientation): #@NoSelf """ Sets the current orientation as a quaternion """ def getLinearVelocity(): #@NoSelf """ Returns the current linear velocity """ def setLinearVelocity(velocity): #@NoSelf """ Sets the current linear velocity """ def getRelativeLinearVelocity(): #@NoSelf """ Returns the relative linear velocity """ def getAngularVelocity(): #@NoSelf """ Returns the angular velocity. """ def setAngularVelocity(velocity): #@NoSelf """ Sets the current angular velocity """ def addForce(force, position=(0, 0, 0)): #@NoSelf """ Adds force at the specified position. """ def addTorque(torque): #@NoSelf """ Adds the specified amount of torque. """ def getMass(): #@NoSelf """ Return sthe mass of the body. """ def setMass(mass): #@NoSelf """ Sets the mass of the body """ def disable(): #@NoSelf """ Disable the body """ def enable(): #@NoSelf """ Enable the body. """ def isEnabled(): #@NoSelf """ Returns True if this body is enabled currently. """ def isConnectedTo(otherBody): #@NoSelf """ Returns true if this body is connected to otherBody via a joint or collision. """ class IJoint(Interface): """ A joint can be used to connect two bodies together. """ class IBallJoint(IJoint): """ A ball joint """ class IPhysicsSimulation(Interface): """ Generic interface to a physics engine. """ def getPhysicsClass(interface): #@NoSelf """ Returns the class for this engine that implements the specified physics interface. """ def collideInternal(space): #@NoSelf """ Collide all colliders with each other inside the space. """ def collide(collider1, collider2): #@NoSelf """ Collide the two colliders together. """ def clearCollisions(): #@NoSelf """ Clear any previous collisions. Typically called before running collisions for a tick. """ def iterate(deltaTime): #@NoSelf """ Iterate the simulation forward by the specified time. """