我想使用我的Vector3f类开始在Java中进行碰撞检测计算
但是, centerDistance 的分配声明(请参阅下面的代码)会显示错误:The operator - is undefined for the argument type (Vector3f)
。
我想在我的技能水平上,我无法弄清楚问题是什么。有没有人可能有线索?
public class BoundingSphere {
private Vector3f m_center;
private float m_radius;
public BoundingSphere(Vector3f center, float radius) {
this.m_center = center;
this.m_radius = radius;
}
public IntersectData IntersectBoundingSphere(BoundingSphere other) {
float radiusDistance = m_radius + other.m_radius;
float centerDistance = (other.getM_center() - m_center).length();
float distance = centerDistance - radiusDistance;
return IntersectData(centerDistance < radiusDistance, distance);
}
public Vector3f getM_center() {
return m_center;
}
public void setM_center(Vector3f m_center) {
this.m_center = m_center;
}
public float getM_radius() {
return m_radius;
}
public void setM_radius(float m_radius) {
this.m_radius = m_radius;
}
}
答案 0 :(得分:1)
对象不支持Java中的算术运算符。你必须制作一个加,减等方法
示例:
public Vector3f add(Vector3f operand) {
//...
return this;
}
public Vector3f sub(Vector3f operand) {
//...
return this;
}
然后你拨打other.getM_center().sub(m_center).length()