Hi all,
I’m playing with panda and ode built in. I have no collision with OdeTriMeshgeom and I don’t know what I’m doing wrong. I surf the net over two days trying to find a solution, but with no succesfull. Someone can help me please?
In this code the ball collide with the plane (groundGeom) but not with trimesh (worldGeom).
I try to debug with lines worldGeom but it look ok.
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.OnscreenText import OnscreenText
from direct.actor.Actor import Actor
from direct.task.Task import Task
from direct.showbase.DirectObject import DirectObject
from direct.directtools.DirectGeometry import LineNodePath
import random, sys, os, math
class Entity():
#constructora
def __init__(self, render, model = None, body = None):
self.render = render
self.model = model
self.body = body
#set model and body
def setModelBody(self, model, body):
self.model = model
self.body = body
#update
def update(self):
self.model.setPosQuat(self.render, self.body.getPosition(), Quat(self.body.getQuaternion()))
class Game():
#Constructor
def __init__(self):
self.deltaTimeAccumulator = 0.0;
self.slowMotion = False
self.entities = []
#Ode world
self.world = OdeWorld()
self.world.setGravity(0, 0, -9.81)
#surface table
self.world.initSurfaceTable(1)
self.world.setSurfaceEntry(0, 0, 150, 0.0, 9.1, 0.9, 0.00001, 0.0, 0.002)
# The surface table is needed for autoCollide
self.world.initSurfaceTable(1)
self.world.setSurfaceEntry(0, 0, 150, 0.0, 9.1, 0.9, 0.00001, 0.0, 0.002)
#Create space
self.space = OdeSimpleSpace()
self.space.setAutoCollideWorld(self.world)
self.contactgroup = OdeJointGroup()
self.space.setAutoCollideJointGroup(self.contactgroup)
#init world
self.lines = LineNodePath(parent = render, thickness = 3.0, colorVec = Vec4(1, 0, 0, 1))
self.initWorld()
#self.space.enable()
#lines
def initWorld(self):
worldModel = loader.loadModel("models/world")
worldModel.reparentTo(render)
worldBody = OdeBody(self.world)
worldMass = OdeMass()
worldMass.setBox(10, 1, 1, 1)
#worldBody.setMass(worldMass)
worldTrimesh = OdeTriMeshData(worldModel, True)
worldGeom = OdeTriMeshGeom(self.space, worldTrimesh)
worldGeom.setBody(worldBody)
worldGeom.setCollideBits(BitMask32(0x00000001))
worldGeom.setCategoryBits(BitMask32(0x00000001))
worldBody.setPosition(worldModel.getPos(render))
worldBody.setQuaternion(worldModel.getQuat(render))
ball = loader.loadModel("smiley")
ball.setPos(-15,-15,11)
ball.reparentTo(render)
M = OdeMass()
M.setSphere(50, 1)
body = OdeBody(self.world)
body.setMass(M)
body.setPosition(ball.getPos(render))
body.setQuaternion(ball.getQuat(render))
ent = Entity(render, ball, body)
self.entities.append(ent)
ballGeom = OdeSphereGeom(self.space, 1)
ballGeom.setCollideBits(BitMask32(0x00000001))
ballGeom.setCategoryBits(BitMask32(0x00000001))
ballGeom.setBody(body)
groundGeom = OdePlaneGeom(self.space, (0, 0, 1, 0))
groundGeom.setCollideBits(BitMask32(0x00000001))
groundGeom.setCategoryBits(BitMask32(0x00000001))
if False: # checking the data
self.lines.reset()
print "self.odeGeom.getNumTriangles()", worldGeom.getNumTriangles()
for i in xrange(worldGeom.getNumTriangles()):
x = Point3(0)
y = Point3(0)
z = Point3(0)
worldGeom.getTriangle( i, x, y, z )
self.lines.drawLines([(x,y),(y,z),(z,x)])
self.lines.create()
#print x,y,z
#Update physics
def updatePhysics(self):
for i in self.entities:
i.update()
game = Game()
##################################################################
#60 fps
stepSize = 1.0 / 60.0
def simulationTask(task):
global game
game.deltaTimeAccumulator += globalClock.getDt()
while game.deltaTimeAccumulator >= stepSize:
game.space.autoCollide()
game.deltaTimeAccumulator -= stepSize
# Step the simulation
game.world.quickStep(stepSize)
game.updatePhysics()
#game.space.empty()
return task.cont
taskMgr.doMethodLater(5.0, simulationTask, "Physics Simulation")
####################################################################
#run
run()
PD: Sorry for my english.
PD2: Sorry for my code if it is not very clear. I’m new on panda3d and I’m playing with it.
PD3: Some code example or tutorial will help alot !!
thanks
edit: Finally I found the error! Line: worldGeom.setBody(worldBody) doesn’t go.