Objects collides when it shouldn't

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Objects collides when it shouldn't

Postby nathanf534 » Mon Jul 19, 2010 9:59 pm

I have a spaceship that I am shooting a laser from. Both the laser and the ship are collidable. When I shoot the laser, it hits the spaceship as it is leaving, even if I place the laser significantly far away (80 units) when it is fired. Hopefully there is something simple I am missing, such as telling the engine to update some position, or something along those lines. Here is my code. I am using Irrlicht with newton.

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.
nathanf534
 
Posts: 19
Joined: Sun Jul 11, 2010 9:01 am

Re: Objects collides when it shouldn't

Postby nathanf534 » Mon Jul 19, 2010 10:14 pm

ahh, actually I just figured it out. The transformation matrix of my laser includes a scale that I added, so the cylinder collision is 10 times larger than it should be.

Stupid bugs, sorry for bothering... again.
nathanf534
 
Posts: 19
Joined: Sun Jul 11, 2010 9:01 am

Re: Objects collides when it shouldn't

Postby Julio Jerez » Mon Jul 19, 2010 11:14 pm

These are my favorite kind of bugs, they fix themself.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron