Bullets and balls

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Bullets and balls

Postby ellorenz » Sat Mar 14, 2009 7:30 am

Hi, i'm new on Newton and i need help to create a object during execution of the program like a bullet or ball and not on of program initializizing, like tutorial .
Example
i fire the bullet (a sphere) hit a box react correctly with newton world



Thank's
ellorenz
 
Posts: 5
Joined: Sat Sep 27, 2008 7:45 am

Re: Bullets and balls

Postby VeT » Sat Mar 14, 2009 2:48 pm

1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy
LiteC+Newton2 download: http://hosted.filefront.com/NeArGa
LiteC+Newton2 discussion: http://tinyurl.com/6l7y9v
VeT
 
Posts: 84
Joined: Thu Jul 31, 2008 11:31 am

Re: Bullets and balls

Postby ellorenz » Sun Mar 15, 2009 7:35 pm

Thank'you very much
Now i'm looking with irrlicht to give the direction
i'm studing the argument on newton velocity

:mrgreen:
ellorenz
 
Posts: 5
Joined: Sat Sep 27, 2008 7:45 am

Re: Bullets and balls

Postby ellorenz » Tue Mar 17, 2009 6:35 pm

Hi i'm back because a need help to give speed on my fired object, i saw the example with lite c but i use irrlicht.
Now i understand how to fire the object in the cam direction but i can't give speed to the object can u help me on
NewtonBodySetVelocity function?
ellorenz
 
Posts: 5
Joined: Sat Sep 27, 2008 7:45 am

Re: Bullets and balls

Postby ellorenz » Wed Mar 18, 2009 6:09 pm

i don't how i can rotate the velocity vector, somebody can help me?

This is the code:

Code: Select all
   dMatrix location (GetIdentityMatrix());
   dVector size (0.5f, 0.5f, 0.5f);
   core::vector3df nstart = mystart;
   //irr::f64 rotazione = cam->getRotation().X * (180.0/3.1416);
   //nstart.rotateXZBy(rotazione,nstart);
   nstart *=IRRTONEWTON;
   location.m_posit.m_y = nstart.Y;
   location.m_posit.m_x = nstart.X;
   location.m_posit.m_z = nstart.Z;
   
   float irrSize = size.m_x*NEWTONTOIRR;

   scene::ISceneNode* billnode = smgr->addSphereSceneNode(irrSize,16,0,-1, start,cam->getRotation());
   
   
   //billnode->setRotation(cam->getRotation());
      
   billnode->setDebugDataVisible(irr::scene::EDS_FULL);
   f32 length = (f32)(end - start).getLength();
   const f32 speed = 0.6f;
   u32 time = (u32)(length / speed);
   scene::ITriangleSelector* billselector = 0;
    billselector = smgr->createTriangleSelectorFromBoundingBox(billnode);
   Selectors.push_back(billselector);
    scene::ISceneNodeAnimator* anim = 0;
    imp.shootednode = billnode;
   
   if (imp.when)
   {
      // create impact note
      imp.when = device->getTimer()->getTime() + (time - 100);
      Impacts.push_back(imp);
   }
   float inertia[3];
   float centerofmass[3];
   float mass = 10;

   imp.shootednode->setMaterialFlag(video::EMF_LIGHTING, true);
   imp.shootednode->setMaterialFlag(video::EMF_WIREFRAME,true);
   core::vector3df position (location.m_posit.m_x, location.m_posit.m_y, location.m_posit.m_z);
      
   collision = NewtonCreateSphere (nWorld, size.m_x, size.m_y, size.m_z, NULL);
   
   imp.shootedBody = NewtonCreateBody (nWorld, collision);
      
   NewtonConvexCollisionCalculateInertialMatrix(collision, inertia, centerofmass);
   NewtonBodySetMassMatrix(imp.shootedBody, mass, mass * inertia[0], mass * inertia[1], mass * inertia[2]);
   
   NewtonBodySetUserData (imp.shootedBody, imp.shootednode);
   NewtonBodySetDestructorCallback (imp.shootedBody, PhysicsBodyDestructor);
   NewtonBodySetTransformCallback (imp.shootedBody, PhysicsSetTransform);
   NewtonBodySetForceAndTorqueCallback (imp.shootedBody, PhysicsApplyForceAndTorque);
   NewtonBodySetMatrix (imp.shootedBody, &location[0][0]);
   PhysicsSetTransform (imp.shootedBody, &location[0][0]);
   dVector vel(-22.0f,0.0f,0.0f);
   NewtonBodySetVelocity(imp.shootedBody, &vel[0]);
ellorenz
 
Posts: 5
Joined: Sat Sep 27, 2008 7:45 am

Re: Bullets and balls

Postby ellorenz » Fri Mar 20, 2009 6:05 pm

I find the solution :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D
Know i post it for irrlicht user
(irrlicht with newton velocity)


Code: Select all
   core::vector3df start = cam->getPosition();
   core::vector3df end = (cam->getTarget() - start);
   start += end*8.0f;
   end = start + (end * cam->getFarValue());
   core::triangle3df triangle;
   core::line3d<f32> line(start, end);
   f32 length = (f32)(end - start).getLength();
   core::vector3df acceleration = end - start;
   const f32 speed = 50.0f;
   u32 time = (u32)(length / speed);
   u32 realtime = device->getTimer()->getRealTime()/1000;
   time += realtime;
   u32 t1 =  time - realtime;

   acceleration /= t1;
   NewtonBodySetVelocity(imp.shootedBody, &acceleration.X);
ellorenz
 
Posts: 5
Joined: Sat Sep 27, 2008 7:45 am

Re: Bullets and balls

Postby ODSTDare » Wed Oct 07, 2009 7:19 pm

Thanks for the link, VeT.

And ellorenz, did you really just quad post?!

*whisper* Edit button *whisper*
ODSTDare
 

Re: Bullets and balls

Postby Stucuk » Wed Oct 07, 2009 9:06 pm

ODSTDare wrote:And ellorenz, did you really just quad post?!


Last post before yours was March 20th, so he didn't just do anything.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron