Android Open Source - gameengine Joint






From Project

Back to project page gameengine.

License

The source code is released under:

Apache License

If you think the Android project gameengine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright 2011 See AUTHORS file.//from   w w w .  ja  va  2 s  .c  o m
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.physics.box2d;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.JointDef.JointType;

public abstract class Joint {
    /*
     * JNI #include <Box2D/Box2D.h>
     */
    /** the address of the joint **/
    protected long addr;

    /** world **/
    private final World world;

    /** temporary float array **/
    private final float[] tmp = new float[2];

    /** joint edge a **/
    protected JointEdge jointEdgeA;

    /** joint edge b **/
    protected JointEdge jointEdgeB;

    /**
     * Constructs a new joint
     * 
     * @param addr
     *            the address of the joint
     */
    protected Joint(World world, long addr) {
        this.world = world;
        this.addr = addr;
    }

    /** Get the type of the concrete joint. */
    public JointType getType() {
        int type = jniGetType(addr);
        if (type > 0 && type < JointType.valueTypes.length)
            return JointType.valueTypes[type];
        else
            return JointType.Unknown;
    }

    private native int jniGetType(long addr); /*
                                               * b2Joint* joint =
                                               * (b2Joint*)addr; return
                                               * joint->GetType();
                                               */

    /** Get the first body attached to this joint. */
    public Body getBodyA() {
        return world.bodies.get(jniGetBodyA(addr));
    }

    private native long jniGetBodyA(long addr); /*
                                                 * b2Joint* joint =
                                                 * (b2Joint*)addr; return
                                                 * (jlong)joint->GetBodyA();
                                                 */

    /** Get the second body attached to this joint. */
    public Body getBodyB() {
        return world.bodies.get(jniGetBodyB(addr));
    }

    private native long jniGetBodyB(long addr); /*
                                                 * b2Joint* joint =
                                                 * (b2Joint*)addr; return
                                                 * (jlong)joint->GetBodyB();
                                                 */

    /** Get the anchor point on bodyA in world coordinates. */
    private final Vector2 anchorA = new Vector2();

    public Vector2 getAnchorA() {
        jniGetAnchorA(addr, tmp);
        anchorA.x = tmp[0];
        anchorA.y = tmp[1];
        return anchorA;
    }

    private native void jniGetAnchorA(long addr, float[] anchorA); /*
                                                                    * b2Joint*
                                                                    * joint =
                                                                    * (b2Joint
                                                                    * *)addr;
                                                                    * b2Vec2 a =
                                                                    * joint
                                                                    * ->GetAnchorA
                                                                    * ();
                                                                    * anchorA[0]
                                                                    * = a.x;
                                                                    * anchorA[1]
                                                                    * = a.y;
                                                                    */

    /** Get the anchor point on bodyB in world coordinates. */
    private final Vector2 anchorB = new Vector2();

    public Vector2 getAnchorB() {
        jniGetAnchorB(addr, tmp);
        anchorB.x = tmp[0];
        anchorB.y = tmp[1];
        return anchorB;
    }

    private native void jniGetAnchorB(long addr, float[] anchorB); /*
                                                                    * b2Joint*
                                                                    * joint =
                                                                    * (b2Joint
                                                                    * *)addr;
                                                                    * b2Vec2 a =
                                                                    * joint
                                                                    * ->GetAnchorB
                                                                    * ();
                                                                    * anchorB[0]
                                                                    * = a.x;
                                                                    * anchorB[1]
                                                                    * = a.y;
                                                                    */

    /** Get the reaction force on body2 at the joint anchor in Newtons. */
    private final Vector2 reactionForce = new Vector2();

    public Vector2 getReactionForce(float inv_dt) {
        jniGetReactionForce(addr, inv_dt, tmp);
        reactionForce.x = tmp[0];
        reactionForce.y = tmp[1];
        return reactionForce;
    }

