hi to all, i'm here another time to request help, i'm doing an fps game, now i need some help for camera collision, i've read tons of tutorial but i don't understand how to do it...
this is my stupid idea
with OgreNewt based on tutorial DemoScene:
for index in xrange(1, 521):
rizzi = self._mgr.createEntity('Indexed%d' % index, 'Indexed ('+ str(index) +').mesh')
rizzinode = self._mgr.getRootSceneNode().createChildSceneNode(rizzi.getName())
#rizzinode = self.sceneManager.getRootSceneNode().createChildSceneNode( "RizziNode%d" % index)
rizzinode.attachObject( rizzi )
## Create the physical version (just static geometry, it can't move so
## it doesn't need a body) and keep track of it
ei = OgreOde.EntityInformer(rizzi,ogre.Matrix4.getScale(rizzinode.getScale()))
geom = ei.createStaticTriangleMesh(self._world, self._space)
print "GETTING", rizzi.getUserObject()
and a camera attach to a sphere but this means 1 FPS how can i do camera collision in correct way?
this is my scene, i need to collide with floor, walls, stairs and pillars
thank you for help
Now the collision works, i used OgreNewt,
this is the code:
for index in xrange(1, 521):
rizzi = self.sceneManager.createEntity('Indexed%d' % index, 'Indexed ('+ str(index) +').mesh')
rizzinode = self.sceneManager.getRootSceneNode().createChildSceneNode("RizziNode%d" % index)
col1 = OgreNewt.TreeCollision(self.World, rizzinode,True)
body1 = OgreNewt.Body( self.World, col1 )
body1.attachToNode( rizzinode )
body1.setPositionOrientation( Ogre.Vector3(0.0,0.0,0.0), Ogre.Quaternion.IDENTITY )
now i've to collide with a camera... how can i do?
Please use code tags when you post code, it makes your posts more readable.
I'm trying to do similar things at the moment (without sucess yet unfortunately). I know of 2 options which should work (although of course I'm sure there are more.
1. the sphere / cylinder approach. Theres a good tutorial for doing this in ODE here: http://www.ogre3d.org/wiki/index.php/Og
... _Character . The benefit is that you get a realistic collision hull for your character, and the ability for him to walk around (or your camera - same difference). The downside is that its not very easy to set up, especially in OgreNewt. Ihave been trying to get this working for about a week, without much success. I'll post what code I have:
def makeWalkingPhysics(self, world, entity):
# make a walking character physics setup
self.torque = 0.0 # forward motion
self.steering = 0.0 # rotation direction on X,Z plane
aab = entity.boundingBox
min = aab.getMinimum() * self.nodeScale
max = aab.getMaximum() * self.nodeScale
center = aab.getCenter() * self.nodeScale
size = ogre.Vector3( abs(max.x-min.x), abs(max.y-min.y), abs(max.z-min.z) )
if size.x < size.z:
radius = size.z / 4.0
radius = size.x / 4.0
feetSphere = OgreNewt.Ellipsoid(world, ogre.Vector3(radius, radius, radius))
feetInertia = OgreNewt.CalcSphereSolid(self.mass, radius)
feetBody = OgreNewt.Body(world, feetSphere)
feetLoc = self.OgreNode.position + ogre.Vector3(0, -size.y /2, 0)
feetBody.setPositionOrientation( feetLoc, ogre.Quaternion.IDENTITY )
self.bodies['feetBody'] = feetBody
torsoCapsule = OgreNewt.Capsule(world, radius, size.y)
torsoInertia = OgreNewt.CalcCylinderSolid(self.mass, radius, size.y - radius)
torsoBody = OgreNewt.Body(world, torsoCapsule)
torsoBody.setPositionOrientation( self.OgreNode.position, ogre.Quaternion.IDENTITY )
self.bodies['torsoBody'] = torsoBody
# connect them, body is child of feet
print world, torsoBody, feetBody
joint = OgreNewt.Hinge(world, torsoBody, feetBody, center-ogre.Vector3(size.x/2,0,0), ogre.Vector3.UNIT_X)
self.bodies['joint'] = joint
# -- Here, we set the userdata of the body to be the actor
# -- Then we set a callback to the physics function at the
# -- very top of this file.
feetBody.setUserData( self )
feetBody.physCallback = self.actorPhysCallback
feetBody.setCustomForceAndTorqueCallback(feetBody, 'physCallback' )
Note - this doesn't actually work for me yet, if you can get it working I'd love to know how you do it.
2. The single sphere approach. This is much simpler to set up, I think you create 2 spheres, with a un-constrained joint between them (so the character doesn't roll around), then just apply torque to the outer sphere, to roll it along the surface. The downside to this is that your collision hull for the character is much less realistic, as you're only using a big sphere to represent them.
Hope that helps in some way
I just looked at your code in the original post .. note that you can use OgreNewt's treeCollisionSceneParser utility to parse an entire tree of nodes, and convert them into a treecollision object. The uitility returns a single body object representing all the nodes in the tree. Would save you having to load every entity in the indexed manner that you seem to be doing in your code.
here's what worked for me (all my environment scene is attached to 'staticRoot' and loaded in using the dotscene xml loader.
stat_col = OgreNewt.TreeCollisionSceneParser( self.world )
stat_col.parseScene( self.staticRoot, True )
self.staticCollisionBody = OgreNewt.Body( self.world, stat_col )
self.staticCollisionBody.attachToNode( self.staticRoot )
the boolean argument after parseScene defines whether to generate an optimized tree or a full tree collision.