在我的libGdx游戏中,我有waypoins(Modelinstance),我需要知道距离它们的距离.
我尝试使用transform.getTranslation(new Vector3),但它返回了模型的翻译.我尚未找到获取模型全局位置的方法.
解决方法:
要获取两个向量之间的距离,请使用dst方法:
public float dst(Vector3 vector)SpecifIEd by:dst in interface Vector<Vector3>Parameters:vector - The other vectorReturns:the distance between this and the other vector
Vector3 reference
跟踪模型的最佳方法是创建一个包装器,该包装器存储对象位置(Vector3)和旋转(Quaternion),并在该包装器中设置渲染方法上的模型位置,如下所示:
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); }}
总结 以上是内存溢出为你收集整理的java-如何在libgdx中查找距离beetwen两个对象全部内容,希望文章能够帮你解决java-如何在libgdx中查找距离beetwen两个对象所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)