    private native void jniGetReactionForce(long addr, float inv_dt, float[] reactionForce); /*
                                                                                              * b2Joint
                                                                                              * *
                                                                                              * joint
                                                                                              * =
                                                                                              * (
                                                                                              * b2Joint
                                                                                              * *
                                                                                              * )
                                                                                              * addr
                                                                                              * ;
                                                                                              * b2Vec2
                                                                                              * f
                                                                                              * =
                                                                                              * joint
                                                                                              * -
                                                                                              * >
                                                                                              * GetReactionForce
                                                                                              * (
                                                                                              * inv_dt
                                                                                              * )
                                                                                              * ;
                                                                                              * reactionForce
                                                                                              * [
                                                                                              * 0
                                                                                              * ]
                                                                                              * =
                                                                                              * f
                                                                                              * .
                                                                                              * x
                                                                                              * ;
                                                                                              * reactionForce
                                                                                              * [
                                                                                              * 1
                                                                                              * ]
                                                                                              * =
                                                                                              * f
                                                                                              * .
                                                                                              * y
                                                                                              * ;
                                                                                              */

    /** Get the reaction torque on body2 in N*m. */
    public float getReactionTorque(float inv_dt) {
        return jniGetReactionTorque(addr, inv_dt);
    }

    private native float jniGetReactionTorque(long addr, float inv_dt); /*
                                                                         * b2Joint*
                                                                         * joint
                                                                         * =
                                                                         * (b2Joint
                                                                         * *
                                                                         * )addr
                                                                         * ;
                                                                         * return
                                                                         * joint
                                                                         * ->
                                                                         * GetReactionTorque
                                                                         * (
                                                                         * inv_dt
                                                                         * );
                                                                         */

    // /// Get the next joint the world joint list.
    // b2Joint* GetNext();
    //
    // /// Get the user data pointer.
    // void* GetUserData() const;
    //
    // /// Set the user data pointer.
    // void SetUserData(void* data);

    /** Short-cut function to determine if either body is inactive. */
    public boolean isActive() {
        return jniIsActive(addr);
    }

    private native boolean jniIsActive(long addr); /*
                                                    * b2Joint* joint =
                                                    * (b2Joint*)addr; return
                                                    * joint->IsActive();
                                                    */
}




Java Source Code List

com.badlogic.gdx.math.MathUtils.java
com.badlogic.gdx.math.Matrix3.java
com.badlogic.gdx.math.Matrix4.java
com.badlogic.gdx.math.Quaternion.java
com.badlogic.gdx.math.Vector2.java
com.badlogic.gdx.math.Vector3.java
com.badlogic.gdx.physics.box2d.BodyDef.java
com.badlogic.gdx.physics.box2d.Body.java
com.badlogic.gdx.physics.box2d.ChainShape.java
com.badlogic.gdx.physics.box2d.CircleShape.java
com.badlogic.gdx.physics.box2d.ContactFilter.java
com.badlogic.gdx.physics.box2d.ContactImpulse.java
com.badlogic.gdx.physics.box2d.ContactListener.java
com.badlogic.gdx.physics.box2d.Contact.java
com.badlogic.gdx.physics.box2d.DestructionListener.java
com.badlogic.gdx.physics.box2d.EdgeShape.java
com.badlogic.gdx.physics.box2d.Filter.java
com.badlogic.gdx.physics.box2d.FixtureDef.java
com.badlogic.gdx.physics.box2d.Fixture.java
com.badlogic.gdx.physics.box2d.JointDef.java
com.badlogic.gdx.physics.box2d.JointEdge.java
com.badlogic.gdx.physics.box2d.Joint.java
com.badlogic.gdx.physics.box2d.Manifold.java
com.badlogic.gdx.physics.box2d.MassData.java
com.badlogic.gdx.physics.box2d.PolygonShape.java
com.badlogic.gdx.physics.box2d.QueryCallback.java
com.badlogic.gdx.physics.box2d.RayCastCallback.java
com.badlogic.gdx.physics.box2d.Shape.java
com.badlogic.gdx.physics.box2d.Transform.java
com.badlogic.gdx.physics.box2d.WorldManifold.java
com.badlogic.gdx.physics.box2d.World.java
com.badlogic.gdx.physics.box2d.joints.DistanceJointDef.java
com.badlogic.gdx.physics.box2d.joints.DistanceJoint.java
com.badlogic.gdx.physics.box2d.joints.FrictionJointDef.java
com.badlogic.gdx.physics.box2d.joints.FrictionJoint.java
com.badlogic.gdx.physics.box2d.joints.GearJointDef.java
com.badlogic.gdx.physics.box2d.joints.GearJoint.java
com.badlogic.gdx.physics.box2d.joints.MouseJointDef.java
com.badlogic.gdx.physics.box2d.joints.MouseJoint.java
com.badlogic.gdx.physics.box2d.joints.PrismaticJointDef.java
com.badlogic.gdx.physics.box2d.joints.PrismaticJoint.java
com.badlogic.gdx.physics.box2d.joints.PulleyJointDef.java
com.badlogic.gdx.physics.box2d.joints.PulleyJoint.java
com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef.java
com.badlogic.gdx.physics.box2d.joints.RevoluteJoint.java
com.badlogic.gdx.physics.box2d.joints.RopeJointDef.java
com.badlogic.gdx.physics.box2d.joints.RopeJoint.java
com.badlogic.gdx.physics.box2d.joints.WeldJointDef.java
com.badlogic.gdx.physics.box2d.joints.WeldJoint.java
com.badlogic.gdx.physics.box2d.joints.WheelJointDef.java
com.badlogic.gdx.physics.box2d.joints.WheelJoint.java
com.badlogic.gdx.utils.Array.java
com.badlogic.gdx.utils.ComparableTimSort.java
com.badlogic.gdx.utils.Disposable.java
com.badlogic.gdx.utils.GdxRuntimeException.java
com.badlogic.gdx.utils.LongArray.java
com.badlogic.gdx.utils.LongMap.java
com.badlogic.gdx.utils.NumberUtils.java
com.badlogic.gdx.utils.Pool.java
com.badlogic.gdx.utils.Sort.java
com.badlogic.gdx.utils.StringBuilder.java
com.badlogic.gdx.utils.TimSort.java
com.garrapeta.MathUtils.java
com.garrapeta.gameengine.Actor.java
com.garrapeta.gameengine.AsyncGameMessage.java
com.garrapeta.gameengine.BitmapManager.java
com.garrapeta.gameengine.Box2DActor.java
com.garrapeta.gameengine.Box2DWorld.java
com.garrapeta.gameengine.GameMessage.java
com.garrapeta.gameengine.GameView.java
com.garrapeta.gameengine.GameWorld.java
com.garrapeta.gameengine.ShapeDrawer.java
com.garrapeta.gameengine.SyncGameMessage.java
com.garrapeta.gameengine.Viewport.java
com.garrapeta.gameengine.actor.Box2DAtomicActor.java
com.garrapeta.gameengine.actor.Box2DCircleActor.java
com.garrapeta.gameengine.actor.Box2DEdgeActor.java
com.garrapeta.gameengine.actor.Box2DLoopActor.java
com.garrapeta.gameengine.actor.Box2DOpenChainActor.java
com.garrapeta.gameengine.actor.Box2DPolygonActor.java
com.garrapeta.gameengine.actor.IAtomicActor.java
com.garrapeta.gameengine.actor.SimpleActor.java
com.garrapeta.gameengine.module.LevelActionsModule.java
com.garrapeta.gameengine.module.LoadedLevelActionsModule.java
com.garrapeta.gameengine.module.SoundModule.java
com.garrapeta.gameengine.module.VibrationModule.java
com.garrapeta.gameengine.utils.IOUtils.java
com.garrapeta.gameengine.utils.LogX.java
com.garrapeta.gameengine.utils.PhysicsUtils.java
com.garrapeta.gameengine.utils.Pool.java