Java – how to find two objects from BEETWEN in libgdx

In my libgdx game, I have waycoins (modelinstances) and I need to know the distance from them. I try to use transform.gettranslation (New vector3), but it returns the translation of the model. I haven't found a method to get the global location of the model

resolvent:

To get the distance between two vectors, use the DST method:

public float dst(Vector3 vector)
Specified by:
dst in interface Vector<Vector3>
Parameters:
vector - The other vector
Returns:
the distance between this and the other vector

Vector3 reference

The best way to track the model is to create a wrapper that stores the object position (vector3) and rotation (quaternion), and set the model position on the rendering method in the wrapper, as follows:

public abstract class ModelWrapper{

    private ModelInstance model;
    private Vector3 position;
    private Quaternion rotation;

    public ModelWrapper(ModelInstance model,Vector3 position,Quaternion rotation) {
        this.model = model;
        this.position = position;
        this.rotation = rotation;
    }

    public ModelInstance getModel() {
        return model;
    }

    public void setModel(ModelInstance model) {
        this.model = model;
    }

    public Vector3 getPosition() {
        return position;
    }

    public void setPosition(Vector3 position) {
        this.position = position;
    }

    public Quaternion getRotation() {
        return rotation;
    }

    public void setRotation(Quaternion rotation) {
        this.rotation = rotation;
    }

    public void render(ModelBatch modelBatch, Environment  environment) {
        this.model.transform.set(this.position,this.rotation);
        modelBatch.render(model, environment);
    }
}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>