How do you make a light pole

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

How do you make a light pole

Postby beroc » Tue Jul 28, 2009 11:33 am

I am looking to create collision objects that are "stuck" to the ground unless enough force is provided to dislodge it. So a light pole is probably the best example that I can think of that would do that. If you place a standard pole sitting straight up on a level surface, it stands perfectly.. Add the light, it will topple in the simulation. Also... if you put a pole on a slope, it will drop. What I want is a pole that stands there until I hit it head on with my car. (bodies flying out the windshields, severe concussions all around)

Can it be done? and how?
beroc
 
Posts: 13
Joined: Mon Aug 28, 2006 2:54 pm

Re: How do you make a light pole

Postby Julio Jerez » Tue Jul 28, 2009 5:11 pm

Oh I am glad you ask because this is one of eth new Pawaaaaa of 2.00
If you look at tutorial_102_UsingJoint
http://newtondynamics.com/wiki/index.php5?title=Tutorials

you will find a very versatile joint called CreateCustomKinematicController.

Basically you do to is you make your normal rigid body,
Then you attack that joint using the pivot point of the body, I guess this will be the lower bottom.
Then you set the maximum forces and torque the joint will allow to Generate before it breaks.
I need to know if you are using the C interface or CPP so the I can tell you how to do the Break when the force exceeds the limits, it is very easy.
The code is self maintained in the sense that body will be at rest and will only work when other body hit it.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How do you make a light pole

Postby beroc » Tue Jul 28, 2009 7:29 pm

I am using C++ OgreNewt (but if that wont accomplish it, I will do what I can with pure C++) With the principles, I will attempt to figure out if it can be done in OgreNewt. Currently I am running 1.53, not 2, but if it takes going to 2, I will update OgreNewt for it as best as possible.

Secondary, I am creating 3ds Max exporters for Ogre that will allow me to simply copy and place objects and generate levels, vehicles, objects and people with ease. So it's kind of important to know the basics. :D

Thanks
beroc
 
Posts: 13
Joined: Mon Aug 28, 2006 2:54 pm

Re: How do you make a light pole

Postby Julio Jerez » Tue Jul 28, 2009 11:04 pm

well the first thing is that yo uneed to be in 2.00 teh lates vesion.
I do not really knwo what is the status of the OgreNewt wrapper, some people had made posted here saying they updated to 2.00 but I still keep getting people saying they are using 1.53

To get the best of Newton you need to be in 2.00
I believe it is simple to update.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How do you make a light pole

Postby beroc » Fri Jul 31, 2009 10:44 pm

OK, updated to 2.0, however, I had to butcher OgreNewt to get it to do some really nice things. So... I am up in the tutorials almost to joints. As it sits right now, I have a world manager on top of Ogre that handles all the little things. One of my favorite things as of thus is some pretty interesting forces. I have a working whirlwind, directional wind and explosions. I got to really get in and learn how to use normals and cross vectors. I am actually pleased with the past couple of days for what all I have done.

I have found something called Autosleep, though I havent tested it. But I am sure it doesnt do what my original question is.. How to make a light pole.

I am using 2.03 since it was not beta.

More questions now:
How can I tell where, in local terms, that an impact has taken place? and the amount of force that is applied to that area.

Also, I see in some demos that there are dust cloud particles and sparks particles coming from vehicles. Does newton tell me where something is contacting another thing at and how fast something like scrapes are?

I can put about 30-40 objects in my solver, and it doesnt slow down that bad, however, when I put more than that, it starts dragging. I get about 100 and it is very noticable. I did some tests and in my code, I made it recreate and load data as I went, I since found that all I had to do was simply tell Newton to reset them and drop all the inertia and I could reuse objects.. This did not fix my problem though. It does seem to work better with spheres then boxes though. My solver actually creates 30-40 various primatives. (which I use to test my forces)

YaY YOUTUBE!!!
beroc
 
Posts: 13
Joined: Mon Aug 28, 2006 2:54 pm

Re: How do you make a light pole

Postby Julio Jerez » Sat Aug 01, 2009 12:35 am

you need to use 2.04, It is importat
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How do you make a light pole

Postby beroc » Sat Aug 01, 2009 1:26 am

Updated, no real change in anything, htough I did some testing, Ogre is not nessicarily a king of dumping polygons. fraps stated my fps with 50 objects was about 24, with 100 was about 13. Then I did tests without newton and came up with 113 and 66 respectively. I dont know exactly how accurate fraps is, but the numbers are out there, by percentage, I lost about 40% of my dps going from 50 to 100, was the same with newton as well. I will just have to be careful about how much I get the engine to do.

Other questions still stand though.
beroc
 
Posts: 13
Joined: Mon Aug 28, 2006 2:54 pm

Re: How do you make a light pole

Postby Julio Jerez » Sat Aug 01, 2009 9:19 am

Y0u need to move to 2.04, it is in 2.04 that you cna us the new joint.

Plus fraps is no a toll to measure fps.
Also are you using solve mode 0? that will be slow
the engone should be able to do about 200 bodies at more than 200 fps.

see the wiki tutorial for a real implemention that hows the FPS.
please update to 2.04
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How do you make a light pole

Postby Julio Jerez » Sat Aug 01, 2009 4:10 pm

Ok here is a joint taht can do waht you want

Code: Select all
class BreakableFixed: public NewtonCustomJoint
{
public:
   BreakableFixed (const dMatrix& pivotAndRotationMatrix, const NewtonBody* body, const NewtonBody* worldBody, float maxForce, float maxTorque)
      :NewtonCustomJoint (6, body, worldBody)
   {
      m_maxForce = fabsf (maxForce);
      m_maxToque = fabsf (maxForce);
      CalculateLocalMatrix (pivotAndRotationMatrix, m_localMatrix0, m_localMatrix1);
   }

protected:
   virtual void SubmitConstrainst (dFloat timestep, int threadIndex)
   {
      // check is the joint violated the force limit
      float comperaMax = m_maxForce * 0.9f;
      for (int i = 0; i < 3; i ++) {
         if (fabsf (NewtonUserJointGetRowForce (m_joint, i) > comperaMax)) {
            // join broke;
            delete this;
            return ;
         }
      }

      // check is the joint violated the torque limit
      comperaMax = m_maxToque * 0.9f;
      for (int i = 0; i < 3; i ++) {
         if (fabsf (NewtonUserJointGetRowForce (m_joint, i + 3) > comperaMax)) {
            // join broke;
            delete this;
            return ;
         }
      }

      dFloat angle;
      dFloat sinAngle;
      dFloat cosAngle;
      dMatrix matrix0;
      dMatrix matrix1;

      // calculate the position of the pivot point and the Jacobian direction vectors, in global space.
      CalculateGlobalMatrix (m_localMatrix0, m_localMatrix1, matrix0, matrix1);

      // Restrict the movement on the pivot point along all tree orthonormal direction
      NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_front[0]);
      NewtonUserJointSetRowMaximumFriction (m_joint, m_maxForce);
      NewtonUserJointSetRowMaximumFriction (m_joint, -m_maxForce);

      NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_up[0]);
      NewtonUserJointSetRowMaximumFriction (m_joint, m_maxForce);
      NewtonUserJointSetRowMaximumFriction (m_joint, -m_maxForce);

      NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_right[0]);
      NewtonUserJointSetRowMaximumFriction (m_joint, m_maxForce);
      NewtonUserJointSetRowMaximumFriction (m_joint, -m_maxForce);


      // get a point along the pin axis at some reasonable large distance from the pivot
#define MIN_JOINT_PIN_LENGTH  50.0f
      dVector q0 (matrix0.m_posit + matrix0.m_front.Scale(MIN_JOINT_PIN_LENGTH));
      dVector q1 (matrix1.m_posit + matrix1.m_front.Scale(MIN_JOINT_PIN_LENGTH));

      // two constraints row perpendicular to the pin vector
      NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_up[0]);
      NewtonUserJointSetRowMaximumFriction (m_joint, m_maxForce);
      NewtonUserJointSetRowMaximumFriction (m_joint, -m_maxForce);

      NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_right[0]);
      NewtonUserJointSetRowMaximumFriction (m_joint, m_maxForce);
      NewtonUserJointSetRowMaximumFriction (m_joint, -m_maxForce);


      // the joint angle can be determine by getting the angle between any two non parallel vectors
      sinAngle = (matrix0.m_up * matrix1.m_up) % matrix0.m_front;
      cosAngle = matrix0.m_up % matrix1.m_up;
      angle = dAtan2 (sinAngle, cosAngle);

      // tell joint error will minimize the exceeded angle error
      NewtonUserJointAddAngularRow (m_joint, angle, &matrix0.m_front[0]);
      NewtonUserJointSetRowMaximumFriction (m_joint,  m_maxToque);
      NewtonUserJointSetRowMaximumFriction (m_joint, -m_maxToque);
   }

protected:
   float m_maxForce;
   float m_maxToque;
   dMatrix m_localMatrix0;
   dMatrix m_localMatrix1;
};



basically you call it wit teh pointe to teh body you want to keep fiex (the pool) and teh body the pole will be atteched to.
The you select and attachemt point (i guess a point at the bottoym so tha when it break is roles aroudn tha pivot )
you also need to spcify an oritation (the pall roation is a good choise)

you also pass the Max force and torque the body can resist before it brakes.
and Badabin Badabum you get want you need.
I do not test it, you let me know if it worlks or if it has a bug
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How do you make a light pole

Postby beroc » Sat Aug 01, 2009 11:10 pm

Okie, got a little problem, probably easily fixed though I am dont know how at the moement...

Code: Select all
#include "Newton.h"
#include "JointLibrary.h"

class BreakableJoint: public NewtonCustomJoint


Error   1   error C2504: 'NewtonCustomJoint' : base class undefined   c:\ogresdk\samples\newton\newton\breakablejoint.h   5   game


NewtonCustomJoint is not defined in neither the Newton.h or JointLibrary.h (checked the debug file as well, but it isnt there.

I also cannot find it in the entire tutorial solution.

I would say that it could be from the NewtonJoint, but the Newton.h file says that is a struct.

or.... am I just using it incorrectly?
beroc
 
Posts: 13
Joined: Mon Aug 28, 2006 2:54 pm

Re: How do you make a light pole

Postby Julio Jerez » Sat Aug 01, 2009 11:44 pm

Maybe the header file is #include "NewtonCustomJoint.h" instead of #include "JointLibrary.h"

I am hopping OgreNewton inp,emet joint using the custom joints. NewtonCustomJoint, or an I wrong?
if not then you will have to recreate the joint using the base class that is used to make Custom joints for Newton in OgreNewton.

Who maintain Ogre Newton?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How do you make a light pole

Postby beroc » Sun Aug 02, 2009 12:45 pm

Oh, yeah, I am feelin' stupid as it goes.. I never included the JointLibrary.lib into my application, it was throwing up all over the place.

But here is the only problem that I have.

Code: Select all
      void test(int n){
         Vector3 pos(0,0,29.5);
         Quaternion rot(Quaternion::IDENTITY);
         dMatrixConverter matrix(pos, rot);
         
         //dVector minLinearLimits (0.0f, 0.0f, 0.0f, 0.0f);
         //dVector maxLinearLimits (0.0f, 0.0f, 0.0f, 0.0f);
         //dVector minAngulaLimits (-0.5f * 3.1416f, 0.0f, 0.0f, 0.0f);
         //dVector maxAngulaLimits ( 0.5f * 3.1416f, 0.0f, 0.0f, 0.0f);
         //NewtonUserJoint* joint;
         //joint=CreateCustomJoint6DOF(&matrix.dmatrix[0][0],&matrix.values[0],
         //   mBodies[n].getCollision(),mBodies[n-1].getCollision());
         // set the hinge Limits
          //CustomJoint6DOF_SetLinearLimits (joint, &minLinearLimits[0], &maxLinearLimits[0]);
          //CustomJoint6DOF_SetAngularLimits (joint, &minAngulaLimits[0], &maxAngulaLimits[0]);
         
         CustomBreakableJoint bjoint;
         bjoint = CustomBreakableJoint(matrix.dmatrix,mBodies[n].getCollision(),
            mBodies[n-1].getCollision(),100,100);
      }

Error   1   error C2512: 'CustomBreakableJoint' : no appropriate default constructor available   c:\ogresdk\samples\newton\newton\world.h   214   game

in the World.h:
Body* mBodies;

in the Body.h file:
NewtonBody* mBody;
NewtonBody* getCollision(){return mBody;}


From the tutorial I got the standard joint to work, I have a light pole... Since I am lazy, I just made it horizontal instead of verticle. The pole pivots on the position as it should and looks nice. (I did this to make sure it all was working as the tutorial shows it)

The only thing I can think of is that I am not sending something to it correctly formating something, but I cant figure it out yet.

My problem with the second part is probably more of a semantics issue. My converter uses a dMatrix as described in the dMath.h file, and it all appears to work fine. Only question that I have about that is this:

Code: Select all
dmatrix=dMatrix(dQuaternion(rot.x,rot.y,rot.z,rot.w),dVector(pos.x,pos.y,pos.z));


I just wanted to know if it was x,y,z,w, and not w,x,y,z. That would not cause my error, but it would produce some strange results down the road.


I am not using OgreNewt, just Ogre and Newton. As opposed to everyone in the world, I have to know how everything works. Kind of in my personality.
beroc
 
Posts: 13
Joined: Mon Aug 28, 2006 2:54 pm

Re: How do you make a light pole

Postby Julio Jerez » Sun Aug 02, 2009 1:09 pm

The quaternion in Newton is encode as [q0 q1 q2 q3]
a unit quaternion will be [1 0 0 0]

just make a unit quetsion in your libray, if the one is in x part of teh vector then is is [x y z w]
is the one is in w then is will be [w, x, y z]
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How do you make a light pole

Postby beroc » Sun Aug 02, 2009 10:15 pm

OK, cant see as it is working. Tried a bunch of different ways... ran into a couple of dumb problems but in the end.... this should have worked.

Code: Select all
      NewtonBody* floor=MakeSimpleBox("floor",0,Vector3(10,1,10),Vector3(0,8,0));
      NewtonBody* b1=MakeSimpleBox("box1",10,Vector3(1,1,1),Vector3(0,10,0),Quaternion::IDENTITY,"Wall");
      NewtonBody* b2=MakeSimpleBox("box2",10,Vector3(1,1,1),Vector3(0,12,0),Quaternion::IDENTITY,"Wall");
      dMatrix m(
         dVector(1,0,0,0),
         dVector(0,1,0,0),
         dVector(0,0,1,0),
         dVector(0,10.75,0,1));
      CustomBreakableJoint joint(m,b2,NULL,100,100);


Note: Box1 is under Box 2.. and Box 2 is linked to the joint. Nothing falls on it, but it falls none the less.

Any ideas?
beroc
 
Posts: 13
Joined: Mon Aug 28, 2006 2:54 pm

Re: How do you make a light pole

Postby beroc » Mon Aug 03, 2009 3:03 am

I apparently am not doing this correctly. I can't even get the custom slider to work. I tried looking over the forums and I dont see any code on how to implement them.

Code: Select all
CustomSlider joint(m,b1, NULL);
joint.SetLimis(-3,3);
beroc
 
Posts: 13
Joined: Mon Aug 28, 2006 2:54 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron