use of com.jme3.collision.CollisionResults in project TeachingInSimulation by ScOrPiOzzy.
the class VS10N051CControl method controlUpdate.
@Override
protected void controlUpdate(float tpf) {
// 监听碰撞
CollisionResults results = new CollisionResults();
rootNode.collideWith(ray, results);
temp = false;
for (CollisionResult result : results) {
if (result.getDistance() > limit) {
continue;
}
Geometry geometry = result.getGeometry();
if (((Node) spatial).hasChild(geometry)) {
continue;
}
temp = true;
}
if (collised != temp) {
collised = temp;
if (collised) {
rotateControl.rotate(JmeConst.NEGATIVE, FastMath.DEG_TO_RAD * 10);
// collision.rotate(0, FastMath.DEG_TO_RAD * -10, 0);
button.doSwitch(1);
// 被碰撞按下之后禁止鼠标监听
MouseEventState.setToMouseVisible(collision, false);
} else {
rotateControl.rotate(JmeConst.POSITIVE, FastMath.DEG_TO_RAD * 10);
// collision.rotate(0, FastMath.DEG_TO_RAD * 10, 0);
button.doSwitch(0);
// 离开碰撞松开之后启用鼠标监听
MouseEventState.setToMouseVisible(collision, true);
}
}
}
use of com.jme3.collision.CollisionResults in project TeachingInSimulation by ScOrPiOzzy.
the class SwingControlEx method controlUpdate.
@Override
protected void controlUpdate(float tpf) {
Vector3f origin = start1.getWorldTranslation();
Vector3f goal = end1.getWorldTranslation();
float limit = FastMath.abs(goal.distance(origin));
Ray ray = new Ray(origin, goal.add(origin.negate()));
CollisionResults results = new CollisionResults();
rootNode.collideWith(ray, results);
for (CollisionResult result : results) {
if (result.getDistance() > limit) {
continue;
}
Geometry geometry = result.getGeometry();
if ("material".equals(geometry.getUserData("type"))) {
Spatial material = geometry.getParent().getParent();
if (Util.notEmpty(material.getUserData("owner"))) {
break;
}
if (material.getNumControls() != 0) {
material.setLocalTranslation(Vector3f.ZERO);
control1 = (ItemControl) material.getControl(0);
control1.setEnabled(false);
pieceLoc1.attachChild(material);
stateManager.getState(MouseEventState.class).setVipModel(material);
}
}
}
origin = start2.getWorldTranslation();
goal = end2.getWorldTranslation();
limit = FastMath.abs(goal.distance(origin));
Ray ray2 = new Ray(origin, goal.add(origin.negate()));
CollisionResults results2 = new CollisionResults();
rootNode.collideWith(ray2, results2);
for (CollisionResult result : results2) {
if (result.getDistance() > limit) {
continue;
}
Geometry geometry = result.getGeometry();
if ("material".equals(geometry.getUserData("type"))) {
Spatial material = geometry.getParent().getParent();
if (Util.notEmpty(material.getUserData("owner"))) {
break;
}
if (material.getNumControls() != 0) {
material.setLocalTranslation(Vector3f.ZERO);
control2 = (ItemControl) material.getControl(0);
control2.setEnabled(false);
pieceLoc2.attachChild(material);
stateManager.getState(MouseEventState.class).setVipModel(material);
}
}
}
if (!swing) {
return;
}
float rad = tpf * speed;
Vector3f per = dir.mult(rad);
if (b) {
total += rad;
for (final Spatial spatial : driveds) {
spatial.rotate(per.x, per.y, per.z);
}
if (total >= degree) {
for (final Spatial spatial : driveds) {
spatial.rotate(0, degree - total, 0);
}
total = degree;
swing = false;
// 此处用于通知检测被当前托盘中工件阻塞的工件开始移动,并不真正设置模型
if (control1 != null) {
control1.onMoving();
}
if (control2 != null) {
control2.onMoving();
}
}
} else {
total -= rad;
for (final Spatial spatial : driveds) {
spatial.rotate(-per.x, -per.y, -per.z);
}
if (total <= 0) {
for (final Spatial spatial : driveds) {
spatial.rotate(0, -total, 0);
}
total = 0;
swing = false;
// 此处用于通知检测被当前托盘中工件阻塞的工件开始移动,并不真正设置模型
if (control1 != null) {
control1.onMoving();
}
if (control2 != null) {
control2.onMoving();
}
}
}
}
Aggregations