Physics example

Started by Thomas., March 10, 2012, 10:29:28 PM

Previous topic - Next topic

aleks1283

Thanks Egon.
In general, my next project is very non-trivial. :) :) :)

aleks1283

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?

EgonOlsen

Quote from: aleks1283 on May 27, 2021, 12:15:14 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.

aleks1283

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.

aleks1283

      Everything started to work.
Added to onDrawFrame -     

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

aleks1283

How get global(world) coordinate of vertex from mesh?In GenerateVertexController

AeroShark333

Quote from: aleks1283 on May 27, 2021, 05:20:48 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..?

aleks1283

 //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);

aleks1283

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? ..

AeroShark333

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...

aleks1283

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 .

aleks1283

SimpleVector[] aaa = getSourceMesh();
aaa[f].matMul(cyl7.getWorldTransformation()); - return wrong world coordinate

AeroShark333

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

aleks1283

#43
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

aleks1283

#44
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