Author Topic: Physics example  (Read 16116 times)

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #30 on: May 22, 2021, 02:38:41 pm »
Thanks Egon.
In general, my next project is very non-trivial. :) :) :)

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #31 on: May 27, 2021, 12:15:14 am »
GenerateVertexController does not work in real time, makes a change in the object from the value (0) of the variable to "private" once and does not work anymore. I looked through the whole forum and I probably did it right. I also use jbullet in the project. Could it beis it that GenerateVertexController is not compatible with Jbullet in the same project?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12244
    • View Profile
    • http://www.jpct.net
Re: Physics example
« Reply #32 on: May 27, 2021, 08:48:11 am »
...makes a change in the object from the value (0) of the variable to "private" once and does not work anymore.
I don't understand what you mean by that!? Are you calling applyVertexController() on the mesh that it has been assigned to? Also, you have to make sure that the object gets recognized as "dynamic", which usually happens automatically, but it might fail if you assign the controller after the first use of the object. In that case, try to explicitly call Object3D.compile(true) on the Object3D in question and see if that helps.

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #33 on: May 27, 2021, 12:52:05 pm »
I can dynamically create the object I want using getPolygonManager. But it seems to me that it will be too slow, since it will be necessary to add an object to the scene and draw a texture on it every time.

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #34 on: May 27, 2021, 02:33:56 pm »
      Everything started to work.
Added to onDrawFrame -     

            cyl7.compile(true);
            cyl7.touch();
            objSkinCyl7.compile(true);
            objSkinCyl7.touch();
            cyl7.getMesh().applyVertexController();
            objSkinCyl7.getMesh().applyVertexController();

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #35 on: May 27, 2021, 05:20:48 pm »
How get global(world) coordinate of vertex from mesh?In GenerateVertexController

Offline AeroShark333

  • float
  • ****
  • Posts: 285
    • View Profile
Re: Physics example
« Reply #36 on: May 27, 2021, 09:41:18 pm »
How get global(world) coordinate of vertex from mesh?In GenerateVertexController
I guess you'd need to pass your Object3D instance to your custom implementation of GenericVertexController.
Then using Object3D.getTransfornedCenter() to find the mesh's center in world coordinates. And using the rotations applied to the Object3D and GenericVertexController.getSourceMesh() to find the individual world coordinates.
...

However, maybe multiplying the sourceMesh with object3d.getWorldTransformation() could work too... Seems to go from object space to world space..?

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #37 on: May 28, 2021, 06:24:11 pm »
 //Dont copy object. -

VVV = new GenericVertexController() {
            @Override
            public void apply() {         
                SimpleVector[] aaa = getSourceMesh();
                SimpleVector[] bbb = getDestinationMesh();           
                                int lll=aaa.length;
                                for (int f=0;f<lll;f++)
                                {
                                    //bbb[f].matMul(objSkinCyl7.getWorldTransformation());
                                    bbb[f].x = X77[f];
                                    bbb[f].y = Y77[f];
                                    bbb[f].z = Z77[f];
                                }
            }
        };
        VVV2 = new GenericVertexController() {
            @Override
            public void apply() {
                SimpleVector[] aaa = getSourceMesh();       
                int lll=aaa.length;
                SimpleVector[] hhh = new SimpleVector[lll];             
                X77 = new float[lll];
                Y77 = new float[lll];
                Z77 = new float[lll];
                for (int f=0;f<lll;f++)
                {                 
                    aaa[f].matMul(cyl7.getWorldTransformation());                           
                    X77[f] = aaa[f].x;
                    Y77[f] = aaa[f].y;
                    Z77[f] = aaa[f].z;
                }
            }
        };
cyl7.setVisibility(false);

///////////
///////////
///////////
//Copy object,but wrong rotate. Infinite rotation -


VVV = new GenericVertexController() {
            @Override
            public void apply() {             
                SimpleVector[] aaa = getSourceMesh();
                SimpleVector[] bbb = getDestinationMesh();

                                int lll=aaa.length;
                                for (int f=0;f<lll;f++)
                                {
                                    //bbb[f].matMul(objSkinCyl7.getWorldTransformation());
                                    bbb[f].x = X77[f];
                                    bbb[f].y = Y77[f];
                                    bbb[f].z = Z77[f];
                                }
            }
        };
        VVV2 = new GenericVertexController() {
            @Override
            public void apply() {               
                SimpleVector[] aaa = getSourceMesh();             
                int lll=aaa.length;
                SimpleVector[] hhh = new SimpleVector[lll];               
                X77 = new float[lll];
                Y77 = new float[lll];
                Z77 = new float[lll];
                for (int f=0;f<lll;f++)
                {                   
                    aaa[f].matMul(cyl7.getRotationMatrix());                 
                    X77[f] = aaa[f].x + cyl7.getTranslation().x;
                    Y77[f] = aaa[f].y + cyl7.getTranslation().y;
                    Z77[f] = aaa[f].z + cyl7.getTranslation().z;
                }
            }
        };

cyl7.setVisibility(false);

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #38 on: May 29, 2021, 11:25:08 am »
Why when I call the multiplication of each vector of the point of the object by the matrix(getRotationMatrix), the incorrect rotation of the object (infinite rotation) starts? ..

Offline AeroShark333

  • float
  • ****
  • Posts: 285
    • View Profile
Re: Physics example
« Reply #39 on: May 29, 2021, 12:20:59 pm »
I thought you only wanted to look up the coordinates of each vertex in world space rather than object space... I don't think the destination mesh should be given in world space coordinates, however...

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #40 on: May 29, 2021, 12:55:13 pm »
Yes,every vertex in world space.
My target mesh will consist of interconnected meshes of several objects, so to speak, it's easy to visualize the fragmented parts - skin tight muscles. Therefore, I need to get the global coordinates of the vertices of the objects as they look in the world inplace with rotation angles, and the target mesh will have to give a copy of the selected objects, and in places where I need this target mesh, I will link with new polygons .

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #41 on: May 29, 2021, 01:40:59 pm »
SimpleVector[] aaa = getSourceMesh();
aaa[f].matMul(cyl7.getWorldTransformation()); - return wrong world coordinate

Offline AeroShark333

  • float
  • ****
  • Posts: 285
    • View Profile
Re: Physics example
« Reply #42 on: May 29, 2021, 02:07:10 pm »
Maybe this would work:

aaa[f].matMul(cyl7.getRotationMatrix());
Then:
aaa[f].matMul(cyl7.getTranslationMatrix());

I'm not sure if this will work... I can't test this out right now, but it would somewhat make sense I hoped... 😅 Otherwise, maybe Egon has better ideas

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #43 on: May 29, 2021, 02:22:14 pm »
Not work

 aaa[f].matMul(cyl1.getTranslationMatrix()); or aaa[f].matMul(cyl1.getWorldTransformation()); - returns coordinates of order 6234 or 2323 in world space when the original(Source object cyl7) coordinates are - 6 ... 7 in world space
« Last Edit: May 29, 2021, 03:22:36 pm by aleks1283 »

Offline aleks1283

  • byte
  • *
  • Posts: 35
    • View Profile
Re: Physics example
« Reply #44 on: May 29, 2021, 02:27:57 pm »
When i do - aaa[f].matMul(cyl7.getRotationMatrix());   // or  aaa[f].rotate(cyl7.getRotationMatrix());         
                    X77[f] = aaa[f].x + cyl7.getTranslation().x;
                    Y77[f] = aaa[f].y + cyl7.getTranslation().y;
                    Z77[f] = aaa[f].z + cyl7.getTranslation().z; all good(coordinates,and the shape of the object) but object wrong(infinite) rotation,instead of the original turn
« Last Edit: May 29, 2021, 03:05:06 pm by aleks1283 »