First, I call addLaser, giving a location 80 units in front of the spaceship.
- Code: Select all
weaponManager->addLaser(dummy->getAbsolutePosition()+vector3df(0,0,80));
The addLaser method calls a method in my physics manager to create the Cylinder collision object, and creates a matrix to rotate the cylinder 90 degrees, to match the laser.
- Code: Select all
matrix4* offset = new matrix4;
offset->setRotationDegrees(vector3df(0,90,0));
physicsManager->addCylinderBody(1,20,offset,0,laser);
and here is where I create the cylinder body. I call the NewtonBodySetMatrix to move the cylinder collision past the spaceship before Newton does any collision calculations, so I'm not sure why it is still colliding.
- Code: Select all
void PhysicsManager::addCylinderBody(float radius,float height,matrix4* offset,int id,ISceneNode* node){
NewtonCollision* collision =NewtonCreateCylinder(nWorld,radius,height,id,&offset->M[0]);
NewtonBody* body=NewtonCreateBody(nWorld,collision);
matrix4 mat=node->getAbsoluteTransformation();
NewtonBodySetMatrix(body, &mat.M[0]);
NewtonBodySetMassMatrix(body,1,10,10,10);
NewtonBodySetForceAndTorqueCallback(body,ApplyForceAndTorqueEvent);
NewtonBodySetTransformCallback(body,callbackTransform);
}
Edit: if I increase the distance from 80 to 200, it doesn't collide with it anymore, but then the laser is almost out of view where it starts, that can't be right.