Hi,
mir sind zwei Sachen aufgefallen, einmal steht in der Hilfe im Playground Sample steht C für Zylinder, da kommt aber ne Kapsel und bei Y erstellt man einen Zylinder.
Das zweite Problem ist da schon ärger:
Code:
#include <irrlicht.h>
#include <IrrODE.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#include <iostream>
using namespace std;
class myBodyEventListener : public IIrrOdeEventListener {
private:
IVideoDriver *m_pDriver;
f32 m_fMinX,m_fMinZ,m_fMaxX,m_fMaxZ;
public:
myBodyEventListener(IVideoDriver *pDriver, f32 fMinX, f32 fMinZ, f32 fMaxX, f32 fMaxZ){
m_pDriver=pDriver;
m_fMinX=fMinX;
m_fMinZ=fMinZ;
m_fMaxX=fMaxX;
m_fMaxZ=fMaxZ;
}
bool onEvent(IIrrOdeEvent *pEvent) {
if (pEvent->getType()==IRR_ODE_EVENT_COLLISION_ID) {
cout<<"collision\n";
static int cnt=0;
CIrrOdeEventCollision *pEvtCol=(CIrrOdeEventCollision *)pEvent;
if (pEvtCol->getGeom()->getBody()!=NULL) {
cnt?cnt=0:cnt=1;
list<ISceneNode *> children=pEvtCol->getBody()->getChildren();
list<ISceneNode *>::Iterator i;
}
}
if (pEvent->getType()==IRR_ODE_EVENT_ACTIVATION_CHANGED_ID) {
CIrrOdeEventActivationChanged *pActEvt=(CIrrOdeEventActivationChanged *)pEvent;
list<ISceneNode *> children=pActEvt->getBody()->getChildren();
list<ISceneNode *>::Iterator i;
}
if (pEvent->getType()==IRR_ODE_EVENT_BODY_CREATED_ID) {
}
if (pEvent->getType()==IRR_ODE_EVENT_BODY_MOVED_ID) {
CIrrOdeEventBodyMoved *pEvt=(CIrrOdeEventBodyMoved *)pEvent;
if (pEvt->getBody()->getBodyId()) {
vector3df pos=pEvt->getBody()->getPosition(),vel=pEvt->getBody()->getLinearVelocity();
if (pos.X<m_fMinX) {
pEvt->getBody()->setLinearVelocity(vector3df(-vel.X,vel.Y,vel.Z)/2);
pEvt->getBody()->setPosition(vector3df(m_fMinX+1,pos.Y,pos.Z));
}
if (pos.X>m_fMaxX) {
pEvt->getBody()->setLinearVelocity(vector3df(-vel.X,vel.Y,vel.Z)/2);
pEvt->getBody()->setPosition(vector3df(m_fMaxX-1,pos.Y,pos.Z));
}
if (pos.Z<m_fMinZ) {
pEvt->getBody()->setLinearVelocity(vector3df(vel.X,vel.Y,-vel.Z)/2);
pEvt->getBody()->setPosition(vector3df(pos.X,pos.Y,m_fMinZ+1 ));
}
if (pos.Z>m_fMaxZ) {
pEvt->getBody()->setLinearVelocity(vector3df(vel.X,vel.Y,-vel.Z)/2);
pEvt->getBody()->setPosition(vector3df(pos.X,pos.Y,m_fMaxZ-1));
}
}
}
return false;
}
bool handlesEvent(IIrrOdeEvent *pEvent) {
return pEvent->getType()==IRR_ODE_EVENT_COLLISION_ID ||
pEvent->getType()==IRR_ODE_EVENT_BODY_CREATED_ID ||
pEvent->getType()==IRR_ODE_EVENT_ACTIVATION_CHANGED_ID ||
pEvent->getType()==IRR_ODE_EVENT_BODY_MOVED_ID;
}
};
int main(int argc, char** argv) {
IrrlichtDevice *device=createDevice(EDT_OPENGL,dimension2d<s32>(640,480),16,false,false,false,0);
device->setWindowCaption(L"HelloOdeWorld");
ISceneManager *smgr = device->getSceneManager();
IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* guienv = device->getGUIEnvironment();
CIrrOdeSceneNodeFactory cFactory(smgr);
smgr->registerSceneNodeFactory(&cFactory);
CIrrOdeManager::getSharedInstance()->initODE();
ITimer *pTimer=device->getTimer();
CIrrOdeManager::getSharedInstance()->setTimer(pTimer);
ISceneNode *pNode=smgr->addSceneNode(CIrrOdeSceneNode::nodeNameToC8(IRR_ODE_WORLD_NAME),smgr->getRootSceneNode());
CIrrOdeWorld *worldNode=reinterpret_cast<CIrrOdeWorld *>(pNode);
worldNode->setGravity(vector3df(0.0f,-10.0f,0.0f));
myBodyEventListener *pColEvtListener=new myBodyEventListener(driver,-125,-125,125,125);
CIrrOdeManager::getSharedInstance()->addEventListener(pColEvtListener);
IAnimatedMesh *Mesh=smgr->getMesh("data/box.3ds");
IAnimatedMeshSceneNode *Groundnode=smgr->addAnimatedMeshSceneNode(Mesh,worldNode);
Groundnode->setMaterialTexture(0,driver->getTexture("data/sphere_bw.jpg"));
Groundnode->setScale(vector3df(150.0f,1.5f,150.0f));
Groundnode->setMaterialFlag(EMF_LIGHTING,false);
CIrrOdeGeomBox *bx=reinterpret_cast<CIrrOdeGeomBox *>(smgr->addSceneNode(CIrrOdeSceneNode::nodeNameToC8(IRR_ODE_GEOM_BOX_NAME),Groundnode));
bx->getSurfaceParameters()->setBounce(1.0f);
bx->getSurfaceParameters()->setModeMu2(true);
bx->getSurfaceParameters()->setModeBounce(true);
bx->getSurfaceParameters()->setMu(10);
bx->getSurfaceParameters()->setMu2(10);
bx->drop();
for(int x=-10;x<10;x++)
{
for(int z=-10;z<10;z++)
{
IAnimatedMeshSceneNode *Chain=smgr->addAnimatedMeshSceneNode(smgr->getMesh("data/box.3ds"),worldNode);
Chain->setMaterialTexture(0,driver->getTexture("data/sphere_bw.jpg"));
Chain->setScale(vector3df(3.0f,3.0f,3.0f));
Chain->setPosition(vector3df(15*x,30-((abs(x)+abs(z))/2)*5,15*z));
Chain->setMaterialFlag(EMF_LIGHTING,false);
CIrrOdeGeomBox *ChainGeomBox=reinterpret_cast<CIrrOdeGeomBox *>(smgr->addSceneNode(CIrrOdeSceneNode::nodeNameToC8(IRR_ODE_GEOM_BOX_NAME),Chain));
ChainGeomBox->getSurfaceParameters()->setModeMu2(true);
ChainGeomBox->getSurfaceParameters()->setMu(10);
ChainGeomBox->getSurfaceParameters()->setMu2(10);
ChainGeomBox->drop();
Chain->setRotation(core::vector3df(45,45,45));
}
}
for( int i = 1;i<11;i++)
{
CIrrOdeBody *BarrelBody=reinterpret_cast<CIrrOdeBody *>(smgr->addSceneNode(CIrrOdeSceneNode::nodeNameToC8(IRR_ODE_BODY_NAME),worldNode));
BarrelBody->setPosition(vector3df(0.0f,80.0f,0.0f));
BarrelBody->setPosition(vector3df(5.5*i,80+9*i,6*i));
ISceneNode *BarrelNode=smgr->addAnimatedMeshSceneNode(smgr->getMesh("data/barrel.b3d"),BarrelBody);
BarrelNode->setMaterialTexture(0,driver->getTexture("data/pavorb1.jpg"));
BarrelNode->setMaterialFlag(EMF_LIGHTING,false);
BarrelNode->setScale(vector3df(10,10,10));
CIrrOdeGeomCylinder *BarrelGeom=reinterpret_cast<CIrrOdeGeomCylinder *>(smgr->addSceneNode(CIrrOdeSceneNode::nodeNameToC8(IRR_ODE_GEOM_CYLINDER_NAME),BarrelNode));
BarrelGeom->setMassTotal(1.5f);
BarrelGeom->getSurfaceParameters()->setBounce(0.2f);
BarrelGeom->getSurfaceParameters()->setModeMu2(true);
BarrelGeom->getSurfaceParameters()->setModeBounce(true);
BarrelGeom->getSurfaceParameters()->setMu(10);
BarrelGeom->getSurfaceParameters()->setMu2(10);
}
ICameraSceneNode *cam=smgr->addCameraSceneNodeFPS(0,100,0.03);
cam->setTarget(vector3df(0.0f,30.0f,0.0f));
IAnimatedMeshSceneNode *camerasphere=smgr->addAnimatedMeshSceneNode(smgr->getMesh("data/sphere.3ds"),worldNode);
camerasphere->setMaterialTexture(0,driver->getTexture("data/sphere_bw.jpg"));
camerasphere->setMaterialFlag(EMF_LIGHTING,false);
camerasphere->setMaterialFlag(EMF_BACK_FACE_CULLING,false);
camerasphere->setMaterialFlag(EMF_WIREFRAME,true);
CIrrOdeGeomSphere *pCamSphere=reinterpret_cast<CIrrOdeGeomSphere *>(smgr->addSceneNode(CIrrOdeSceneNode::nodeNameToC8(IRR_ODE_GEOM_SPHERE_NAME),camerasphere));
cam->setPosition(vector3df(20,20,0));
worldNode->initPhysics();
while (pTimer->isStopped()) pTimer->start();
while(device->run()) {
pCamSphere->setPosition(cam->getAbsolutePosition());
camerasphere->setPosition(cam->getAbsolutePosition());
CIrrOdeManager::getSharedInstance()->step();
driver->beginScene(true, true, SColor(0,200,200,200));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Die Zylinder kollidieren nicht miteinander
Wenn ich aber statt einem Zylinder eine Box oder eine Kugel als Geom nehme, funktionieren die Kollisionen.
Wie lös ich das? Oder liegt der Fehler tiefer im Wrapper?
MfG
FTC