Menu

How to set up TODEDynamic's mass center in BCB6?

2015-10-05
2022-02-15
  • Chen Jau-Huei

    Chen Jau-Huei - 2015-10-05

    Dear all,
    I use the sample file: BCBDemos\physics\simple
    ( I want to creat a tube which can be out of shape by foce and momen.)
    I build a pipe, which has more than one node. And affected by gravity.

      TGLPipe *pipe;
      TGLODEDynamic *dyn;
      TODEElementCylinder **elem;
      pipe = (TGLPipe *)(ODEObjects->AddNewChild(__classid(TGLPipe)));
      pipe->Radius = 1;
      pipe->Position->SetPoint(Random(),5*Random()+2*pipe->Radius,Random());
      pipe->Radius = 0.25*(Random()+1);
      //Add some node
      pipe->AddNode(0,0,0);
      pipe->AddNode(0,1,1);
      pipe->AddNode(0,1,5);
    

    Set up elem and dyn

      for(int i = 0 ; i< pipe->Nodes->Count-1 ; i++)
      {
        elem[i] = (TODEElementCylinder *) dyn>AddNewElement(__classid(TODEElementCylinder));
        elem[i]->Length = sqrt( (pipe->Nodes->Items[i]->X-pipe->Nodes->Items[i+1]->X)*(pipe->Nodes->Items[i]->X-pipe->Nodes->Items[i+1]->X)+
                                (pipe->Nodes->Items[i]->Y-pipe->Nodes->Items[i+1]->Y)*(pipe->Nodes->Items[i]->Y-pipe->Nodes->Items[i+1]->Y)+
                                (pipe->Nodes->Items[i]->Z-pipe->Nodes->Items[i+1]->Z)*(pipe->Nodes->Items[i]->Z-pipe->Nodes->Items[i+1]->Z));
        elem[i]->Density = 1;
        elem[i]->Radius = pipe->Radius;
        elem[i]->Direction->SetVector(0,1,0);
        elem[i]->Position->SetPoint(
                                        (pipe->Nodes->Items[i]->X+pipe->Nodes->Items[i+1]->X)/2.0,
                                        (pipe->Nodes->Items[i]->Y+pipe->Nodes->Items[i+1]->Y)/2.0,
                                        (pipe->Nodes->Items[i]->Z+pipe->Nodes->Items[i+1]->Z)/2.0
                                        );
        elem[i]->Up->SetVector(
                                        pipe->Nodes->Items[i+1]->X-pipe->Nodes->Items[i]->X,
                                        pipe->Nodes->Items[i+1]->Y-pipe->Nodes->Items[i]->Y,
                                        pipe->Nodes->Items[i+1]->Z-pipe->Nodes->Items[i]->Z
                                        );
      }
    

    But the "dyn->Mess.c" allways {0,0,0,0}
    event I use

    dyn->Mass.c[0] = 100;
    

    to change the value, it still {0,0,0,0}

    How can I do?

    Thanks

     

    Last edit: Chen Jau-Huei 2015-10-05
  • Pavel Vassiliev

    Pavel Vassiliev - 2015-10-05

    Hi Chen,
    The BCB6 branch is now not active, so I think that nobady could help you in your deal. Please, migrate to more fresh compiler like C++Builder in RAD Studio XE8 or RAD Studio 10.
    PW

     
  • Chen Jau-Huei

    Chen Jau-Huei - 2015-10-06

    Our company just has BCB6 and BCB XE4,
    but I think that they will be same code.
    Because they use the same library, GLSCENE.

     

    Last edit: Chen Jau-Huei 2015-10-06
  • Pavel Vassiliev

    Pavel Vassiliev - 2015-10-06

    Chen,
    May be your unit code is the same, but the GLScene libraray is different for BCB6 and RAD Studio, so it's better to use XE4 or later. And add in attachments the whole project files.
    PW

     

    Last edit: Pavel Vassiliev 2015-10-06
  • Chen Jau-Huei

    Chen Jau-Huei - 2015-10-06

    Thanks.
    I'd think XE4 is beter tnan BCB6.
    But I can't setup GLScene to XE4.

     

    Last edit: Chen Jau-Huei 2015-10-06
  • Chen Jau-Huei

    Chen Jau-Huei - 2015-10-06

    I find a solution :
    First creat a TGLDummyCube object (dummy).
    Let

    pipe->Parent = dummy;
    

    And then Move dummy to pipe mass center (cx,cy,cz)

    dummy->Position->SetPoint(cx,cy,cz);
    

    Setup each elem as

       elem->Position->SetPoint(
        (pipe->Nodes->Items[i]->X+pipe->Nodes->Items[i+1]->X)/2.0-cx,
        (pipe->Nodes->Items[i]->Y+pipe->Nodes->Items[i+1]->Y)/2.0-cy,
        (pipe->Nodes->Items[i]->Z+pipe->Nodes->Items[i+1]->Z)/2.0-cz
       );
    

    Note : It should subtract (cx,cy,xz) for each elem

    Move pipe back, because pipe's parent has moved (cx,cy,cz)

    pipe->Position->SetPoint(-cx,-cy,-cz);
    

    But I don't think it's good answer.

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.