Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - sentsent

#1
Support / Re: Rotate problem
August 05, 2016, 12:49:43 PM
Thank You for advice.

Now I understand " thread safe" rules. I have something wrong in code. I have moved "thread code" to onDrawFrame in GLSurfaceView.Renderer and unfortunatelly effect is the same.

Anyway I changed my mind and I dont' want to create and rotate dummy object, because i figured out that I can't add rigidbody as a child to dummy object.
So I'll try my rigidbody go forward with setLinearVelocity, and somehow turn left each 100ms (for example). But applyTorqueImpulse does not change rigidbody move direction.

#2
Support / Rotate problem
August 04, 2016, 03:58:20 PM
try {

            playerDummyObj = Object3D.createDummyObj();

            AssetManager.AssetInputStream fis = (AssetManager.AssetInputStream) MainActivity.MA.getResources().openRawResource(
                    R.raw.terra);
            playerObj3d = Loader.loadASC(fis, SCALE*0.20F, true);
            playerObj3d.setTexture("cliff");

            AssetManager.AssetInputStream fisShield = (AssetManager.AssetInputStream) MainActivity.MA.getResources().openRawResource(
                    R.raw.terra);
            shieldBall = Loader.loadASC(fisShield, SCALE*0.20F, true);
            shieldBall.setTexture("cliff");


        } catch (Exception e) {
            e.printStackTrace();
        }

        MainActivity.WORLD.addObject(playerObj3d);
        MainActivity.WORLD.addObject(shieldBall);

        Transform shapeTransform = new Transform();
        shapeTransform.setIdentity();
        shapeTransform.origin.set(new Vector3f(0F, 0.5F, 0F));

        Transform shieldBallTransform = new Transform();
        shieldBallTransform.setIdentity();
        shieldBallTransform.origin.set(new Vector3f(0.5F, 0.5F, 0F));

        SphereShape shape = new SphereShape(1F);
        shape.setLocalScaling(new Vector3f(SCALE,SCALE,SCALE));

        SphereShape shieldBallShape = new SphereShape(1F);
        shieldBallShape.setLocalScaling(new Vector3f(SCALE,SCALE,SCALE));

        Vector3f localInertia = new Vector3f(0, 0, 0);
        Vector3f shieldLocalInertia = new Vector3f(0, 0, 0);

        shape.calculateLocalInertia(mass, localInertia);
        shieldBallShape.calculateLocalInertia(mass, shieldLocalInertia);

        JPCTBulletMotionState ms = new JPCTBulletMotionState(playerObj3d, shapeTransform);
        RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, ms, shape, localInertia);
        body = new RigidBody(rbInfo);
        Jbullet.dynamicWorld.addRigidBody(body);

        JPCTBulletMotionState msShield = new JPCTBulletMotionState(shieldBall, shieldBallTransform);
        RigidBodyConstructionInfo rbInfoShield = new RigidBodyConstructionInfo(mass, msShield, shieldBallShape, shieldLocalInertia);
        RigidBody shieldBody = new RigidBody(rbInfoShield);
        Jbullet.dynamicWorld.addRigidBody(shieldBody);

        playerDummyObj.translate(0F, 2F, 0F);
        shieldBall.addParent(playerDummyObj);

        new Thread(new Runnable() {
            @Override
            public void run() {

                while (true) {

//                   playerDummyObj.clearTranslation();
                    playerDummyObj.rotateAxis(playerDummyObj.getRotationMatrix().getYAxis(),-0.02f);

                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();


Hello, I have such a code and my problem is to get  shieldBall run around the invisible playerDummyObj with Y axis.

What I observe is:  nothing happens in a few seconds, then rapidly shieldBall rotates around itself and goes away in three directions at the same time very fast (it's like a photon :D )

Any idea how to make my shieldBall slowly run around playerDummyObj  like an earth around the sun?